Smart buttons randomly failing to capture payments.

LesNewell
Contributor
Contributor

I have recently tried implementing smart buttons using code based on the code generated from the smart buttons code generator. I was previously using the old pay now button. I am getting a lot of refused payments, especially if my customer is using a PayPal account. This includes customers I have dealt with who have known good accounts. I appear to be losing roughly 30% of my transactions. Here is an example of my code:

 

 

Near the start of my page:
<script src="https://www.paypal.com/sdk/js?client-id={ID removed}&currency=GBP"></script>
This code is called after my customer agrees to terms and conditions:

paypal.Buttons({
		style: {
			shape: 'rect',
			color: 'silver',
			layout: 'vertical',
			label: 'pay',
		},
		createOrder: function(data, actions) {
		  	JL().info("Creating order");
			return actions.order.create({
			  purchase_units: [{
				  amount: {value: '60'},
				custom_id: '38539',
			  }],
			});
		},
		onApprove: function(data, actions) {
		  	JL().info("Approving order 38539");
		  	JL().info(data);
			showLoading();
			try{
				return actions.order.capture().then(function(details) {
					JL().info(details);
					JL().info("Success");
					appender.sendBatch();
					alert("Transaction completed successfully");
					window.location.href = 'somewhere';
				});			
			}catch(err)
			{
				JL().info(actions);
				hideLoading();
				alert(err.message);
				throw(err);
			}
		}
	}).render('#paypal-button-container');

 

 

The JL stuff is jsnlog which I put in later to try to debug the problem. showLoading and hideLoading show/hide a progress throbber.

When the transaction fails I get an exception that contains the really helpful message "Script error"

 

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

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