{

Apple Pay

Initialize and authorize Apple Pay payments.

Note:

  • These messages are not needed when using the menu.
  • No authentication is required.

For more details see Apple Pay.

Initialize an Apple Pay session

Initialize a new merchant session for a payment with Apple Pay. The session is only valid for 5 minutes and should be started when the shopper clicks on the Apple Pay button.

POST /applepay/merchants/{merchant_key}/payments/{order_key}/initialize

Identifiers

Name Description
merchant_key The key of the merchant.
order_key The key for the order.

Parameters

Not applicable.

Request

Field Type M Description
validationUrl String M The validation URL that is generated by the Apple device.
displayName String M The name to display on the the payment sheet.
domainName String M The domain of the website on which the payment will occur. The value must match the domain from which the request is started. If there is a mismatch between this field and the domain that the Apple device determined, then the Apple Pay session will be terminated by the Apple device (with a generic error message or nothing happens).

Response

The returned response is the opaque Apple Pay merchant session in string format. This string needs to be converted to a JavaScript object before it can be passed to the Apple device.

HTTP Status

Status Meaning
201 (Created) Apple Pay merchant session was created successfully.
400 (Bad Request) The request was not valid or no certificate for registration was found.

Initialize Apple Pay example Command line:

>  curl \
    -X POST \
    --header 'Content-Type: application/json' \
    https://testsecure.docdatapayments.com/applepay/merchants/4ef08825-993a-424d-a769-3ee97116a1b6/payments/94D261BBF80E4AC7212B127D3BD2E279/initialize \
    -d '{
        "validationUrl" : "https://...",
        "displayName"   : "My Shop",
        "domainName"    : "www.myshop.com"
    }'

< Http 201 Created
<    '{
          "..." : "...",
    }'

JavaScript:

function initializeSession(event) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState === 4) {
                if (this.status === 201) {
                    session.completeMerchantValidation(JSON.parse(this.responseText));
                } else {
                    session.abort();
                }
            }

        };

        xhttp.open("POST", "https://testsecure.docdatapayments.com/applepay/merchants/4ef08825-993a-424d-a769-3ee97116a1b6/payments/94D261BBF80E4AC7212B127D3BD2E279/initialize", true);
        xhttp.setRequestHeader("Content-type", "application/json");
        xhttp.send('{ "validationUrl":"' + event.validationURL + '"' +
                   ', "displayName": "' + merchantDisplayName + '"' +
                   ', "domainName": "' + window.location.hostname + '"}');
}

Authorize an Apple Pay payment

Performs the authorization via the Payment Service to complete the payment.

POST /applepay/merchants/{merchant_key}/payments/{order_key}/authorize

Identifiers

Name Description
merchant_key The key of the merchant.
order_key The key for the order.

Parameters

Not applicable.

Request

The request data is passed on as-is received from the Apple device in the on authorize payment event. No modifications are allowed.

Response

Not applicable.

HTTP Status

Status Meaning
201 (Created) The payment is successfully authorized.
400 (Bad Request) The request was not valid or no payment could not be authorized.

Initialize Apple Pay example

Command Line:

> curl \
    -X POST \
    --header 'Content-Type: application/json' \
    https://testsecure.docdatapayments.com/applepay/merchants/4ef08825-993a-424d-a769-3ee97116a1b6/payments/94D261BBF80E4AC7212B127D3BD2E279/authorize \
    -d '{
        "..." : "...",
    }'

< Http 201 Created

JavaScript:

function authorizePayment(event) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState === 4) {
                if (this.status === 201) {
                    session.completeMerchantValidation(JSON.parse(this.responseText));
                } else {
                    session.abort();
                }
            }

        };

        xhttp.open("POST", "https://testsecure.docdatapayments.com/applepay/merchants/4ef08825-993a-424d-a769-3ee97116a1b6/payments/94D261BBF80E4AC7212B127D3BD2E279/authorize", true);
        xhttp.setRequestHeader("Content-type", "application/json");
        xhttp.send('{ "validationUrl":"' + event.validationURL + '"' +
                   ', "displayName": "' + merchantDisplayName + '"' +
                   ', "domainName": "' + window.location.hostname + '"}');
}