如何使用Authorize.net上的创建事务请求创建付款配置文件

时间:2017-10-04 19:28:18

标签: 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'."
         }
      ]
   }
}

1 个答案:

答案 0 :(得分:2)

您的请求中的字段顺序很重要。它们必须与文档中的内容相匹配。这意味着该字段需要在 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."
            }
        ]
    }
}

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

{
   "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."
            }
        ]
    }
}