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

addPaymentMethod

POST /ams/api/v1/paymentMethods/addPaymentMethod

After consulting addable payment methods, the merchant uses this API to bind the selected payment method to the wallet, or redirect the user to a third party's page, such as a bank's page, or a third-party wallet's page, to finish the binding process.

Note:

  • Before calling this API to bind a payment method, if the payment method type is CARD (credit card/debit card), the cachecard API must be called in order to get the temporary card token.

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:

Note: Set the data type of each field (except array) as String. This means that you must use double quotation marks (" ") to enclose the field value. Examples:

  • If the data type of a field is Integer and its value is 20, set it as "20".
  • If the data type of a field is Boolean and its value is true, set it as "true".

Request parameters

Field

Data type

Required

Description

Examples

requestId

String

Yes

The unique ID that is assigned by a merchant to identify a payment method adding request. DWS uses this field for idempotence control.

More information about this field:

  • Maximum length: 64 characters

Note: This field is an API idempotency field.

"54635453532638728382372"

customerId

String

No

The unique ID that is used to identify a buyer. This field is composed of 16 digits and begins with 21.

More information about this field:

  • Maximum length: 32 characters

"2162878776333"

referenceCustomerId

String

No

Customer ID in the merchant system.

More information about this field:

  • Maximum length: 64 characters
  • This field and referenceUserId can only have one for each request

"13232262878776333"

isTemporary

Boolean

No

Whether it is a temporary value.

Note:
When the referenceUserId field is not null, the value of this field is false.

"false"

paymentMethodDetail

PaymentMethodDetail

Yes

The details of this payment method. See PaymentMethodDetail for details.

"paymentMethodDetail": {

"card": {

"cardToken": "PYMT66b223296bd041378ed1b3863b64e1a9",

"paymentMethodDetailMetadata": "{\"externalUserId\":\"300027498992\"}"

},

"paymentMethodDetailType": "CARD"

},

env

Env

No

The environment information, such as device information.

See Env for details.

Note: terminalType must be specified. And when terminalType is specified as APP/WEP, osType must be specified.

/

Response parameters

Field

Data type

Required

Description

Examples

result

Result

Yes

The request result, which contains information such as status and error codes.

/

requestId

String

Yes

The unique ID that is assigned by a merchant to identify an addPaymentMethod request. DWS uses this field for idempotence control.

More information about this field:

  • Maximum length: 64 characters

Note: This field is an API idempotency field.

"3b33b0b9-efaf-42cd-a38a-9853bc071bfd"

paymentMethodDetail

PaymentMethodDetail

No

The details of this payment method. See PaymentMethodDetail for details.

{

"card":{

"cardToken":"PYMT1342cf7ca558402cb2d77af09066d906",

"paymentMethodDetailMetadata":"{\"externalUserId\":\"1023240523\"}"

},

"paymentMethodDetailType":"CARD"

}

expiryTime

Datetime

No

The expiry time of cardToken.

The value follows the ISO 8601 standard format.

"2019-11-27T12:01:01+08:30"

actionForm

ActionForm

No

The next action is provided when the processing result is not final, as a reference for the next action.

{

"challengeRenderValue": "+6222***508",

"challengeType": "sms"

}

Result processing logic

In the response, the result.resultStatus field indicates the result of the addPaymentMethod request. The following table describes each result status:

Result status

Description

S

The addPaymentMethod request is accepted successfully.

The corresponding result.resultCode is SUCCESS, and result.resultMessage is success.

U

The status of the addPaymentMethod request is unknown.

The corresponding result.resultCode is UNKNOWN_EXCEPTION, and result.resultMessage is An API call failed, which is caused by unknown reasons. For details, see the Common error codes section.

F

The addPaymentMethod request failed. The corresponding result.resultCode and result.resultMessage may vary based on different situations. For details, see the following Error codes section.

Error codes

Result code

Result status

Result message

Further action

SUCCESS

S

Success

/

PROCESS_FAIL

F

A general business failure occurred. Don't retry.

Human intervention is usually needed. It is recommended that you contact the technical support team to troubleshoot the issue.

PARAM_ILLEGAL

F

Illegal parameters. For example, non-numeric input, or invalid date.

Check and verify whether the request fields, including the header fields and body fields, are correct and valid.

For details on the fields of each API, see the specific API Structure section.

UNKNOWN_EXCEPTION

U

API failed due to unknown reasons.

Call the interface again to resolve the issue. If the issue persists, contact Alipay Technical Support.

REPEAT_REQ_INCONSISTENT

F

Repeat request inconsistent.

Ensure the fields in the requests are the same.

USER_NOT_EXIST

F

The user does not exist.

Contact Alipay Technical Support for detailed reasons.

USER_STATUS_ABNORMAL

F

The user status is abnormal.

Contact the digital wallet to check the user status.

RISK_REJECT

F

Risk reject

The request is rejected because of the high risk.

KEY_NOT_FOUND

F

Key is not found.

Check whether the private key or public key exists. If not, upload the private key in Alipay Developer Center.

INVALID_API

F

API is invalid (or not active).

Check whether the API name, HTTP method, or request format is correct when sending the request.

INVALID_CLIENT

F

Invalid client.

Check whether the client ID is correct, or contact Alipay Technical Support for detailed reasons.

INVALID_SIGNATURE

F

Signature is invalid.

Check whether the private key used to sign a request matches the public key of Alipay Developer Center.

REQUEST_TRAFFIC_EXCEED_LIMIT

U

Request traffic exceeds the limit.

Call the interface again to resolve the issue. If the issue persists, contact Alipay Technical Support.

ACCESS_DENIED

F

Access denied.

Contact Alipay Technical Support for detailed reasons.

SEND_TIMES_EXCEED_LIMIT

F

The send times exceeds the limit

Contact Alipay technical support to know the specific limitation.

METHOD_NOT_SUPPORTED

F

The server does not implement the requested HTTP method.

Ensure the HTTP method is POST.

Samples

Request

The merchant sends a request to DWS.

copy
{
    "customerId":"2162220004751145",
    "env":{
        "clientIp":"203.***.***.***",
        "deviceTokenId":"mu-b3Ess_Qoq3zYaaBecD-mJ52tH7RzQ0-4AhB12n7mysEYgfwEAAAAA",
        "language":"en-SG",
        "sessionId":"********************************",
        "terminalType":"APP",
        "umidTokenId":"BKFLtqFLOh9E/zV/KkRprBxhbakBCMZ+"
    },
    "isTemp":false,
    "paymentMethodDetail":{
        "card":{
            "cardToken":"PYMT1342cf7ca558402cb2d77af09066d906",
            "paymentMethodDetailMetadata":"{\"externalUserId\":\"1023240523\"}"
        },
        "paymentMethodDetailType":"CARD"
    },
    "requestId":"c9f9dfc2-a30f-40f8-ac60-3ba32e3e1ac2",
    "redirectUrl":"https://pages.xxx.com/member/payment-method-add?wh_weex=true&channel=payment-options&redirectUrl=https%3A%2F%2Fpages.xxx.com%2Fwow%2Fi%2Fsg%2Fmember%2Fpayment-options%3Fhybrid%3D1&xxx_event_id=379_1645760576329_47947&merchantTransId=c9f9dfc2-a30f-40f8-ac60-3ba32e3e1ac2"
}

Response

DWS returns the request result.

copy
{
    "actionForm":{

    },
    "requestId":"c9f9dfc2-a30f-40f8-ac60-3ba32e3e1ac2",
    "paymentMethodDetail":{
        "card":{},
        "paymentMethodDetailType":"CARD"
    },
    "result":{
      "resultStatus":"S",
      "resultCode":"SUCCESS",
      "resultMsg":"success"
  }
}