Authorize a payment via Google Pay.

Note:

  • These API requests/interactions are not needed when using the provided menu by CM.com.
  • Authentication is not required for these API resources.

For more details see Google Pay.

Authorize Google Pay Payment

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

POST /mobile/googlepay/merchants/{merchant_key}/payments/{order_key}/authorize

Identifiers

NameTypeDescription
merchant_keyMerchantKeyThe key of the merchant.
order_keyOrderKeyThe key of the order.

Parameters

Not applicable.

Request

The paymentData.paymentMethodData received from the Google Payments client must be sent as-is to the Payment System.
Modifications are not allowed.

Response

The response has the following fields :

FieldTypeMDescription
transactionIdString(1, 255)MThe id of the payment.
statusEnum(32)MThe authorization status of the payment.
urlsBlockCRequired for state AUTHENTICATION_REQUIRED.
urlBlockMThe redirect details for the shopper.
+ purposeString(1, 64)MThe purpose of this URL.
+ methodString(1, 16)MThe HTTP method to be used, either "GET" or "POST".
+ urlUrlMThe url the shopper must be redirected to.
+ orderNumber(1, 10)MOrder in which urls should be displayed or handled.
+ parametersMapOMap with parameter name/values pairs for the body of the redirect request. The keys and values are of type String(1,255).
reasonString(1, 255)OThe reason of authorization status.

For the field status the following values are possible:

StatusDescription
AUTHENTICATION_REQUIREDThe authentication is required to complete the payment.
SUCCESSThe Payment is success.
FAILEDThe payment is failed due to an error.
UNKNOWNUnknown error during authentication.

HTTP Status

StatusMeaning
200 (OK)The payment is successfully authorized.
400 (Bad Request)The request was not valid.
500 (Internal Server Error)Something went wrong in processing the request.

Initialize Google Pay example

Command Line:

> curl \
    -X POST \
    --header 'Content-Type: application/json' \
    https://testsecure.docdatapayments.com/mobile/googlepay/merchants/4ef08825-993a-424d-a769-3ee97116a1b6/payments/3B88E0EF13E37D6A56AE949AD9E56961/authorize \
    -d '{
        "..." : "...",
    }'
 
< Http 200 OK 
<    '{
        "transactionId" : "1607025630",
        "status"    : "AUTHENTICATION_REQUIRED",
        "urls": [
          {
            "purpose": "REDIRECT",
            "method": "POST",
            "url": "https://testsecure.docdatapayments.com/ps_sim/3dsecureauthentication.jsf?data=NTU1NTU1NTU1NTU1NDQ0NA==",
            "order": 1,
            "parameters": {
                "MD": "1607025630",
                "PaReq": "eJxVUdtOg0AQ/RXCs3aXpfSWYRssGvuANto+GwKbFi1Lu4C2Pvo9fpVf4gyFVknYzDl7cmbnDEwP+dZ6V6bMCu3bTo/bltJJkWZ67dur5d31yJ5KWG6MUuGzSmqjJESqLOO1srLUtxfBk9oLLjgf4jHmo/7AltCwElpfibY9AayDaGCSTawrCXGyv5k/SI6fQEULIVdmHkqHTD08uTcGduJAx7mim7Kq38oXvQXWMJAUta7MUXpiBKwDUJvtWdwjMRHALg9Y1FSVaHDIUjmfBevzH96KKEw+oteViD4DHxgpII0rJbuBLT6c8NGkPwDW8BDn1Fn+fH1brnvlchzpxMCOGgUn4Lp085cBTNZg8Ec5HtL7OwTqsCu0QgWmc64hVWUiH02qjOUIt+9he2KAXcaZ3VO6SUU5ooSybQA5ZhiNcLnTWBIARnLWro21C8bq3+J/Adr/tHg=",
                "TermUrl": "https://testsecure.docdatapayments.com/ps/returnFromAuthorization?paymentReference=1607025630D52DC2B7C9433E3CB96D6801F1FC1B07"
            }
         }
      ]
}'

JavaScript (for details about the JavaScript functions see Google Pay):

    function authorizeGooglePayPayment(merchantKey, orderKey, serverUrl, environment, request) {
        const paymentsClient = getGooglePaymentsClient();
        paymentsClient.loadPaymentData(JSON.parse(request))
            .then(function(paymentData) {
                window.showGooglePaySpinner();
                // handle the response
                processPayment(merchantKey, orderKey, serverUrl, JSON.stringify(paymentData.paymentMethodData));
            })
            .catch(function(e) {
                console.error(e);
            });
    }

    function getGooglePaymentsClient(environment) {
        if (paymentsClient === null) {
            paymentsClient = new google.payments.api.PaymentsClient({environment: environment});
        }
        return paymentsClient;
    }

    function processPayment(merchantKey, orderKey, serverUrl, paymentMethodData) {
            var xhttp = new XMLHttpRequest();
        
            xhttp.onreadystatechange = function() {
                if (this.readyState === 4) {
                    console.debug("Got response from Payment Server, polling order status...");
                    window.pollOrderStatus();
                }
            };
        
            var authorizationUrl = serverUrl + "/mobile/googlepay/merchants/" + merchantKey + "/payments/" + orderKey + "/authorize";
        
            xhttp.open("POST", authorizationUrl, true);
            xhttp.setRequestHeader("Content-type", "application/json");
            xhttp.send(paymentMethodData);
    }