Get a session

A session can be fetched server side using the user’s rewardsAccessToken, customerId and deviceId.
POST /payment-service-definitions/wpay-everydaypay/sessions

{
    "request": {
        "data": {
            "rewardsAccessToken": "2sSVapXfQixwW30huM6JggmcxWlw",
            "customerId": "21b93354043ccda7b45c5778f9738bde2e97496c3ab5d7586bdee25450f9bd2b",
            "deviceId": "4e95fcad-e81c-4018-85c1-e2d2c46ee6de"
        },
        "meta": {}
    }
}
This will return the session for the user
{
    "type": "payment-service-session",
    "response": {
        "data": {
            "customerType": "NEW",
            "walletManagementUrl": "<<URL>>?apiKey=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9&authRef=9dab34c7-ca0b-43d9-b3fb-60fc30124b3b"
        },
        "meta": {}
    }
}

Create a transaction

Next, a transaction can be created using the same identifiers.
POST /transactions

{
    "amount": 1299,
    "currency": "AUD",
    "country": "AU",
    "intent": "capture",
    "buyer_external_identifier": "user-edp",
    "shipping_details_id": "01da1af5-66fa-4439-a520-e166fecebc43",
    "payment_method": {
        "method": "wpay-everydaypay",
        "country": "AU",
        "currency": "AUD",
        "redirect_url": "https://example.com"
    },
     "connection_options": {
        "wpay-everydaypay": {
            "rewardsAccessToken": "2sSVapXfQixwW30huM6JggmcxWlw",
            "customerId": "21b93354043ccda7b45c5778f9738bde2e97496c3ab5d7586bdee25450f9bd2b",
            "deviceId": "4e95fcad-e81c-4018-85c1-e2d2c46ee6de"
        }
    }
}
Please note that the intent needs to be capture and that a buyer needs to be present with both a billing address and a shipping address.For the addresses, the line1, city, country, postal_code and state fields need to be set.
This will return a response with an approval URL.
{
    "type": "transaction",
    "id": "dfa9e5b0-7b50-42dc-8420-95d34dd59d24",
    "method": "givingblock",
    "merchant_account_id": "default",
    "status": "buyer_approval_pending",
    "amount": 1299,
    "currency": "AUD",
    "country": "AU",
    "intent": "capture",
    "payment_method": {
        "type": "payment-method",
        "method": "wpay-everydaypay",
        "mode": "redirect",
        "approval_url": "https://tgb-preprod.com/?charityID=1189132672&version=2&donationDataId=54e15be4-2576-421d-a938-bf93e5a57743&apiUserUuid=a658a418-d116-4e72-9014-f2f37a3976ab",
        ...
    },
    ...
}
The user can then be redirected to this URL to complete the payment. After completion, the status of the transaction will be either capture_succeeded or authorization_failed/authorization_declined.

Embed integration

Everyday Pay can be added to Embed using the same connection options.
const { setup } = require(`@gr4vy/embed`)

setup({
  gr4vyId: 'wpay-test',
  environment: 'sandbox',
  token: '[TOKEN]',
  amount: 1299,
  currency: 'AUD',
  country: 'AU',
  element: '.container',
  form: '#cardform',
  buyerExternalIdentifier: "user-edp",
  shippingDetailsId: "01da1af5-66fa-4439-a520-e166fecebc43",
  connectionOptions: {
    "wpay-everydaypay": {
        "rewardsAccessToken": "2sSVapXfQixwW30huM6JggmcxWlw",
        "customerId": "21b93354043ccda7b45c5778f9738bde2e97496c3ab5d7586bdee25450f9bd2b",
        "deviceId": "4e95fcad-e81c-4018-85c1-e2d2c46ee6de"
    }
  }
})
Please note that Embed is not able to collect all the required billing and shipping address fields. We recommend creating a buyer with the required fields before loading Embed.For the addresses, the line1, city, country, postal_code and state fields need to be set.