Smart Payment Buttons - random errors causing headache

RohanDeveloper
New Community Member

Hi everybody,

 

I'm really hoping that somebody can shed some light onto this one for me - as I think I am going to end up follicularly challenged before too long.

 

We have managed to get the 'Smart' payment button all setup, and for the vast majority of transactions everything works just fine.  However, we are getting some issues that our customers are reporting - and we just can't replicate them.

 

Right now, the largest issue is as follows:

 

  1. Customer clicks on the 'Pay with PayPal' button.
  2. PayPal loads up in a new window.
  3. Customer logs into PayPal.
  4. Customer clicks the 'Pay now' button.
  5. PayPal returns an error saying "Error: The string did not match the expected pattern.".  A generic JavaScript error, and not very helpful.

This specific error is only after the customer has authorised the payment, I've tested the exact same order JSON and it works - so it doesn't appear to be related to the data we are sending (and as I stated previously, the vast majority of transactions are working just fine).

 

Does anybody have any idea what exactly is going on?

 

Many thanks in advance!

 

Steve

Login to Me Too
1 REPLY 1

Dohab
Contributor
Contributor

I don't know what sdk you are using, but when you capture a transaction, make sure you send back the response json object from here https://developer.paypal.com/docs/api/orders/v2/#orders_authorize 

as is.

If you send anything else, the error occurs.

 

I use node without any sdk, so my code looks like this:

 

 

 

app.post('/successpament', async (req, res)=>{

		request.post({
			headers: {
				"content-type": "application/json"
			},
			auth: {
				'username': CLIENT_ID,
				'password': SECRET,
				
			},
			uri: '<a href="https://api.sandbox.paypal.com/v2/checkout/orders/" target="_blank">https://api.sandbox.paypal.com/v2/checkout/orders/</a>' + req.session.orderid + '/capture'

		}, await function(err, result, body) {
			if (err) throw err;
			
			res.send( body );
		});
	});

 

 

 

 

The await function returns 'body'  which is exactly what you need to send back to your 'onApproval' function.

 

That was my case anyway.

 

PS: the uri is 'https://api.sandbox.paypal.com/v2/checkout/orders/' + req.session.orderid + '/capture' but it's been formatted in paypal replay box as <a>

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.