PayPal rejects my request to create an order (400 bad Request) if I include the customer’s phone number.
I am using the V2 Orders API, using C and CURL.
Here is an example of the JSON data I POST to
https://api.sandbox.paypal.com/v2/checkout/orders
{
intent:"CAPTURE",
payer:
{
name:
{
given_name:"BOB",
surname:"SMITH"
},
email_address:"[email protected]",
phone:
{
country_code:"011",
national_number:"4162876593"
},
address:
{
address_line_1:"4180 YONGE STREET",
admin_area_2:"TORONTO",
admin_area_1:"ON",
postal_code:"M1S 2A9",
country_code:"CA"
}
},
purchase_units:
[
{
amount:
{
currency_code:"CAD",
value:"90.00"
}
}
],
application_context:
{
brand_name:"Benefit Gala",
landing_page:"LOGIN",
shipping_preference:"NO_SHIPPING",
user_action:"PAY_NOW",
payment_method:
{
payee_preferred:"IMMEDIATE_PAYMENT_REQUIRED"
},
return_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=Y",
cancel_url:"https://Gala.domain.com/cgi-bin/paypal?FZ=4&MF=4&K=SMITH&MR=M&PP=C"
}
}
I have tried a large variety of ways of specifying the phone number.
phone:{ country_code:"01", national_number:"14162876593" },
phone:{ country_code:"01", phone_number: { national_number:"14162876593" } },
and many others.
If I omit the phone number entirely, my request is accepted and the order is created and it can be subsequently captured.
If I include any variant of a phone number object, I get a 400 Bad Request returned.
Somewhere in the PayPal documentation it mentions that in order for the phone number to "be available" it is necessary to turn on Contact Number Required in the merchant account preferences. I have tried all three choices (On, Off, Optional) without effect.
The PayPal documentation has very few detailed examples and most of what I find with Google is for a language library like Java or PHP, which doesn’t help me.
Is anyone passing a payer phone number when creating an order ? A sample of your JSON please !
2
Answers
Mohammed, thanks very much for this !!
The unexpected answer is that the quotes around the field names are required. I have seen many examples where they were not included, and in fact it worked fine without those quotes when the phone number was not specified.
The "phone_type" object is ignored, with HOME specified, the number is still displayed by PayPal as MOBILE, but I can live with that.
Thanks again !!
The payer’s definition (from the api doc) states that:
So I don’t think it’ll accept the the country code.
Also the phone attribute in the payer’s definition is of type phone_with_type :
So its content should follow this structure:
I’m not familiar with paypal’s api, but it seems to me (unless I’m mistaken) that your example doesn’t match what’s described the api’s documentation.
Here is an example from paypal’s documentation that I think is similar to what you want to do :
Update : Test program and results from Paypal’s Sandbox
I added a test program at the end of the answer (and its output from my testing).
The program sends 4 requests using 4 json payloads:
In my testing (in paypal’s sandbox), the first 3 jsons result in a response with a
400 Bad Request
status code. Only the 4th one works and result in a response with a201 Created
status code.Test Program
Before using the program the string
ACCESS_TOKEN_HERE
should be replaced by a valid access token (how to generate it).To build the program with gcc :
gcc -lcurl -o test-paypal test-paypal.c
Output of the test program