@fire-spark/payments 0.13.2 → 0.14.0
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 +60 -1
- package/dist/index.js +41 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,59 @@ declare const validateTendersAgainstRules: (input: {
|
|
|
96
96
|
effect: MixedPaymentsEffect | null;
|
|
97
97
|
}) => ValidateTendersResult;
|
|
98
98
|
//#endregion
|
|
99
|
+
//#region src/challenge.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* 3-D Secure (or any bank) challenge a provider asks before it charges.
|
|
102
|
+
* The template shows it (`PaymentUI.challenge`): an iframe or popup on the
|
|
103
|
+
* web, a WebView on React Native. When the bank finishes, Fire Spark closes
|
|
104
|
+
* the payment on the server and its return page posts
|
|
105
|
+
* `PaymentChallengeMessage` to `window.parent`, `window.opener` and
|
|
106
|
+
* `window.ReactNativeWebView`.
|
|
107
|
+
*/
|
|
108
|
+
type PaymentChallenge = {
|
|
109
|
+
/** Bank page to open. */
|
|
110
|
+
url: string;
|
|
111
|
+
/** `GET`: open `url`. `POST`: submit `parameters` as a form to `url`. */
|
|
112
|
+
method: "GET" | "POST";
|
|
113
|
+
/** Form fields of a `POST` challenge (e.g. `creq`, `threeDSSessionData`). */
|
|
114
|
+
parameters: {
|
|
115
|
+
name: string;
|
|
116
|
+
value: string;
|
|
117
|
+
}[];
|
|
118
|
+
/** Provider label of the flow (e.g. `3DSV1`, `3DSV2`), for logs. */
|
|
119
|
+
version: string | null;
|
|
120
|
+
};
|
|
121
|
+
type PaymentChallengeInput = PaymentChallenge & {
|
|
122
|
+
/** Aborted when the attempt is cancelled or times out: close the view. */
|
|
123
|
+
signal: AbortSignal;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* `completed`: the Fire Spark return page posted its message. `false`: the
|
|
127
|
+
* customer closed the challenge first (the adapter asks the server anyway).
|
|
128
|
+
*/
|
|
129
|
+
type PaymentChallengeResult = {
|
|
130
|
+
completed: boolean;
|
|
131
|
+
};
|
|
132
|
+
declare const PAYMENT_CHALLENGE_MESSAGE = "fire-spark:payment-challenge";
|
|
133
|
+
/** What the Fire Spark return page posts when the challenge ends. */
|
|
134
|
+
type PaymentChallengeMessage = {
|
|
135
|
+
type: typeof PAYMENT_CHALLENGE_MESSAGE;
|
|
136
|
+
/** Tender status after the server closed it (`PAID`, `FAILED`, ...). */
|
|
137
|
+
status: string;
|
|
138
|
+
attempt_reference: string | null;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Reads a `message` event payload (an object, or the JSON string a
|
|
142
|
+
* React Native WebView delivers).
|
|
143
|
+
*/
|
|
144
|
+
declare const parsePaymentChallengeMessage: (data: unknown) => PaymentChallengeMessage | null;
|
|
145
|
+
/**
|
|
146
|
+
* HTML that opens the challenge by itself: a form posted on load
|
|
147
|
+
* (`POST`) or a redirect (`GET`). Use it as an iframe `srcdoc`, a popup
|
|
148
|
+
* document or a WebView `source={{ html }}`.
|
|
149
|
+
*/
|
|
150
|
+
declare const paymentChallengeDocument: (challenge: PaymentChallenge) => string;
|
|
151
|
+
//#endregion
|
|
99
152
|
//#region src/money.d.ts
|
|
100
153
|
/** One monetary amount. Arithmetic stays on Big until a caller serializes. */
|
|
101
154
|
type Money = Big;
|
|
@@ -297,6 +350,12 @@ type PaymentUI = {
|
|
|
297
350
|
text: string;
|
|
298
351
|
}): Promise<boolean>;
|
|
299
352
|
action(input: PaymentAction): void;
|
|
353
|
+
/**
|
|
354
|
+
* Shows a bank challenge (3-D Secure) until Fire Spark's return page
|
|
355
|
+
* posts its message or the customer closes it. Optional: without it, a
|
|
356
|
+
* provider that requires a challenge fails with `INVALID_REQUEST`.
|
|
357
|
+
*/
|
|
358
|
+
challenge?(input: PaymentChallengeInput): Promise<PaymentChallengeResult>;
|
|
300
359
|
};
|
|
301
360
|
/** Persistent key-value store per device. */
|
|
302
361
|
type PaymentStorage = {
|
|
@@ -732,4 +791,4 @@ declare const scopedPaymentStorage: (storage: PaymentStorage, paymentId: string)
|
|
|
732
791
|
/** For tests and web previews; apps provide AsyncStorage or localStorage. */
|
|
733
792
|
declare const memoryPaymentStorage: () => PaymentStorage;
|
|
734
793
|
//#endregion
|
|
735
|
-
export { ACTIVE_INTENT_STATUSES, AllocateTenderInput, AllocateTendersInput, AllocateTendersResult, AllocatedTender, AllocationError, CURRENCY_DECIMALS, ChargeConversion, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, type DeviceField, MANUAL_PAYMENT_METHODS, MergePaymentTenderOutcome, MergePaymentTenderResult, Money, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, type PaymentAction, type PaymentAdapter, type PaymentAdapterCapabilities, type PaymentAmount, type PaymentCardType, type PaymentCollectAt, type PaymentContext, type PaymentCustomer, type PaymentEntryMode, type PaymentEnvironment, PaymentError, PaymentErrorCode, PaymentErrorDictionary, PaymentErrorEntry, PaymentErrorReason, type PaymentIntentStatus, type PaymentMetadata, type PaymentMetadataPayment, type PaymentOperation, type PaymentPolicy, type PaymentResult, type PaymentReversal, type PaymentServer, type PaymentStorage, PaymentTenderUpdate, type PaymentUI, REDEMPTION_METHOD, RawPaymentError, RedeemLike, RedeemSource, RedemptionDetails, RedemptionGroup, RedemptionReward, RulesTender, StandardPaymentError, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, type TaxBreakdown, TaxLine, type TerminalContext, type TerminalOperation, type TerminalOperations, type TerminalResult, ValidateTendersResult, activeIntent, allocateTenders, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupRedeems, hasRedeemPayment, isBatchCloseDue, isDeliveryFee, isIntentCovered, isManualPayment, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, money, moneyMax, moneyMin, moneyNumber, moneyNumbers, moneySum, moneyZero, nextIntentStatus, orderRedeems, primaryTender, primaryTenderOf, prorateMinor, realTenders, redeemsCoverTotal, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, splitMoney, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
|
|
794
|
+
export { ACTIVE_INTENT_STATUSES, AllocateTenderInput, AllocateTendersInput, AllocateTendersResult, AllocatedTender, AllocationError, CURRENCY_DECIMALS, ChargeConversion, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, type DeviceField, MANUAL_PAYMENT_METHODS, MergePaymentTenderOutcome, MergePaymentTenderResult, Money, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_CHALLENGE_MESSAGE, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, type PaymentAction, type PaymentAdapter, type PaymentAdapterCapabilities, type PaymentAmount, type PaymentCardType, PaymentChallenge, PaymentChallengeInput, PaymentChallengeMessage, PaymentChallengeResult, type PaymentCollectAt, type PaymentContext, type PaymentCustomer, type PaymentEntryMode, type PaymentEnvironment, PaymentError, PaymentErrorCode, PaymentErrorDictionary, PaymentErrorEntry, PaymentErrorReason, type PaymentIntentStatus, type PaymentMetadata, type PaymentMetadataPayment, type PaymentOperation, type PaymentPolicy, type PaymentResult, type PaymentReversal, type PaymentServer, type PaymentStorage, PaymentTenderUpdate, type PaymentUI, REDEMPTION_METHOD, RawPaymentError, RedeemLike, RedeemSource, RedemptionDetails, RedemptionGroup, RedemptionReward, RulesTender, StandardPaymentError, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, type TaxBreakdown, TaxLine, type TerminalContext, type TerminalOperation, type TerminalOperations, type TerminalResult, ValidateTendersResult, activeIntent, allocateTenders, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupRedeems, hasRedeemPayment, isBatchCloseDue, isDeliveryFee, isIntentCovered, isManualPayment, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, money, moneyMax, moneyMin, moneyNumber, moneyNumbers, moneySum, moneyZero, nextIntentStatus, orderRedeems, parsePaymentChallengeMessage, paymentChallengeDocument, primaryTender, primaryTenderOf, prorateMinor, realTenders, redeemsCoverTotal, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, splitMoney, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
|
package/dist/index.js
CHANGED
|
@@ -939,6 +939,46 @@ const validateTendersAgainstRules = (input) => {
|
|
|
939
939
|
};
|
|
940
940
|
};
|
|
941
941
|
//#endregion
|
|
942
|
+
//#region src/challenge.ts
|
|
943
|
+
const PAYMENT_CHALLENGE_MESSAGE = "fire-spark:payment-challenge";
|
|
944
|
+
/**
|
|
945
|
+
* Reads a `message` event payload (an object, or the JSON string a
|
|
946
|
+
* React Native WebView delivers).
|
|
947
|
+
*/
|
|
948
|
+
const parsePaymentChallengeMessage = (data) => {
|
|
949
|
+
let value = data;
|
|
950
|
+
if (typeof value === "string") try {
|
|
951
|
+
value = JSON.parse(value);
|
|
952
|
+
} catch {
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
if (!value || typeof value !== "object") return null;
|
|
956
|
+
const message = value;
|
|
957
|
+
if (message.type !== "fire-spark:payment-challenge") return null;
|
|
958
|
+
if (typeof message.status !== "string") return null;
|
|
959
|
+
const reference = message.attempt_reference;
|
|
960
|
+
return {
|
|
961
|
+
type: PAYMENT_CHALLENGE_MESSAGE,
|
|
962
|
+
status: message.status,
|
|
963
|
+
attempt_reference: typeof reference === "string" ? reference : null
|
|
964
|
+
};
|
|
965
|
+
};
|
|
966
|
+
const escapeHtml = (value) => {
|
|
967
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
968
|
+
};
|
|
969
|
+
/**
|
|
970
|
+
* HTML that opens the challenge by itself: a form posted on load
|
|
971
|
+
* (`POST`) or a redirect (`GET`). Use it as an iframe `srcdoc`, a popup
|
|
972
|
+
* document or a WebView `source={{ html }}`.
|
|
973
|
+
*/
|
|
974
|
+
const paymentChallengeDocument = (challenge) => {
|
|
975
|
+
const action = escapeHtml(challenge.url);
|
|
976
|
+
if (challenge.method === "GET") return `<!doctype html><html><head><meta charset="utf-8"></head><body>${`<script>window.location.replace(${JSON.stringify(challenge.url).replace(/</g, "\\u003c")});<\/script>`}</body></html>`;
|
|
977
|
+
return `<!doctype html><html><head><meta charset="utf-8"></head><body>${`<form id="fs-challenge" method="POST" action="${action}">${challenge.parameters.map((field) => {
|
|
978
|
+
return `<input type="hidden" name="${escapeHtml(field.name)}" value="${escapeHtml(field.value)}">`;
|
|
979
|
+
}).join("")}</form>`}<script>document.getElementById("fs-challenge").submit();<\/script></body></html>`;
|
|
980
|
+
};
|
|
981
|
+
//#endregion
|
|
942
982
|
//#region src/amount.ts
|
|
943
983
|
/** ISO 4217 minor units; anything not listed uses 2. */
|
|
944
984
|
const CURRENCY_DECIMALS = {
|
|
@@ -1442,4 +1482,4 @@ const memoryPaymentStorage = () => {
|
|
|
1442
1482
|
};
|
|
1443
1483
|
};
|
|
1444
1484
|
//#endregion
|
|
1445
|
-
export { ACTIVE_INTENT_STATUSES, CURRENCY_DECIMALS, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, MANUAL_PAYMENT_METHODS, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, PaymentError, REDEMPTION_METHOD, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, activeIntent, allocateTenders, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupRedeems, hasRedeemPayment, isBatchCloseDue, isDeliveryFee, isIntentCovered, isManualPayment, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, money, moneyMax, moneyMin, moneyNumber, moneyNumbers, moneySum, moneyZero, nextIntentStatus, orderRedeems, primaryTender, primaryTenderOf, prorateMinor, realTenders, redeemsCoverTotal, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, splitMoney, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
|
|
1485
|
+
export { ACTIVE_INTENT_STATUSES, CURRENCY_DECIMALS, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, MANUAL_PAYMENT_METHODS, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_CHALLENGE_MESSAGE, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, PaymentError, REDEMPTION_METHOD, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, activeIntent, allocateTenders, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupRedeems, hasRedeemPayment, isBatchCloseDue, isDeliveryFee, isIntentCovered, isManualPayment, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, money, moneyMax, moneyMin, moneyNumber, moneyNumbers, moneySum, moneyZero, nextIntentStatus, orderRedeems, parsePaymentChallengeMessage, paymentChallengeDocument, primaryTender, primaryTenderOf, prorateMinor, realTenders, redeemsCoverTotal, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, splitMoney, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fire-spark/payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Fire Spark payments contract: adapters, errors, amounts and policy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"big.js": "6.2.1",
|
|
21
|
-
"@fire-spark/types": "^0.
|
|
21
|
+
"@fire-spark/types": "^0.14.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/big.js": "6.2.2",
|