@cimplify/sdk 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +136 -18
- package/dist/advanced.mjs +136 -18
- package/dist/{client-DnAfLDhV.d.mts → client-6MsOWo8f.d.mts} +20 -1
- package/dist/{client-hKTJv1I1.d.ts → client-CVJ0S99a.d.ts} +20 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +136 -18
- package/dist/index.mjs +136 -18
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +136 -18
- package/dist/react.mjs +136 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ab as AUTHORIZATION_TYPE, ag as AUTH_MUTATION, a0 as AbortablePromise, cd as AddressData, cG as AddressInfo, aQ as AmountToPay, co as AuthResponse, A as AuthService, m as AuthStatus, cI as AuthenticatedCustomer, cK as AuthenticatedData, c1 as AvailabilityCheck, c2 as AvailabilityResult, bG as AvailableSlot, bJ as Booking, bI as BookingStatus, bK as BookingWithDetails, b8 as BufferTimes, bn as Business, bB as BusinessHours, bm as BusinessPreferences, B as BusinessService, bA as BusinessSettings, bl as BusinessType, by as BusinessWithLocations, a4 as CHECKOUT_MODE, ah as CHECKOUT_MUTATION, a7 as CHECKOUT_STEP, ad as CONTACT_TYPE, bR as CancelBookingInput, bS as CancelBookingResult, b2 as CancelOrderInput, ba as CancellationPolicy, i as CartOperations, b as CatalogueQueries, aD as CatalogueResult, aE as CatalogueSnapshot, bC as CategoryInfo, bO as CheckSlotAvailabilityInput, bP as CheckSlotAvailabilityResult, cr as CheckoutAddressInfo, cO as CheckoutCartData, cN as CheckoutCartItem, ct as CheckoutCustomerInfo, N as CheckoutFormData, b0 as CheckoutInput, D as CheckoutMode, j as CheckoutOperations, H as CheckoutOrderType, J as CheckoutPaymentMethod, V as CheckoutResult, j as CheckoutService, _ as CheckoutStatus, $ as CheckoutStatusContext, K as CheckoutStep, C as CimplifyClient, a as CimplifyConfig, t as CimplifyElement, s as CimplifyElements, a3 as ContactType, c9 as CreateAddressInput, cb as CreateMobileMoneyInput, c4 as Customer, c5 as CustomerAddress, bM as CustomerBooking, bL as CustomerBookingServiceItem, c7 as CustomerLinkPreferences, c6 as CustomerMobileMoney, b7 as CustomerServicePreferences, al as DEFAULT_COUNTRY, ak as DEFAULT_CURRENCY, ac as DEVICE_TYPE, bH as DayAvailability, bh as DepositResult, a2 as DeviceType, v as ELEMENT_TYPES, E as EVENT_TYPES, cF as ElementAppearance, cR as ElementEventHandler, z as ElementEventType, x as ElementOptions, y as ElementType, cL as ElementsCheckoutData, cM as ElementsCheckoutResult, cJ as ElementsCustomerInfo, w as ElementsOptions, cf as EnrollAndLinkOrderInput, ci as EnrollAndLinkOrderResult, cc as EnrollmentData, ao as Err, aP as FeeBearerType, F as FetchQuoteInput, aN as FulfillmentLink, aM as FulfillmentStatus, aL as FulfillmentType, cv as FxQuote, cu as FxQuoteRequest, cw as FxRateResponse, q as FxService, bN as GetAvailableSlotsInput, l as GetOrdersOptions, G as GetProductsOptions, cQ as IframeToParentMessage, I as InventoryService, c3 as InventorySummary, af as LINK_MUTATION, ae as LINK_QUERY, aR as LineItem, aI as LineType, c8 as LinkData, ch as LinkEnrollResult, L as LinkService, cj as LinkSession, cg as LinkStatusResult, r as LiteBootstrap, p as LiteService, bq as Location, bk as LocationAppointment, c0 as LocationStock, bo as LocationTaxBehavior, bp as LocationTaxOverrides, bt as LocationTimeProfile, bz as LocationWithDetails, M as MESSAGE_TYPES, aa as MOBILE_MONEY_PROVIDER, ce as MobileMoneyData, cs as MobileMoneyDetails, a1 as MobileMoneyProvider, W as NextAction, aj as ORDER_MUTATION, a5 as ORDER_TYPE, cD as ObservabilityHooks, an as Ok, aS as Order, aH as OrderChannel, a$ as OrderFilter, aO as OrderFulfillmentSummary, aV as OrderGroup, aZ as OrderGroupDetails, aW as OrderGroupPayment, aU as OrderGroupPaymentState, aY as OrderGroupPaymentSummary, aT as OrderHistory, aJ as OrderLineState, aK as OrderLineStatus, a_ as OrderPaymentEvent, O as OrderQueries, aX as OrderSplitDetail, aF as OrderStatus, cE as OrderType, n as OtpResult, a6 as PAYMENT_METHOD, ai as PAYMENT_MUTATION, a8 as PAYMENT_STATE, a9 as PICKUP_TIME_TYPE, cP as ParentToIframeMessage, cH as PaymentMethodInfo, aG as PaymentState, cq as PickupTime, cp as PickupTimeType, P as PriceQuote, bc as PricingOverrides, Z as ProcessAndResolveOptions, X as ProcessCheckoutOptions, Y as ProcessCheckoutResult, b_ as ProductStock, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, f as QuoteDynamicBuckets, e as QuoteStatus, g as QuoteUiMessage, R as RefreshQuoteInput, h as RefreshQuoteResult, b3 as RefundOrderInput, b6 as ReminderMethod, b9 as ReminderSettings, cx as RequestContext, cA as RequestErrorEvent, cm as RequestOtpInput, cy as RequestStartEvent, cz as RequestSuccessEvent, bQ as RescheduleBookingInput, bT as RescheduleBookingResult, bf as ResourceAssignment, am as Result, cB as RetryEvent, cl as RevokeAllSessionsResult, ck as RevokeSessionResult, bv as Room, bd as SchedulingMetadata, bg as SchedulingResult, o as SchedulingService, S as SearchOptions, bD as Service, bU as ServiceAvailabilityParams, bV as ServiceAvailabilityResult, bw as ServiceCharge, bb as ServiceNotes, bi as ServiceScheduleRequest, b4 as ServiceStatus, cC as SessionChangeEvent, bE as Staff, be as StaffAssignment, b5 as StaffRole, bj as StaffScheduleItem, bY as Stock, bZ as StockLevel, bW as StockOwnershipType, bX as StockStatus, bx as StorefrontBootstrap, bu as Table, T as TableInfo, br as TimeRange, bs as TimeRanges, bF as TimeSlot, ca as UpdateAddressInput, b1 as UpdateOrderStatusInput, U as UpdateProfileInput, b$ as VariantStock, cn as VerifyOtpInput, aB as combine, aC as combineObject, c as createCimplifyClient, u as createElements, aq as err, av as flatMap, az as fromPromise, k as generateIdempotencyKey, aw as getOrElse, as as isErr, ar as isOk, au as mapError, at as mapResult, ap as ok, ay as toNullable, aA as tryCatch, ax as unwrap } from './client-CVJ0S99a.js';
|
|
2
2
|
export { QueryBuilder, query } from './advanced.js';
|
|
3
3
|
import { A as ApiError } from './payment-CLIWNMaP.js';
|
|
4
4
|
export { B as AddOn, at as AddOnDetails, aP as AddOnGroupDetails, G as AddOnOption, aO as AddOnOptionDetails, H as AddOnOptionPrice, F as AddOnWithOptions, aU as AddToCartInput, ai as AdjustmentType, ap as AppliedDiscount, a_ as AuthorizationType, ao as BenefitType, T as Bundle, Y as BundleComponentData, _ as BundleComponentInfo, R as BundlePriceType, W as BundleProduct, ay as BundleSelectionData, aw as BundleSelectionInput, ax as BundleStoredSelection, U as BundleSummary, X as BundleWithDetails, aD as Cart, au as CartAddOn, ag as CartChannel, aE as CartItem, aR as CartItemDetails, af as CartStatus, aW as CartSummary, aF as CartTotals, K as Category, L as CategorySummary, an as ChosenPrice, h as CimplifyError, N as Collection, Q as CollectionProduct, O as CollectionSummary, a4 as ComponentGroup, a5 as ComponentGroupWithComponents, a9 as ComponentPriceBreakdown, a7 as ComponentSelectionInput, a1 as ComponentSourceType, a2 as Composite, a6 as CompositeComponent, aA as CompositePriceBreakdown, a8 as CompositePriceResult, $ as CompositePricingMode, aB as CompositeSelectionData, a7 as CompositeSelectionInput, az as CompositeStoredSelection, a3 as CompositeWithDetails, b as Currency, C as CurrencyCode, p as DepositType, D as DigitalProductType, aq as DiscountBreakdown, ar as DiscountDetails, aI as DisplayAddOn, aJ as DisplayAddOnOption, aG as DisplayCart, aH as DisplayCartItem, g as ERROR_HINTS, E as ErrorCode, e as ErrorCodeType, f as ErrorHint, a0 as GroupPricingBehavior, b2 as InitializePaymentResult, I as InventoryType, aC as LineConfiguration, ac as LocationProductPrice, M as Money, d as Pagination, P as PaginationParams, b1 as Payment, b5 as PaymentErrorDetails, b0 as PaymentMethod, aZ as PaymentMethodType, a$ as PaymentProcessingState, aY as PaymentProvider, b3 as PaymentResponse, aX as PaymentStatus, b4 as PaymentStatusResponse, ab as Price, aj as PriceAdjustment, am as PriceDecisionPath, aa as PriceEntryType, al as PricePathTaxInfo, ah as PriceSource, q as Product, J as ProductAddOn, ad as ProductAvailability, o as ProductRenderHint, ae as ProductTimeProfile, n as ProductType, s as ProductVariant, x as ProductVariantValue, r as ProductWithDetails, S as SalesChannel, as as SelectedAddOnOption, b6 as SubmitAuthorizationInput, ak as TaxPathComponent, aS as UICart, aK as UICartBusiness, aM as UICartCustomer, aL as UICartLocation, aN as UICartPricing, aT as UICartResponse, aV as UpdateCartItemInput, u as VariantAxis, z as VariantAxisSelection, w as VariantAxisValue, v as VariantAxisWithValues, av as VariantDetails, aQ as VariantDetailsDTO, t as VariantDisplayAttribute, y as VariantLocationAvailability, V as VariantStrategy, Z as ZERO, c as currencyCode, k as enrichError, j as getErrorHint, i as isCimplifyError, l as isRetryableError, m as money, a as moneyFromNumber } from './payment-CLIWNMaP.js';
|
package/dist/index.js
CHANGED
|
@@ -1339,6 +1339,10 @@ var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
|
1339
1339
|
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
1340
1340
|
var MAX_CONSECUTIVE_NETWORK_ERRORS = 5;
|
|
1341
1341
|
var CARD_PROVIDER_PAYSTACK = "paystack";
|
|
1342
|
+
var NEXT_ACTION_NONE = "none";
|
|
1343
|
+
var NEXT_ACTION_CARD_POPUP = "card_popup";
|
|
1344
|
+
var NEXT_ACTION_REDIRECT = "redirect";
|
|
1345
|
+
var NEXT_ACTION_AUTHORIZATION = "authorization";
|
|
1342
1346
|
function normalizeCardPopupError(error) {
|
|
1343
1347
|
if (!error || error === "PAYMENT_CANCELLED" || error === "CANCELLED") {
|
|
1344
1348
|
return "PAYMENT_CANCELLED";
|
|
@@ -1378,7 +1382,8 @@ function isValidMobileMoneyProvider(value) {
|
|
|
1378
1382
|
return VALID_MOBILE_MONEY_PROVIDERS.has(value);
|
|
1379
1383
|
}
|
|
1380
1384
|
function normalizeAuthorizationType(value) {
|
|
1381
|
-
|
|
1385
|
+
const lower = value?.toLowerCase();
|
|
1386
|
+
return lower === "otp" || lower === "pin" ? lower : void 0;
|
|
1382
1387
|
}
|
|
1383
1388
|
function formatMoney2(value) {
|
|
1384
1389
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
@@ -1425,6 +1430,9 @@ var CheckoutResolver = class {
|
|
|
1425
1430
|
if (!checkoutResult.order_id) {
|
|
1426
1431
|
return this.fail("CHECKOUT_FAILED", "Checkout did not return an order ID.", false);
|
|
1427
1432
|
}
|
|
1433
|
+
if (checkoutResult.next_action) {
|
|
1434
|
+
return this.resolveNextAction(checkoutResult);
|
|
1435
|
+
}
|
|
1428
1436
|
let latestCheckoutResult = checkoutResult;
|
|
1429
1437
|
let authorizationType = normalizeAuthorizationType(checkoutResult.authorization_type);
|
|
1430
1438
|
let paymentReference = checkoutResult.payment_reference;
|
|
@@ -1540,6 +1548,110 @@ var CheckoutResolver = class {
|
|
|
1540
1548
|
return this.fail("CHECKOUT_FAILED", message, true);
|
|
1541
1549
|
}
|
|
1542
1550
|
}
|
|
1551
|
+
async resolveNextAction(checkoutResult) {
|
|
1552
|
+
const action = checkoutResult.next_action;
|
|
1553
|
+
if (this.isSuccessfulStatus(checkoutResult.payment_status)) {
|
|
1554
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1555
|
+
}
|
|
1556
|
+
let latestCheckoutResult = checkoutResult;
|
|
1557
|
+
let paymentReference = checkoutResult.payment_reference;
|
|
1558
|
+
switch (action.type) {
|
|
1559
|
+
case NEXT_ACTION_NONE:
|
|
1560
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1561
|
+
case NEXT_ACTION_CARD_POPUP: {
|
|
1562
|
+
const provider = normalizeCardProvider(action.provider);
|
|
1563
|
+
this.emit("awaiting_authorization", {
|
|
1564
|
+
display_text: "Complete payment in the card authorization popup.",
|
|
1565
|
+
order_id: checkoutResult.order_id,
|
|
1566
|
+
order_number: checkoutResult.order_number
|
|
1567
|
+
});
|
|
1568
|
+
if (!this.allowPopups) {
|
|
1569
|
+
return this.fail(
|
|
1570
|
+
"PROVIDER_UNAVAILABLE",
|
|
1571
|
+
"Card payment popup is unavailable in this environment.",
|
|
1572
|
+
false
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
const popupResult = await openCardPopup(
|
|
1576
|
+
provider,
|
|
1577
|
+
checkoutResult,
|
|
1578
|
+
this.checkoutData.customer.email || "customer@cimplify.io",
|
|
1579
|
+
this.getOrderCurrency(checkoutResult),
|
|
1580
|
+
this.signal
|
|
1581
|
+
);
|
|
1582
|
+
if (!popupResult.success) {
|
|
1583
|
+
const popupError = normalizeCardPopupError(popupResult.error);
|
|
1584
|
+
if (popupError === "POPUP_BLOCKED") {
|
|
1585
|
+
return this.fail(
|
|
1586
|
+
"POPUP_BLOCKED",
|
|
1587
|
+
"Unable to open card payment popup. Please allow popups and try again.",
|
|
1588
|
+
true
|
|
1589
|
+
);
|
|
1590
|
+
}
|
|
1591
|
+
if (popupError === "PROVIDER_UNAVAILABLE") {
|
|
1592
|
+
return this.fail("PROVIDER_UNAVAILABLE", "Card payment provider is unavailable.", false);
|
|
1593
|
+
}
|
|
1594
|
+
return this.fail("PAYMENT_CANCELLED", "Card payment was cancelled before completion.", true);
|
|
1595
|
+
}
|
|
1596
|
+
paymentReference = popupResult.reference || paymentReference;
|
|
1597
|
+
break;
|
|
1598
|
+
}
|
|
1599
|
+
case NEXT_ACTION_REDIRECT: {
|
|
1600
|
+
if (typeof window !== "undefined" && this.returnUrl) {
|
|
1601
|
+
window.location.assign(action.authorization_url);
|
|
1602
|
+
return this.fail("REDIRECT_REQUIRED", "Redirecting to complete payment authorization.", true);
|
|
1603
|
+
}
|
|
1604
|
+
if (typeof window !== "undefined") {
|
|
1605
|
+
const popup = window.open(
|
|
1606
|
+
action.authorization_url,
|
|
1607
|
+
"cimplify-auth",
|
|
1608
|
+
"width=520,height=760,noopener,noreferrer"
|
|
1609
|
+
);
|
|
1610
|
+
if (!popup) {
|
|
1611
|
+
return this.fail(
|
|
1612
|
+
"POPUP_BLOCKED",
|
|
1613
|
+
"Authorization popup was blocked. Please allow popups and retry.",
|
|
1614
|
+
true
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
break;
|
|
1619
|
+
}
|
|
1620
|
+
case NEXT_ACTION_AUTHORIZATION: {
|
|
1621
|
+
const authType = normalizeAuthorizationType(action.authorization_type);
|
|
1622
|
+
const authorization = await this.handleAuthorization({
|
|
1623
|
+
authorizationType: authType,
|
|
1624
|
+
paymentReference,
|
|
1625
|
+
displayText: action.display_text,
|
|
1626
|
+
provider: checkoutResult.provider
|
|
1627
|
+
});
|
|
1628
|
+
if (!authorization.ok) {
|
|
1629
|
+
return authorization.result;
|
|
1630
|
+
}
|
|
1631
|
+
if (authorization.value) {
|
|
1632
|
+
latestCheckoutResult = authorization.value;
|
|
1633
|
+
paymentReference = authorization.value.payment_reference || paymentReference;
|
|
1634
|
+
if (this.isSuccessfulStatus(authorization.value.payment_status)) {
|
|
1635
|
+
return this.finalizeSuccess(authorization.value);
|
|
1636
|
+
}
|
|
1637
|
+
if (this.isFailureStatus(authorization.value.payment_status)) {
|
|
1638
|
+
return this.fail(
|
|
1639
|
+
"AUTHORIZATION_FAILED",
|
|
1640
|
+
authorization.value.display_text || "Payment authorization failed.",
|
|
1641
|
+
false
|
|
1642
|
+
);
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
break;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
return this.pollUntilTerminal({
|
|
1649
|
+
orderId: checkoutResult.order_id,
|
|
1650
|
+
latestCheckoutResult,
|
|
1651
|
+
paymentReference,
|
|
1652
|
+
authorizationType: normalizeAuthorizationType(checkoutResult.authorization_type)
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1543
1655
|
async pollUntilTerminal(input) {
|
|
1544
1656
|
let consecutiveErrors = 0;
|
|
1545
1657
|
let latestCheckoutResult = input.latestCheckoutResult;
|
|
@@ -3168,6 +3280,7 @@ var CimplifyElement = class {
|
|
|
3168
3280
|
this.iframe = null;
|
|
3169
3281
|
this.container = null;
|
|
3170
3282
|
this.mounted = false;
|
|
3283
|
+
this.pendingInit = null;
|
|
3171
3284
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
3172
3285
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
3173
3286
|
this.listening = false;
|
|
@@ -3293,23 +3406,9 @@ var CimplifyElement = class {
|
|
|
3293
3406
|
);
|
|
3294
3407
|
this.iframe = iframe;
|
|
3295
3408
|
this.container.appendChild(iframe);
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
this.
|
|
3299
|
-
type: MESSAGE_TYPES.INIT,
|
|
3300
|
-
businessId: resolvedBusinessId,
|
|
3301
|
-
publicKey,
|
|
3302
|
-
demoMode: publicKey.length === 0,
|
|
3303
|
-
prefillEmail: this.options.prefillEmail,
|
|
3304
|
-
appearance: this.parent.getAppearance(),
|
|
3305
|
-
orderTypes: this.options.orderTypes,
|
|
3306
|
-
defaultOrderType: this.options.defaultOrderType,
|
|
3307
|
-
renderSubmitButton: true
|
|
3308
|
-
});
|
|
3309
|
-
const token = this.parent.getAccessToken();
|
|
3310
|
-
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3311
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3312
|
-
}
|
|
3409
|
+
this.pendingInit = {
|
|
3410
|
+
businessId: resolvedBusinessId,
|
|
3411
|
+
publicKey: this.parent.getPublicKey()
|
|
3313
3412
|
};
|
|
3314
3413
|
}
|
|
3315
3414
|
handleMessage(event) {
|
|
@@ -3330,6 +3429,25 @@ var CimplifyElement = class {
|
|
|
3330
3429
|
switch (message.type) {
|
|
3331
3430
|
case MESSAGE_TYPES.READY:
|
|
3332
3431
|
if (this.iframe && message.height) this.iframe.style.height = `${message.height}px`;
|
|
3432
|
+
if (this.pendingInit) {
|
|
3433
|
+
const { publicKey } = this.pendingInit;
|
|
3434
|
+
this.sendMessage({
|
|
3435
|
+
type: MESSAGE_TYPES.INIT,
|
|
3436
|
+
businessId: this.pendingInit.businessId,
|
|
3437
|
+
publicKey,
|
|
3438
|
+
demoMode: publicKey.length === 0,
|
|
3439
|
+
prefillEmail: this.options.prefillEmail,
|
|
3440
|
+
appearance: this.parent.getAppearance(),
|
|
3441
|
+
orderTypes: this.options.orderTypes,
|
|
3442
|
+
defaultOrderType: this.options.defaultOrderType,
|
|
3443
|
+
renderSubmitButton: true
|
|
3444
|
+
});
|
|
3445
|
+
const token = this.parent.getAccessToken();
|
|
3446
|
+
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3447
|
+
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3448
|
+
}
|
|
3449
|
+
this.pendingInit = null;
|
|
3450
|
+
}
|
|
3333
3451
|
this.emit(EVENT_TYPES.READY, { height: message.height });
|
|
3334
3452
|
break;
|
|
3335
3453
|
case MESSAGE_TYPES.HEIGHT_CHANGE:
|
package/dist/index.mjs
CHANGED
|
@@ -1337,6 +1337,10 @@ var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
|
1337
1337
|
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
1338
1338
|
var MAX_CONSECUTIVE_NETWORK_ERRORS = 5;
|
|
1339
1339
|
var CARD_PROVIDER_PAYSTACK = "paystack";
|
|
1340
|
+
var NEXT_ACTION_NONE = "none";
|
|
1341
|
+
var NEXT_ACTION_CARD_POPUP = "card_popup";
|
|
1342
|
+
var NEXT_ACTION_REDIRECT = "redirect";
|
|
1343
|
+
var NEXT_ACTION_AUTHORIZATION = "authorization";
|
|
1340
1344
|
function normalizeCardPopupError(error) {
|
|
1341
1345
|
if (!error || error === "PAYMENT_CANCELLED" || error === "CANCELLED") {
|
|
1342
1346
|
return "PAYMENT_CANCELLED";
|
|
@@ -1376,7 +1380,8 @@ function isValidMobileMoneyProvider(value) {
|
|
|
1376
1380
|
return VALID_MOBILE_MONEY_PROVIDERS.has(value);
|
|
1377
1381
|
}
|
|
1378
1382
|
function normalizeAuthorizationType(value) {
|
|
1379
|
-
|
|
1383
|
+
const lower = value?.toLowerCase();
|
|
1384
|
+
return lower === "otp" || lower === "pin" ? lower : void 0;
|
|
1380
1385
|
}
|
|
1381
1386
|
function formatMoney2(value) {
|
|
1382
1387
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
@@ -1423,6 +1428,9 @@ var CheckoutResolver = class {
|
|
|
1423
1428
|
if (!checkoutResult.order_id) {
|
|
1424
1429
|
return this.fail("CHECKOUT_FAILED", "Checkout did not return an order ID.", false);
|
|
1425
1430
|
}
|
|
1431
|
+
if (checkoutResult.next_action) {
|
|
1432
|
+
return this.resolveNextAction(checkoutResult);
|
|
1433
|
+
}
|
|
1426
1434
|
let latestCheckoutResult = checkoutResult;
|
|
1427
1435
|
let authorizationType = normalizeAuthorizationType(checkoutResult.authorization_type);
|
|
1428
1436
|
let paymentReference = checkoutResult.payment_reference;
|
|
@@ -1538,6 +1546,110 @@ var CheckoutResolver = class {
|
|
|
1538
1546
|
return this.fail("CHECKOUT_FAILED", message, true);
|
|
1539
1547
|
}
|
|
1540
1548
|
}
|
|
1549
|
+
async resolveNextAction(checkoutResult) {
|
|
1550
|
+
const action = checkoutResult.next_action;
|
|
1551
|
+
if (this.isSuccessfulStatus(checkoutResult.payment_status)) {
|
|
1552
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1553
|
+
}
|
|
1554
|
+
let latestCheckoutResult = checkoutResult;
|
|
1555
|
+
let paymentReference = checkoutResult.payment_reference;
|
|
1556
|
+
switch (action.type) {
|
|
1557
|
+
case NEXT_ACTION_NONE:
|
|
1558
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1559
|
+
case NEXT_ACTION_CARD_POPUP: {
|
|
1560
|
+
const provider = normalizeCardProvider(action.provider);
|
|
1561
|
+
this.emit("awaiting_authorization", {
|
|
1562
|
+
display_text: "Complete payment in the card authorization popup.",
|
|
1563
|
+
order_id: checkoutResult.order_id,
|
|
1564
|
+
order_number: checkoutResult.order_number
|
|
1565
|
+
});
|
|
1566
|
+
if (!this.allowPopups) {
|
|
1567
|
+
return this.fail(
|
|
1568
|
+
"PROVIDER_UNAVAILABLE",
|
|
1569
|
+
"Card payment popup is unavailable in this environment.",
|
|
1570
|
+
false
|
|
1571
|
+
);
|
|
1572
|
+
}
|
|
1573
|
+
const popupResult = await openCardPopup(
|
|
1574
|
+
provider,
|
|
1575
|
+
checkoutResult,
|
|
1576
|
+
this.checkoutData.customer.email || "customer@cimplify.io",
|
|
1577
|
+
this.getOrderCurrency(checkoutResult),
|
|
1578
|
+
this.signal
|
|
1579
|
+
);
|
|
1580
|
+
if (!popupResult.success) {
|
|
1581
|
+
const popupError = normalizeCardPopupError(popupResult.error);
|
|
1582
|
+
if (popupError === "POPUP_BLOCKED") {
|
|
1583
|
+
return this.fail(
|
|
1584
|
+
"POPUP_BLOCKED",
|
|
1585
|
+
"Unable to open card payment popup. Please allow popups and try again.",
|
|
1586
|
+
true
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
if (popupError === "PROVIDER_UNAVAILABLE") {
|
|
1590
|
+
return this.fail("PROVIDER_UNAVAILABLE", "Card payment provider is unavailable.", false);
|
|
1591
|
+
}
|
|
1592
|
+
return this.fail("PAYMENT_CANCELLED", "Card payment was cancelled before completion.", true);
|
|
1593
|
+
}
|
|
1594
|
+
paymentReference = popupResult.reference || paymentReference;
|
|
1595
|
+
break;
|
|
1596
|
+
}
|
|
1597
|
+
case NEXT_ACTION_REDIRECT: {
|
|
1598
|
+
if (typeof window !== "undefined" && this.returnUrl) {
|
|
1599
|
+
window.location.assign(action.authorization_url);
|
|
1600
|
+
return this.fail("REDIRECT_REQUIRED", "Redirecting to complete payment authorization.", true);
|
|
1601
|
+
}
|
|
1602
|
+
if (typeof window !== "undefined") {
|
|
1603
|
+
const popup = window.open(
|
|
1604
|
+
action.authorization_url,
|
|
1605
|
+
"cimplify-auth",
|
|
1606
|
+
"width=520,height=760,noopener,noreferrer"
|
|
1607
|
+
);
|
|
1608
|
+
if (!popup) {
|
|
1609
|
+
return this.fail(
|
|
1610
|
+
"POPUP_BLOCKED",
|
|
1611
|
+
"Authorization popup was blocked. Please allow popups and retry.",
|
|
1612
|
+
true
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
break;
|
|
1617
|
+
}
|
|
1618
|
+
case NEXT_ACTION_AUTHORIZATION: {
|
|
1619
|
+
const authType = normalizeAuthorizationType(action.authorization_type);
|
|
1620
|
+
const authorization = await this.handleAuthorization({
|
|
1621
|
+
authorizationType: authType,
|
|
1622
|
+
paymentReference,
|
|
1623
|
+
displayText: action.display_text,
|
|
1624
|
+
provider: checkoutResult.provider
|
|
1625
|
+
});
|
|
1626
|
+
if (!authorization.ok) {
|
|
1627
|
+
return authorization.result;
|
|
1628
|
+
}
|
|
1629
|
+
if (authorization.value) {
|
|
1630
|
+
latestCheckoutResult = authorization.value;
|
|
1631
|
+
paymentReference = authorization.value.payment_reference || paymentReference;
|
|
1632
|
+
if (this.isSuccessfulStatus(authorization.value.payment_status)) {
|
|
1633
|
+
return this.finalizeSuccess(authorization.value);
|
|
1634
|
+
}
|
|
1635
|
+
if (this.isFailureStatus(authorization.value.payment_status)) {
|
|
1636
|
+
return this.fail(
|
|
1637
|
+
"AUTHORIZATION_FAILED",
|
|
1638
|
+
authorization.value.display_text || "Payment authorization failed.",
|
|
1639
|
+
false
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return this.pollUntilTerminal({
|
|
1647
|
+
orderId: checkoutResult.order_id,
|
|
1648
|
+
latestCheckoutResult,
|
|
1649
|
+
paymentReference,
|
|
1650
|
+
authorizationType: normalizeAuthorizationType(checkoutResult.authorization_type)
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1541
1653
|
async pollUntilTerminal(input) {
|
|
1542
1654
|
let consecutiveErrors = 0;
|
|
1543
1655
|
let latestCheckoutResult = input.latestCheckoutResult;
|
|
@@ -3166,6 +3278,7 @@ var CimplifyElement = class {
|
|
|
3166
3278
|
this.iframe = null;
|
|
3167
3279
|
this.container = null;
|
|
3168
3280
|
this.mounted = false;
|
|
3281
|
+
this.pendingInit = null;
|
|
3169
3282
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
3170
3283
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
3171
3284
|
this.listening = false;
|
|
@@ -3291,23 +3404,9 @@ var CimplifyElement = class {
|
|
|
3291
3404
|
);
|
|
3292
3405
|
this.iframe = iframe;
|
|
3293
3406
|
this.container.appendChild(iframe);
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
this.
|
|
3297
|
-
type: MESSAGE_TYPES.INIT,
|
|
3298
|
-
businessId: resolvedBusinessId,
|
|
3299
|
-
publicKey,
|
|
3300
|
-
demoMode: publicKey.length === 0,
|
|
3301
|
-
prefillEmail: this.options.prefillEmail,
|
|
3302
|
-
appearance: this.parent.getAppearance(),
|
|
3303
|
-
orderTypes: this.options.orderTypes,
|
|
3304
|
-
defaultOrderType: this.options.defaultOrderType,
|
|
3305
|
-
renderSubmitButton: true
|
|
3306
|
-
});
|
|
3307
|
-
const token = this.parent.getAccessToken();
|
|
3308
|
-
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3309
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3310
|
-
}
|
|
3407
|
+
this.pendingInit = {
|
|
3408
|
+
businessId: resolvedBusinessId,
|
|
3409
|
+
publicKey: this.parent.getPublicKey()
|
|
3311
3410
|
};
|
|
3312
3411
|
}
|
|
3313
3412
|
handleMessage(event) {
|
|
@@ -3328,6 +3427,25 @@ var CimplifyElement = class {
|
|
|
3328
3427
|
switch (message.type) {
|
|
3329
3428
|
case MESSAGE_TYPES.READY:
|
|
3330
3429
|
if (this.iframe && message.height) this.iframe.style.height = `${message.height}px`;
|
|
3430
|
+
if (this.pendingInit) {
|
|
3431
|
+
const { publicKey } = this.pendingInit;
|
|
3432
|
+
this.sendMessage({
|
|
3433
|
+
type: MESSAGE_TYPES.INIT,
|
|
3434
|
+
businessId: this.pendingInit.businessId,
|
|
3435
|
+
publicKey,
|
|
3436
|
+
demoMode: publicKey.length === 0,
|
|
3437
|
+
prefillEmail: this.options.prefillEmail,
|
|
3438
|
+
appearance: this.parent.getAppearance(),
|
|
3439
|
+
orderTypes: this.options.orderTypes,
|
|
3440
|
+
defaultOrderType: this.options.defaultOrderType,
|
|
3441
|
+
renderSubmitButton: true
|
|
3442
|
+
});
|
|
3443
|
+
const token = this.parent.getAccessToken();
|
|
3444
|
+
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3445
|
+
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3446
|
+
}
|
|
3447
|
+
this.pendingInit = null;
|
|
3448
|
+
}
|
|
3331
3449
|
this.emit(EVENT_TYPES.READY, { height: message.height });
|
|
3332
3450
|
break;
|
|
3333
3451
|
case MESSAGE_TYPES.HEIGHT_CHANGE:
|
package/dist/react.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CimplifyClient,
|
|
1
|
+
import { C as CimplifyClient, Y as ProcessCheckoutResult, _ as CheckoutStatus, $ as CheckoutStatusContext, bq as Location, bn as Business, aS as Order, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, P as PriceQuote, g as QuoteUiMessage, s as CimplifyElements, w as ElementsOptions, cK as AuthenticatedData, cG as AddressInfo, cH as PaymentMethodInfo, cM as ElementsCheckoutResult, X as ProcessCheckoutOptions } from './client-6MsOWo8f.mjs';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import { q as Product, d as Pagination, h as CimplifyError, r as ProductWithDetails, K as Category, aw as BundleSelectionInput, a7 as ComponentSelectionInput, N as Collection, X as BundleWithDetails, a3 as CompositeWithDetails, a8 as CompositePriceResult, C as CurrencyCode } from './payment-CLIWNMaP.mjs';
|
|
4
4
|
import { A as AdSlot, a as AdPosition, e as AdContextValue } from './ads-t3FBTU8p.mjs';
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CimplifyClient,
|
|
1
|
+
import { C as CimplifyClient, Y as ProcessCheckoutResult, _ as CheckoutStatus, $ as CheckoutStatusContext, bq as Location, bn as Business, aS as Order, d as QuoteBundleSelectionInput, Q as QuoteCompositeSelectionInput, P as PriceQuote, g as QuoteUiMessage, s as CimplifyElements, w as ElementsOptions, cK as AuthenticatedData, cG as AddressInfo, cH as PaymentMethodInfo, cM as ElementsCheckoutResult, X as ProcessCheckoutOptions } from './client-CVJ0S99a.js';
|
|
2
2
|
import React, { ReactNode } from 'react';
|
|
3
3
|
import { q as Product, d as Pagination, h as CimplifyError, r as ProductWithDetails, K as Category, aw as BundleSelectionInput, a7 as ComponentSelectionInput, N as Collection, X as BundleWithDetails, a3 as CompositeWithDetails, a8 as CompositePriceResult, C as CurrencyCode } from './payment-CLIWNMaP.js';
|
|
4
4
|
import { A as AdSlot, a as AdPosition, e as AdContextValue } from './ads-t3FBTU8p.js';
|
package/dist/react.js
CHANGED
|
@@ -1563,6 +1563,10 @@ var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
|
1563
1563
|
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
1564
1564
|
var MAX_CONSECUTIVE_NETWORK_ERRORS = 5;
|
|
1565
1565
|
var CARD_PROVIDER_PAYSTACK = "paystack";
|
|
1566
|
+
var NEXT_ACTION_NONE = "none";
|
|
1567
|
+
var NEXT_ACTION_CARD_POPUP = "card_popup";
|
|
1568
|
+
var NEXT_ACTION_REDIRECT = "redirect";
|
|
1569
|
+
var NEXT_ACTION_AUTHORIZATION = "authorization";
|
|
1566
1570
|
function normalizeCardPopupError(error) {
|
|
1567
1571
|
if (!error || error === "PAYMENT_CANCELLED" || error === "CANCELLED") {
|
|
1568
1572
|
return "PAYMENT_CANCELLED";
|
|
@@ -1602,7 +1606,8 @@ function isValidMobileMoneyProvider(value) {
|
|
|
1602
1606
|
return VALID_MOBILE_MONEY_PROVIDERS.has(value);
|
|
1603
1607
|
}
|
|
1604
1608
|
function normalizeAuthorizationType(value) {
|
|
1605
|
-
|
|
1609
|
+
const lower = value?.toLowerCase();
|
|
1610
|
+
return lower === "otp" || lower === "pin" ? lower : void 0;
|
|
1606
1611
|
}
|
|
1607
1612
|
function formatMoney2(value) {
|
|
1608
1613
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
@@ -1649,6 +1654,9 @@ var CheckoutResolver = class {
|
|
|
1649
1654
|
if (!checkoutResult.order_id) {
|
|
1650
1655
|
return this.fail("CHECKOUT_FAILED", "Checkout did not return an order ID.", false);
|
|
1651
1656
|
}
|
|
1657
|
+
if (checkoutResult.next_action) {
|
|
1658
|
+
return this.resolveNextAction(checkoutResult);
|
|
1659
|
+
}
|
|
1652
1660
|
let latestCheckoutResult = checkoutResult;
|
|
1653
1661
|
let authorizationType = normalizeAuthorizationType(checkoutResult.authorization_type);
|
|
1654
1662
|
let paymentReference = checkoutResult.payment_reference;
|
|
@@ -1764,6 +1772,110 @@ var CheckoutResolver = class {
|
|
|
1764
1772
|
return this.fail("CHECKOUT_FAILED", message, true);
|
|
1765
1773
|
}
|
|
1766
1774
|
}
|
|
1775
|
+
async resolveNextAction(checkoutResult) {
|
|
1776
|
+
const action = checkoutResult.next_action;
|
|
1777
|
+
if (this.isSuccessfulStatus(checkoutResult.payment_status)) {
|
|
1778
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1779
|
+
}
|
|
1780
|
+
let latestCheckoutResult = checkoutResult;
|
|
1781
|
+
let paymentReference = checkoutResult.payment_reference;
|
|
1782
|
+
switch (action.type) {
|
|
1783
|
+
case NEXT_ACTION_NONE:
|
|
1784
|
+
return this.finalizeSuccess(checkoutResult);
|
|
1785
|
+
case NEXT_ACTION_CARD_POPUP: {
|
|
1786
|
+
const provider = normalizeCardProvider(action.provider);
|
|
1787
|
+
this.emit("awaiting_authorization", {
|
|
1788
|
+
display_text: "Complete payment in the card authorization popup.",
|
|
1789
|
+
order_id: checkoutResult.order_id,
|
|
1790
|
+
order_number: checkoutResult.order_number
|
|
1791
|
+
});
|
|
1792
|
+
if (!this.allowPopups) {
|
|
1793
|
+
return this.fail(
|
|
1794
|
+
"PROVIDER_UNAVAILABLE",
|
|
1795
|
+
"Card payment popup is unavailable in this environment.",
|
|
1796
|
+
false
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
const popupResult = await openCardPopup(
|
|
1800
|
+
provider,
|
|
1801
|
+
checkoutResult,
|
|
1802
|
+
this.checkoutData.customer.email || "customer@cimplify.io",
|
|
1803
|
+
this.getOrderCurrency(checkoutResult),
|
|
1804
|
+
this.signal
|
|
1805
|
+
);
|
|
1806
|
+
if (!popupResult.success) {
|
|
1807
|
+
const popupError = normalizeCardPopupError(popupResult.error);
|
|
1808
|
+
if (popupError === "POPUP_BLOCKED") {
|
|
1809
|
+
return this.fail(
|
|
1810
|
+
"POPUP_BLOCKED",
|
|
1811
|
+
"Unable to open card payment popup. Please allow popups and try again.",
|
|
1812
|
+
true
|
|
1813
|
+
);
|
|
1814
|
+
}
|
|
1815
|
+
if (popupError === "PROVIDER_UNAVAILABLE") {
|
|
1816
|
+
return this.fail("PROVIDER_UNAVAILABLE", "Card payment provider is unavailable.", false);
|
|
1817
|
+
}
|
|
1818
|
+
return this.fail("PAYMENT_CANCELLED", "Card payment was cancelled before completion.", true);
|
|
1819
|
+
}
|
|
1820
|
+
paymentReference = popupResult.reference || paymentReference;
|
|
1821
|
+
break;
|
|
1822
|
+
}
|
|
1823
|
+
case NEXT_ACTION_REDIRECT: {
|
|
1824
|
+
if (typeof window !== "undefined" && this.returnUrl) {
|
|
1825
|
+
window.location.assign(action.authorization_url);
|
|
1826
|
+
return this.fail("REDIRECT_REQUIRED", "Redirecting to complete payment authorization.", true);
|
|
1827
|
+
}
|
|
1828
|
+
if (typeof window !== "undefined") {
|
|
1829
|
+
const popup = window.open(
|
|
1830
|
+
action.authorization_url,
|
|
1831
|
+
"cimplify-auth",
|
|
1832
|
+
"width=520,height=760,noopener,noreferrer"
|
|
1833
|
+
);
|
|
1834
|
+
if (!popup) {
|
|
1835
|
+
return this.fail(
|
|
1836
|
+
"POPUP_BLOCKED",
|
|
1837
|
+
"Authorization popup was blocked. Please allow popups and retry.",
|
|
1838
|
+
true
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
break;
|
|
1843
|
+
}
|
|
1844
|
+
case NEXT_ACTION_AUTHORIZATION: {
|
|
1845
|
+
const authType = normalizeAuthorizationType(action.authorization_type);
|
|
1846
|
+
const authorization = await this.handleAuthorization({
|
|
1847
|
+
authorizationType: authType,
|
|
1848
|
+
paymentReference,
|
|
1849
|
+
displayText: action.display_text,
|
|
1850
|
+
provider: checkoutResult.provider
|
|
1851
|
+
});
|
|
1852
|
+
if (!authorization.ok) {
|
|
1853
|
+
return authorization.result;
|
|
1854
|
+
}
|
|
1855
|
+
if (authorization.value) {
|
|
1856
|
+
latestCheckoutResult = authorization.value;
|
|
1857
|
+
paymentReference = authorization.value.payment_reference || paymentReference;
|
|
1858
|
+
if (this.isSuccessfulStatus(authorization.value.payment_status)) {
|
|
1859
|
+
return this.finalizeSuccess(authorization.value);
|
|
1860
|
+
}
|
|
1861
|
+
if (this.isFailureStatus(authorization.value.payment_status)) {
|
|
1862
|
+
return this.fail(
|
|
1863
|
+
"AUTHORIZATION_FAILED",
|
|
1864
|
+
authorization.value.display_text || "Payment authorization failed.",
|
|
1865
|
+
false
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
break;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return this.pollUntilTerminal({
|
|
1873
|
+
orderId: checkoutResult.order_id,
|
|
1874
|
+
latestCheckoutResult,
|
|
1875
|
+
paymentReference,
|
|
1876
|
+
authorizationType: normalizeAuthorizationType(checkoutResult.authorization_type)
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1767
1879
|
async pollUntilTerminal(input) {
|
|
1768
1880
|
let consecutiveErrors = 0;
|
|
1769
1881
|
let latestCheckoutResult = input.latestCheckoutResult;
|
|
@@ -3346,6 +3458,7 @@ var CimplifyElement = class {
|
|
|
3346
3458
|
this.iframe = null;
|
|
3347
3459
|
this.container = null;
|
|
3348
3460
|
this.mounted = false;
|
|
3461
|
+
this.pendingInit = null;
|
|
3349
3462
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
3350
3463
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
3351
3464
|
this.listening = false;
|
|
@@ -3471,23 +3584,9 @@ var CimplifyElement = class {
|
|
|
3471
3584
|
);
|
|
3472
3585
|
this.iframe = iframe;
|
|
3473
3586
|
this.container.appendChild(iframe);
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
this.
|
|
3477
|
-
type: MESSAGE_TYPES.INIT,
|
|
3478
|
-
businessId: resolvedBusinessId,
|
|
3479
|
-
publicKey,
|
|
3480
|
-
demoMode: publicKey.length === 0,
|
|
3481
|
-
prefillEmail: this.options.prefillEmail,
|
|
3482
|
-
appearance: this.parent.getAppearance(),
|
|
3483
|
-
orderTypes: this.options.orderTypes,
|
|
3484
|
-
defaultOrderType: this.options.defaultOrderType,
|
|
3485
|
-
renderSubmitButton: true
|
|
3486
|
-
});
|
|
3487
|
-
const token = this.parent.getAccessToken();
|
|
3488
|
-
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3489
|
-
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3490
|
-
}
|
|
3587
|
+
this.pendingInit = {
|
|
3588
|
+
businessId: resolvedBusinessId,
|
|
3589
|
+
publicKey: this.parent.getPublicKey()
|
|
3491
3590
|
};
|
|
3492
3591
|
}
|
|
3493
3592
|
handleMessage(event) {
|
|
@@ -3508,6 +3607,25 @@ var CimplifyElement = class {
|
|
|
3508
3607
|
switch (message.type) {
|
|
3509
3608
|
case MESSAGE_TYPES.READY:
|
|
3510
3609
|
if (this.iframe && message.height) this.iframe.style.height = `${message.height}px`;
|
|
3610
|
+
if (this.pendingInit) {
|
|
3611
|
+
const { publicKey } = this.pendingInit;
|
|
3612
|
+
this.sendMessage({
|
|
3613
|
+
type: MESSAGE_TYPES.INIT,
|
|
3614
|
+
businessId: this.pendingInit.businessId,
|
|
3615
|
+
publicKey,
|
|
3616
|
+
demoMode: publicKey.length === 0,
|
|
3617
|
+
prefillEmail: this.options.prefillEmail,
|
|
3618
|
+
appearance: this.parent.getAppearance(),
|
|
3619
|
+
orderTypes: this.options.orderTypes,
|
|
3620
|
+
defaultOrderType: this.options.defaultOrderType,
|
|
3621
|
+
renderSubmitButton: true
|
|
3622
|
+
});
|
|
3623
|
+
const token = this.parent.getAccessToken();
|
|
3624
|
+
if (token && this.type !== ELEMENT_TYPES.AUTH) {
|
|
3625
|
+
this.sendMessage({ type: MESSAGE_TYPES.SET_TOKEN, token });
|
|
3626
|
+
}
|
|
3627
|
+
this.pendingInit = null;
|
|
3628
|
+
}
|
|
3511
3629
|
this.emit(EVENT_TYPES.READY, { height: message.height });
|
|
3512
3630
|
break;
|
|
3513
3631
|
case MESSAGE_TYPES.HEIGHT_CHANGE:
|