Skip to main content

Overview​

This document describes how to integrate Google Pay with Oceanpayment via a server-to-server connection, including payment parameter submission, transaction processing, and result delivery.

For other Google Pay integration methods, see the Google Pay integration guide.

Flowchart​

Request​

1. Load the Oceanpayment SDK​

// Load the Oceanpayment JS file
<script src="https://secure.oceanpayment.com/pages/js/oceanpayment-googlepay.js"></script>

<script src="https://secure.oceanpayment.com/pub/js/jquery/jq.js"></script>

2. Create a Container​

// Load the Google Pay payment button
<div id="oceanpayment-googlepayelement"></div>

3. Initialize​

Use init(); to initialize and render the payment UI component in the container.

  • Pass true to submit requests to the sandbox environment.
  • Pass an empty value to submit requests to the production environment.
  • billCountry: The country or region code where the store is registered, in ISO 3166 format.
<script>
$(function() {
// Pass true to submit requests to the sandbox environment; pass an empty value to submit requests to the production environment.
onePageGooglePay.init(true, {
transactionInfo: {
// Pass the actual order amount and currency
orderCurrency: ORDER_CURRENCY, /* Transaction currency */
orderAmount: ORDER_AMOUNT, /* Transaction amount */
billCountry: BILLING_COUNTRY, /* Store registration country/region code */
}
});
});
</script>

4. Customize Styles​

You can use an online CSS file to override the default styles of the Oceanpayment payment page. cssUrl is empty by default during initialization. See cssUrl.

<script>
$(function() {
onePageGooglePay.init(true, {
cssUrl: '', /* Pass the URL of an online CSS file to control the button size */
buttonStyle: {
buttonColor: '', /* Button color */
buttonType: '', /* Button type */
buttonRadius: '', /* Corner radius */
buttonSizeMode: '', /* Size mode */
buttonLocale: '' /* Button language */
}
});
});
</script>

5. Update the Order Amount and Currency​

When the order amount or currency changes—for example, due to changes in product prices, discounts, taxes, or shipping fees—the merchant can call this method to update the transaction information.

<script>
function updateTransactionInfo() {
onePageGooglePay.updateTransactionInfo({
transactionInfo: {
orderCurrency: ORDER_CURRENCY, //Currency
orderAmount: ORDER_AMOUNT //Amount
}
});
}
</script>

6. Display the Google Pay Payment Sheet​

  • Call onePageGooglePay.validateResults() to control whether the Google Pay payment sheet is displayed. After Google Pay is initialized, call this method at the appropriate time based on your website’s form validation results.
    • If required fields, such as billing information, fail validation, call onePageGooglePay.validateResults(false) to prevent the payment sheet from appearing.
    • Once all required fields pass validation, call onePageGooglePay.validateResults(true) to display the payment sheet.
<script>
function validateResults() {
onePageGooglePay.validateResults(true);
}
</script>

7. Submit the Payment​

  • Call the payment method and prevent duplicate submissions.
  • Use transformToJson(formData){} to convert the required parameters to JSON format.
  • Then call checkout() to submit the required parameters to the Oceanpayment payment gateway.
// Submit parameters
<script>
function opGooglepay() {
var register = $("#payForm");
var formData = register.serializeArray();
onePageGooglePay.checkout(transformToJson(formData));
}
// Output JSON data
function transformToJson(formData){
var obj={}
for (var i in formData) {
obj[formData[i].name]=formData[i]['value'];
}
return obj;
}
</script>

QuickPay​

You can also use the QuickPay embedded API to create a subscription for quick payments.

Response​

1. Listen for the Result​

Listen for the payment result event on the frontend. See the full list of response parameters.

Note

Oceanpayment sends the payment result to the backUrl page. The backUrl value must exactly match the current page’s address and full path for the CallBack() method to receive the payment result.

var oceanpaymentGooglePayCallBack = function(data){}

2. Check the Result​

If data.code = 3, the user closed the Google Pay payment sheet. The response format is:

{"code":3,"msg":"","method":"GooglePay"}

3. 3DS Flow​

When data.code = 2, the Google Pay button has loaded successfully. Receive the payment response in the else block and handle these two cases:

  • If xml->pay_url is empty, xml contains the payment result. An asynchronous notification is also sent to noticeUrl.
  • If xml->pay_url is not empty, redirect the user to pay_url to complete 3DS verification. The payment result will then be sent to backUrl again. By default, receive it using $_POST. An asynchronous notification is also sent to noticeUrl.
var oceanpaymentGooglePayCallBack = function(data){
if (data.code == 2) {
// Display the button and initiate payment
opGooglepay();
}else{
/* Handle the order response */
//console.log(data);
}
}

4. Response Example​

<?xml version="1.0" encoding="UTF-8"?>
<response>
<notice_type>transaction</notice_type>
<push_dateTime>2025-09-03 10:21:14</push_dateTime>
<account>995149</account>
<terminal>99514901</terminal>
<signValue>924347D8E9C9BAC2EC91449C70540FF49E0DD5711F03E8A871DCA34CED023AB6</signValue>
<methods>GooglePay</methods>
<order_number>JSCSE-3128790866</order_number>
<card_country>PL</card_country>
<order_currency>USD</order_currency>
<order_amount>0.01</order_amount>
<order_notes></order_notes>
<card_number>411111***1111</card_number>
<card_type>Visa</card_type>
<payment_country></payment_country>
<payment_id>250902111334242179639</payment_id>
<payment_authType>2</payment_authType>
<payment_status>-1</payment_status>
<payment_details>80093:3D Authorized Service not completed</payment_details>
<payment_solutions></payment_solutions>
<payment_risk></payment_risk>
<payment_amount></payment_amount>
<payment_exchangeRate></payment_exchangeRate>
<auth_reason></auth_reason>
<auth_code></auth_code>
<pay_userId></pay_userId>
<pay_url>https://secure.oceanpayment.com:443/gateway/direct/redirect?pay_id=af5e28ee57061f4fd1dd307a7bc56c7289d9041d0b5494195d91b7c5166b6e30</pay_url>
</response>
  • Redirect the user to pay_url:
HTTP/1.2 301 Moved Permanently
Location: {pay_url}

Payment Status​

See Payment Status for details.

Asynchronous Notification​

You also need to receive the transaction’s asynchronous notification via noticeUrl.

Signature​

See Signature Generation and Verification for details.