尝试将$ ajax发布到使用XML数据的authorize.net API时出错

时间:2015-12-07 21:23:31

标签: javascript ajax xml api authorize.net

我目前正在尝试向Authorize.net AIM API发出请求。我已成功发送帖子Man的帖子。我遇到的问题与发布的数据必须是xml这一事实有关。当我尝试将数据设置为xml时,如下面的示例所示,我收到错误的意外令牌ILLEGAL。任何有关此错误的帮助都会很棒。另外,如果有更好的方法来格式化帖子的xml,请告诉我我已经环顾四周但没有成功。

&

2 个答案:

答案 0 :(得分:0)

Luke你现在可以用JSON发布你的请求,Authorize.Net支持JSON,这里是Authorize.net的样本收费信用卡请求

{
    "createTransactionRequest": {
        "merchantAuthentication": {
            "name": "API_LOGIN_ID",
            "transactionKey": "API_TRANSACTION_KEY"
        },
        "refId": "123456",
        "transactionRequest": {
            "transactionType": "authCaptureTransaction",
            "amount": "5",
            "payment": {
                "creditCard": {
                    "cardNumber": "5424000000000015",
                    "expirationDate": "1220",
                    "cardCode": "999"
                }
            },
            "lineItems": {
                "lineItem": {
                    "itemId": "1",
                    "name": "vase",
                    "description": "Cannes logo",
                    "quantity": "18",
                    "unitPrice": "45.00"
                }
            },
            "tax": {
                "amount": "4.26",
                "name": "level2 tax name",
                "description": "level2 tax"
            },
            "duty": {
                "amount": "8.55",
                "name": "duty name",
                "description": "duty description"
            },
            "shipping": {
                "amount": "4.26",
                "name": "level2 tax name",
                "description": "level2 tax"
            },
            "poNumber": "456654",
            "customer": {
                "id": "99999456654"
            },
            "billTo": {
                "firstName": "Ellen",
                "lastName": "Johnson",
                "company": "Souveniropolis",
                "address": "14 Main Street",
                "city": "Pecan Springs",
                "state": "TX",
                "zip": "44628",
                "country": "USA"
            },
            "shipTo": {
                "firstName": "China",
                "lastName": "Bayles",
                "company": "Thyme for Tea",
                "address": "12 Main Street",
                "city": "Pecan Springs",
                "state": "TX",
                "zip": "44628",
                "country": "USA"
            },
            "customerIP": "192.168.1.1",
            "transactionSettings": {
                "setting": {
                    "settingName": "testRequest",
                    "settingValue": "false"
                }
            },
            "userFields": {
                "userField": [
                    {
                        "name": "MerchantDefinedFieldName1",
                        "value": "MerchantDefinedFieldValue1"
                    },
                    {
                        "name": "favorite_color",
                        "value": "blue"
                    }
                ]
            }
        }
    }
}

答案 1 :(得分:0)

我最终使用PHP来发出请求,并且我能够使用xml周围的单引号将xml形成为字符串,如本示例所示。

$retCustXml = '
        <createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
          <merchantAuthentication>
            <name>'.$loginID.'</name>
            <transactionKey>'.$transactionKey.'</transactionKey>
          </merchantAuthentication>
          <refId>1234546</refId>
          <transactionRequest>
            <transactionType>authCaptureTransaction</transactionType>
            <amount>'.$amount.'</amount>
            <profile>
              <customerProfileId>'.$customerProfileId.'</customerProfileId>
              <paymentProfile>
                <paymentProfileId>'.$paymentProfileId.'</paymentProfileId>
              </paymentProfile>
            </profile>
            <order>
              <invoiceNumber>'.$invoiceNumber.'</invoiceNumber>
              <description>'.$description.'</description>
            </order>
          </transactionRequest>


 </createTransactionRequest>

&#39 ;; 谢谢你的帮助。