如何使用 Authorize.net 上的创建交易请求创建付款资料

How to create payment profile with the create transaction request on Authorize.net

我想使用 createTransactionRequest 创建付款配置文件。

这是我传递的请求参数。

{
   "createTransactionRequest":{
      "merchantAuthentication":{
         "name":"***",
         "transactionKey":"***"
      },
      "transactionRequest":{
         "transactionType":"authCaptureTransaction",
         "amount":"4.95",
         "payment":{
            "creditCard":{
               "cardNumber":"5424000000000015",
               "expirationDate":"1217",
               "cardCode":123
            }
         },
         "billTo":{
            "firstName":"first name",
            "lastName":"last name",
            "address":"test address",
            "city":"test city",
            "state":"TX",
            "zip":"12345",
            "country":"USA"
         },
         "profile":{
            "createProfile":true
         }
      }
   }
}

这里是响应错误。

{
   "messages":{
      "resultCode":"Error",
      "message":[
         {
            "code":"E00003",
            "text":"The element 'transactionRequest' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element 'profile' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'. List of possible elements expected: 'shipTo, customerIP, cardholderAuthentication, retail, employeeId, transactionSettings, userFields, surcharge, merchantDescriptor, subMerchant, tip' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd'."
         }
      ]
   }
}

请求中字段的顺序很重要。它们必须与文档中的内容相匹配。这意味着该字段需要 之前 JSON:

中的 billTo 字段
{
   "createTransactionRequest":{
      "merchantAuthentication":{
         "name":"***",
         "transactionKey":"***"
      },
      "transactionRequest":{
         "transactionType":"authCaptureTransaction",
         "amount":"4.95",
         "payment":{
            "creditCard":{
               "cardNumber":"5424000000000015",
               "expirationDate":"1217",
               "cardCode":123
            }
         },
         "profile":{
            "createProfile":true
         },
         "billTo":{
            "firstName":"first name",
            "lastName":"last name",
            "address":"test address",
            "city":"test city",
            "state":"TX",
            "zip":"12345",
            "country":"USA"
         },
      }
   }
}

这个请求产生了这个响应:

{
    "transactionResponse": {
        "responseCode": "1",
        "authCode": "Y77MQH",
        "avsResultCode": "Y",
        "cvvResultCode": "P",
        "cavvResultCode": "2",
        "transId": "40007520179",
        "refTransID": "",
        "transHash": "94D188D090B695D7C6D47D9293840BE3",
        "testRequest": "0",
        "accountNumber": "XXXX0015",
        "accountType": "MasterCard",
        "messages": [
            {
                "code": "1",
                "description": "This transaction has been approved."
            }
        ],
        "transHashSha2": "9768048279544EDB22BAAAC194CA3EDBA705FBC569AC9555F3A2A86E545938849CEB2D9519885A4CC69328BBB7DDC36E0852998CAD5FAC1F6CA6427599E3493B"
    },
    "profileResponse": {
        "messages": {
            "resultCode": "Error",
            "message": [
                {
                    "code": "E00102",
                    "text": "Customer Info is missing."
                }
            ]
        }
    },
    "messages": {
        "resultCode": "Ok",
        "message": [
            {
                "code": "I00001",
                "text": "Successful."
            }
        ]
    }
}

您似乎需要在 customer 部分添加 id 字段:

{
   "createTransactionRequest":{
      "merchantAuthentication":{
         "name":"***",
         "transactionKey":"***"
      },
      "transactionRequest":{
         "transactionType":"authCaptureTransaction",
         "amount":"4.95",
         "payment":{
            "creditCard":{
               "cardNumber":"5424000000000015",
               "expirationDate":"1217",
               "cardCode":123
            }
         },
         "profile":{
            "createProfile":true
         },
         "customer":{
            "id":<yourIdForThisUser>
         },
         "billTo":{
            "firstName":"first name",
            "lastName":"last name",
            "address":"test address",
            "city":"test city",
            "state":"TX",
            "zip":"12345",
            "country":"USA"
         },
      }
   }
}

结果:

{
    "transactionResponse": {
        "responseCode": "1",
        "authCode": "SCSVNX",
        "avsResultCode": "Y",
        "cvvResultCode": "P",
        "cavvResultCode": "2",
        "transId": "40007520393",
        "refTransID": "",
        "transHash": "DFB7FE5B8D3FAFE0A18A6B5C125838A3",
        "testRequest": "0",
        "accountNumber": "XXXX0015",
        "accountType": "MasterCard",
        "messages": [
            {
                "code": "1",
                "description": "This transaction has been approved."
            }
        ],
        "transHashSha2": "57C6A161A948E5A7F5303FCD2FE8CDF3E1D3C38B989161675D47FD61526F3DA9EDBD497169F978860B78A2C5FEC1B6E54807086DF4B0CE346538DDDD9E25C4A8"
    },
    "profileResponse": {
        "messages": {
            "resultCode": "Ok",
            "message": [
                {
                    "code": "I00001",
                    "text": "Successful."
                }
            ]
        },
        "customerProfileId": "1502546960",
        "customerPaymentProfileIdList": [
            "1502081232"
        ],
        "customerShippingAddressIdList": []
    },
    "messages": {
        "resultCode": "Ok",
        "message": [
            {
                "code": "I00001",
                "text": "Successful."
            }
        ]
    }
}