load form in the back, redirect ok, auth fails

This commit is contained in:
carmenmaymo 2023-08-18 15:39:24 +02:00
parent 10613711b9
commit a1f4ead149
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
2 changed files with 63 additions and 56 deletions

View file

@ -72,7 +72,6 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
loadPaypalScript(PayPalCommerceGateway, () => {
bootstrapped = true;
const applepay = paypal.Applepay();
console.log(applepay)
applepay.config()
.then(applepayConfig => {
const appleContainer = document.getElementById("applepay-container");
@ -96,7 +95,6 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
let applePaySession = () => {
const session = new ApplePaySession(4, paymentRequest)
session.begin()
console.log(session)
if (needShipping) {
session.onshippingmethodselected = function (event) {
jQuery.ajax({
@ -115,9 +113,7 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
},
success: (applePayShippingMethodUpdate, textStatus, jqXHR) => {
let response = applePayShippingMethodUpdate.data
console.log('onshippingmethod', response)
selectedShippingMethod = event.shippingMethod
console.log(selectedShippingMethod)
//order the response shipping methods, so that the selected shipping method is the first one
let orderedShippingMethods = response.newShippingMethods.sort((a, b) => {
if (a.label === selectedShippingMethod.label) {
@ -156,7 +152,6 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
success: (applePayShippingContactUpdate, textStatus, jqXHR) => {
let response = applePayShippingContactUpdate.data
updatedContactInfo = event.shippingContact
console.log('onshippingcontact', response)
if (applePayShippingContactUpdate.success === false) {
response.errors = createAppleErrors(response.errors)
}
@ -209,6 +204,7 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
let createOrderInPayPal = actionHandler.createOrder()
const processInWooAndCapture = async (data) => {
try {
console.log('processInWooAndCapture', data)
const billingContact = data.billing_contact
const shippingContact = data.shipping_contact
jQuery.ajax({
@ -222,32 +218,7 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
'billing_contact': billingContact,
'token': event.payment.token,
'shipping_method': selectedShippingMethod,
'mollie-payments-for-woocommerce_issuer_applepay': 'applepay',
'woocommerce-process-checkout-nonce': nonce,
'billing_first_name': billingContact.givenName || '',
'billing_last_name': billingContact.familyName || '',
'billing_company': '',
'billing_country': billingContact.countryCode || '',
'billing_address_1': billingContact.addressLines[0] || '',
'billing_address_2': billingContact.addressLines[1] || '',
'billing_postcode': billingContact.postalCode || '',
'billing_city': billingContact.locality || '',
'billing_state': billingContact.administrativeArea || '',
'billing_phone': billingContact.phoneNumber || '000000000000',
'billing_email': shippingContact.emailAddress || '',
'shipping_first_name': shippingContact.givenName || '',
'shipping_last_name': shippingContact.familyName || '',
'shipping_company': '',
'shipping_country': shippingContact.countryCode || '',
'shipping_address_1': shippingContact.addressLines[0] || '',
'shipping_address_2': shippingContact.addressLines[1] || '',
'shipping_postcode': shippingContact.postalCode || '',
'shipping_city': shippingContact.locality || '',
'shipping_state': shippingContact.administrativeArea || '',
'shipping_phone': shippingContact.phoneNumber || '000000000000',
'shipping_email': shippingContact.emailAddress || '',
'order_comments': '',
'payment_method': 'ppcp-gateway',
'funding_source': 'applepay',
'_wp_http_referer': '/?wc-ajax=update_order_review',
'paypal_order_id': data.paypal_order_id,
@ -255,18 +226,18 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
complete: (jqXHR, textStatus) => {
},
success: (authorizationResult, textStatus, jqXHR) => {
let result = authorizationResult.data
if (authorizationResult.success === true) {
redirectionUrl = result['returnUrl'];
session.completePayment(result['responseToApple'])
window.location.href = redirectionUrl
} else {
result.errors = createAppleErrors(result.errors)
session.completePayment(result)
}
console.log('success authorizationResult', authorizationResult)
if (authorizationResult.result === "success") {
redirectionUrl = authorizationResult.redirect;
//session.completePayment(ApplePaySession.STATUS_SUCCESS)
window.location.href = redirectionUrl
} else {
//session.completePayment(ApplePaySession.STATUS_FAILURE)
}
},
error: (jqXHR, textStatus, errorThrown) => {
console.log('error authorizationResult', errorThrown)
session.completePayment(ApplePaySession.STATUS_FAILURE)
console.warn(textStatus, errorThrown)
session.abort()
},
@ -276,6 +247,7 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
}
}
createOrderInPayPal([], []).then((orderId) => {
console.log('createOrderInPayPal', orderId)
applepay.confirmOrder(
{
orderId: orderId,
@ -283,27 +255,18 @@ import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper
billingContact: event.payment.billingContact
}
).then(
confirmResult => {
() => {
session.completePayment(ApplePaySession.STATUS_SUCCESS);
let data = {
billing_contact: event.payment.billingContact,
shipping_contact: event.payment.shippingContact,
paypal_order_id: orderId
}
processInWooAndCapture(data).then(
() => {
console.log('done in woo and capture')
let result = confirmResult.data
redirectionUrl = result['returnUrl'];
session.completePayment(result['responseToApple'])
window.location.href = redirectionUrl
}
)
processInWooAndCapture(data)
}
)
.catch(err => {
).catch(err => {
console.error('Error confirming order with applepay token');
session.completePayment(ApplePaySession.STATUS_FAILURE);
console.error('Error confirming order with applepay token');
console.error(err);
}
);