cancel
Showing results for 
Search instead for 
Did you mean: 

Requesting payment ID returns 500 Internal Server Error

SOLVED
Highlighted
Member

Requesting payment ID returns 500 Internal Server Error

Hello how do you do,

 

I'm trying to setup PayPal payments but I got stuck in an 500 internal server error when posting a curl request to:

https://api.sandbox.paypal.com/v1/payments/payment

 

Here's the data I'm sending

{"intent":"sale","redirect_urls":{"return_url":"https://www.excellent-way.com/payment-return/","cancel_url":"https://www.excellent-way.com/payment-return/"},"payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"7.47","currency":"USD"},"description":"This is the payment transaction description."}]}

 

Here's the full curl log:

* Hostname was found in DNS cache
*   Trying 173.0.82.78...
* Connected to api.sandbox.paypal.com (173.0.82.78) port 443 (#80)
* SSL connection using TLSv1.2 / AES256-SHA256
* Server certificate:
* 	 subject: C=US; ST=California; L=San Jose; O=PayPal, Inc.; OU=PayPal Production; CN=api.sandbox.paypal.com
* 	 start date: 2016-01-13 00:00:00 GMT
* 	 expire date: 2018-01-13 23:59:59 GMT
* 	 issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 Secure Server CA - G4
* 	 SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> POST /v1/payments/payment HTTP/1.1
Host: api.sandbox.paypal.com
Accept: application/json
Accept-Language: en_US
content-type: application/x-www-form-urlencoded
Authorization: Bearer XXXXXXXX
Content-Length: 540

* upload completely sent off: 540 out of 540 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Sat, 02 Dec 2017 10:51:41 GMT
* Server Apache is not blacklisted
< Server: Apache
< paypal-debug-id: a442e2f24ee14
< Connection: close
< HTTP_X_PP_AZ_LOCATOR: sandbox.slc
< Paypal-Debug-Id: a442e2f24ee14
< Set-Cookie: X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dapiplatformproxyserv%26TIME%3D3179618906%26HTTP_X_PP_AZ_LOCATOR%3Dsandbox.slc; Expires=Sat, 02 Dec 2017 11:21:41 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
< Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT
< Vary: Authorization
< Content-Length: 0
< Content-Type: text/plain; charset=ISO-8859-1
< 
* Closing connection 80

I've tried live as well as sandbox, both return same error..

I checked the server status and it's working, what could be the issue?

 

Thank You,

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Requesting payment ID returns 500 Internal Server Error

Hello,

You appear to be passing "application/x-www-form-urlencoded" for the "content-type", when it should be "application/json".

 

You appear to be sending it in some of your requests, but not in the ones where the failures occur.

Let me know the outcome !


Was my post helpful? If so, please give me a kudos!
6 REPLIES
Moderator

Re: Requesting payment ID returns 500 Internal Server Error

Hi @EhabSherif

Here is how the request should look.

Submit with this request and it should work ok.

{
"intent":"sale",
"redirect_urls":{
"return_url":"https://www.excellent-way.com/payment-return",
"cancel_url":"https://www.excellent-way.com/payment-return"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}

Was my post helpful? If so, please give me a kudos!
Member

Re: Requesting payment ID returns 500 Internal Server Error

Same problem I'm afraid..

 

Here's my PHP curl request if it helps..

 

function makePayment($accessToken){
	$data = '{
	"intent":"sale",
	"redirect_urls":{
	"return_url":"https://www.excellent-way.com/payment-return",
	"cancel_url":"https://www.excellent-way.com/payment-return"
	},
	"payer":{
	"payment_method":"paypal"
	},
	"transactions":[
	{
	"amount":{
	"total":"7.47",
	"currency":"USD"
	},
	"description":"This is the payment transaction description."
	}
	]
	}';

	$verbose = fopen('php://temp', 'w+');
	$curl = curl_init();
	curl_setopt_array($curl, array(
		CURLOPT_RETURNTRANSFER => 1,
		CURLOPT_VERBOSE => true,
		CURLOPT_STDERR => $verbose,
		CURLOPT_SSL_VERIFYPEER => false,
		CURLOPT_SSL_VERIFYHOST => false,
		CURLOPT_URL => "https://api.sandbox.paypal.com/v1/payments/payment",
		CURLOPT_POST => 1,
		CURLOPT_HTTPHEADER => array(
		'Accept: application/json',
		'Accept-Language: en_US',
		'content-type: application/x-www-form-urlencoded',
		'Authorization: Bearer ' . $accessToken
		),
		CURLOPT_POSTFIELDS => $data,
	));

	$response = curl_exec($curl);
	if ($response === FALSE) {
		printf("cUrl error (#%d): %s<br>\n", curl_errno($curl),
			   htmlspecialchars(curl_error($curl)));
	}
	rewind($verbose);
	$verboseLog = stream_get_contents($verbose);
	echo "<pre>", htmlspecialchars($verboseLog), "</pre>\n";
	curl_close($curl);
	return json_decode($response,true);
}

Thanks

Moderator

Re: Requesting payment ID returns 500 Internal Server Error

Hello,

Can you share the paypal-debug-id returned for this attempt ?

Was my post helpful? If so, please give me a kudos!
Member

Re: Requesting payment ID returns 500 Internal Server Error

Paypal-Debug-Id: e7d0755746156

Moderator

Re: Requesting payment ID returns 500 Internal Server Error

Hello,

You appear to be passing "application/x-www-form-urlencoded" for the "content-type", when it should be "application/json".

 

You appear to be sending it in some of your requests, but not in the ones where the failures occur.

Let me know the outcome !


Was my post helpful? If so, please give me a kudos!
Member

Re: Requesting payment ID returns 500 Internal Server Error

That was the problem indeed Smiley Happy Thanks