@cimplify/sdk 0.6.3 → 0.6.4
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/index.js +64 -24
- package/dist/index.mjs +64 -24
- package/package.json +1 -1
- package/dist/ads-Cz14AMnc.d.mts +0 -3441
- package/dist/ads-Cz14AMnc.d.ts +0 -3441
- package/dist/index.d.mts +0 -377
- package/dist/index.d.ts +0 -377
- package/dist/react.d.mts +0 -132
- package/dist/react.d.ts +0 -132
package/dist/index.js
CHANGED
|
@@ -1099,14 +1099,14 @@ function detectMobileMoneyProvider(phoneNumber) {
|
|
|
1099
1099
|
// src/utils/paystack.ts
|
|
1100
1100
|
async function openPaystackPopup(options, signal) {
|
|
1101
1101
|
if (typeof window === "undefined") {
|
|
1102
|
-
return { success: false, error: "
|
|
1102
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1103
1103
|
}
|
|
1104
1104
|
let PaystackPop;
|
|
1105
1105
|
try {
|
|
1106
1106
|
const imported = await import('@paystack/inline-js');
|
|
1107
1107
|
PaystackPop = imported.default;
|
|
1108
1108
|
} catch {
|
|
1109
|
-
return { success: false, error: "
|
|
1109
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1110
1110
|
}
|
|
1111
1111
|
return new Promise((resolve) => {
|
|
1112
1112
|
let settled = false;
|
|
@@ -1165,6 +1165,41 @@ async function openPaystackPopup(options, signal) {
|
|
|
1165
1165
|
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
1166
1166
|
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
1167
1167
|
var MAX_CONSECUTIVE_NETWORK_ERRORS = 5;
|
|
1168
|
+
var CARD_PROVIDER_PAYSTACK = "paystack";
|
|
1169
|
+
function normalizeCardPopupError(error) {
|
|
1170
|
+
if (!error || error === "PAYMENT_CANCELLED" || error === "CANCELLED") {
|
|
1171
|
+
return "PAYMENT_CANCELLED";
|
|
1172
|
+
}
|
|
1173
|
+
if (error === "PROVIDER_UNAVAILABLE") {
|
|
1174
|
+
return "PROVIDER_UNAVAILABLE";
|
|
1175
|
+
}
|
|
1176
|
+
if (error === "POPUP_BLOCKED") {
|
|
1177
|
+
return "POPUP_BLOCKED";
|
|
1178
|
+
}
|
|
1179
|
+
return "PAYMENT_FAILED";
|
|
1180
|
+
}
|
|
1181
|
+
function normalizeCardProvider(value) {
|
|
1182
|
+
const normalized = value?.trim().toLowerCase();
|
|
1183
|
+
return normalized && normalized.length > 0 ? normalized : CARD_PROVIDER_PAYSTACK;
|
|
1184
|
+
}
|
|
1185
|
+
async function openCardPopup(provider, checkoutResult, email, currency, signal) {
|
|
1186
|
+
if (typeof window === "undefined") {
|
|
1187
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1188
|
+
}
|
|
1189
|
+
if (provider === CARD_PROVIDER_PAYSTACK) {
|
|
1190
|
+
return openPaystackPopup(
|
|
1191
|
+
{
|
|
1192
|
+
key: checkoutResult.public_key || "",
|
|
1193
|
+
email,
|
|
1194
|
+
accessCode: checkoutResult.client_secret,
|
|
1195
|
+
reference: checkoutResult.payment_reference || checkoutResult.client_secret,
|
|
1196
|
+
currency
|
|
1197
|
+
},
|
|
1198
|
+
signal
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1202
|
+
}
|
|
1168
1203
|
function normalizeAuthorizationType(value) {
|
|
1169
1204
|
return value === "otp" || value === "pin" ? value : void 0;
|
|
1170
1205
|
}
|
|
@@ -1205,7 +1240,7 @@ var CheckoutResolver = class {
|
|
|
1205
1240
|
this.orderType = options.orderType;
|
|
1206
1241
|
this.cartTotal = options.cartTotal;
|
|
1207
1242
|
this.cartCurrency = options.cartCurrency;
|
|
1208
|
-
this.
|
|
1243
|
+
this.allowPopups = options.allowPopups ?? typeof window !== "undefined";
|
|
1209
1244
|
}
|
|
1210
1245
|
async resolve(checkoutResult) {
|
|
1211
1246
|
try {
|
|
@@ -1220,44 +1255,49 @@ var CheckoutResolver = class {
|
|
|
1220
1255
|
return this.finalizeSuccess(checkoutResult);
|
|
1221
1256
|
}
|
|
1222
1257
|
if (checkoutResult.client_secret && checkoutResult.public_key) {
|
|
1223
|
-
|
|
1224
|
-
return this.fail(
|
|
1225
|
-
"PAYSTACK_HANDOFF_REQUIRED",
|
|
1226
|
-
"Card authorization requires Elements. Use elements.processCheckout() for card flows.",
|
|
1227
|
-
true
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1258
|
+
const provider = normalizeCardProvider(checkoutResult.provider);
|
|
1230
1259
|
this.emit("awaiting_authorization", {
|
|
1231
|
-
authorization_type: authorizationType,
|
|
1232
1260
|
display_text: "Complete payment in the card authorization popup.",
|
|
1233
1261
|
order_id: checkoutResult.order_id,
|
|
1234
|
-
order_number: checkoutResult.order_number
|
|
1235
|
-
provider: checkoutResult.provider ?? "paystack"
|
|
1262
|
+
order_number: checkoutResult.order_number
|
|
1236
1263
|
});
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1264
|
+
if (!this.allowPopups) {
|
|
1265
|
+
return this.fail(
|
|
1266
|
+
"PROVIDER_UNAVAILABLE",
|
|
1267
|
+
"Card payment popup is unavailable in this environment.",
|
|
1268
|
+
false
|
|
1269
|
+
);
|
|
1270
|
+
}
|
|
1271
|
+
const popupResult = await openCardPopup(
|
|
1272
|
+
provider,
|
|
1273
|
+
checkoutResult,
|
|
1274
|
+
this.checkoutData.customer.email || "customer@cimplify.io",
|
|
1275
|
+
this.getOrderCurrency(checkoutResult),
|
|
1245
1276
|
this.signal
|
|
1246
1277
|
);
|
|
1247
1278
|
if (!popupResult.success) {
|
|
1248
|
-
|
|
1279
|
+
const popupError = normalizeCardPopupError(popupResult.error);
|
|
1280
|
+
if (popupError === "POPUP_BLOCKED") {
|
|
1249
1281
|
return this.fail(
|
|
1250
1282
|
"POPUP_BLOCKED",
|
|
1251
1283
|
"Unable to open card payment popup. Please allow popups and try again.",
|
|
1252
1284
|
true
|
|
1253
1285
|
);
|
|
1254
1286
|
}
|
|
1287
|
+
if (popupError === "PROVIDER_UNAVAILABLE") {
|
|
1288
|
+
return this.fail(
|
|
1289
|
+
"PROVIDER_UNAVAILABLE",
|
|
1290
|
+
"Card payment provider is unavailable.",
|
|
1291
|
+
false
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1255
1294
|
return this.fail(
|
|
1256
|
-
|
|
1295
|
+
"PAYMENT_CANCELLED",
|
|
1257
1296
|
"Card payment was cancelled before completion.",
|
|
1258
1297
|
true
|
|
1259
1298
|
);
|
|
1260
1299
|
}
|
|
1300
|
+
paymentReference = popupResult.reference || paymentReference;
|
|
1261
1301
|
}
|
|
1262
1302
|
if (checkoutResult.authorization_url) {
|
|
1263
1303
|
if (typeof window !== "undefined" && this.returnUrl) {
|
|
@@ -1787,7 +1827,7 @@ var CheckoutService = class {
|
|
|
1787
1827
|
cartTotal: cart.pricing.total_price,
|
|
1788
1828
|
cartCurrency: checkoutData.pay_currency || cart.pricing.currency || "GHS",
|
|
1789
1829
|
orderType: checkoutData.order_type,
|
|
1790
|
-
|
|
1830
|
+
allowPopups: data.allow_popups
|
|
1791
1831
|
});
|
|
1792
1832
|
const resolved = await resolver.resolve(processResult.value);
|
|
1793
1833
|
return ok(resolved);
|
package/dist/index.mjs
CHANGED
|
@@ -1097,14 +1097,14 @@ function detectMobileMoneyProvider(phoneNumber) {
|
|
|
1097
1097
|
// src/utils/paystack.ts
|
|
1098
1098
|
async function openPaystackPopup(options, signal) {
|
|
1099
1099
|
if (typeof window === "undefined") {
|
|
1100
|
-
return { success: false, error: "
|
|
1100
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1101
1101
|
}
|
|
1102
1102
|
let PaystackPop;
|
|
1103
1103
|
try {
|
|
1104
1104
|
const imported = await import('@paystack/inline-js');
|
|
1105
1105
|
PaystackPop = imported.default;
|
|
1106
1106
|
} catch {
|
|
1107
|
-
return { success: false, error: "
|
|
1107
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1108
1108
|
}
|
|
1109
1109
|
return new Promise((resolve) => {
|
|
1110
1110
|
let settled = false;
|
|
@@ -1163,6 +1163,41 @@ async function openPaystackPopup(options, signal) {
|
|
|
1163
1163
|
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
1164
1164
|
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
1165
1165
|
var MAX_CONSECUTIVE_NETWORK_ERRORS = 5;
|
|
1166
|
+
var CARD_PROVIDER_PAYSTACK = "paystack";
|
|
1167
|
+
function normalizeCardPopupError(error) {
|
|
1168
|
+
if (!error || error === "PAYMENT_CANCELLED" || error === "CANCELLED") {
|
|
1169
|
+
return "PAYMENT_CANCELLED";
|
|
1170
|
+
}
|
|
1171
|
+
if (error === "PROVIDER_UNAVAILABLE") {
|
|
1172
|
+
return "PROVIDER_UNAVAILABLE";
|
|
1173
|
+
}
|
|
1174
|
+
if (error === "POPUP_BLOCKED") {
|
|
1175
|
+
return "POPUP_BLOCKED";
|
|
1176
|
+
}
|
|
1177
|
+
return "PAYMENT_FAILED";
|
|
1178
|
+
}
|
|
1179
|
+
function normalizeCardProvider(value) {
|
|
1180
|
+
const normalized = value?.trim().toLowerCase();
|
|
1181
|
+
return normalized && normalized.length > 0 ? normalized : CARD_PROVIDER_PAYSTACK;
|
|
1182
|
+
}
|
|
1183
|
+
async function openCardPopup(provider, checkoutResult, email, currency, signal) {
|
|
1184
|
+
if (typeof window === "undefined") {
|
|
1185
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1186
|
+
}
|
|
1187
|
+
if (provider === CARD_PROVIDER_PAYSTACK) {
|
|
1188
|
+
return openPaystackPopup(
|
|
1189
|
+
{
|
|
1190
|
+
key: checkoutResult.public_key || "",
|
|
1191
|
+
email,
|
|
1192
|
+
accessCode: checkoutResult.client_secret,
|
|
1193
|
+
reference: checkoutResult.payment_reference || checkoutResult.client_secret,
|
|
1194
|
+
currency
|
|
1195
|
+
},
|
|
1196
|
+
signal
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
return { success: false, error: "PROVIDER_UNAVAILABLE" };
|
|
1200
|
+
}
|
|
1166
1201
|
function normalizeAuthorizationType(value) {
|
|
1167
1202
|
return value === "otp" || value === "pin" ? value : void 0;
|
|
1168
1203
|
}
|
|
@@ -1203,7 +1238,7 @@ var CheckoutResolver = class {
|
|
|
1203
1238
|
this.orderType = options.orderType;
|
|
1204
1239
|
this.cartTotal = options.cartTotal;
|
|
1205
1240
|
this.cartCurrency = options.cartCurrency;
|
|
1206
|
-
this.
|
|
1241
|
+
this.allowPopups = options.allowPopups ?? typeof window !== "undefined";
|
|
1207
1242
|
}
|
|
1208
1243
|
async resolve(checkoutResult) {
|
|
1209
1244
|
try {
|
|
@@ -1218,44 +1253,49 @@ var CheckoutResolver = class {
|
|
|
1218
1253
|
return this.finalizeSuccess(checkoutResult);
|
|
1219
1254
|
}
|
|
1220
1255
|
if (checkoutResult.client_secret && checkoutResult.public_key) {
|
|
1221
|
-
|
|
1222
|
-
return this.fail(
|
|
1223
|
-
"PAYSTACK_HANDOFF_REQUIRED",
|
|
1224
|
-
"Card authorization requires Elements. Use elements.processCheckout() for card flows.",
|
|
1225
|
-
true
|
|
1226
|
-
);
|
|
1227
|
-
}
|
|
1256
|
+
const provider = normalizeCardProvider(checkoutResult.provider);
|
|
1228
1257
|
this.emit("awaiting_authorization", {
|
|
1229
|
-
authorization_type: authorizationType,
|
|
1230
1258
|
display_text: "Complete payment in the card authorization popup.",
|
|
1231
1259
|
order_id: checkoutResult.order_id,
|
|
1232
|
-
order_number: checkoutResult.order_number
|
|
1233
|
-
provider: checkoutResult.provider ?? "paystack"
|
|
1260
|
+
order_number: checkoutResult.order_number
|
|
1234
1261
|
});
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1262
|
+
if (!this.allowPopups) {
|
|
1263
|
+
return this.fail(
|
|
1264
|
+
"PROVIDER_UNAVAILABLE",
|
|
1265
|
+
"Card payment popup is unavailable in this environment.",
|
|
1266
|
+
false
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
const popupResult = await openCardPopup(
|
|
1270
|
+
provider,
|
|
1271
|
+
checkoutResult,
|
|
1272
|
+
this.checkoutData.customer.email || "customer@cimplify.io",
|
|
1273
|
+
this.getOrderCurrency(checkoutResult),
|
|
1243
1274
|
this.signal
|
|
1244
1275
|
);
|
|
1245
1276
|
if (!popupResult.success) {
|
|
1246
|
-
|
|
1277
|
+
const popupError = normalizeCardPopupError(popupResult.error);
|
|
1278
|
+
if (popupError === "POPUP_BLOCKED") {
|
|
1247
1279
|
return this.fail(
|
|
1248
1280
|
"POPUP_BLOCKED",
|
|
1249
1281
|
"Unable to open card payment popup. Please allow popups and try again.",
|
|
1250
1282
|
true
|
|
1251
1283
|
);
|
|
1252
1284
|
}
|
|
1285
|
+
if (popupError === "PROVIDER_UNAVAILABLE") {
|
|
1286
|
+
return this.fail(
|
|
1287
|
+
"PROVIDER_UNAVAILABLE",
|
|
1288
|
+
"Card payment provider is unavailable.",
|
|
1289
|
+
false
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1253
1292
|
return this.fail(
|
|
1254
|
-
|
|
1293
|
+
"PAYMENT_CANCELLED",
|
|
1255
1294
|
"Card payment was cancelled before completion.",
|
|
1256
1295
|
true
|
|
1257
1296
|
);
|
|
1258
1297
|
}
|
|
1298
|
+
paymentReference = popupResult.reference || paymentReference;
|
|
1259
1299
|
}
|
|
1260
1300
|
if (checkoutResult.authorization_url) {
|
|
1261
1301
|
if (typeof window !== "undefined" && this.returnUrl) {
|
|
@@ -1785,7 +1825,7 @@ var CheckoutService = class {
|
|
|
1785
1825
|
cartTotal: cart.pricing.total_price,
|
|
1786
1826
|
cartCurrency: checkoutData.pay_currency || cart.pricing.currency || "GHS",
|
|
1787
1827
|
orderType: checkoutData.order_type,
|
|
1788
|
-
|
|
1828
|
+
allowPopups: data.allow_popups
|
|
1789
1829
|
});
|
|
1790
1830
|
const resolved = await resolver.resolve(processResult.value);
|
|
1791
1831
|
return ok(resolved);
|