Overview
There are two supported approaches for integrating Apple Pay to bind a card and create a QuickPay ID. Choose the integration method that best fits your business and technical requirements.
- Embedded Creation: The merchant integrates the Apple Pay button using the Oceanpayment Embedded Component. Upon successful payment, a QuickPay ID is automatically generated.
- Direct Integration Creation: The merchant integrates the official Apple Pay button and directly calls the Oceanpayment server-side API to create a QuickPay ID after a successful payment.
How It Works
- Embedded Creation
- Direct Integration Creation
When using Embedded Integration with Apple Pay, the merchant must first add the Oceanpayment-hosted domain verification file for each registered domain.
- Include the Oceanpayment SDK on your page:
<script src="https://secure.oceanpayment.com/pages/js/oceanpayment-applepay.js"></script>
<script src="https://secure.oceanpayment.com/pub/js/jquery/jq.js"></script>
- Create a
<div>container on your page:
// Load the Apple Pay button
<div id="oceanpayment-applepayelement"></div>
- Initialize and render the payment UI component into the container by calling
init().
- Pass true to use the sandbox environment.
- Leave this parameter empty to use the production environment.
- Set mode to
quickpayto enable QuickPay ID creation mode. billCountry: The country/region code of the store's registered location, in ISO 3166 format.
// Initialize Oceanpayment
<script>
$(function() {
// Set to `true` for the sandbox environment. Leave empty for the production environment.
onePageApplePay.init(true, {
terminal: '99514901', /*Oceanpayment terminal*/
mode: "quickpay",
transactionInfo: {
// Pass the actual order amount, currency, and country information.
orderCurrency:ORDER_CURRENCY, /* Transaction currency */
orderAmount:ORDER_AMOUNT, /* Transaction amount */
billCountry:BILLING_COUNTRY, /* Store Registration Country/Region Code */
orderNumber:ORDER_NUMBER, /*Order number*/
billAddress:BILLING_ADDRESS /*Billing address*/
}
});
});
</script>
- Custom Styling
- You can override the default styles of the Oceanpayment payment page by providing an online CSS stylesheet to customize its appearance. The cssUrl parameter is optional and defaults to an empty value during initialization. For details, see
cssUrl.
<script>
$(function() {
onePageApplePay.init(true, {
cssUrl: '',/*The URL of the online CSS stylesheet used to customize the style and size of the Apple Pay button.*/
buttonStyle: {
buttonstyle:'', /*Button color*/
type:'' /*Button type*/
}
});
});
</script>
- Update Order Amount and Currency
- When the order amount or currency changes, such as due to changes in product prices, discounts, taxes, or shipping fees, merchants can call this method to update the transaction information.
<script>
function updateTransactionInfo() {
onePageApplePay.updateTransactionInfo({
transactionInfo: {
orderCurrency: ORDER_CURRENCY, //Currency
orderAmount: ORDER_AMOUNT //Amount
}
});
}
</script>
- Trigger the Google Pay Payment Popup
- Merchants can use the
onePageApplePay.validateResults()method to control whether the Apple Pay payment popup is displayed. Call this method at the appropriate time after Google Pay has been initialized, based on the results of the website's form validation.- If required fields, such as billing information, fail validation, call onePageApplePay.validateResults(false) to prevent the payment popup from being displayed.
- Once all required fields pass validation, call onePageApplePay.validateResults(true) to display the payment popup.
<script>
function validateResults() {
onePageApplePay.validateResults(true);
}
</script>
- QuickPay ID Creation
- When calling the Create QuickPay ID method, implement duplicate submission prevention during the payment process.
- Use the
transformToJson(formData){}method to convert the required submission parameters into JSON format. - Then call
onePageApplePay.checkout()to submit the required parameters to the Oceanpayment. For details, see Create QuickPay ID Parameters.
// Submit parameters
<script>
function opApplepay() {
// Get the form element
var register = $("#payForm");
var formData = register.serializeArray();
// Submit payment parameters to the Oceanpayment
onePageApplePay.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>
- Become an official Apple Pay developer and obtain the Apple Pay Payment Token.
- Pass the Apple Pay Payment Token to Oceanpayment and create a QuickPay ID by submitting the required parameters(/docs/payment/parameter#create-quickpay-id):
cURL -X POST 'https://test-secure.oceanpayment.com/gateway/directservice/create' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'account=995149' \
-d 'terminal=99514901' \
-d 'signValue=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' \
-d 'customer_id=customer_id20250507174225' \
-d 'methods=ApplePay' \
-d 'pay_accountNumber='{"paymentData":{"data":"P/Qqc9AoboM0V9smWAWuYJO2hA5eOEQMkeuLAP/n6UkOobJHMGlDYNYRJOVTZKjQXvkjBuppGVpp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qtkQjjwWibaFQVLhe4H0m9nXpNAiEAvYABRkpGwM9Uo8UAU+KQgKIdkO9IXcciWyGo93SQQvMAAAAAAAA=","header":{"publicKeyHash":"LfT8NhajbyOZdSZ5fWF9tJjQk9ZUoy+CnI5PZsD/e7M=","ephemeralPublicKey":"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExekguuW80+zLuywKufjWwQpasFSw11HrGbjBqZx7PXI0wpY2JOWRZ26OMSUvyBJKP43gqJZny7+dw1xDxq2bBw==","transactionId":"8d31b7aef561befa41d5a881918983a6fbecb0f399a490ef15bc1dc50fe2c890"},"version":"EC_v1"},"paymentMethod":{"displayName":"MasterCard 0049","network":"MasterCard","type":"credit"},"transactionIdentifier":"8d31b7aef561befa41d5a881918983a6fbecb0f399a490ef15bc1dc50fe2c890"}'\
-d 'order_notes=' \
-d 'billing_firstName=Vergil' \
-d 'billing_lastName=Pan' \
-d 'billing_email=test@gmail.com' \
-d 'billing_phone=13800138000' \
-d 'billing_country=US' \
-d 'billing_state=AL' \
-d 'billing_city=Washington D.C.' \
-d 'billing_address=705A big Road' \
-d 'billing_zip=529012' \
Handle the Response
The merchant should save the returned card information quickpay_id, which is in UUID format and is used to initiate QuickPay/Subscription Payments.
- Embedded Creation
- Direct Integration Creation
Oceanpayment will redirect the card binding result to the backUrl page. The backUrl value must exactly match the current page URL, including the complete path. Otherwise, the oceanpaymentApplePayCallBack() method cannot be triggered to receive the payment response information.
var oceanpaymentApplePayCallBack = function(data){}
- When card information validation fails,
data.msgwill return the corresponding error message. For example:
{"code":-1, "msg":"xxx"}
- The card binding response is returned as follows:
- If
data.msgis empty, the card information verification is successful. - If
data.code= 2, the Apple Pay button has been successfully loaded.
var oceanpaymentApplePayCallBack = function(data){
if (data.code == 2) {
// Trigger the button to create a QuickPay ID
opApplepay();
}else{
/* Handle the response result */
//console.log(data);
}
}
- When
data.code= 3, it indicates that the user has closed the Apple Pay payment dialog. The returned data format is as follows:
{"code":3,"msg":"","method":"ApplePay"}
- Response example
<?xml version="1.0" encoding="UTF-8"?>
<response>
<account>995149</account>
<terminal>99514901</terminal>
<signValue>79e63f6995a84934da921bab8a2ba8cb492971a36130a76d58ea18355af7f578</signValue>
<customer_id>customer_id20240507174225</customer_id>
<order_notes></order_notes>
<card_number>411111***1111</card_number>
<card_type>VISA</card_type>
<card_country>PL</card_country>
<quickpay_id>37ca4cff-4e99-4cd6-9869-8d6c7ad259d7</quickpay_id>
<quickpay_status>1</quickpay_status>
<quickpay_details>1:Success</quickpay_details>
</response>
<?xml version="1.0" encoding="UTF-8"?>
<response>
<account>995149</account>
<terminal>99514901</terminal>
<signValue>79e63f6995a84934da921bab8a2ba8cb492971a36130a76d58ea18355af7f578</signValue>
<customer_id>customer_id20240507174225</customer_id>
<order_notes></order_notes>
<card_number>411111***1111</card_number>
<card_type>VISA</card_type>
<card_country>PL</card_country>
<quickpay_id>37ca4cff-4e99-4cd6-9869-8d6c7ad259d7</quickpay_id>
<quickpay_status>1</quickpay_status>
<quickpay_details>1:Success</quickpay_details>
</response>
Signature
See Signature and Verification for details on request signing and response validation.