@payriff-sdk/react 1.0.0 → 1.0.1
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/PayriffProvider.js +11 -3
- package/package.json +2 -2
package/dist/PayriffProvider.js
CHANGED
|
@@ -10,10 +10,18 @@ const FALLBACK_MESSAGES = {
|
|
|
10
10
|
order_not_payable: 'This order can no longer be paid.',
|
|
11
11
|
invalid_public_key: 'Payments are not available on this site.',
|
|
12
12
|
};
|
|
13
|
+
/** Payriff errors are plain objects with a string `type`. A thrown Error/TypeError is something else. */
|
|
14
|
+
function isPayriffError(err) {
|
|
15
|
+
return !!err && typeof err === 'object' && !(err instanceof Error) && typeof err.type === 'string';
|
|
16
|
+
}
|
|
13
17
|
export function toReactError(err) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
if (!isPayriffError(err)) {
|
|
19
|
+
// Its text could be anything (e.g. "Payriff is not a function"); keep it out of the customer's view.
|
|
20
|
+
console.error('[payriff] unexpected error:', err);
|
|
21
|
+
return { type: 'sdk', code: 'unexpected', message: 'Something went wrong. Please try again.' };
|
|
22
|
+
}
|
|
23
|
+
const message = ('message' in err && typeof err.message === 'string' && err.message) || FALLBACK_MESSAGES[err.type] || 'Payment failed.';
|
|
24
|
+
return { ...err, message };
|
|
17
25
|
}
|
|
18
26
|
/** Loads Payriff.js once for everything inside it, and shares the payment state with usePayriff(). */
|
|
19
27
|
export function PayriffProvider({ publishableKey, apiBase, locale, theme, autoAdvance, children }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payriff-sdk/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "React components for Payriff.js card payments",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "npm test"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@payriff-sdk/payriff-js": "^1.2.
|
|
25
|
+
"@payriff-sdk/payriff-js": "^1.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=18"
|