Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solution

Server-to-server mode

This article describes how to integrate card payment methods through the server-to-server mode, which is suitable for merchants who have high requirements for the degree of customization of the payment process.

The server-to-server integration mode requires that you are PCI qualified. Provide the following materials to complete verification according to business requirements:

For more information about PCI DSS compliance requirements, see PCI DSS standard.

User experience

The following figures show the user experience in the first-time and saved card payments.

First-time payments

Web user experience

image.png

Saved card payments

Web user experience

image.png

Payment flow

For card payments with the server-to-server mode, the payment flow is composed of the following steps:

图7.png

  1. The buyer enters the checkout page.
  2. Create the pay request
    After the buyer selects a payment method and submits the order, call the pay API to obtain the payment link to complete the payment.
  3. Handle the payment continuation URL
    The payment continuation URL is to be returned to the client. You need to redirect the buyer to the payment continuation URL. The payment continuation URL proceeds the payment process with different operations based on the characteristics of payment methods, such as collecting information, redirecting users, invoking the app, displaying QR codes, and performing verifications.
  4. Get the payment result
    Obtain the payment result using one of the following two methods:
    • Asynchronous notification: Specify the paymentNotifyUrl in the pay API to set the address for receiving asynchronous notifications. When the payment is successful or expires, Antom uses notifyPayment to send asynchronous notifications to you.
    • Synchronous inquiry: Call the inquiryPayment API to check the payment status.
  1. Get the capture result
    For card payments, you need to obtain the capture result using one of the following two methods:
    • Asynchronous notification: Specify paymentNotifyUrl in the pay API to set the address for receiving asynchronous notifications. When the payment request is successful or expires, Antom uses notifyCapture to send asynchronous notifications to you.
    • Synchronous inquiry: Call the inquiryPayment API to check the payment request status.

Integration steps

Start your integration by taking the following steps:

  1. (Optional) Display payment methods
  2. Authorize payment
  3. Obtain the pre-authorized payment results
  4. Capture
  5. Obtain the capture results

Step 1: (Optional) Display payment methods Client-side

Add the logos and names of the payment methods you plan to integrate. This allows buyers to easily choose their preferred method of payment. You can source the logos and names in two ways:

  • Contact Antom Technical Support.
  • Call the consult API to obtain the payment methods and logo URL supported by the current transactions based on the currency, transaction initiation terminal type, buyer region, and contracted payment methods.

The following figure shows the page effect after adding a payment method:

image.png

Step 2: Authorize payment Server-side

When the buyer selects a payment method provided by Antom, the card information collection page is displayed for the buyer. During this process, you need to collect the buyer's card, environment, and order information. Call the pay API, and submit an authorization request for payment.

Initiate a payment request Server-side

Antom provides server-side API libraries for multiple languages. The following code uses Java as an example. You need to install Java 6 or later.

Install an API library

You can find the latest version on GitHub.

copy
<dependency>
  <groupId>com.alipay.global.sdk</groupId>
  <artifactId>global-open-sdk-java</artifactId>
  <version>2.0.21</version>
</dependency>

Initialize the request instance

copy
String merchantPrivateKey = "YOUR PRIVATE KEY";
String alipayPublicKey = "ALIPAY PUBLIC KEY"
AlipayClient defaultAlipayClient = new DefaultAlipayClient(EndPointConstants.SG,
                merchantPrivateKey, alipayPublicKey);

Create a payment request

When sending a request for the pay API, you can also choose the following features according to your business needs:

    • Enable 3D authentication: Specify the value of is3DSAuthentication in the pay API to set whether the transaction is authenticated by using 3D Secure.
    • Salvage transaction intelligently: Automatically initiate a 3D Secure authentication for a non-3D Secure transaction if required by the card issuer to salvage a failed transaction.
    • Value-added risk control services: Antom provides upgraded risk control services at a transaction level, and intelligently decides risk control strategies based on the risk level of a transaction.
    • Address Verification System (AVS) service: This service verifies whether the provided billing address matches the cardholder's address on record at the issuing bank. AVS helps to prevent fraudulent transactions.
    • Store card info: Obtain the buyer's agreement to store card information at the first payment, so that the card information does not need to be entered again for the next payment.
    • Merchant-initiated transactions (MIT): Initiate scheduled or unscheduled transactions without buyer involvement.
    • Specify card brand: When the buyer chooses co-badged card payment, you can specify the card brand or the region where the card is authorized for payment.
    • MPI capability: The merchant prioritizes the third-party verification before the transaction is initiated, passes in the verification result information in the payment request, and specifies non-3D verification, which is not available if the merchant does not capture the card information.
    • Installment payments: When making a payment, buyers can choose the installment payment method and make regular payments for each installment period. After the buyer completes the payment for the initial installment period, Antom settles the full order amount based on the settlement period specified in the contract.

The following parameters are included in the payment request.

Parameter name

Is required?

Description

productCode

Yes

The value is fixed as CASHIER_PAYMENT.in this scenario.

paymentRequestId

Yes

The unique ID assigned by a merchant to identify a payment request.

paymentAmount

Yes

The payment amount that the merchant requests to receive in the order currency.

paymentMethod

Yes

The payment method that is used to collect the payment by the merchant or acquirer.

paymentRedirectUrl

Yes

The merchant page URL that the buyer is redirected to after the payment is completed.

settlementStrategy

No

The settlement strategy for the payment request.

order

Yes

The order information, such as buyer, merchant, goods, amount, shipping information, and purchase environment.

paymentMethodMetaData

Yes

Card element information: cardNo, cvv, expiryYear, expiryMonth, cardholderName, billingAddress.

env

Yes

Environmental information: used to improve payment success rate

For more information about the complete parameters, refer to the pay API.

Sample codes of calling the pay API

The following sample code is used for initiating a payment:

copy
  AlipayPayRequest alipayPayRequest = new AlipayPayRequest();
  alipayPayRequest.setClientId(CLIENT_ID);
  alipayPayRequest.setPath("/ams/sandbox/api/v1/payments/pay");
  alipayPayRequest.setProductCode(ProductCodeType.CASHIER_PAYMENT);

  // replace to your paymentRequestId
  alipayPayRequest.setPaymentRequestId("paymentRequestId01");

  // set amount
  Amount amount = new Amount();
  amount.setCurrency("SGD");
  amount.setValue("4200");
  alipayPayRequest.setPaymentAmount(amount);

  // set paymentMethod
  PaymentMethod paymentMethod = new PaymentMethod();
  paymentMethod.setPaymentMethodType("CARD");
  alipayPayRequest.setPaymentMethod(paymentMethod);

  //if merchant collect card info, set card info in this paymentMethodMetaData
  Map<String, Object> paymentMethodMetaData = new HashMap<String, Object>();
  paymentMethodMetaData.put("cardNo", "4054695723100768");
  paymentMethodMetaData.put("cvv", "712");
  paymentMethodMetaData.put("expiryMonth", "06");
  paymentMethodMetaData.put("expiryYear", "28");
  paymentMethodMetaData.put("tokenize", false);
  JSONObject cardholderName = new JSONObject();
  cardholderName.put("firstName", "Alan");
  cardholderName.put("lastName", "Wallex");
  paymentMethodMetaData.put("cardholderName", cardholderName);
  paymentMethod.setPaymentMethodMetaData(paymentMethodMetaData);


  // set order Info
  Order order = new Order();
  order.setReferenceOrderId("3232db07-91f7-4364-85bc-829a4c1c653f");
  order.setOrderDescription("antom test order");
  order.setOrderAmount(amount);
  Buyer buyer = new Buyer();
  buyer.setReferenceBuyerId("yourBuyerId");
  order.setBuyer(buyer);
  order.setOrderAmount(amount);
  alipayPayRequest.setOrder(order);

  //set env Info
  Env env = new Env();
  env.setTerminalType(TerminalType.WEB);
  env.setClientIp("114.121.121.01");
  alipayPayRequest.setEnv(env);
  order.setEnv(env);

  // set auth capture payment mode
  PaymentFactor paymentFactor = new PaymentFactor();
  paymentFactor.setAuthorization(true);
  alipayPayRequest.setPaymentFactor(paymentFactor);

  // replace to your notify url
  alipayPayRequest.setPaymentNotifyUrl("http://www.yourNotifyUrl.com");

  // replace to your redirect url
  alipayPayRequest.setPaymentRedirectUrl("http://www.yourRedirectUrl.com");

  //do the Payment
  AlipayPayResponse alipayPayResponse = null;
  try {
      alipayPayResponse = defaultAlipayClient.execute(alipayPayRequest);
  } catch (AlipayApiException e) {
      String errorMsg = e.getMessage();
      // handle error condition
  }

The following code shows a sample of the request message:

copy
{
    "paymentNotifyUrl": "http://www.yourNotifyUrl.com",
    "paymentRequestId": "paymentRequestId01",
    "env": {
        "terminalType": "WEB",
        "clientIp": "114.121.121.01"
    },
    "paymentAmount": {
        "currency": "SGD",
        "value": "4200"
    },
    "productCode": "CASHIER_PAYMENT",
    "paymentRedirectUrl": "http://www.yourRedirectUrl.com",
    "paymentFactor": {
        "isAuthorization": true
    },
    "paymentMethod": {
        "paymentMethodMetaData": {
            "cvv": "712",
            "cardholderName": {
                "firstName": "Alan",
                "lastName": "Wallex"
            },
            "expiryMonth": "06",
            "expiryYear": "28",
            "cardNo": "4054695723100768"
        },
        "paymentMethodType": "CARD"
    },
    "order": {
        "orderAmount": {
            "currency": "SGD",
            "value": "4200"
        },
        "referenceOrderId": "3232db07-91f7-4364-85bc-829a4c1c653f",
        "env": {
            "terminalType": "WEB",
            "clientIp": "114.121.121.01"
        },
        "orderDescription": "antom test order",
        "buyer": {
            "referenceBuyerId": "yourBuyerId"
        }
    }
}

FAQs

How to set the value of terminalType?

If the buyer initiates a transaction from PC, the terminalType needs to be specified as WEB.

Can I use Chinese characters in the value of the request parameters?

To avoid incompatibility of a certain payment method, do not use Chinese characters for fields in the request, such as QRIS and Mastercard.

How to set the URL to receive the payment notification?

Antom sends you the payment result via notifyPayment, which you can specify in the pay API via the paymentNotifyUrl parameter. If the address of each payment is the same, you can also configure it in the Antom Dashboard. If you have configured the address and set the parameter in the API, Antom will use the address set in the API.

Receive a payment response

The returned parameters contain the following content:

  • normalUrl: Redirect URL address.
  • paymentId: Order ID.

The following code is the sample response:

Successful authorization
copy
{
    "paymentAmount": {
        "currency": "SGD",
        "value": "4200"
    },
    "paymentCreateTime": "2021-11-12T01:27:50-08:00",
    "paymentId": "20211112194010800100188570271832381",
    "paymentRequestId": "paymentRequestId01",
    "paymentResultInfo": {
        "avsResultRaw": "A",
        "cvvResultRaw": "Y",
        "networkTransactionId": "sampleNetworkTransactionId123456"
    },
    "result": {
        "resultCode": "SUCCESS",
        "resultMessage": "success.",
        "resultStatus": "S"
    }
}

FAQs

What is the normalUrl?

For web transactions, Antom returns normalUrl, which the merchant server needs to pass to the merchant client for redirection. When you initiate payment for the same order again, you need to obtain a new normalUrl for redirection.

What is the paymentId

If you store the corresponding order number for subsequent refunds and reconciliations, you can specify the paymentId.

Redirect to the payment continuation URL Client-side

The merchant server passes the normalUrl to the front-end, and the front-end page handles the redirection process to normalUrl.

Step 3: Obtain the pre-authorized payment results Server-side

When the buyer completes the payment or the payment times out, you can get the corresponding payment result from the Antom asynchronous notification or by actively inquiring the payment result.

The response obtained from asynchronous notifications and inquiryPayment contains the authorization payment result as well as other key information such as:

API

Authorization result

AVS info

CVV info

3DS authentication info

notifyPayment

resultStatus

avsResultRaw

cvvResultRaw

threeDSResult (only available for the 3DS authentication authorization)

inquiryPayment

paymentStatus

avsResultRaw

cvvResultRaw

threeDSResult (only available for the 3DS authentication authorization)

Receive the asynchronous notification

When a payment is completed or fails, Antom sends an asynchronous notification (notifyPayment) to the address that you specified in the pay API via the paymentNotifyUrl parameter. If the address of each payment is the same, you can also configure the address in Antom Dashboard.

The following sample code shows a notification for a 3D payment:

copy
{
    "notifyType": "PAYMENT_RESULT",
    "result": {
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "success"
    },
    "paymentRequestId": "paymentRequestId01",
    "paymentId": "2020010123456789XXXX",
    "paymentAmount": {
        "value": "4200",
        "currency": "SGD"
    },
    "paymentCreateTime": "2020-01-01T12:01:00+08:30",
    "paymentTime": "2020-01-01T12:01:01+08:30",
    "paymentResultInfo": {
        "avsResultRaw": "A",
        "cvvResultRaw": "Y",
        "networkTransactionId": "sampleNetworkTransactionId123456",
        "threeDSResult": {
            "eci": "02",
            "threeDSVersion": "2.2.0",
            "caav": "cavvSample",
            "dsTransactionId": "sample_dsTranasctionId"
        }
    }
}

The following sample code shows a notification for a non-3D payment:

copy
{
    "notifyType": "PAYMENT_RESULT",
    "result": {
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "success"
    },
    "paymentRequestId": "paymentRequestId01",
    "paymentId": "2020010123456789XXXX",
    "paymentAmount": {
        "value": "4200",
        "currency": "SGD"
    },
    "paymentCreateTime": "2020-01-01T12:01:00+08:30",
    "paymentTime": "2020-01-01T12:01:01+08:30",
    "paymentResultInfo": {
        "avsResultRaw": "A",
        "cvvResultRaw": "Y",
        "networkTransactionId": "sampleNetworkTransactionId123456"
    }
}

How to verify the signature of the notification and make a response to the notification, see Sign a request and verify the signature.

FAQs

When will Antom send the asynchronous notification?

It depends on whether the payment is completed:

  • If the payment is successfully completed, Antom will usually send you an asynchronous notification within 3 to 5 seconds. For some payment methods like OTC, the notification might take a bit longer.
  • If the payment is not completed, you need to wait for Antom to close the order before sending an asynchronous notification. The time it takes for different payment methods to close the order varies, usually defaulting to 14 minutes.
Will the asynchronous notification be re-sent?

Yes, the asynchronous notification will be re-sent automatically within 24 hours for the following cases:

  • If you didn't receive the asynchronous notification due to network reasons.
  • If you receive an asynchronous notification from Antom, but you didn't make a response to the notification in the Sample code format.

The notification can be resent up to 8 times or until a correct response is received to terminate delivery. The sending intervals are as follows: 0 minutes, 2 minutes, 10 minutes, 10 minutes, 1 hour, 2 hours, 6 hours, and 15 hours.

When responding to the notification, do I need to add a digital signature?

If you receive an asynchronous notification from Antom, you are required to return the response in the Sample code format, but you do not need to countersign the response.

What are the key parameters in the notification that I need to use?

Pay attention to the following key parameters:

  • result: Indicates the payment result of the order.
  • paymentRequestId: Indicates the payment request number you generated for consult, cancel, and reconciliation.
  • paymentId: Indicates the payment order number generated by Antom, used for refund and reconciliation.
  • paymentAmount: Indicates the payment amount.

Inquire about the payment result

Initiating a query request will involve the following parameters.

Parameter name

is required?

Description

paymentRequestId

No

The payment request number generated by the merchant

The following is the sample code when calling the inquiryPayment API:

copy
AlipayClient defaultAlipayClient = new DefaultAlipayClient(EndPointConstants.SG,
        merchantPrivateKey, alipayPublicKey);

AlipayPayQueryRequest alipayPayQueryRequest = new AlipayPayQueryRequest();
alipayPayQueryRequest.setClientId(CLIENT_ID);
alipayPayQueryRequest.setPath("/ams/api/v1/payments/inquiryPayment");
alipayPayQueryReuqest.setPaymentRequestId("paymentRequestId01");

AlipayPayQueryResponse alipayPayQueryResponse;
try {
    alipayPayQueryResponse = defaultAlipayClient.execute(alipayPayQueryRequest);
} catch (AlipayApiException e) {
    String errorMsg = e.getMessage();
    // handle error condition
}

The following code shows a sample of the request message:

copy
{
  "paymentRequestId": "paymentRequestId01"
}

The following code shows a sample of the response message for a 3D payment:

copy
{
    "result": {
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "Success"
    },
    "paymentStatus": "SUCCESS",
    "paymentRequestId": "paymentRequestId01",
    "paymentId": "2019060811401080010018882020035XXXX",
    "paymentAmount": {
        "value": "4200",
        "currency": "SGD"
    },
    "paymentCreateTime": "2019-06-01T12:01:01+08:30",
    "paymentTime": "2019-06-01T12:01:01+08:30",
    "paymentResultInfo": {
        "avsResultRaw": "A",
        "cvvResultRaw": "Y",
        "networkTransactionId": "sampleNetworkTransactionId123456",
        "threeDSResult": {
            "eci": "02",
            "threeDSVersion": "2.2.0",
            "caav": "cavvSample",
            "dsTransactionId": "sample_dsTranasctionId"
        }
    }
}

The following code shows a sample of the response message for a non-3D payment:

copy
{
    "result": {
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "Success"
    },
    "paymentStatus": "SUCCESS",
    "paymentRequestId": "paymentRequestId01",
    "paymentId": "2019060811401080010018882020035XXXX",
    "paymentAmount": {
        "value": "4200",
        "currency": "SGD"
    },
    "paymentCreateTime": "2019-06-01T12:01:01+08:30",
    "paymentTime": "2019-06-01T12:01:01+08:30",
    "paymentResultInfo": {
        "avsResultRaw": "A",
        "cvvResultRaw": "Y",
        "networkTransactionId": "sampleNetworkTransactionId123456"
    }
}

FAQs

What are the key parameters in the notification that I need to use?

Pay attention to the following key parameters:

  • result: Represents the result of this inquiryPayment API call, the result of the order needs to be judged according to paymentStatus, SUCCESS and FAIL represent the final result, PROCESSING represents the processing.
  • paymentAmount: Indicates the payment amount.
How often should I call the API?

It is recommended to initiate a round-robin query at an interval of 2 seconds, and you can initiate a round poll after initiating the pay API until the final payment result is queried or an asynchronous payment result notification is received.

Step 4: Capture Server-side

By default, Antom automatically handles funds capture for you. If you specify the value of paymentFactor.captureMode to MANUAL when calling the pay API, you must capture the funds of the payment by calling the capture API.

  • Automatic capture: Antom automatically captures funds immediately after the buyer authorizes the payment. The capture result is then communicated to you via an asynchronous notification. Automatic capture is activated when one of the following conditions is met:
    • You set the value of paymentFactor.captureMode in the pay API to AUTOMATIC.
    • You leave the value of paymentFactor.captureMode in the pay API empty or you do not pass in this parameter.
  • Manual capture: You must initiate fund capture by calling the capture API within seven days after successful authorization, otherwise Antom automatically unfreezes the authorized funds of the payment. The total capture amount must be equal to the total authorized amount.

Note: For card payments, it is recommended to confirm the successful capture result before shipping.

The key request parameters in the capture API are shown in the following table:

Parameter

Description

captureRequestId

A unique identifier that you assign to a capture request.

paymentId

A unique identifier that Antom assigns to an order.

captureAmount

The capture amount, which must be equal to the total authorized amount.

The following is a sample code and packet for initiating a payment.

copy
AlipayCaptureRequest alipayCaptureRequest = new AlipayCaptureRequest();
alipayCaptureRequest.setPath("/ams/sandbox/api/v1/payments/capture");
alipayCaptureRequest.setClientId(CLIENT_ID);

Amount amount = new Amount();
amount.setCurrency("SGD");
amount.setValue("4200");
alipayCaptureRequest.setCaptureAmount(amount);

alipayCaptureRequest.setCaptureRequestId("captureRequestId01");
alipayCaptureRequest.setPaymentId("2019060811401080010018882020035XXXX");

AlipayCaptureResponse alipayCaptureResponse= null;

try{
    alipayCaptureResponse = defaultAlipayClient.execute(alipayCaptureRequest);
}catch (AlipayApiException e){
    String errorMsg = e.getMessage();
}

The following code shows a sample of the response message:

copy
{
    "paymentId": "2019060811401080010018882020035XXXX",
    "captureRequestId": "captureRequestId01",
    "captureAmount": {
        "currency": "SGD",
        "value": "4200"
    }
}

Step 5: Obtain the capture results Server-side

When the buyer completes the capture or the capture times out, you can get the corresponding payment result from the Antom asynchronous notification or by actively inquiring the payment result.

Receive the asynchronous notification

When a payment is completed or fails, Antom sends an asynchronous notification via notifyCapture. You can specify in the pay API via the paymentNotifyUrl parameter. If the address of each payment is the same, you can also configure it in the Antom Dashboard.

The following is the notification request sample code:

copy
  "captureAmount": {
    "currency": "SGD",
    "value": "4200"
  },
  "notifyType": "CAPTURE_RESULT",
  "captureId": "2022XXXXXXX",
  "captureRequestId": "captureRequestId01",
  "captureTime": "2022-11-10T00:34:52-08:00",
  "paymentId": "2022XXXXXXX",
  "result": {
    "resultCode": "SUCCESS",
    "resultMessage": "success.",
    "resultStatus": "S"
  }
}

The following code is a notification sample of a failed payment:

copy
  "captureAmount": {
    "currency": "SGD",
    "value": "4200"
  },
  "notifyType": "CAPTURE_RESULT",
  "captureId": "2022XXXXXXX",
  "captureRequestId": "captureRequestId01",
  "captureTime": "2022-11-10T00:34:52-08:00",
  "paymentId": "2022XXXXXXX",
  "result": {
    "resultCode": "PROCESS_FAIL",
    "resultMessage": "fail.",
    "resultStatus": "F"
  }
}

How to verify the signature of the notification and make a response to the notification, see Sign a request and verify the signature.

FAQs

When will Antom send the asynchronous notification?

It depends on whether the payment is completed:

  • If the payment is successfully completed, Antom will usually send you an asynchronous notification within 3 to 5 seconds. For some payment methods like OTC, the notification might take a bit longer.
  • If the payment is not completed, you need to wait for Antom to close the order before sending an asynchronous notification. The time it takes for different payment methods to close the order varies, usually defaulting to 14 minutes.
Will the asynchronous notification be re-sent?

Yes, the asynchronous notification will be re-sent automatically within 24 hours for the following cases:

  • If you didn't receive the asynchronous notification due to network reasons.
  • If you receive an asynchronous notification from Antom, but you didn't make a response to the notification in the Sample code format.

The notification can be resent up to 8 times or until a correct response is received to terminate delivery. The sending intervals are as follows: 0 minutes, 2 minutes, 10 minutes, 10 minutes, 1 hour, 2 hours, 6 hours, and 15 hours.

When responding to the notification, do I need to add a digital signature?

If you receive an asynchronous notification from Antom, you are required to return the response in the Sample code format, but you do not need to countersign the response.

What are the key parameters in the notification that I need to use?

Pay attention to the following key parameters:

  • result: Indicates the payment result of the order.
  • notifyType: CAPTURE_RESULT
  • paymentId: Indicates the payment order number generated by Antom, used for refund and reconciliation.
  • acquirerReferenceNo: For merchants that access card payment in Singapore and Hong Kong, the specific acquiring station number will be notified in the notification.

Inquire about the payment result

Initiating a query request will involve the following parameters.

Parameter name

is required?

Description

paymentRequestId

No

The payment request number generated by the merchant

The following is the sample code:

copy
  AlipayClient defaultAlipayClient = new DefaultAlipayClient(EndPointConstants.SG,
          merchantPrivateKey, alipayPublicKey);

  AlipayPayQueryRequest alipayPayQueryRequest = new AlipayPayQueryRequest();
  alipayPayQueryRequest.setClientId(CLIENT_ID);
  alipayPayQueryRequest.setPath("/ams/sandbox/api/v1/payments/inquiryPayment");
  alipayPayQueryRequest.setPaymentRequestId("paymentRequestId01");

  AlipayPayQueryResponse alipayPayQueryResponse;
  try {
      alipayPayQueryResponse = defaultAlipayClient.execute(alipayPayQueryRequest);
  } catch (AlipayApiException e) {
      String errorMsg = e.getMessage();
      // handle error condition
  }

The following is the request message:

copy
{
  "paymentRequestId": "paymentRequestId01"
}

Value of capture status

The value of the transactions field in the API response is the capture status:

Parameter

Description

transactions.transationType

The value is CAPTURE. It indicates the capture status.

transactions.transactionResult

The capture result.

The value of transactions indicates the capture status. See the following code samples for details:

copy
{
    "transactions": [
        {
            "transactionType": "CAPTURE",
            "transactionStatus": "SUCCESS",
            "transactionRequestId": "test_test_test_XXXX",
            "transactionAmount": {
                "currency": "SGD",
                "value": "4200"
            },
            "transactionId": "2022XXXXXXXX",
            "transactionResult": {
                "resultStatus": "S",
                "resultCode": "SUCCESS",
                "resultMessage": "success"
            }
        }
    ]
}

The value of transactions indicates the capture status. See the following code samples for a failed capture:

copy
{
    "transactions": [
        {
            "transactionType": "CAPTURE",
            "transactionStatus": "FAIL",
            "transactionRequestId": "test_test_test_XXXX",
            "transactionAmount": {
                "currency": "SGD",
                "value": "4200"
            },
            "transactionTime": "2022-09-29T07:13:50-07:00",
            "transactionId": "2022XXXXXXXX",
            "transactionResult": {
                "resultStatus": "F",
                "resultCode": "PROCESS_FAIL",
                "resultMessage": "General business failure. No retry."
            }
        }
    ]
}

The value of transactions indicates the capture status. See the following code samples for a capture that is in processing:

copy
{
    "transactions": [
        {
            "transactionType": "CAPTURE",
            "transactionStatus": "PROCESSING",
            "transactionRequestId": "test_test_test_XXXX",
            "transactionAmount": {
                "currency": "SGD",
                "value": "4200"
            },
            "transactionId": "2022XXXXXXXX",
            "transactionResult": {
                "resultStatus": "U",
                "resultCode": "PAYMENT_IN_PROCESS",
                "resultMessage": "payment in process"
            }
        }
    ]
}

FAQs

What are the key parameters in the notification that I need to use?

Pay attention to the following key parameters:

  • result: Represents the result of this inquiryCapture API call, the result of the order needs to be judged according to transactionResult, SUCCESS and FAIL represent the final result, PROCESSING represents the processing.
How often should I call the API?

It is recommended to initiate a round-robin query at an interval of 2 seconds, and you can initiate a round poll after initiating the order consult API until the final capture result is queried or an asynchronous capture result notification is received.

Best practice

Follow these best practices to improve integration efficiency.

Customize the payment timeout

In the Checkout Payment scenario, the default timeout on the Antom side is 14 minutes. After the payment timeout, the buyer can't continue to pay. You can specify the timeout time through the paymentExpireTime parameter of the pay API. After exceeding the specified time, the buyer cannot scan the code or log in to the checkout page.

The following sample code shows how to specify the paymentExpireTime parameter in the pay API:

copy
{
  "env": {
    "osType": "ANDROID",
    "terminalType": "APP"
  },
  "order": {
    "orderAmount": {
      "currency": "CNY",
      "value": "1314"
    },
    "orderDescription": "Cappuccino #grande (Mika's coffee shop)",
    "referenceOrderId": "ORDER_0517884936248XXXX"
  },
  "paymentAmount": {
    "currency": "CNY",
    "value": "1314"
  },
  "paymentMethod": {
    "paymentMethodType": "ALIPAY_CN"
  },
  "paymentExpiryTime":"2024-01-20T08:51:06+08:00",
  "paymentNotifyUrl": "https://www.gaga.com/notify",
  "paymentRedirectUrl": "imeituan://",
  "paymentRequestId": "iJ9lsVgTx8pX7qJpvW6rfqEE2Kdv9M3lgL8e1999ydfz52uMSqwvT3qXYw8IFBYt",
  "productCode": "CASHIER_PAYMENT",
  "settlementStrategy": {
    "settlementCurrency": "USD"
  }
}

It is recommended to set the interface timeout to 10s to increase the response success rate.

Suggestions on processing logic for merchant results pages

  1. Handling redirection issues

When the buyer has successfully completed a payment but encounters issues redirecting to the paymentRedirectUrl that you specified, whether due to network issues or payment method limitations, take note of the following two points:

    • You cannot use the client redirection as the basis for determining the success of the payment.
    • If the paymentRedirectUrl of the payment method page fails to redirect to the merchant page, the buyer may manually click the original merchant page. To prevent buyers from mistakenly attempting to pay for the order again, it is recommended to implement a pop-up window on the original merchant page. This pop-up should allow for transaction result inquiries. When buyers click on this pop-up, it should display the transaction outcome, thereby preventing any duplicate payment attempts.
  1. Trigger order result query after redirection

If the merchant side is pulled up after triggering a call to the inquiryPayment API, then the following different results are suggested:

    • Successful payment: The page will display the content related to the shipment after successful payment.
    • Payment Failure: Indicate that the payment failed and offer guidance for retrying the payment to encourage order completion.
    • Payment processing: Display the landing effect and implement a brief pause of 3-5 seconds before querying the server again for the payment outcome. If the result remains inconclusive (neither success nor failure), it is recommended to display "order processing" or "order management portal to view the final result.". Refrain from attributing the delay to “network processing”.

Payment failed retry

When a payment attempt for an order fails, and the buyer can retry payment for the same order, we recommend adhering to the following integration process for a seamless experience:

  1. In the payment request, set the referenceOrderId to the order ID and the paymentRequestId to the payment order ID.
  2. If payment needs to be retried for the same order, check the order status first. If payment has already succeeded, display "Completed Payment" to the buyer. If not, call the pay API again to obtain a new normalUrl for redirection. Though referenceOrderId remains the same since it's the same order, you must update the paymentRequestId for the subsequent payment attempt.
  3. Verify that each merchant order only has one successful payment associated with it. If multiple successful payments are detected for a single order, call the cancel API to initiate a refund for the buyer.
  4. For payment methods that do not offer refunds, it is recommended to cancel the initial payment before initiating a new one.

Obtain payment results

In order to guarantee the stable acquisition of payment results and avoid the situation where the buyer's payment is completed but you do not get the payment result. It is recommended that you check the payment results at the following stages:

  1. When the merchant payment result page is displayed.
  2. Before shipping to the buyer.
  3. When you receive the Antom reconciliation file.