How to interrupt PayPal Checkout transaction flow through server integration without errors?

cawecoy
Contributor
Contributor

I am following [this PayPal Checkout's guide to set up transaction through server integration](https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/).

I need to interrupt the transaction flow when some validation fails on the server.

 

On the server:

 

if($this->validate() == false){
return response()->json(['validationError' => true]);
}

 

On the client:

 

paypal.Buttons({
createOrder: function() {
return fetch('/my-server/create-paypal-transaction', {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
if(data.hasOwnProperty('validationError')){
return false; // I GUESS I NEED TO RETURN SOMETHING TO INTERRUPT TRANSACTION HERE, BUT WHAT?
}
return data.orderID;
});
},
onError: function (err) {
// Show an error page here, when an error occurs
}
}).render('#paypal-button-container');

 

By doing that, **the PayPal window is launched and immediately closed: this is the main issue what I want to avoid**. And I get this error on client console:

 

update_client_config_error
Object { err: "Expected an order id to be passed\nze/</<@https://www.sandbox.paypal.com/smart/buttons?locale.lang=pt&locale.country=BR&style.label=pay&style....", timestamp: "1579888892327", referer: "www.sandbox.paypal.com", buttonSessionID: "70540b6b82_mtg6mde6mjy", sessionID: "4462f1e2f2_mtc6ntm6ndy", env: "sandbox" }
buttons:928:21581
unhandled_error
Object { err: "Expected an order id to be passed\nze/</<@https://www.sandbox.paypal.com/smart/buttons?locale.lang=pt&locale.country=BR&style.label=pay&style....", timestamp: "1579888892433", referer: "www.sandbox.paypal.com", buttonSessionID: "70540b6b82_mtg6mde6mjy", sessionID: "4462f1e2f2_mtc6ntm6ndy", env: "sandbox" }
buttons:928:21581
Error: Expected an order id to be passed

 

So, how to interrupt PayPal Checkout transaction flow through server integration without errors on client?

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

MTS_Jennifer
Moderator
Moderator

Hello,

Thank you for posting to the Merchant Technical Support Community.

If you are trying to interrupt the PayPal Checkout to create a confirmation page, here is the information:

https://developer.paypal.com/docs/checkout/integration-features/confirmation-page/

 

That would one way to interrupt the checkout is to force a confirmation page. If you have a confirmation page then your customers would be redirected to your confirmation page after choosing their funding method through PayPal.

 

Thank you,

Jennifer

PayPal

View solution in original post

Login to Me Too
3 REPLIES 3
Solved

MTS_Jennifer
Moderator
Moderator

Hello,

Thank you for posting to the Merchant Technical Support Community.

If you are trying to interrupt the PayPal Checkout to create a confirmation page, here is the information:

https://developer.paypal.com/docs/checkout/integration-features/confirmation-page/

 

That would one way to interrupt the checkout is to force a confirmation page. If you have a confirmation page then your customers would be redirected to your confirmation page after choosing their funding method through PayPal.

 

Thank you,

Jennifer

PayPal

Login to Me Too

danjrichardson
New Community Member

Whilst useful information, this isn't answering the original question.

I'm in a similar situation where I want to prevent the unhandled_error console error if an order id cannot be created via the createOrder method on the server.

Login to Me Too

voss01
Contributor
Contributor

have you solved it?

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.