Skip to content

Commit

Permalink
Testing apple pay
Browse files Browse the repository at this point in the history
  • Loading branch information
Petrisor Frincu committed Sep 3, 2024
1 parent f3f26b5 commit c7512f1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/web/components/PayPal/ApplePayButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,38 @@ const applePayPayment = async () => {
paymentSession.onpaymentauthorized = async (event: ApplePayJS.ApplePayPaymentAuthorizedEvent) => {
try {
console.log('Starting transaction creation...');
const transaction = await createTransaction('applepay');
if (!transaction || !transaction.id) throw new Error('Transaction creation failed.');
console.log('Creating order...');
const order = await createOrder({
paymentId: cart.value.methodOfPaymentId,
shippingPrivacyHintAccepted: shippingPrivacyAgreement.value,
});
if (!order || !order.order || !order.order.id) throw new Error('Order creation failed.');
console.log('Confirming Apple Pay order...');
await applePay.confirmOrder({
orderId: transaction?.id ?? '',
orderId: transaction.id,
token: event.payment.token,
billingContact: event.payment.billingContact,
});
console.log('Executing order...');
await executeOrder({
mode: 'paypal',
plentyOrderId: Number.parseInt(orderGetters.getId(order)),
// eslint-disable-next-line promise/always-return
paypalTransactionId: transaction?.id ?? '',
paypalTransactionId: transaction.id,
});
paymentSession.completePayment(ApplePaySession.STATUS_SUCCESS);
console.log('Payment successful, clearing cart and navigating...');
clearCartItems();
navigateTo(localePath(paths.confirmation + '/' + order.order.id + '/' + order.order.accessKey));
} catch (error) {
console.error(error);
console.error('Error during payment process:', error);
paymentSession.completePayment(ApplePaySession.STATUS_FAILURE);
}
};
Expand Down

0 comments on commit c7512f1

Please sign in to comment.