// Metro module 6218 (f6219). import { createContext, useContext } from "react"; import OrderRecord from "../../payments/records/OrderRecord"; import ContextUtils from "../../../utils/ContextUtils"; import { shallow } from "../../../_bundle/Module3802"; import { createWithEqualityFn } from "../../../_bundle/identity_700"; import { patchOrder, createOrder } from "../../payments/native/OrderActionCreators"; import Module12 from "../../../_bundle/Module12"; import { captureBillingException } from "../../../utils/BillingUtils"; import { showCheckoutOrderErrorModal } from "./showCheckoutOrderErrorModal"; function $mk117975($env) { return () => { const r1 = $env; return (0, $env.$parent[2])(r1[0], r1[1]); }; } function $mk117976($env) { return () => (0, $env.$parent[4])($env[0]); } let env3946 = {}; const [r26, c3946_6] = ContextUtils(); const context = createContext("unset_context"); const c3946_7 = context; export { context as NativeCheckoutStoreContextOrNull }; export function useNativeCheckoutStore(a0, r3 = shallow) { return c3946_6()(a0, r3); } export function useNativeCheckoutStoreOrNull(a0, r4 = shallow) { const context = useContext(c3946_7); return context !== "unset_context" ? context(a0, r4) : null; } export function createNativeStore(a0) { let env15592 = { $parent: env3946 }; env15592[0] = a0.order; env15592[1] = a0.checkoutInitParameters; env15592[2] = a0.contextMetadata; env15592[3] = a0.paymentGateway; env15592[4] = a0.orderRequired; env15592[5] = a0.onOrderRetryCancellation; return createWithEqualityFn((a0, a1) => { let env25750 = { $parent: env15592 }; env25750[0] = a0; env25750[1] = a1; env25750[2] = function runPatchOrderLineItems() { return env25750[3].apply(this, arguments); }; env25750[3] = function _runPatchOrderLineItems() { const r9 = async (orderLineItems, externalGatewayFacet) => { const orderRecord = (0, env25750[1])().orderRecord; if (orderRecord == null) { throw new Error("Patch being called in a missing order state"); } let c31953_0 = await patchOrder({ orderId: orderRecord.id, expectedRevision: orderRecord.revision, orderLineItems, externalGatewayFacet }); (0, env25750[0])({ orderRecord: OrderRecord.createFromServer(c31953_0) }); return c31953_0; }; env25750[3] = r9; return r9.apply(this, arguments); }; env25750[4] = function runRecreateOrder() { return env25750[5].apply(this, arguments); }; env25750[5] = function _runRecreateOrder() { const r9 = async (c31405_0) => { let c31405_1, c31405_2; L18: { let env31954; c31405_2 = env25750; const r30 = env31954 = {}; c31405_1 = r30; env31954[0] = void 0; const orderRecord = (0, env25750[1])().orderRecord; if (orderRecord != null) { const orderLineItems2 = orderRecord.orderLineItems.map((orderLineItem) => ({ sku_id: orderLineItem.sku_id, quantity: orderLineItem.quantity, purchase_type: orderLineItem.purchase_type, subscription_plan_id: orderLineItem.subscription_plan_id })); const r39 = Module12.some(orderLineItems2, (a0) => a0.subscription_plan_id != null); let subscriptionFacet = void 0; if (r39) { const r47 = { subscription_preview: { currency: c31405_0.currency, country_code: c31405_0.country } }; const activeSubscription = env15592[1].activeSubscription; subscriptionFacet = r47; if (activeSubscription != null) { r47.subscription_id = env15592[1].activeSubscription.id; subscriptionFacet = r47; } } env31954[0] = await createOrder({ orderLineItems: orderLineItems2, paymentGateway: env15592[3], isGift: env15592[1].isGift, subscriptionFacet, externalGatewayFacet: orderRecord.externalGatewayFacet != null ? { line_items: orderRecord.externalGatewayFacet.line_items.map((line_item) => ({ external_product_id: line_item.external_product_id })) } : void 0, countryCode: c31405_0.country }); (0, env25750[0])({ orderRecord: OrderRecord.createFromServer(env31954[0]) }); break L18; } return void 0; } }; env25750[5] = r9; return r9.apply(this, arguments); }; const r6 = env15592[0]; const orderRecord = r6 != null ? OrderRecord.createFromServer(r6) : null; env25750[7] = async (c29693_0, c29693_1) => { let r25, r27; let c29693_2, c29693_3, c29693_4; let c29693_5 = 0; const r12 = env25750; try { let env31406; c29693_3 = r12; const r33 = env31406 = { $parent: r12 }; c29693_2 = r33; env31406[0] = c29693_0; env31406[1] = c29693_1; c29693_5 = 2; (0, env25750[0])({ isPatchOrderLoading: true }); r25 = await (0, env25750[2])(c29693_0, c29693_1); c29693_5 = 0; (0, env25750[0])({ isPatchOrderLoading: false }); } catch ($e) { const r31 = $e; let r7 = r31; c29693_4 = r31; let r32 = c29693_5; if (r32 !== 0) { while (true) { if (r32 !== 1) { try { const r66 = c29693_4; c29693_5 = 1; env31406[2] = r66; const r72 = env31406[2]; const id = (0, env25750[1])().orderRecord?.id; const r79 = c29693_2; captureBillingException(r72, { tags: { source: "NativeCheckoutStore_patchOrderLineItems" }, extra: { orderId: id } }); r27 = await showCheckoutOrderErrorModal($mk117975(r79)); c29693_5 = 0; (0, env25750[0])({ isPatchOrderLoading: false }); } catch (r63) { r7 = r63; c29693_4 = r63; r32 = c29693_5; if (r32 === 0) { break; } continue; } return r27; } try { const r116 = c29693_4; c29693_5 = 0; (0, env25750[0])({ isPatchOrderLoading: false }); throw r116; } catch (r114) { r7 = r114; c29693_4 = r114; r32 = c29693_5; if (r32 === 0) { break; } } } } throw r7; } return r25; }; env25750[6] = async (c29694_0) => { let c29694_1, c29694_2, c29694_3; let c29694_4 = 0; const r12 = env25750; L10: { try { let env31407; c29694_2 = r12; const r33 = env31407 = { $parent: r12 }; c29694_1 = r33; env31407[0] = c29694_0; c29694_4 = 2; (0, env25750[0])({ isCreateOrderLoading: true }); await (0, env25750[4])(c29694_0); c29694_4 = 1; c29694_4 = 0; (0, env25750[0])({ isCreateOrderLoading: false }); } catch ($e) { const r31 = $e; let r7 = r31; c29694_3 = r31; let r32 = c29694_4; if (r32 !== 0) { while (true) { if (r32 === 1) { try { const r117 = c29694_3; c29694_4 = 0; (0, env25750[0])({ isCreateOrderLoading: false }); throw r117; } catch (r115) { r7 = r115; c29694_3 = r115; r32 = c29694_4; if (r32 === 0) { break; } } } else { try { const r66 = c29694_3; c29694_4 = 1; env31407[1] = r66; const r71 = env31407[1]; const id = (0, env25750[1])().orderRecord?.id; const r78 = c29694_1; const r79 = c29694_2; captureBillingException(r71, { tags: { source: "NativeCheckoutStore_recreateOrder" }, extra: { orderId: id } }); const r88 = r79.$parent[5]; await showCheckoutOrderErrorModal($mk117976(r78), r88); c29694_4 = 0; (0, env25750[0])({ isCreateOrderLoading: false }); break L10; } catch (r63) { r7 = r63; c29694_3 = r63; r32 = c29694_4; if (r32 === 0) { break; } } } } } throw r7; } } }; return { orderRecord, setOrder: (a0) => (0, env25750[0])({ orderRecord: OrderRecord.createFromServer(a0) }), getCheckoutContextRecord: () => { const orderRecord = (0, env25750[1])().orderRecord; return orderRecord != null ? orderRecord.checkoutContextRecord : null; }, isPatchOrderLoading: false, patchOrderLineItems: function() { return env25750[7].apply(this, arguments); }, isCreateOrderLoading: false, recreateOrder: function() { return env25750[6].apply(this, arguments); }, checkoutInitParameters: env15592[1], contextMetadata: env15592[2], orderRequired: env15592[4], checkoutSucceeded: false, setCheckoutSucceeded: () => (0, env25750[0])({ checkoutSucceeded: true }), onOrderRetryCancellation: env15592[5] }; }, shallow); } export { r26 as NativeCheckoutStoreContext };