不好请求Paypal

时间:2014-05-05 07:59:05

标签: json rest paypal

您好我正在使用JS开发Web应用程序, 所以我正在使用Paypal REST API开发支付类。 当我发送请求到paypal服务器。 我收到一条消息:

a bad Request 400
{
debug_id: "d32874630015c"

information_link:“https://developer.paypal.com/webapps/developer/docs/api

/#MALFORMED_REQUEST"
message: "Incoming JSON request does not map to API request"
name: "MALFORMED_REQUEST"
}

我在json对象中使用Json表达式:

"{
  "transactions":{
      "transactions":[],
      "amount": {
          "currency": "USD",
          "total": "7.47",
          "details": {
              "shipping":"",
              "subtotal":"",
              "tax":"",
              "fee":""
          }
      },
     "description": "This is the payment transaction description."
   },
  "links": [],
  "intent": "sale",
  "payer":{
      "fundingInstruments": {
          "creditCard": {
              "id":"",
              "number":"4417119669820331",
              "type":"visa",
              "expire_month":"11",
              "expire_year":"2018",
              "cvv2":"874", 
              "first_name":"Joe",
              "last_name":"Shopper",
              "billing_address": {
                  "line1":"52 N Main ST",
                  "line2":"",
                  "country_code":"US",
                  "postal_code":"43210",
                  "state":"OH",
                  "phone":"",
                  "city":"Johnstown"
              },
              "payer_id":"",
              "state":"",
              "valid_until":""
            },
            "creditCardToken": {
                "creditCardId":"",
                "payerId":"",
                "last4":"",
                "type":"",
                "expireMonth":"",
                "expireYear":""
            }
        },
        "paymentMethod":"credit_card"
    }
}"

1 个答案:

答案 0 :(得分:0)

您的JSON中存在很多错误。

{
   "transactions":[
      {
         "amount":{
            "currency":"USD",
            "total":"7.47"
         },
         "description":"This is the payment transaction description."
      }
   ],
   "intent":"sale",
   "payer":{
      "payment_method":"credit_card",
      "funding_instruments":[
         {
            "credit_card":{
               "number":"4417119669820331",
               "type":"visa",
               "expire_month":"11",
               "expire_year":"2018",
               "cvv2":"874",
               "first_name":"Joe",
               "last_name":"Shopper",
               "billing_address":{
                  "line1":"52 N Main ST",
                  "country_code":"US",
                  "postal_code":"43210",
                  "state":"OH",
                  "city":"Johnstown"
               }
            }
         }
      ]
   }
}

您需要确保遵守Rest API Reference中的命名方案。请注意fundingInstruments(您的)与funding_instruments(文档)和creditCard(您的)和credit_card(文档)。此外,funding_instruments是一个数组,因此您需要在工具列表中包含[]

您列出了transactions两次,并且包含的​​信息不应包括payer_idstatecreditcardtoken,而这些信息不存在。如果要将值设置为"",最好不要包含它,因为服务器可能会检查它是否格式正确并给出了此错误。