@payriff-sdk/react 1.0.0 → 1.0.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/README.md CHANGED
@@ -93,6 +93,5 @@ This is for the customer only. Your server decides whether the order is paid, fr
93
93
 
94
94
  - **Next.js:** the components are client components (`'use client'` is built in) and render an empty container
95
95
  on the server.
96
- - **Sandbox:** `<PayriffProvider apiBase="https://sb-api.payriff.com" …>` with your sandbox key.
97
96
  - **HTTPS:** the card fields only load on HTTPS pages, `https://localhost` included.
98
97
  - React 18 or newer. StrictMode is supported.
@@ -11,7 +11,7 @@ export type PayriffReactError = PayriffError & {
11
11
  export interface PayriffProviderProps {
12
12
  /** Your publishable key (pr_pk_live_…). Never the secret key. */
13
13
  publishableKey: string;
14
- /** Default `https://api.payriff.com`. Use `https://sb-api.payriff.com` for the sandbox. */
14
+ /** Default (and only accepted value) `https://api.payriff.com`. */
15
15
  apiBase?: PayriffApiBase;
16
16
  /** Default `az`. */
17
17
  locale?: PayriffLocale;
@@ -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
- const e = (err && typeof err === 'object' ? err : { type: 'sdk', code: 'unknown', message: String(err) });
15
- const message = ('message' in e && typeof e.message === 'string' && e.message) || FALLBACK_MESSAGES[e.type] || 'Payment failed.';
16
- return { ...e, message };
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.0",
3
+ "version": "1.0.2",
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.1"
25
+ "@payriff-sdk/payriff-js": "^1.2.3"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=18"