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
Name | Type | Description |
---|---|---|
merchant_key | MerchantKey | The key of the merchant. |
order_key | OrderKey | The 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 :
Field | Type | M | Description |
---|---|---|---|
transactionId | String(1, 255) | M | The id of the payment. |
status | Enum(32) | M | The authorization status of the payment. |
urls | Block | C | Required for state AUTHENTICATION_REQUIRED. |
url | Block | M | The redirect details for the shopper. |
+ purpose | String(1, 64) | M | The purpose of this URL. |
+ method | String(1, 16) | M | The HTTP method to be used, either "GET" or "POST". |
+ url | Url | M | The url the shopper must be redirected to. |
+ order | Number(1, 10) | M | Order in which urls should be displayed or handled. |
+ parameters | Map | O | Map with parameter name/values pairs for the body of the redirect request. The keys and values are of type String(1,255). |
reason | String(1, 255) | O | The reason of authorization status. |
For the field status
the following values are possible:
Status | Description |
---|---|
AUTHENTICATION_REQUIRED | The authentication is required to complete the payment. |
SUCCESS | The Payment is success. |
FAILED | The payment is failed due to an error. |
UNKNOWN | Unknown error during authentication. |
HTTP Status
Status | Meaning |
---|---|
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);
}