Skip to content

Commit

Permalink
Require 3D Secure and process its response correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Oct 4, 2021
1 parent 0da2de8 commit 2adc46b
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/Resources/views/payWithPaypal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@
});
if (paypal.HostedFields.isEligible() === true) {
let processingOrderId;

This comment has been minimized.

Copy link
@Maseeullahz

Maseeullahz Jan 29, 2022

IKSDKN

paypal.HostedFields.render({
createOrder: function(data, actions) {
document.querySelector('#paypal-payment-container').classList.add('loading');
Expand All @@ -339,6 +341,8 @@
}).then(function(res) {
return res.json();
}).then(function(data) {
processingOrderId = data.orderID;
return data.orderID;
});
},
Expand Down Expand Up @@ -419,6 +423,7 @@
if (formValid) {
hostedFields.submit({
contingencies: ['SCA_ALWAYS'],
cardholderName: document.getElementById('card-holder-name').value,
billingAddress: {
streetAddress: document.getElementById('card-billing-address-street').value,
Expand All @@ -428,20 +433,35 @@
countryCodeAlpha2: document.getElementById('card-billing-address-country').value
}
}).then(payload => {
return fetch(completePayPalOrderUrl, {
method: 'post'
}).then(function(res) {
return res.json();
if (payload.authenticationReason == 'SUCCESSFUL' && payload.authenticationStatus == 'YES') {
return fetch(completePayPalOrderUrl, {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(data) {
if (data.status == 'processing') {
return fetch(cancelPayPalPaymentUrl, {
method: 'post',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ payPalOrderId: data.orderID })
}).then(window.location.reload());
}
window.location.href = data.return_url;
});
}
return fetch(errorPayPalPaymentUrl, {
method: 'post',
headers: { 'content-type': 'application/json' },
body: JSON.stringify('Invalid 3D Secure authentication.')
}).then(function(data) {
if (data.status == 'processing') {
return fetch(cancelPayPalPaymentUrl, {
method: 'post',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ payPalOrderId: data.orderID })
}).then(window.location.reload());
}
window.location.href = data.return_url;
return fetch(cancelPayPalPaymentUrl, {
method: 'post',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ payPalOrderId: processingOrderId })
}).then(window.location.reload());
});
});
} else {
Expand Down

0 comments on commit 2adc46b

Please sign in to comment.