|
329 | 329 | }); |
330 | 330 |
|
331 | 331 | if (paypal.HostedFields.isEligible() === true) { |
| 332 | + let processingOrderId; |
| 333 | +
|
332 | 334 | paypal.HostedFields.render({ |
333 | 335 | createOrder: function(data, actions) { |
334 | 336 | document.querySelector('#paypal-payment-container').classList.add('loading'); |
|
339 | 341 | }).then(function(res) { |
340 | 342 | return res.json(); |
341 | 343 | }).then(function(data) { |
| 344 | + processingOrderId = data.orderID; |
| 345 | +
|
342 | 346 | return data.orderID; |
343 | 347 | }); |
344 | 348 | }, |
|
419 | 423 |
|
420 | 424 | if (formValid) { |
421 | 425 | hostedFields.submit({ |
| 426 | + contingencies: ['SCA_ALWAYS'], |
422 | 427 | cardholderName: document.getElementById('card-holder-name').value, |
423 | 428 | billingAddress: { |
424 | 429 | streetAddress: document.getElementById('card-billing-address-street').value, |
|
428 | 433 | countryCodeAlpha2: document.getElementById('card-billing-address-country').value |
429 | 434 | } |
430 | 435 | }).then(payload => { |
431 | | - return fetch(completePayPalOrderUrl, { |
432 | | - method: 'post' |
433 | | - }).then(function(res) { |
434 | | - return res.json(); |
| 436 | + if (payload.authenticationReason == 'SUCCESSFUL' && payload.authenticationStatus == 'YES') { |
| 437 | + return fetch(completePayPalOrderUrl, { |
| 438 | + method: 'post' |
| 439 | + }).then(function(res) { |
| 440 | + return res.json(); |
| 441 | + }).then(function(data) { |
| 442 | + if (data.status == 'processing') { |
| 443 | + return fetch(cancelPayPalPaymentUrl, { |
| 444 | + method: 'post', |
| 445 | + headers: { 'content-type': 'application/json' }, |
| 446 | + body: JSON.stringify({ payPalOrderId: data.orderID }) |
| 447 | + }).then(window.location.reload()); |
| 448 | + } |
| 449 | +
|
| 450 | + window.location.href = data.return_url; |
| 451 | + }); |
| 452 | + } |
| 453 | +
|
| 454 | +
|
| 455 | + return fetch(errorPayPalPaymentUrl, { |
| 456 | + method: 'post', |
| 457 | + headers: { 'content-type': 'application/json' }, |
| 458 | + body: JSON.stringify('Invalid 3D Secure authentication.') |
435 | 459 | }).then(function(data) { |
436 | | - if (data.status == 'processing') { |
437 | | - return fetch(cancelPayPalPaymentUrl, { |
438 | | - method: 'post', |
439 | | - headers: { 'content-type': 'application/json' }, |
440 | | - body: JSON.stringify({ payPalOrderId: data.orderID }) |
441 | | - }).then(window.location.reload()); |
442 | | - } |
443 | | -
|
444 | | - window.location.href = data.return_url; |
| 460 | + return fetch(cancelPayPalPaymentUrl, { |
| 461 | + method: 'post', |
| 462 | + headers: { 'content-type': 'application/json' }, |
| 463 | + body: JSON.stringify({ payPalOrderId: processingOrderId }) |
| 464 | + }).then(window.location.reload()); |
445 | 465 | }); |
446 | 466 | }); |
447 | 467 | } else { |
|
0 commit comments