in support-frontend/assets/helpers/subscriptionsForms/submit.ts [234:307]
function onPaymentAuthorised(
paymentAuthorisation: PaymentAuthorisation,
dispatch: Dispatch<Action>,
state: SubscriptionsState,
currency?: IsoCurrency,
): void {
const {
billingPeriod,
fulfilmentOption,
orderIsAGift,
productOption,
productPrices,
} = state.page.checkoutForm.product;
const productType = getSubscriptionType(state);
const { paymentMethod } = state.page.checkoutForm.payment;
const { csrf } = state.page.checkoutForm;
const addresses = getAddresses(state);
const pricingCountry =
addresses.deliveryAddress?.country ?? addresses.billingAddress.country;
const productPrice = getProductPrice(
productPrices,
pricingCountry,
billingPeriod,
fulfilmentOption,
productOption,
);
const data = buildRegularPaymentRequest(
state,
paymentAuthorisation,
addresses,
productPrice.promotions,
currency,
);
const handleSubscribeResult = (result: PaymentResult) => {
if (result.paymentStatus === 'success') {
if (result.subscriptionCreationPending) {
dispatch(setStage('thankyou-pending', productType, paymentMethod.name));
} else {
dispatch(setStage('thankyou', productType, paymentMethod.name));
}
const printPriceDiscounted = getPrintDiscountedPrice(
productPrice,
data.appliedPromotion?.promoCode,
);
const { currencyId } = state.common.internationalisation;
// GTM: track print subscription conversion
successfulSubscriptionConversion(
printPriceDiscounted,
currencyId,
paymentMethod.name,
billingPeriod,
productType,
);
// QM: track print subscription conversion
sendEventSubscriptionCheckoutConversion(
productType,
!!orderIsAGift,
productPrice,
billingPeriod,
);
} else if (result.error) {
dispatch(setSubmissionError(result.error));
}
};
dispatch(setFormSubmitted(true));
void postRegularPaymentRequest(routes.subscriptionCreate, data, csrf).then(
handleSubscribeResult,
);
}