@cimplify/sdk 0.6.11 → 0.6.12
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 +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +534 -102
- package/dist/advanced.mjs +534 -102
- package/dist/{client-BngAGN0v.d.mts → client-2Rmdqutj.d.ts} +15 -926
- package/dist/{client-DM3-ZG29.d.ts → client-BIbWQK7v.d.mts} +15 -926
- package/dist/{index-DaKJxoEh.d.mts → index-DAztg_LQ.d.ts} +35 -35
- package/dist/{index-pztT_bcJ.d.ts → index-Dqaywky7.d.mts} +35 -35
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +590 -105
- package/dist/index.mjs +587 -106
- package/dist/payment-CLIWNMaP.d.mts +1133 -0
- package/dist/payment-CLIWNMaP.d.ts +1133 -0
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +562 -105
- package/dist/react.mjs +562 -105
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +27 -0
- package/dist/utils.mjs +24 -1
- package/package.json +1 -1
- package/dist/payment-Cu75tmUc.d.mts +0 -196
- package/dist/payment-Cu75tmUc.d.ts +0 -196
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS,
|
|
2
|
-
import './payment-
|
|
1
|
+
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, s as categorizePaymentError, y as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, j as formatPriceWithTax, e as formatProductPrice, m as getBasePrice, k as getCurrencySymbol, o as getDiscountPercentage, l as getDisplayPrice, q as getMarkupPercentage, r as getProductCurrency, g as getTaxAmount, h as hasTaxInfo, n as isOnSale, v as isPaymentStatusFailure, w as isPaymentStatusRequiresAction, x as isPaymentStatusSuccess, i as isTaxInclusive, t as normalizePaymentResponse, u as normalizeStatusResponse, p as parsePrice } from './index-Dqaywky7.mjs';
|
|
2
|
+
import './payment-CLIWNMaP.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS,
|
|
2
|
-
import './payment-
|
|
1
|
+
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, s as categorizePaymentError, y as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, j as formatPriceWithTax, e as formatProductPrice, m as getBasePrice, k as getCurrencySymbol, o as getDiscountPercentage, l as getDisplayPrice, q as getMarkupPercentage, r as getProductCurrency, g as getTaxAmount, h as hasTaxInfo, n as isOnSale, v as isPaymentStatusFailure, w as isPaymentStatusRequiresAction, x as isPaymentStatusSuccess, i as isTaxInclusive, t as normalizePaymentResponse, u as normalizeStatusResponse, p as parsePrice } from './index-DAztg_LQ.js';
|
|
2
|
+
import './payment-CLIWNMaP.js';
|
package/dist/utils.js
CHANGED
|
@@ -145,6 +145,25 @@ function parsePrice(value) {
|
|
|
145
145
|
const parsed = parseFloat(cleaned);
|
|
146
146
|
return isNaN(parsed) ? 0 : parsed;
|
|
147
147
|
}
|
|
148
|
+
function hasTaxInfo(priceInfo) {
|
|
149
|
+
return priceInfo.tax_info !== void 0 && priceInfo.tax_info !== null;
|
|
150
|
+
}
|
|
151
|
+
function getTaxAmount(priceInfo) {
|
|
152
|
+
return parsePrice(priceInfo.tax_info?.tax_amount);
|
|
153
|
+
}
|
|
154
|
+
function isTaxInclusive(priceInfo) {
|
|
155
|
+
return priceInfo.tax_info?.is_inclusive === true;
|
|
156
|
+
}
|
|
157
|
+
function formatPriceWithTax(priceInfo, currency = "GHS") {
|
|
158
|
+
const finalPrice = formatPrice(priceInfo.final_price, currency);
|
|
159
|
+
if (!hasTaxInfo(priceInfo)) {
|
|
160
|
+
return finalPrice;
|
|
161
|
+
}
|
|
162
|
+
if (isTaxInclusive(priceInfo)) {
|
|
163
|
+
return `${finalPrice} (incl. tax)`;
|
|
164
|
+
}
|
|
165
|
+
return `${finalPrice} + ${formatPrice(getTaxAmount(priceInfo), currency)} tax`;
|
|
166
|
+
}
|
|
148
167
|
function getDisplayPrice(product) {
|
|
149
168
|
if (product.price_info) {
|
|
150
169
|
return parsePrice(product.price_info.final_price);
|
|
@@ -238,6 +257,10 @@ var ERROR_SUGGESTIONS = {
|
|
|
238
257
|
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
239
258
|
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
240
259
|
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
260
|
+
QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
|
|
261
|
+
QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
|
|
262
|
+
QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
|
|
263
|
+
QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
|
|
241
264
|
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
242
265
|
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
243
266
|
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
@@ -513,6 +536,7 @@ exports.formatNumberCompact = formatNumberCompact;
|
|
|
513
536
|
exports.formatPrice = formatPrice;
|
|
514
537
|
exports.formatPriceAdjustment = formatPriceAdjustment;
|
|
515
538
|
exports.formatPriceCompact = formatPriceCompact;
|
|
539
|
+
exports.formatPriceWithTax = formatPriceWithTax;
|
|
516
540
|
exports.formatProductPrice = formatProductPrice;
|
|
517
541
|
exports.getBasePrice = getBasePrice;
|
|
518
542
|
exports.getCurrencySymbol = getCurrencySymbol;
|
|
@@ -520,10 +544,13 @@ exports.getDiscountPercentage = getDiscountPercentage;
|
|
|
520
544
|
exports.getDisplayPrice = getDisplayPrice;
|
|
521
545
|
exports.getMarkupPercentage = getMarkupPercentage;
|
|
522
546
|
exports.getProductCurrency = getProductCurrency;
|
|
547
|
+
exports.getTaxAmount = getTaxAmount;
|
|
548
|
+
exports.hasTaxInfo = hasTaxInfo;
|
|
523
549
|
exports.isOnSale = isOnSale;
|
|
524
550
|
exports.isPaymentStatusFailure = isPaymentStatusFailure;
|
|
525
551
|
exports.isPaymentStatusRequiresAction = isPaymentStatusRequiresAction;
|
|
526
552
|
exports.isPaymentStatusSuccess = isPaymentStatusSuccess;
|
|
553
|
+
exports.isTaxInclusive = isTaxInclusive;
|
|
527
554
|
exports.normalizePaymentResponse = normalizePaymentResponse;
|
|
528
555
|
exports.normalizeStatusResponse = normalizeStatusResponse;
|
|
529
556
|
exports.parsePrice = parsePrice;
|
package/dist/utils.mjs
CHANGED
|
@@ -143,6 +143,25 @@ function parsePrice(value) {
|
|
|
143
143
|
const parsed = parseFloat(cleaned);
|
|
144
144
|
return isNaN(parsed) ? 0 : parsed;
|
|
145
145
|
}
|
|
146
|
+
function hasTaxInfo(priceInfo) {
|
|
147
|
+
return priceInfo.tax_info !== void 0 && priceInfo.tax_info !== null;
|
|
148
|
+
}
|
|
149
|
+
function getTaxAmount(priceInfo) {
|
|
150
|
+
return parsePrice(priceInfo.tax_info?.tax_amount);
|
|
151
|
+
}
|
|
152
|
+
function isTaxInclusive(priceInfo) {
|
|
153
|
+
return priceInfo.tax_info?.is_inclusive === true;
|
|
154
|
+
}
|
|
155
|
+
function formatPriceWithTax(priceInfo, currency = "GHS") {
|
|
156
|
+
const finalPrice = formatPrice(priceInfo.final_price, currency);
|
|
157
|
+
if (!hasTaxInfo(priceInfo)) {
|
|
158
|
+
return finalPrice;
|
|
159
|
+
}
|
|
160
|
+
if (isTaxInclusive(priceInfo)) {
|
|
161
|
+
return `${finalPrice} (incl. tax)`;
|
|
162
|
+
}
|
|
163
|
+
return `${finalPrice} + ${formatPrice(getTaxAmount(priceInfo), currency)} tax`;
|
|
164
|
+
}
|
|
146
165
|
function getDisplayPrice(product) {
|
|
147
166
|
if (product.price_info) {
|
|
148
167
|
return parsePrice(product.price_info.final_price);
|
|
@@ -236,6 +255,10 @@ var ERROR_SUGGESTIONS = {
|
|
|
236
255
|
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
237
256
|
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
238
257
|
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
258
|
+
QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
|
|
259
|
+
QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
|
|
260
|
+
QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
|
|
261
|
+
QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
|
|
239
262
|
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
240
263
|
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
241
264
|
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
@@ -502,4 +525,4 @@ function detectMobileMoneyProvider(phoneNumber) {
|
|
|
502
525
|
return null;
|
|
503
526
|
}
|
|
504
527
|
|
|
505
|
-
export { CURRENCY_SYMBOLS, MOBILE_MONEY_PROVIDERS, categorizePaymentError, detectMobileMoneyProvider, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getProductCurrency, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, normalizePaymentResponse, normalizeStatusResponse, parsePrice };
|
|
528
|
+
export { CURRENCY_SYMBOLS, MOBILE_MONEY_PROVIDERS, categorizePaymentError, detectMobileMoneyProvider, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatPriceWithTax, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getProductCurrency, getTaxAmount, hasTaxInfo, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isTaxInclusive, normalizePaymentResponse, normalizeStatusResponse, parsePrice };
|
package/package.json
CHANGED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
declare const __money: unique symbol;
|
|
2
|
-
/** Decimal monetary amount as a string (e.g. "29.99"). Branded to prevent mixing with plain strings. */
|
|
3
|
-
type Money = string & {
|
|
4
|
-
readonly [__money]: true;
|
|
5
|
-
};
|
|
6
|
-
/** Create a Money value from a string decimal. */
|
|
7
|
-
declare function money(value: string): Money;
|
|
8
|
-
/** Create a Money value from a number. Converts to a 2-decimal string. */
|
|
9
|
-
declare function moneyFromNumber(value: number): Money;
|
|
10
|
-
/** Zero money constant. */
|
|
11
|
-
declare const ZERO: Money;
|
|
12
|
-
/** ISO 4217 currency codes supported by the platform */
|
|
13
|
-
type CurrencyCode = "USD" | "EUR" | "GBP" | "JPY" | "CNY" | "CHF" | "CAD" | "AUD" | "GHS" | "NGN" | "KES" | "ZAR" | "XOF" | "XAF" | "EGP" | "TZS" | "UGX" | "RWF" | "ETB" | "ZMW" | "BWP" | "MUR" | "NAD" | "MWK" | "AOA" | "CDF" | "GMD" | "GNF" | "LRD" | "SLL" | "MZN" | "BIF" | "INR" | "BRL" | "MXN" | "KRW" | "TRY" | "THB" | "MYR" | "PHP" | "IDR" | "VND" | "SGD" | "HKD" | "TWD" | "AED" | "SAR" | "ILS";
|
|
14
|
-
/** Assert a string as CurrencyCode at API boundaries. */
|
|
15
|
-
declare function currencyCode(value: string): CurrencyCode;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use `CurrencyCode` instead. Kept for backward compatibility.
|
|
18
|
-
*/
|
|
19
|
-
type Currency = CurrencyCode;
|
|
20
|
-
/** Pagination parameters */
|
|
21
|
-
interface PaginationParams {
|
|
22
|
-
page?: number;
|
|
23
|
-
limit?: number;
|
|
24
|
-
offset?: number;
|
|
25
|
-
}
|
|
26
|
-
/** Pagination metadata in response */
|
|
27
|
-
interface Pagination {
|
|
28
|
-
total_count: number;
|
|
29
|
-
current_page: number;
|
|
30
|
-
page_size: number;
|
|
31
|
-
total_pages: number;
|
|
32
|
-
}
|
|
33
|
-
/** Strongly-typed error codes for better DX */
|
|
34
|
-
declare const ErrorCode: {
|
|
35
|
-
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
36
|
-
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
37
|
-
readonly TIMEOUT: "TIMEOUT";
|
|
38
|
-
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
39
|
-
readonly FORBIDDEN: "FORBIDDEN";
|
|
40
|
-
readonly NOT_FOUND: "NOT_FOUND";
|
|
41
|
-
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
42
|
-
readonly CART_EMPTY: "CART_EMPTY";
|
|
43
|
-
readonly CART_EXPIRED: "CART_EXPIRED";
|
|
44
|
-
readonly CART_NOT_FOUND: "CART_NOT_FOUND";
|
|
45
|
-
readonly ITEM_UNAVAILABLE: "ITEM_UNAVAILABLE";
|
|
46
|
-
readonly VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND";
|
|
47
|
-
readonly VARIANT_OUT_OF_STOCK: "VARIANT_OUT_OF_STOCK";
|
|
48
|
-
readonly ADDON_REQUIRED: "ADDON_REQUIRED";
|
|
49
|
-
readonly ADDON_MAX_EXCEEDED: "ADDON_MAX_EXCEEDED";
|
|
50
|
-
readonly CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED";
|
|
51
|
-
readonly DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED";
|
|
52
|
-
readonly CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED";
|
|
53
|
-
readonly PAYMENT_FAILED: "PAYMENT_FAILED";
|
|
54
|
-
readonly PAYMENT_CANCELLED: "PAYMENT_CANCELLED";
|
|
55
|
-
readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
|
|
56
|
-
readonly CARD_DECLINED: "CARD_DECLINED";
|
|
57
|
-
readonly INVALID_OTP: "INVALID_OTP";
|
|
58
|
-
readonly OTP_EXPIRED: "OTP_EXPIRED";
|
|
59
|
-
readonly AUTHORIZATION_FAILED: "AUTHORIZATION_FAILED";
|
|
60
|
-
readonly PAYMENT_ACTION_NOT_COMPLETED: "PAYMENT_ACTION_NOT_COMPLETED";
|
|
61
|
-
readonly SLOT_UNAVAILABLE: "SLOT_UNAVAILABLE";
|
|
62
|
-
readonly BOOKING_CONFLICT: "BOOKING_CONFLICT";
|
|
63
|
-
readonly SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND";
|
|
64
|
-
readonly OUT_OF_STOCK: "OUT_OF_STOCK";
|
|
65
|
-
readonly INSUFFICIENT_QUANTITY: "INSUFFICIENT_QUANTITY";
|
|
66
|
-
};
|
|
67
|
-
type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
68
|
-
/** API error structure */
|
|
69
|
-
interface ApiError {
|
|
70
|
-
code: string;
|
|
71
|
-
message: string;
|
|
72
|
-
retryable: boolean;
|
|
73
|
-
}
|
|
74
|
-
interface ErrorHint {
|
|
75
|
-
docs_url: string;
|
|
76
|
-
suggestion: string;
|
|
77
|
-
}
|
|
78
|
-
declare const ERROR_HINTS: Record<string, ErrorHint>;
|
|
79
|
-
/**
|
|
80
|
-
* Custom error class for SDK errors with typed error codes.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* try {
|
|
85
|
-
* await client.cart.addItem({ item_id: "prod_123" });
|
|
86
|
-
* } catch (error) {
|
|
87
|
-
* if (isCimplifyError(error)) {
|
|
88
|
-
* switch (error.code) {
|
|
89
|
-
* case ErrorCode.ITEM_UNAVAILABLE:
|
|
90
|
-
* toast.error("This item is no longer available");
|
|
91
|
-
* break;
|
|
92
|
-
* case ErrorCode.VARIANT_OUT_OF_STOCK:
|
|
93
|
-
* toast.error("Selected option is out of stock");
|
|
94
|
-
* break;
|
|
95
|
-
* default:
|
|
96
|
-
* toast.error(error.message);
|
|
97
|
-
* }
|
|
98
|
-
* }
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare class CimplifyError extends Error {
|
|
103
|
-
code: string;
|
|
104
|
-
retryable: boolean;
|
|
105
|
-
docs_url?: string | undefined;
|
|
106
|
-
suggestion?: string | undefined;
|
|
107
|
-
constructor(code: string, message: string, retryable?: boolean, docs_url?: string | undefined, suggestion?: string | undefined);
|
|
108
|
-
/** User-friendly message safe to display */
|
|
109
|
-
get userMessage(): string;
|
|
110
|
-
}
|
|
111
|
-
/** Type guard for CimplifyError */
|
|
112
|
-
declare function isCimplifyError(error: unknown): error is CimplifyError;
|
|
113
|
-
declare function getErrorHint(code: string): ErrorHint | undefined;
|
|
114
|
-
declare function enrichError(error: CimplifyError, options?: {
|
|
115
|
-
isTestMode?: boolean;
|
|
116
|
-
}): CimplifyError;
|
|
117
|
-
/** Check if error is retryable */
|
|
118
|
-
declare function isRetryableError(error: unknown): boolean;
|
|
119
|
-
|
|
120
|
-
type PaymentStatus = "pending" | "processing" | "created" | "pending_confirmation" | "success" | "succeeded" | "failed" | "declined" | "authorized" | "refunded" | "partially_refunded" | "partially_paid" | "paid" | "unpaid" | "requires_action" | "requires_payment_method" | "requires_capture" | "captured" | "cancelled" | "completed" | "voided" | "error" | "unknown";
|
|
121
|
-
type PaymentProvider = "stripe" | "paystack" | "mtn" | "vodafone" | "airtel" | "cellulant" | "offline" | "cash" | "manual";
|
|
122
|
-
type PaymentMethodType = "card" | "mobile_money" | "bank_transfer" | "cash" | "custom";
|
|
123
|
-
/** Authorization types for payment verification (OTP, PIN, etc.) */
|
|
124
|
-
type AuthorizationType = "otp" | "pin" | "phone" | "birthday" | "address";
|
|
125
|
-
/** Payment processing state machine states (for UI) */
|
|
126
|
-
type PaymentProcessingState = "initial" | "preparing" | "processing" | "verifying" | "awaiting_authorization" | "success" | "error" | "timeout";
|
|
127
|
-
interface PaymentMethod {
|
|
128
|
-
type: PaymentMethodType;
|
|
129
|
-
provider?: string;
|
|
130
|
-
phone_number?: string;
|
|
131
|
-
card_last_four?: string;
|
|
132
|
-
custom_value?: string;
|
|
133
|
-
}
|
|
134
|
-
interface Payment {
|
|
135
|
-
id: string;
|
|
136
|
-
order_id: string;
|
|
137
|
-
business_id: string;
|
|
138
|
-
amount: Money;
|
|
139
|
-
currency: CurrencyCode;
|
|
140
|
-
payment_method: PaymentMethod;
|
|
141
|
-
status: PaymentStatus;
|
|
142
|
-
provider: PaymentProvider;
|
|
143
|
-
provider_reference?: string;
|
|
144
|
-
failure_reason?: string;
|
|
145
|
-
created_at: string;
|
|
146
|
-
updated_at: string;
|
|
147
|
-
}
|
|
148
|
-
interface InitializePaymentResult {
|
|
149
|
-
payment_id: string;
|
|
150
|
-
status: PaymentStatus;
|
|
151
|
-
redirect_url?: string;
|
|
152
|
-
authorization_url?: string;
|
|
153
|
-
reference: string;
|
|
154
|
-
provider: PaymentProvider;
|
|
155
|
-
}
|
|
156
|
-
/** Normalized payment response from checkout or payment initialization */
|
|
157
|
-
interface PaymentResponse {
|
|
158
|
-
method: string;
|
|
159
|
-
provider: string;
|
|
160
|
-
requires_action: boolean;
|
|
161
|
-
public_key?: string;
|
|
162
|
-
client_secret?: string;
|
|
163
|
-
access_code?: string;
|
|
164
|
-
redirect_url?: string;
|
|
165
|
-
transaction_id?: string;
|
|
166
|
-
order_id?: string;
|
|
167
|
-
reference?: string;
|
|
168
|
-
metadata?: Record<string, unknown>;
|
|
169
|
-
instructions?: string;
|
|
170
|
-
display_text?: string;
|
|
171
|
-
requires_authorization?: boolean;
|
|
172
|
-
authorization_type?: AuthorizationType;
|
|
173
|
-
provider_payment_id?: string;
|
|
174
|
-
}
|
|
175
|
-
/** Payment status polling response */
|
|
176
|
-
interface PaymentStatusResponse {
|
|
177
|
-
status: PaymentStatus;
|
|
178
|
-
paid: boolean;
|
|
179
|
-
amount?: Money;
|
|
180
|
-
currency?: CurrencyCode;
|
|
181
|
-
reference?: string;
|
|
182
|
-
message?: string;
|
|
183
|
-
}
|
|
184
|
-
interface PaymentErrorDetails {
|
|
185
|
-
code: string;
|
|
186
|
-
message: string;
|
|
187
|
-
recoverable: boolean;
|
|
188
|
-
technical?: string;
|
|
189
|
-
}
|
|
190
|
-
interface SubmitAuthorizationInput {
|
|
191
|
-
reference: string;
|
|
192
|
-
auth_type: AuthorizationType;
|
|
193
|
-
value: string;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export { type ApiError as A, type CurrencyCode as C, ErrorCode as E, type InitializePaymentResult as I, type Money as M, type PaginationParams as P, type SubmitAuthorizationInput as S, ZERO as Z, moneyFromNumber as a, type Currency as b, currencyCode as c, type Pagination as d, type ErrorCodeType as e, type ErrorHint as f, ERROR_HINTS as g, CimplifyError as h, isCimplifyError as i, getErrorHint as j, enrichError as k, isRetryableError as l, money as m, type PaymentStatus as n, type PaymentProvider as o, type PaymentMethodType as p, type AuthorizationType as q, type PaymentProcessingState as r, type PaymentMethod as s, type Payment as t, type PaymentResponse as u, type PaymentStatusResponse as v, type PaymentErrorDetails as w };
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
declare const __money: unique symbol;
|
|
2
|
-
/** Decimal monetary amount as a string (e.g. "29.99"). Branded to prevent mixing with plain strings. */
|
|
3
|
-
type Money = string & {
|
|
4
|
-
readonly [__money]: true;
|
|
5
|
-
};
|
|
6
|
-
/** Create a Money value from a string decimal. */
|
|
7
|
-
declare function money(value: string): Money;
|
|
8
|
-
/** Create a Money value from a number. Converts to a 2-decimal string. */
|
|
9
|
-
declare function moneyFromNumber(value: number): Money;
|
|
10
|
-
/** Zero money constant. */
|
|
11
|
-
declare const ZERO: Money;
|
|
12
|
-
/** ISO 4217 currency codes supported by the platform */
|
|
13
|
-
type CurrencyCode = "USD" | "EUR" | "GBP" | "JPY" | "CNY" | "CHF" | "CAD" | "AUD" | "GHS" | "NGN" | "KES" | "ZAR" | "XOF" | "XAF" | "EGP" | "TZS" | "UGX" | "RWF" | "ETB" | "ZMW" | "BWP" | "MUR" | "NAD" | "MWK" | "AOA" | "CDF" | "GMD" | "GNF" | "LRD" | "SLL" | "MZN" | "BIF" | "INR" | "BRL" | "MXN" | "KRW" | "TRY" | "THB" | "MYR" | "PHP" | "IDR" | "VND" | "SGD" | "HKD" | "TWD" | "AED" | "SAR" | "ILS";
|
|
14
|
-
/** Assert a string as CurrencyCode at API boundaries. */
|
|
15
|
-
declare function currencyCode(value: string): CurrencyCode;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use `CurrencyCode` instead. Kept for backward compatibility.
|
|
18
|
-
*/
|
|
19
|
-
type Currency = CurrencyCode;
|
|
20
|
-
/** Pagination parameters */
|
|
21
|
-
interface PaginationParams {
|
|
22
|
-
page?: number;
|
|
23
|
-
limit?: number;
|
|
24
|
-
offset?: number;
|
|
25
|
-
}
|
|
26
|
-
/** Pagination metadata in response */
|
|
27
|
-
interface Pagination {
|
|
28
|
-
total_count: number;
|
|
29
|
-
current_page: number;
|
|
30
|
-
page_size: number;
|
|
31
|
-
total_pages: number;
|
|
32
|
-
}
|
|
33
|
-
/** Strongly-typed error codes for better DX */
|
|
34
|
-
declare const ErrorCode: {
|
|
35
|
-
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
36
|
-
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
37
|
-
readonly TIMEOUT: "TIMEOUT";
|
|
38
|
-
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
39
|
-
readonly FORBIDDEN: "FORBIDDEN";
|
|
40
|
-
readonly NOT_FOUND: "NOT_FOUND";
|
|
41
|
-
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
42
|
-
readonly CART_EMPTY: "CART_EMPTY";
|
|
43
|
-
readonly CART_EXPIRED: "CART_EXPIRED";
|
|
44
|
-
readonly CART_NOT_FOUND: "CART_NOT_FOUND";
|
|
45
|
-
readonly ITEM_UNAVAILABLE: "ITEM_UNAVAILABLE";
|
|
46
|
-
readonly VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND";
|
|
47
|
-
readonly VARIANT_OUT_OF_STOCK: "VARIANT_OUT_OF_STOCK";
|
|
48
|
-
readonly ADDON_REQUIRED: "ADDON_REQUIRED";
|
|
49
|
-
readonly ADDON_MAX_EXCEEDED: "ADDON_MAX_EXCEEDED";
|
|
50
|
-
readonly CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED";
|
|
51
|
-
readonly DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED";
|
|
52
|
-
readonly CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED";
|
|
53
|
-
readonly PAYMENT_FAILED: "PAYMENT_FAILED";
|
|
54
|
-
readonly PAYMENT_CANCELLED: "PAYMENT_CANCELLED";
|
|
55
|
-
readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
|
|
56
|
-
readonly CARD_DECLINED: "CARD_DECLINED";
|
|
57
|
-
readonly INVALID_OTP: "INVALID_OTP";
|
|
58
|
-
readonly OTP_EXPIRED: "OTP_EXPIRED";
|
|
59
|
-
readonly AUTHORIZATION_FAILED: "AUTHORIZATION_FAILED";
|
|
60
|
-
readonly PAYMENT_ACTION_NOT_COMPLETED: "PAYMENT_ACTION_NOT_COMPLETED";
|
|
61
|
-
readonly SLOT_UNAVAILABLE: "SLOT_UNAVAILABLE";
|
|
62
|
-
readonly BOOKING_CONFLICT: "BOOKING_CONFLICT";
|
|
63
|
-
readonly SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND";
|
|
64
|
-
readonly OUT_OF_STOCK: "OUT_OF_STOCK";
|
|
65
|
-
readonly INSUFFICIENT_QUANTITY: "INSUFFICIENT_QUANTITY";
|
|
66
|
-
};
|
|
67
|
-
type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
68
|
-
/** API error structure */
|
|
69
|
-
interface ApiError {
|
|
70
|
-
code: string;
|
|
71
|
-
message: string;
|
|
72
|
-
retryable: boolean;
|
|
73
|
-
}
|
|
74
|
-
interface ErrorHint {
|
|
75
|
-
docs_url: string;
|
|
76
|
-
suggestion: string;
|
|
77
|
-
}
|
|
78
|
-
declare const ERROR_HINTS: Record<string, ErrorHint>;
|
|
79
|
-
/**
|
|
80
|
-
* Custom error class for SDK errors with typed error codes.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* try {
|
|
85
|
-
* await client.cart.addItem({ item_id: "prod_123" });
|
|
86
|
-
* } catch (error) {
|
|
87
|
-
* if (isCimplifyError(error)) {
|
|
88
|
-
* switch (error.code) {
|
|
89
|
-
* case ErrorCode.ITEM_UNAVAILABLE:
|
|
90
|
-
* toast.error("This item is no longer available");
|
|
91
|
-
* break;
|
|
92
|
-
* case ErrorCode.VARIANT_OUT_OF_STOCK:
|
|
93
|
-
* toast.error("Selected option is out of stock");
|
|
94
|
-
* break;
|
|
95
|
-
* default:
|
|
96
|
-
* toast.error(error.message);
|
|
97
|
-
* }
|
|
98
|
-
* }
|
|
99
|
-
* }
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare class CimplifyError extends Error {
|
|
103
|
-
code: string;
|
|
104
|
-
retryable: boolean;
|
|
105
|
-
docs_url?: string | undefined;
|
|
106
|
-
suggestion?: string | undefined;
|
|
107
|
-
constructor(code: string, message: string, retryable?: boolean, docs_url?: string | undefined, suggestion?: string | undefined);
|
|
108
|
-
/** User-friendly message safe to display */
|
|
109
|
-
get userMessage(): string;
|
|
110
|
-
}
|
|
111
|
-
/** Type guard for CimplifyError */
|
|
112
|
-
declare function isCimplifyError(error: unknown): error is CimplifyError;
|
|
113
|
-
declare function getErrorHint(code: string): ErrorHint | undefined;
|
|
114
|
-
declare function enrichError(error: CimplifyError, options?: {
|
|
115
|
-
isTestMode?: boolean;
|
|
116
|
-
}): CimplifyError;
|
|
117
|
-
/** Check if error is retryable */
|
|
118
|
-
declare function isRetryableError(error: unknown): boolean;
|
|
119
|
-
|
|
120
|
-
type PaymentStatus = "pending" | "processing" | "created" | "pending_confirmation" | "success" | "succeeded" | "failed" | "declined" | "authorized" | "refunded" | "partially_refunded" | "partially_paid" | "paid" | "unpaid" | "requires_action" | "requires_payment_method" | "requires_capture" | "captured" | "cancelled" | "completed" | "voided" | "error" | "unknown";
|
|
121
|
-
type PaymentProvider = "stripe" | "paystack" | "mtn" | "vodafone" | "airtel" | "cellulant" | "offline" | "cash" | "manual";
|
|
122
|
-
type PaymentMethodType = "card" | "mobile_money" | "bank_transfer" | "cash" | "custom";
|
|
123
|
-
/** Authorization types for payment verification (OTP, PIN, etc.) */
|
|
124
|
-
type AuthorizationType = "otp" | "pin" | "phone" | "birthday" | "address";
|
|
125
|
-
/** Payment processing state machine states (for UI) */
|
|
126
|
-
type PaymentProcessingState = "initial" | "preparing" | "processing" | "verifying" | "awaiting_authorization" | "success" | "error" | "timeout";
|
|
127
|
-
interface PaymentMethod {
|
|
128
|
-
type: PaymentMethodType;
|
|
129
|
-
provider?: string;
|
|
130
|
-
phone_number?: string;
|
|
131
|
-
card_last_four?: string;
|
|
132
|
-
custom_value?: string;
|
|
133
|
-
}
|
|
134
|
-
interface Payment {
|
|
135
|
-
id: string;
|
|
136
|
-
order_id: string;
|
|
137
|
-
business_id: string;
|
|
138
|
-
amount: Money;
|
|
139
|
-
currency: CurrencyCode;
|
|
140
|
-
payment_method: PaymentMethod;
|
|
141
|
-
status: PaymentStatus;
|
|
142
|
-
provider: PaymentProvider;
|
|
143
|
-
provider_reference?: string;
|
|
144
|
-
failure_reason?: string;
|
|
145
|
-
created_at: string;
|
|
146
|
-
updated_at: string;
|
|
147
|
-
}
|
|
148
|
-
interface InitializePaymentResult {
|
|
149
|
-
payment_id: string;
|
|
150
|
-
status: PaymentStatus;
|
|
151
|
-
redirect_url?: string;
|
|
152
|
-
authorization_url?: string;
|
|
153
|
-
reference: string;
|
|
154
|
-
provider: PaymentProvider;
|
|
155
|
-
}
|
|
156
|
-
/** Normalized payment response from checkout or payment initialization */
|
|
157
|
-
interface PaymentResponse {
|
|
158
|
-
method: string;
|
|
159
|
-
provider: string;
|
|
160
|
-
requires_action: boolean;
|
|
161
|
-
public_key?: string;
|
|
162
|
-
client_secret?: string;
|
|
163
|
-
access_code?: string;
|
|
164
|
-
redirect_url?: string;
|
|
165
|
-
transaction_id?: string;
|
|
166
|
-
order_id?: string;
|
|
167
|
-
reference?: string;
|
|
168
|
-
metadata?: Record<string, unknown>;
|
|
169
|
-
instructions?: string;
|
|
170
|
-
display_text?: string;
|
|
171
|
-
requires_authorization?: boolean;
|
|
172
|
-
authorization_type?: AuthorizationType;
|
|
173
|
-
provider_payment_id?: string;
|
|
174
|
-
}
|
|
175
|
-
/** Payment status polling response */
|
|
176
|
-
interface PaymentStatusResponse {
|
|
177
|
-
status: PaymentStatus;
|
|
178
|
-
paid: boolean;
|
|
179
|
-
amount?: Money;
|
|
180
|
-
currency?: CurrencyCode;
|
|
181
|
-
reference?: string;
|
|
182
|
-
message?: string;
|
|
183
|
-
}
|
|
184
|
-
interface PaymentErrorDetails {
|
|
185
|
-
code: string;
|
|
186
|
-
message: string;
|
|
187
|
-
recoverable: boolean;
|
|
188
|
-
technical?: string;
|
|
189
|
-
}
|
|
190
|
-
interface SubmitAuthorizationInput {
|
|
191
|
-
reference: string;
|
|
192
|
-
auth_type: AuthorizationType;
|
|
193
|
-
value: string;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export { type ApiError as A, type CurrencyCode as C, ErrorCode as E, type InitializePaymentResult as I, type Money as M, type PaginationParams as P, type SubmitAuthorizationInput as S, ZERO as Z, moneyFromNumber as a, type Currency as b, currencyCode as c, type Pagination as d, type ErrorCodeType as e, type ErrorHint as f, ERROR_HINTS as g, CimplifyError as h, isCimplifyError as i, getErrorHint as j, enrichError as k, isRetryableError as l, money as m, type PaymentStatus as n, type PaymentProvider as o, type PaymentMethodType as p, type AuthorizationType as q, type PaymentProcessingState as r, type PaymentMethod as s, type Payment as t, type PaymentResponse as u, type PaymentStatusResponse as v, type PaymentErrorDetails as w };
|