// Metro module 4519 (f4520). import { Endpoints, REDIRECTED_PAYMENT_SOURCES } from "../../../Constants"; import { PaymentSourceTypes } from "../../../_bundle/Module505"; import { dispatchConfirmationError, popupBridgeState } from "./BillingSharedActionCreators"; import * as _StripeUtils from "../../../utils/StripeUtils"; import { HTTP, getAPIBaseURL } from "../../../_bundle/sendRequest"; let c2727_6, c2727_7; const r24 = {}; r24[PaymentSourceTypes.GIROPAY] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: (a0) => ({ stripeConfirmPayment: a0.stripe.confirmGiropayPayment, paymentMethod: { billing_details: { name: a0.paymentSource.billingAddress.name } } }) }; r24[PaymentSourceTypes.SOFORT] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: (a0) => { const paymentSource = a0.paymentSource; return { stripeConfirmPayment: a0.stripe.confirmSofortPayment, paymentMethod: { sofort: { country: paymentSource.billingAddress.country }, billing_details: { name: paymentSource.billingAddress.name, email: paymentSource.email } } }; } }; r24[PaymentSourceTypes.PRZELEWY24] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: ({ paymentSource, stripe }) => { if (paymentSource.bank == null) { throw dispatchConfirmationError(`PaymentSource (${paymentSource.id}) missing bank info for p24.`); } return { stripeConfirmPayment: stripe.confirmP24Payment, paymentMethod: { p24: { bank: paymentSource.bank }, billing_details: { name: paymentSource.billingAddress.name, email: paymentSource.email } } }; } }; r24[PaymentSourceTypes.BANCONTACT] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: (a0) => { const paymentSource = a0.paymentSource; return { stripeConfirmPayment: a0.stripe.confirmBancontactPayment, paymentMethod: { billing_details: { name: paymentSource.billingAddress.name, email: paymentSource.email } } }; } }; r24[PaymentSourceTypes.EPS] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: ({ paymentSource, stripe }) => { if (paymentSource.bank == null) { throw dispatchConfirmationError(`PaymentSource (${paymentSource.id}) missing bank info for EPS.`); } return { stripeConfirmPayment: stripe.confirmEpsPayment, paymentMethod: { eps: { bank: paymentSource.bank }, billing_details: { name: paymentSource.billingAddress.name } } }; } }; r24[PaymentSourceTypes.IDEAL] = { confirmationType: "stripe_redirect_confirmation", constructStripeConfirmPaymentHandler: ({ paymentSource, stripe }) => { const paymentMethod = { ideal: {}, billing_details: { name: paymentSource.billingAddress.name } }; if (paymentSource.bank != null) { paymentMethod.ideal = { bank: paymentSource.bank }; } return { stripeConfirmPayment: stripe.confirmIdealPayment, paymentMethod }; } }; c2727_6 = r24; const r42 = {}; r42[PaymentSourceTypes.SEPA_DEBIT] = { confirmationType: "stripe_direct_confirmation", constructStripeConfirmPaymentHandler: ({ stripe, paymentMethodId: paymentMethodId4 }) => { if (paymentMethodId4 == null) { throw dispatchConfirmationError("On a sepa payment payment method id cannot be null"); } return { stripeConfirmPayment: stripe.confirmSepaDebitPayment, paymentMethod: paymentMethodId4 }; } }; r42[PaymentSourceTypes.PIX] = { confirmationType: "stripe_direct_confirmation", constructStripeConfirmPaymentHandler: (a0) => ({ stripeConfirmPayment: a0.stripe.confirmPixPayment, paymentMethod: a0.paymentMethodId, pendingCustomerAction: true }) }; c2727_7 = r42; class PaymentConfirmationHandler { constructor(a0, a1) { this.paymentSource = a0; this.payment = a1; this.paymentSourceType = a0.type; this.paymentId = a1.payment_id; } performRedirect(a0) { window.open(a0); } } export { c2727_6 as STRIPE_REDIRECTED_PAYMENT_METHOD_REGISTRY }; export function getIsStripeRedirectedPaymentSource(a0) { return REDIRECTED_PAYMENT_SOURCES.has(a0) && a0 in c2727_6; } export { c2727_7 as STRIPE_DIRECT_CONFIRM_PAYMENT_METHOD_REGISTRY }; export function getIsStripeDirectConfirmationPaymentSource(a0) { return a0 in c2727_7; } class StripePaymentConfirmationHandler extends PaymentConfirmationHandler { constructor(a0, a1) { if (a0 == null) { throw dispatchConfirmationError("Payment source cannot be null on a redirect."); } super(a0, a1); this.stripe = null; const paymentSourceType = this.paymentSourceType; if (REDIRECTED_PAYMENT_SOURCES.has(paymentSourceType) && paymentSourceType in c2727_6) { this.handlerRegistry = c2727_6[this.paymentSourceType]; } else { if (!(this.paymentSourceType in c2727_7)) { throw dispatchConfirmationError("Invalid Payment Source Type - redirect or direct confirmation handlers not found."); } this.handlerRegistry = c2727_7[this.paymentSourceType]; } } async getStripe() { let stripe; const _this = this; let _this7, c25235_1; L17: { c25235_1 = void 0; if (_this.stripe == null) { _this7 = _this; _this7.stripe = await _StripeUtils.getStripe(); if (_this.stripe == null) { throw dispatchConfirmationError("Stripe cannot be null on a redirect."); } stripe = _this.stripe; break L17; } if (_this.stripe == null) { throw dispatchConfirmationError("Stripe cannot be null on a redirect."); } return _this.stripe; } return stripe; } async getPaymentIntentInfo() { const _this2 = this; let c29403_0 = (await HTTP.get({ url: Endpoints.BILLING_STRIPE_PAYMENT_INTENTS(_this2.paymentId), oldFormErrors: true, rejectWithError: true })).body; return { clientSecret: c29403_0.stripe_payment_intent_client_secret, paymentMethodId: c29403_0.stripe_payment_intent_payment_method_id }; } async getStripeRedirect({ clientSecret, state, paymentMethodId }) { const _this3 = this; let c25237_2; c25237_2 = void 0; let c29404_0 = await _this3.getStripe(); let c29404_1 = _this3.handlerRegistry.constructStripeConfirmPaymentHandler({ stripe: c29404_0, paymentSource: _this3.paymentSource, paymentMethodId }); let c29404_2 = c29404_1.stripeConfirmPayment; let c29404_3 = c29404_1.paymentMethod; const aPIBaseURL = getAPIBaseURL(); const paymentSourceType = _this3.paymentSourceType; let c25237_0 = state; if (state == null) { c25237_0 = ""; } let c29404_4 = await c29404_2(clientSecret, { payment_method: c29404_3, return_url: aPIBaseURL + Endpoints.BILLING_POPUP_BRIDGE_CALLBACK_REDIRECT_PREFIX(paymentSourceType, c25237_0, "success") }, { handleActions: false }); let c29404_5 = c29404_4.paymentIntent; let c29404_6 = c29404_4.error; if (c29404_6 != null) { throw dispatchConfirmationError(c29404_6); } if (c29404_5 == null) { throw dispatchConfirmationError("paymentIntent not available with successful api call"); } const next_action = c29404_5.next_action; if ((next_action == null ? void 0 : next_action.redirect_to_url?.url) == null) { throw dispatchConfirmationError("confirm payment did not return a redirect url"); } return c29404_5.next_action.redirect_to_url.url; } async confirmRedirectedPaymentSource({ clientSecret: clientSecret2, paymentMethodId: paymentMethodId2 }) { const _this4 = this; let c25238_1; c25238_1 = void 0; let c29405_0 = await popupBridgeState(_this4.paymentSourceType); let c29405_1 = await _this4.getStripeRedirect({ clientSecret: clientSecret2, state: c29405_0, paymentMethodId: paymentMethodId2 }); _this4.performRedirect(c29405_1); } async confirmDirectPaymentSource({ clientSecret: clientSecret3, paymentMethodId: paymentMethodId3 }) { const _this5 = this; let c25239_1; c25239_1 = void 0; let c29406_0 = await _this5.getStripe(); let c29406_1 = _this5.handlerRegistry.constructStripeConfirmPaymentHandler({ stripe: c29406_0, paymentSource: _this5.paymentSource, paymentMethodId: paymentMethodId3 }); let c29406_2 = c29406_1.stripeConfirmPayment; let c29406_3 = c29406_1.paymentMethod; let c29406_4 = c29406_1.pendingCustomerAction; let c29406_5 = await (0, c29406_2)(clientSecret3, { payment_method: c29406_3 }); let c29406_6 = c29406_5.paymentIntent; let c29406_7 = c29406_5.error; if (c29406_7 != null) { throw dispatchConfirmationError(c29406_7); } if (c29406_6 == null) { throw dispatchConfirmationError("paymentIntent not available with successful stripe call"); } return { pendingCustomerAction: c29406_4, customerActionCancelled: c29406_6.status === "requires_action" }; } async confirmPayment() { const _this6 = this; let c25240_1; let c29407_0, c29407_1, c29407_2, c29407_3; L15: { c25240_1 = void 0; c29407_0 = void 0; c29407_1 = void 0; c29407_2 = void 0; c29407_3 = void 0; c29407_0 = await _this6.getPaymentIntentInfo(); c29407_1 = c29407_0.clientSecret; c29407_2 = c29407_0.paymentMethodId; if (_this6.handlerRegistry.confirmationType === "stripe_redirect_confirmation") { await _this6.confirmRedirectedPaymentSource({ clientSecret: c29407_1, paymentMethodId: c29407_2 }); break L15; } c29407_3 = await _this6.confirmDirectPaymentSource({ clientSecret: c29407_1, paymentMethodId: c29407_2 }); return { redirectConfirmation: false, pendingCustomerAction: c29407_3.pendingCustomerAction, customerActionCancelled: c29407_3.customerActionCancelled }; } return { redirectConfirmation: true }; } } export { StripePaymentConfirmationHandler }; class AdyenPaymentConfirmationHandler extends PaymentConfirmationHandler { constructor(a0, a1) { if (a0 == null) { throw dispatchConfirmationError("Payment source cannot be null on a redirect."); } super(a0, a1); } handleAdyenConfirmation() { let r10; const adyen_redirect_url = this.payment.adyen_redirect_url; if (adyen_redirect_url == null) { throw dispatchConfirmationError("redirect url cannot be null on a redirect for adyen."); } if (REDIRECTED_PAYMENT_SOURCES.has(this.paymentSource.type)) { this.performRedirect(adyen_redirect_url); r10 = { redirectConfirmation: true, redirectURL: adyen_redirect_url }; } else { r10 = { redirectConfirmation: false, redirectURL: adyen_redirect_url }; } return r10; } confirmPayment() { return Promise.resolve(this.handleAdyenConfirmation()); } } export { AdyenPaymentConfirmationHandler };