@fire-spark/payments-pagoplux-card 0.13.1 → 0.13.2
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.d.ts +3 -1
- package/dist/index.js +34 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -132,6 +132,8 @@ type PagopluxCardOptions = {
|
|
|
132
132
|
/** Secure random source; default `crypto.getRandomValues`. */
|
|
133
133
|
random?: PagopluxRandom;
|
|
134
134
|
};
|
|
135
|
+
/** Store key over the Connection Settings one, from the device config. */
|
|
136
|
+
declare const pagopluxPublicKeyOf: (config: Record<string, unknown>) => string | null;
|
|
135
137
|
/**
|
|
136
138
|
* PagoPlux API de Pago, card not present. The template collects the card
|
|
137
139
|
* (`collector`); the adapter encrypts it on the device (AES-256-ECB per
|
|
@@ -204,4 +206,4 @@ declare const pagopluxErrors: Readonly<Record<string, import("@fire-spark/paymen
|
|
|
204
206
|
/** Spark code for a code 2 decline from its message, else `null`. */
|
|
205
207
|
declare const pagopluxDeclineCode: (message: string | null) => "AMBIGUOUS" | "BATCH_CLOSE_REQUIRED" | "CANCELLED_BY_USER" | "CARD_DECLINED" | "EXPIRED_CARD" | "FINANCING_EXPIRED" | "FINANCING_REJECTED" | "FRAUD_SUSPECTED" | "INSUFFICIENT_BALANCE" | "INSUFFICIENT_FUNDS" | "INVALID_CARD" | "INVALID_CREDENTIALS" | "INVALID_PIN" | "INVALID_REQUEST" | "LIMIT_EXCEEDED" | "MANUAL_REVERSAL_REQUIRED" | "NETWORK_ERROR" | "PROVIDER_UNAVAILABLE" | "REVERSAL_NOT_ALLOWED" | "TERMINAL_BUSY" | "TERMINAL_NEEDS_INIT" | "TERMINAL_NOT_CONFIGURED" | "TERMINAL_UNAVAILABLE" | "TIMEOUT" | "TRANSFER_ALREADY_USED" | "TRANSFER_AMOUNT_MISMATCH" | "TRANSFER_NOT_FOUND" | "UNKNOWN" | "USER_TIMEOUT" | "WALLET_EXPIRED" | "WALLET_REJECTED" | null;
|
|
206
208
|
//#endregion
|
|
207
|
-
export { PAGOPLUX_CARD_POLICY, PAGOPLUX_METHOD, PAGOPLUX_OTP_TRIES, PAGOPLUX_PROVIDER, type PagopluxAddressEntry, type PagopluxBuyerEntry, type PagopluxCardCollector, type PagopluxCardEntry, type PagopluxCardForm, type PagopluxCardFormInput, PagopluxCardOptions, type PagopluxChargeOutcome, type PagopluxEncryptedCard, type PagopluxOtpSession, PagopluxRandom, defaultRandom, encryptPagopluxCard, fromBase64, pagopluxAes, pagopluxCardPayments, pagopluxDeclineCode, pagopluxErrors, pagopluxRsa, pagopluxSymmetricKey, parsePagopluxPublicKey, toBase64 };
|
|
209
|
+
export { PAGOPLUX_CARD_POLICY, PAGOPLUX_METHOD, PAGOPLUX_OTP_TRIES, PAGOPLUX_PROVIDER, type PagopluxAddressEntry, type PagopluxBuyerEntry, type PagopluxCardCollector, type PagopluxCardEntry, type PagopluxCardForm, type PagopluxCardFormInput, PagopluxCardOptions, type PagopluxChargeOutcome, type PagopluxEncryptedCard, type PagopluxOtpSession, PagopluxRandom, defaultRandom, encryptPagopluxCard, fromBase64, pagopluxAes, pagopluxCardPayments, pagopluxDeclineCode, pagopluxErrors, pagopluxPublicKeyOf, pagopluxRsa, pagopluxSymmetricKey, parsePagopluxPublicKey, toBase64 };
|
package/dist/index.js
CHANGED
|
@@ -247,9 +247,30 @@ const pagopluxDeclineCode = (message) => {
|
|
|
247
247
|
const fail = (code, message) => {
|
|
248
248
|
return new PaymentError(createPaymentError(code, { provider_message: message }));
|
|
249
249
|
};
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
250
|
+
const keyText = (value) => {
|
|
251
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
252
|
+
};
|
|
253
|
+
/** The API sends only the entry of the channel's store (if any). */
|
|
254
|
+
const storeSettingsOf = (config) => {
|
|
255
|
+
const stores = config.stores;
|
|
256
|
+
if (!stores || typeof stores !== "object") return {};
|
|
257
|
+
const [first] = Object.values(stores);
|
|
258
|
+
return first && typeof first === "object" ? first : {};
|
|
259
|
+
};
|
|
260
|
+
/** Store key over the Connection Settings one, from the device config. */
|
|
261
|
+
const pagopluxPublicKeyOf = (config) => {
|
|
262
|
+
const store = storeSettingsOf(config);
|
|
263
|
+
return keyText(store.encryption_public_key) ?? keyText(config.encryption_public_key);
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Key of the order's store, asked to Spark (`encryption_key`): the store
|
|
267
|
+
* may charge through its own PagoPlux account. An API without the
|
|
268
|
+
* operation falls back to the device config.
|
|
269
|
+
*/
|
|
270
|
+
const publicKeyFor = async (ctx) => {
|
|
271
|
+
const answer = await ctx.server.call("encryption_key", {}).catch(() => null);
|
|
272
|
+
const key = keyText(answer?.encryption_public_key) ?? pagopluxPublicKeyOf(ctx.config);
|
|
273
|
+
if (key) return key;
|
|
253
274
|
throw fail("INVALID_CREDENTIALS", "Missing PagoPlux encryption_public_key");
|
|
254
275
|
};
|
|
255
276
|
const installmentOptionsOf = (config) => {
|
|
@@ -494,7 +515,8 @@ const pagopluxCardPayments = (options) => {
|
|
|
494
515
|
} : outcome;
|
|
495
516
|
};
|
|
496
517
|
const start = async (ctx) => {
|
|
497
|
-
const
|
|
518
|
+
const keyPromise = publicKeyFor(ctx);
|
|
519
|
+
keyPromise.catch(() => void 0);
|
|
498
520
|
const f1 = {
|
|
499
521
|
amount: ctx.amount.value,
|
|
500
522
|
currency: ctx.amount.currency
|
|
@@ -510,6 +532,13 @@ const pagopluxCardPayments = (options) => {
|
|
|
510
532
|
const error = createPaymentError("CANCELLED_BY_USER", { attempt: ctx.attempt });
|
|
511
533
|
return failedResult(ctx, error);
|
|
512
534
|
}
|
|
535
|
+
let publicKey;
|
|
536
|
+
try {
|
|
537
|
+
publicKey = await keyPromise;
|
|
538
|
+
} catch (cause) {
|
|
539
|
+
if (cause instanceof PaymentError) return failedResult(ctx, cause.error);
|
|
540
|
+
throw cause;
|
|
541
|
+
}
|
|
513
542
|
const sealed = encryptPagopluxCard(form.card, publicKey, options.random);
|
|
514
543
|
ctx.ui.message({
|
|
515
544
|
text: "Procesando pago…",
|
|
@@ -556,4 +585,4 @@ const pagopluxCardPayments = (options) => {
|
|
|
556
585
|
};
|
|
557
586
|
};
|
|
558
587
|
//#endregion
|
|
559
|
-
export { PAGOPLUX_CARD_POLICY, PAGOPLUX_METHOD, PAGOPLUX_OTP_TRIES, PAGOPLUX_PROVIDER, defaultRandom, encryptPagopluxCard, fromBase64, pagopluxAes, pagopluxCardPayments, pagopluxDeclineCode, pagopluxErrors, pagopluxRsa, pagopluxSymmetricKey, parsePagopluxPublicKey, toBase64 };
|
|
588
|
+
export { PAGOPLUX_CARD_POLICY, PAGOPLUX_METHOD, PAGOPLUX_OTP_TRIES, PAGOPLUX_PROVIDER, defaultRandom, encryptPagopluxCard, fromBase64, pagopluxAes, pagopluxCardPayments, pagopluxDeclineCode, pagopluxErrors, pagopluxPublicKeyOf, pagopluxRsa, pagopluxSymmetricKey, parsePagopluxPublicKey, toBase64 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fire-spark/payments-pagoplux-card",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "Fire Spark PagoPlux card adapter (API de Pago): card encrypted on the device, charged by Spark, OTP for Diners/Interdin/Discover",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@noble/ciphers": "^1.3.0",
|
|
21
|
-
"@fire-spark/
|
|
22
|
-
"@fire-spark/
|
|
21
|
+
"@fire-spark/payments": "^0.13.2",
|
|
22
|
+
"@fire-spark/types": "^0.13.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"tsdown": "^0.22.14",
|