401 Unauthorized responses on sandbox

gRegorLove
Contributor
Contributor

I have set up the Express Checkout with checkout.js per https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-bu... (and subsequent pages). I am testing with credit card transactions and consistently getting a 401 Unauthorized response.

 

For example:

 

POST https://www.sandbox.paypal.com/webapps/hermes/api/payment/PAY-1EE13341N03083707LI5NGIY/execute

401 Unauthorized {"ack":"permission_denied","message":"Permission Denied"}

I've seen REST API documentation saying that payment_method should be set to "paypal" though no corollary documentation/examples for this checkout.js method. Looking in the rest.js source on https://github.com/paypal/paypal-checkout, it appears payment_method defaults to "paypal" anyway.

 

 

I've tried rotating the random credit card numbers I'm using for testing to no avail. Yesterday, very intermittently, I would sometimes get a 401 Unauthorized followed by a retry that then worked. Most of the time I was getting 401 followed by 400. Today I haven't been able to get any successful card transactions, always getting 401.

 

The payment Javascript is really basic and yes, the sandbox clientID and production clientID are set correctly in the script:

 

var tx_total = 100;
var tx_description = 'Test transaction';

paypal.Button.render({

	env: 'sandbox',

	client: {
		sandbox:    '[redacted]',
		production: '[redacted]'
	},

	style: {
		label: 'buynow',
		branding: true,
		size: 'medium'
	},

	commit: true,

	payment: function(data, actions) {
		return actions.payment.create({
			payment: {
				intent: 'sale',
				transactions: [
					{
						amount: {
							total: tx_total,
							currency: 'USD'
						},
						description: tx_description
					}
				]
			}
		});
	}

	// onAuthorize code redacted
}, '#paypal-button');

This is under a client's PayPal account, not mine, by the way.

 

 

Login to Me Too
3 REPLIES 3

MTS_Andre
Moderator
Moderator

Hi, checked the logs for PAY-1EE13341N03083707LI5NGIY (Sandbox) and I can see a valid transaction created 44966262WC836093C. Could you share the corrleationID / Debug ID of the failed execute call related to PAY-1EE13341N03083707LI5NGIY ? It is in the response. In this way I will check exactly that failure.

Login to Me Too

gRegorLove
Contributor
Contributor

@MTS_Andre: Thanks for your help. I don't have the details for that specific transaction, but I just attempted another and included details below. This time I got a 401 Unauthorized followed by a second call to execute that succeeded. The onError() callback seems to be called on the first 401 response, though.

I don't see a correlation ID in any of the response headers or response bodies, but I've included the debug IDs below:

POST https://www.sandbox.paypal.com/v1/payments/payment
{"transactions":[{"amount":{"total":795,"currency":"USD"},"description":"Membership"}],"intent":"sale","redirect_urls":{"return_url":"https://www.sandbox.paypal.com","cancel_url":"https://www.sandbox.paypal.com"},"payer":{"payment_method":"paypal"}}

201 Created
paypal-debug-id: 71ad7fd0aab40
{"id":"PAY-97X47659L8325653DLI6AAJI","intent":"sale","state":"created","payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"795.00","currency":"USD"},"description":"Membership","related_resources":[]}],"create_time":"2017-12-21T18:40:36Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-97X47659L8325653DLI6AAJI","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-01788361D69745944","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-97X47659L8325653DLI6AAJI/execute","rel":"execute","method":"POST"}]}
POST https://www.sandbox.paypal.com/webapps/hermes/api/payment/PAY-97X47659L8325653DLI6AAJI/execute
{"data":{"payer_id":"ZESFVBBXJNRNG"},"meta":{}}

401 Unauthorized
Paypal-Debug-Id: cd7745b8b5b98
{"ack":"permission_denied","message":"Permission Denied"}
POST https://www.sandbox.paypal.com/webapps/hermes/api/payment/PAY-97X47659L8325653DLI6AAJI/execute
{"data":{"payer_id":"ZESFVBBXJNRNG"},"meta":{}}

200 OK
Paypal-Debug-Id: 3684223cecf20
{"ack":"success","data":{"id":"PAY-97X47659L8325653DLI6AAJI","intent":"sale","state":"approved","cart":"01788361D69745944","create_time":"2017-12-21T18:41:22Z","payer":{"payment_method":"paypal","status":"UNVERIFIED","payer_info":{"email":"[redacted]","first_name":"Gregor","middle_name":"Gregor","last_name":"Morrill","payer_id":"ZESFVBBXJNRNG","country_code":"US","shipping_address":{"recipient_name":"Gregor Morrill","line1":"1234 Test","city":"Chicago","state":"IL","postal_code":"60613","country_code":"US"}}},"transactions":[{"amount":{"total":"795.00","currency":"USD","details":{}},"item_list":{},"related_resources":[{"sale":{"id":"6F818598VE957800T","state":"completed","payment_mode":"INSTANT_TRANSFER","protection_eligibility":"ELIGIBLE","parent_payment":"PAY-97X47659L8325653DLI6AAJI","create_time":"2017-12-21T18:41:22Z","update_time":"2017-12-21T18:41:22Z","amount":{"total":"795.00","currency":"USD","details":{"subtotal":"795.00"}}}}]}]},"meta":{"calc":"3684223cecf20","rlog":"%2FP3kPXJZXVIJGT26TplBpEWsCcLN2HOLM4oEkJb2ucRYAgChqld%2FmUNi5bqMc3SDT%2FLrCaLBctAGEqv%2BFGXacA_1607a614041"},"server":"c28BMdhixm2Ts9huFBPhoaVpuGEbV_6Bj952Ok1SVPLWYTc5LmC8v6-FjSABFz2YH2jXKngJpADg2U2XBhFrcbuozEDdSd8GAGRJWq6bAkpQfRXty1niFgW6FoqOd6bItT5fPiJ-CT_lJtDSZeBq05i7ATZzNjjaNKmTKnkOHeBHMj23A0yb77C-XlfiDTma4pc_rf9d_jLTb-YMzvY6BqSqcNAv2u_u0e3s15II3KvB1Tm-Iqz6CoivRlwdAvJV"}

Thanks for any assistance!

Edit: fixed response code 200 => 201, added a paypal-debug-id

Login to Me Too

MTS_Andre
Moderator
Moderator

Hi Gregor, I did some check but is better if you can open a request to us in MTS so that I can investigate further. Open a ticket with us by loading this link https://www.paypal-techsupport.com/ and at the bottom click on "Contact Support". I will see the ticket there or if you want to post the ticket number here I will take it. Thanks.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.