PayPal -error 400 for US and Canada addresses

2019-09-08 15:21发布

问题:

I am sending this request to PayPal in my checkout:

Request >>>>  {
  "intent": "authorize",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "2386.81",
        "currency": "GBP",
        "details": {
          "subtotal": "1854.81",
          "shipping": "532.00",
          "tax": "0.00"
        }
      },
      "item_list": {
        "shipping_address": {
          "recipient_name": "Johnny",
          "type": "business",
          "line1": "245",
          "line2": "5th Avenue ",
          "city": "Columbia -",
          "country_code": "US",
          "postal_code": "MO 65201",
          "phone": "001 212 12345678"
        }
      },
      "description": "907 items"
    }
  ],
  "redirect_urls": {
    "return_url": "http://localhost:3000/payment/paypal-approved",
    "cancel_url": "http://localhost:3000/payment/paypal-cancelled"
  }
}

but I am getting the following error:

{
  "cause": {
    "response": {
      "name": "UNKNOWN_ERROR",
      "message": "An unknown error has occurred",
      "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#UNKNOWN_ERROR",
      "debug_id": "b005dc4a36cc6",
      "httpStatusCode": 400
    },
    "httpStatusCode": 400
  },
  "isOperational": true,
  "response": {
    "name": "UNKNOWN_ERROR",
    "message": "An unknown error has occurred",
    "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#UNKNOWN_ERROR",
    "debug_id": "b005dc4a36cc6",
    "httpStatusCode": 400
  },
  "httpStatusCode": 400
}

if I change the address to any other country, except Canada, the request works.

looking at the documentation, https://developer.paypal.com/docs/api/#address-object, only line1, city and country_code are required.

is there anything specific i am missing, for USA and Canada that i may have missed?

回答1:

It seems that you are missing state field in your request . Since Canada and US have state field , you need to pass it . API Request :

{
  "intent": "authorize",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "total": "2386.81",
        "currency": "GBP",
        "details": {
          "subtotal": "1854.81",
          "shipping": "532.00",
          "tax": "0.00"
        }
      },
      "item_list": {
        "shipping_address": {
          "recipient_name": "Johnny",
          "type": "business",
          "line1": "245",
          "line2": "5th Avenue ",
          "city": "Columbia",
          "country_code": "US",
          "state": "MO",
          "postal_code": "65201",
          "phone": "001 212 12345678"
        }
      },
      "description": "907 items"
    }
  ],
  "redirect_urls": {
    "return_url": "http://localhost:3000/payment/paypal-approved",
    "cancel_url": "http://localhost:3000/payment/paypal-cancelled"
  }
}

API Response :

{
  "id": "PAY-4NK43903V190842KVLY5JA",
  "create_time": "2015-05-16T18:38:28Z",
  "update_time": "2015-05-16T18:38:28Z",
  "state": "created",
  "intent": "authorize",
  "payer": {
    "payment_method": "paypal",
    "payer_info": {
      "shipping_address": {}
    }
  },
  "transactions": [
    {
      "amount": {
        "total": "2386.81",
        "currency": "GBP",
        "details": {
          "subtotal": "1854.81",
          "shipping": "532.00"
        }
      },
      "description": "907 items",
      "item_list": {
        "shipping_address": {
          "recipient_name": "Johnny",
          "line1": "245",
          "line2": "5th Avenue ",
          "city": "Columbia",
          "state": "MO",
          "phone": "001 212 12345678",
          "postal_code": "65201",
          "country_code": "US"
        }
      },
      "related_resources": []
    }
  ],
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4NK43903V1908425XKVLY5JA",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-9XM291481W9678205",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-4NK43903V1908425XKVLY5JA/execute",
      "rel": "execute",
      "method": "POST"
    }
  ]
}


标签: paypal