@outerjoyn/react-native 1.4.1 → 1.5.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/README.md +37 -1
- package/package.json +6 -2
- package/src/OuterJoynProvider.tsx +11 -1
- package/src/OuterJoynSheet.tsx +21 -2
- package/src/__contracts__/pay-breakdown.contract.ts +119 -0
- package/src/components/CheckoutPointsApply.tsx +80 -14
- package/src/core/types.ts +19 -1
- package/src/core/version.ts +17 -2
- package/src/index.ts +13 -2
- package/src/react-native-codegen-types.d.ts +58 -0
- package/src/react-native-sse.d.ts +39 -0
- package/src/types.ts +15 -0
- package/src/useOuterJoyn.ts +10 -1
- package/src/widgets.tsx +17 -0
package/README.md
CHANGED
|
@@ -75,13 +75,49 @@ function HomeScreen() {
|
|
|
75
75
|
function CheckoutScreen() {
|
|
76
76
|
const { openPay } = useOuterJoyn();
|
|
77
77
|
return (
|
|
78
|
-
<Button
|
|
78
|
+
<Button
|
|
79
|
+
title="Pay with Points"
|
|
80
|
+
onPress={() =>
|
|
81
|
+
openPay({
|
|
82
|
+
orderTotalCents: 4999,
|
|
83
|
+
// Send the breakdown you have. The server derives the redeemable
|
|
84
|
+
// basis from it and fails closed (422) without it on most
|
|
85
|
+
// storefronts. Omit a field you don't have — `absent` is NOT `0`.
|
|
86
|
+
merchandiseSubtotalCents: 4200,
|
|
87
|
+
taxCents: 399,
|
|
88
|
+
shippingCents: 400,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
/>
|
|
79
92
|
);
|
|
80
93
|
}
|
|
81
94
|
```
|
|
82
95
|
|
|
83
96
|
**~20 lines of code.** Theme, field visibility, and availability come from platform config automatically.
|
|
84
97
|
|
|
98
|
+
### Order breakdown (important)
|
|
99
|
+
|
|
100
|
+
`orderTotalCents` alone is only enough when the storefront is in `tender` mode with
|
|
101
|
+
both "include tax" and "include shipping" on. Every other configuration derives the
|
|
102
|
+
**redeemable basis** from the breakdown and rejects the reserve without it:
|
|
103
|
+
|
|
104
|
+
| Storefront mode | Redeemable basis | Required fields |
|
|
105
|
+
|---|---|---|
|
|
106
|
+
| `coupon` | uncapped | — |
|
|
107
|
+
| `discount` | merchandise subtotal | `merchandiseSubtotalCents` |
|
|
108
|
+
| `tender`, tax off / ship off | merchandise subtotal | `merchandiseSubtotalCents` |
|
|
109
|
+
| `tender`, tax on | merchandise + tax | `merchandiseSubtotalCents`, `taxCents` |
|
|
110
|
+
| `tender`, ship on | merchandise + shipping | `merchandiseSubtotalCents`, `shippingCents` |
|
|
111
|
+
| `tender`, tax on + ship on | full order total | — |
|
|
112
|
+
|
|
113
|
+
A missing required field returns 422 `merchandise_subtotal_required`,
|
|
114
|
+
`tax_amount_required`, or `shipping_amount_required`.
|
|
115
|
+
|
|
116
|
+
**Do not substitute `0` for a value you don't have.** The gateway distinguishes
|
|
117
|
+
absent from zero: `0` asserts a genuinely zero subtotal and caps redemption at
|
|
118
|
+
nothing, while an omitted field produces a clear 422 instead of a silent
|
|
119
|
+
zero-point checkout.
|
|
120
|
+
|
|
85
121
|
## Components
|
|
86
122
|
|
|
87
123
|
### Provider + Hook
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outerjoyn/react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Drop-in loyalty SDK for React Native. Works in Expo Go.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"typecheck": "tsc --noEmit"
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"sync:version": "node scripts/sync-version.js",
|
|
16
|
+
"check:version": "node scripts/sync-version.js --check",
|
|
17
|
+
"version": "node scripts/sync-version.js",
|
|
18
|
+
"prepublishOnly": "npm run check:version && npm run typecheck"
|
|
15
19
|
},
|
|
16
20
|
"keywords": [
|
|
17
21
|
"outerjoyn",
|
|
@@ -608,7 +608,14 @@ export function OuterJoynProvider({
|
|
|
608
608
|
);
|
|
609
609
|
|
|
610
610
|
const openPay = useCallback(
|
|
611
|
-
(opts: {
|
|
611
|
+
(opts: {
|
|
612
|
+
orderTotalCents: number;
|
|
613
|
+
merchantOrderId?: string;
|
|
614
|
+
currencyCode?: string;
|
|
615
|
+
merchandiseSubtotalCents?: number;
|
|
616
|
+
taxCents?: number;
|
|
617
|
+
shippingCents?: number;
|
|
618
|
+
}) => {
|
|
612
619
|
analyticsRef.current?.trackOpen('pay');
|
|
613
620
|
openSheet('pay', opts);
|
|
614
621
|
},
|
|
@@ -759,6 +766,9 @@ export function OuterJoynProvider({
|
|
|
759
766
|
theme={resolvedTheme}
|
|
760
767
|
orderTotal={sheetProps.orderTotalCents}
|
|
761
768
|
currencyCode={sheetProps.currencyCode}
|
|
769
|
+
merchandiseSubtotalCents={sheetProps.merchandiseSubtotalCents}
|
|
770
|
+
taxCents={sheetProps.taxCents}
|
|
771
|
+
shippingCents={sheetProps.shippingCents}
|
|
762
772
|
onSuccess={handleSheetSuccess}
|
|
763
773
|
onError={handleSheetError}
|
|
764
774
|
onClose={closeSheet}
|
package/src/OuterJoynSheet.tsx
CHANGED
|
@@ -9,6 +9,25 @@ import {
|
|
|
9
9
|
Linking,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import { WebView } from 'react-native-webview';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `react-native-webview` declares its component as
|
|
15
|
+
* `class WebView<P = undefined> extends Component<WebViewProps & P>`. Left at
|
|
16
|
+
* that default, React's JSX prop resolution reduces the element's accepted
|
|
17
|
+
* props to `never`, so EVERY prop we pass reports "Type X is not assignable to
|
|
18
|
+
* type 'never'" — errors that point at this file but originate in that
|
|
19
|
+
* declaration. It also cascades: `onShouldStartLoadWithRequest`'s parameter
|
|
20
|
+
* loses its contextual type and trips `noImplicitAny`.
|
|
21
|
+
*
|
|
22
|
+
* Supplying the type argument explicitly (`{}` — we add no extra props) is
|
|
23
|
+
* enough to keep the intersection well-formed. This is a type-level fix only:
|
|
24
|
+
* `WebViewTyped` IS `WebView` at runtime.
|
|
25
|
+
*
|
|
26
|
+
* Because `prepublishOnly` runs `typecheck`, the `never` cascade blocked every
|
|
27
|
+
* publish of this package — see `src/react-native-codegen-types.d.ts` for the
|
|
28
|
+
* other half of that story.
|
|
29
|
+
*/
|
|
30
|
+
const WebViewTyped = WebView<{}>;
|
|
12
31
|
import type { WebViewMessage, SDKError } from './types';
|
|
13
32
|
import { generateWidgetHTML } from './html';
|
|
14
33
|
|
|
@@ -66,7 +85,7 @@ export function OuterJoynSheet({
|
|
|
66
85
|
title,
|
|
67
86
|
heightRatio = 0.85,
|
|
68
87
|
}: SheetProps) {
|
|
69
|
-
const webViewRef = useRef<WebView
|
|
88
|
+
const webViewRef = useRef<WebView<{}>>(null);
|
|
70
89
|
const [loading, setLoading] = useState(true);
|
|
71
90
|
|
|
72
91
|
const html = generateWidgetHTML(
|
|
@@ -135,7 +154,7 @@ export function OuterJoynSheet({
|
|
|
135
154
|
<ActivityIndicator size="large" color="#6366f1" />
|
|
136
155
|
</View>
|
|
137
156
|
)}
|
|
138
|
-
<
|
|
157
|
+
<WebViewTyped
|
|
139
158
|
ref={webViewRef}
|
|
140
159
|
source={{ html }}
|
|
141
160
|
style={styles.webView}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CONTRACT — the pay order breakdown survives the whole RN → hosted-widget chain.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS FILE EXISTS
|
|
5
|
+
*
|
|
6
|
+
* The breakdown crosses FOUR hand-maintained mirrors before it reaches the
|
|
7
|
+
* gateway, and every one of them is a place a field can be silently dropped:
|
|
8
|
+
*
|
|
9
|
+
* openPay(opts) core/types.ts (mirror 1)
|
|
10
|
+
* → openSheet('pay', opts) → sheetProps
|
|
11
|
+
* → <PaySheet {...} /> OuterJoynProvider (mirror 2)
|
|
12
|
+
* → PaySheetProps types.ts (mirror 3)
|
|
13
|
+
* → widgetOptions widgets.tsx (mirror 4)
|
|
14
|
+
* → hosted oj.pay.open() → frame INIT → checkout POST
|
|
15
|
+
*
|
|
16
|
+
* This exact mirror shape has drawn blood three times on the web SDK's
|
|
17
|
+
* `PayOpenOptions`: #5126 dropped `merchandiseSubtotalCents` (discount-mode
|
|
18
|
+
* checkouts could never reserve) and #5130 dropped `applicationMode`. A dropped
|
|
19
|
+
* field does not fail loudly — it produces a 422 at reserve time, or worse, a
|
|
20
|
+
* silently capped redemption. Types alone never caught it because each mirror
|
|
21
|
+
* is independently well-formed.
|
|
22
|
+
*
|
|
23
|
+
* WHAT THIS PINS
|
|
24
|
+
*
|
|
25
|
+
* A compile error here means a breakdown field exists on one side of a mirror
|
|
26
|
+
* and not the other. The package's `typecheck` script runs `tsc --noEmit` over
|
|
27
|
+
* `src`, and `prepublishOnly` runs `typecheck` — so this also blocks a publish
|
|
28
|
+
* that would ship a broken chain. It is types-only: no runtime, no test runner,
|
|
29
|
+
* nothing exported from the package index.
|
|
30
|
+
*
|
|
31
|
+
* WHAT THIS CANNOT PIN
|
|
32
|
+
*
|
|
33
|
+
* That `widgets.tsx` actually FORWARDS each field into `widgetOptions` — a
|
|
34
|
+
* mirror can carry a key while the plumbing drops it (the #5126 shape). The
|
|
35
|
+
* forwarding is guarded on the hosted side by
|
|
36
|
+
* `src/sdk/__tests__/pay-open-options.contract.test.tsx`, whose runtime layer
|
|
37
|
+
* asserts the values reach the iframe INIT payload.
|
|
38
|
+
*
|
|
39
|
+
* `absent` IS NOT `0`
|
|
40
|
+
*
|
|
41
|
+
* The gateway guards on `== null` (Go `*int` + `omitempty`), so a `0` asserts a
|
|
42
|
+
* genuinely zero subtotal and caps redemption at nothing, while an omitted
|
|
43
|
+
* field fails closed with a diagnosable 422. Every field below is therefore
|
|
44
|
+
* OPTIONAL on purpose — do not "fix" a mirror by defaulting one to 0.
|
|
45
|
+
*/
|
|
46
|
+
import type { OuterJoynContextValue } from '../core/types';
|
|
47
|
+
import type { PaySheetProps } from '../types';
|
|
48
|
+
|
|
49
|
+
/** Compile error unless T and U have exactly the same keys. */
|
|
50
|
+
type SameKeys<T, U> = [keyof T] extends [keyof U]
|
|
51
|
+
? [keyof U] extends [keyof T]
|
|
52
|
+
? true
|
|
53
|
+
: { missing_from_first: Exclude<keyof U, keyof T> }
|
|
54
|
+
: { missing_from_second: Exclude<keyof T, keyof U> };
|
|
55
|
+
|
|
56
|
+
/** The breakdown fields, as the gateway's redeemable-basis ladder reads them. */
|
|
57
|
+
type BreakdownKeys = 'merchandiseSubtotalCents' | 'taxCents' | 'shippingCents';
|
|
58
|
+
|
|
59
|
+
type OpenPayOptions = Parameters<OuterJoynContextValue['openPay']>[0];
|
|
60
|
+
|
|
61
|
+
// --- Mirror 1: openPay's options carry the breakdown ------------------------
|
|
62
|
+
type OpenPayBreakdown = Pick<OpenPayOptions, BreakdownKeys & keyof OpenPayOptions>;
|
|
63
|
+
const _openPayCarriesBreakdown: SameKeys<
|
|
64
|
+
OpenPayBreakdown,
|
|
65
|
+
Record<BreakdownKeys, unknown>
|
|
66
|
+
> = true;
|
|
67
|
+
|
|
68
|
+
// --- Mirror 3: PaySheetProps carry the breakdown ----------------------------
|
|
69
|
+
type PaySheetBreakdown = Pick<PaySheetProps, BreakdownKeys & keyof PaySheetProps>;
|
|
70
|
+
const _paySheetCarriesBreakdown: SameKeys<
|
|
71
|
+
PaySheetBreakdown,
|
|
72
|
+
Record<BreakdownKeys, unknown>
|
|
73
|
+
> = true;
|
|
74
|
+
|
|
75
|
+
// --- Mirrors 1 ⇄ 3 agree, so the provider can pass them straight through ----
|
|
76
|
+
const _mirrorsAgree: SameKeys<OpenPayBreakdown, PaySheetBreakdown> = true;
|
|
77
|
+
|
|
78
|
+
// --- Every field is optional: `absent` must remain expressible --------------
|
|
79
|
+
// `{}` must satisfy the breakdown slice. If a field were made required, or
|
|
80
|
+
// defaulted to 0 to "simplify", this line stops compiling.
|
|
81
|
+
const _absenceIsExpressible: OpenPayBreakdown = {};
|
|
82
|
+
const _absenceIsExpressibleOnSheet: PaySheetBreakdown = {};
|
|
83
|
+
|
|
84
|
+
// --- Fields are numeric minor units, not strings or bigints -----------------
|
|
85
|
+
const _minorUnits: OpenPayBreakdown = {
|
|
86
|
+
merchandiseSubtotalCents: 4200,
|
|
87
|
+
taxCents: 399,
|
|
88
|
+
shippingCents: 400,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// --- `currencyCode` rides the same mirrors ----------------------------------
|
|
92
|
+
// It travels the identical four-mirror path and has ALREADY been a dead path
|
|
93
|
+
// once: the provider read `sheetProps.currencyCode` while `openPay`'s options
|
|
94
|
+
// never declared it, so no caller could set it (fixed in #5613). Dropping it
|
|
95
|
+
// again does not 422 — the gateway defaults nothing, but the SDK sends 'USD',
|
|
96
|
+
// so a non-USD order silently records a same-currency session with NO FX
|
|
97
|
+
// conversion and values points at parity. That is a mispricing, not an error,
|
|
98
|
+
// which is exactly why it needs a compile-time pin rather than a test.
|
|
99
|
+
type CurrencyKey = 'currencyCode';
|
|
100
|
+
const _openPayCarriesCurrency: SameKeys<
|
|
101
|
+
Pick<OpenPayOptions, CurrencyKey & keyof OpenPayOptions>,
|
|
102
|
+
Record<CurrencyKey, unknown>
|
|
103
|
+
> = true;
|
|
104
|
+
const _paySheetCarriesCurrency: SameKeys<
|
|
105
|
+
Pick<PaySheetProps, CurrencyKey & keyof PaySheetProps>,
|
|
106
|
+
Record<CurrencyKey, unknown>
|
|
107
|
+
> = true;
|
|
108
|
+
|
|
109
|
+
// Reference the bindings so `noUnusedLocals` stays satisfiable if enabled.
|
|
110
|
+
export type __PayBreakdownContract = [
|
|
111
|
+
typeof _openPayCarriesBreakdown,
|
|
112
|
+
typeof _paySheetCarriesBreakdown,
|
|
113
|
+
typeof _mirrorsAgree,
|
|
114
|
+
typeof _absenceIsExpressible,
|
|
115
|
+
typeof _absenceIsExpressibleOnSheet,
|
|
116
|
+
typeof _minorUnits,
|
|
117
|
+
typeof _openPayCarriesCurrency,
|
|
118
|
+
typeof _paySheetCarriesCurrency,
|
|
119
|
+
];
|
|
@@ -16,12 +16,19 @@
|
|
|
16
16
|
* <CheckoutPointsApply
|
|
17
17
|
* ref={checkoutRef}
|
|
18
18
|
* orderTotalCents={4999}
|
|
19
|
+
* merchandiseSubtotalCents={4299}
|
|
20
|
+
* taxCents={400}
|
|
21
|
+
* shippingCents={300}
|
|
19
22
|
* onPointsChanged={(applied) => setDiscount(applied.totalValueAmount)}
|
|
20
23
|
* />
|
|
21
24
|
*
|
|
22
25
|
* // To finalize all reservations:
|
|
23
26
|
* await checkoutRef.current?.confirmAll();
|
|
24
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* Pass the order breakdown alongside the total. Most storefront bases require
|
|
30
|
+
* `merchandiseSubtotalCents`; without it the reserve fails closed with
|
|
31
|
+
* `merchandise_subtotal_required`.
|
|
25
32
|
*/
|
|
26
33
|
import React, { useState, useCallback, useMemo, useRef, useEffect, useImperativeHandle, forwardRef } from 'react';
|
|
27
34
|
import {
|
|
@@ -70,6 +77,34 @@ export interface CheckoutPointsApplyHandle {
|
|
|
70
77
|
export interface CheckoutPointsApplyProps {
|
|
71
78
|
/** Order total in cents (required) */
|
|
72
79
|
orderTotalCents: number;
|
|
80
|
+
/**
|
|
81
|
+
* Merchandise subtotal in cents — the order total minus tax and shipping.
|
|
82
|
+
*
|
|
83
|
+
* REQUIRED for every storefront basis except `tender` with both
|
|
84
|
+
* `redeem_include_tax` and `redeem_include_shipping` enabled (where the order
|
|
85
|
+
* total itself is the redeemable basis). Omitting it on any other basis makes
|
|
86
|
+
* the reserve fail closed with `merchandise_subtotal_required` — the server
|
|
87
|
+
* will not silently widen a partial basis to gross.
|
|
88
|
+
*
|
|
89
|
+
* Pass it whenever you know it; there is no cost to sending it on a basis
|
|
90
|
+
* that ignores it.
|
|
91
|
+
*/
|
|
92
|
+
merchandiseSubtotalCents?: number;
|
|
93
|
+
/** Tax in cents. Required when the storefront's basis includes tax. */
|
|
94
|
+
taxCents?: number;
|
|
95
|
+
/** Shipping in cents. Required when the storefront's basis includes shipping. */
|
|
96
|
+
shippingCents?: number;
|
|
97
|
+
/**
|
|
98
|
+
* ISO 4217 currency of the order. Defaults to `'USD'`.
|
|
99
|
+
*
|
|
100
|
+
* This is NOT cosmetic: the server prices the order against it, converting
|
|
101
|
+
* from the issuer's valuation currency at the current FX rate. Sending `USD`
|
|
102
|
+
* for a non-USD order records a same-currency session with NO conversion, so
|
|
103
|
+
* points are valued at parity — a silent mispricing rather than an error.
|
|
104
|
+
*
|
|
105
|
+
* Pass the currency the order is actually denominated in.
|
|
106
|
+
*/
|
|
107
|
+
currencyCode?: string;
|
|
73
108
|
/** Called whenever the user adjusts sliders */
|
|
74
109
|
onPointsChanged?: (payload: PointsChangedPayload) => void;
|
|
75
110
|
/** Called when the user taps "Link another program". If provided, overrides the default sheet flow. */
|
|
@@ -80,6 +115,10 @@ export interface CheckoutPointsApplyProps {
|
|
|
80
115
|
|
|
81
116
|
export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, CheckoutPointsApplyProps>(function CheckoutPointsApply({
|
|
82
117
|
orderTotalCents,
|
|
118
|
+
merchandiseSubtotalCents,
|
|
119
|
+
taxCents,
|
|
120
|
+
shippingCents,
|
|
121
|
+
currencyCode = 'USD',
|
|
83
122
|
onPointsChanged,
|
|
84
123
|
onLinkAnother,
|
|
85
124
|
style,
|
|
@@ -150,6 +189,28 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
150
189
|
const validOrderTotal = (typeof orderTotalCents === 'number' && !Number.isNaN(orderTotalCents))
|
|
151
190
|
? orderTotalCents : 0;
|
|
152
191
|
|
|
192
|
+
// The order breakdown the server needs to compute the redeemable basis.
|
|
193
|
+
// Only send a field the caller actually supplied: the server distinguishes
|
|
194
|
+
// "absent" (fail closed) from a real 0, so coercing undefined to 0 here
|
|
195
|
+
// would assert a zero merchandise subtotal and cap redemption at nothing.
|
|
196
|
+
const validCents = (v: number | undefined) =>
|
|
197
|
+
typeof v === 'number' && Number.isFinite(v) ? v : undefined;
|
|
198
|
+
const breakdown: Record<string, number> = {};
|
|
199
|
+
const ms = validCents(merchandiseSubtotalCents);
|
|
200
|
+
const tx = validCents(taxCents);
|
|
201
|
+
const sh = validCents(shippingCents);
|
|
202
|
+
if (ms !== undefined) breakdown.merchandiseSubtotalCents = ms;
|
|
203
|
+
if (tx !== undefined) breakdown.taxCents = tx;
|
|
204
|
+
if (sh !== undefined) breakdown.shippingCents = sh;
|
|
205
|
+
|
|
206
|
+
// The server requires a 3-letter ISO 4217 code and rejects anything else
|
|
207
|
+
// with a 400, so a caller passing '' or 'usd' must not break the reserve.
|
|
208
|
+
// Unlike the breakdown above, an omitted currency has a safe default —
|
|
209
|
+
// there is no "absent means fail closed" semantics here.
|
|
210
|
+
const orderCurrency = (typeof currencyCode === 'string' && currencyCode.trim().length === 3)
|
|
211
|
+
? currencyCode.trim().toUpperCase()
|
|
212
|
+
: 'USD';
|
|
213
|
+
|
|
153
214
|
// In demo mode or no apiClient, skip API calls
|
|
154
215
|
if (demoMode || !apiClient) {
|
|
155
216
|
setConfirmedPrograms((prev) => {
|
|
@@ -179,7 +240,8 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
179
240
|
}>('/api/sdk/pay/checkout', {
|
|
180
241
|
merchantOrderId: `checkout_${Date.now()}`,
|
|
181
242
|
orderTotalCents: validOrderTotal,
|
|
182
|
-
currencyCode:
|
|
243
|
+
currencyCode: orderCurrency,
|
|
244
|
+
...breakdown,
|
|
183
245
|
reservations: [{
|
|
184
246
|
memberCurrencyId: prog.memberCurrencyId,
|
|
185
247
|
currencyId: prog.currencyId,
|
|
@@ -219,7 +281,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
219
281
|
setApiLoading((prev) => ({ ...prev, [progId]: false }));
|
|
220
282
|
}
|
|
221
283
|
},
|
|
222
|
-
[programs, sliderValues, demoMode, apiClient, orderTotalCents, buildPayload, onPointsChanged, redemptionTokens],
|
|
284
|
+
[programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, buildPayload, onPointsChanged, redemptionTokens],
|
|
223
285
|
);
|
|
224
286
|
|
|
225
287
|
const handleRemove = useCallback(
|
|
@@ -522,18 +584,22 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
522
584
|
</View>
|
|
523
585
|
)}
|
|
524
586
|
|
|
525
|
-
{/* Link another program
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
587
|
+
{/* Link another program.
|
|
588
|
+
Rendered unconditionally: `ctx.openConnect` is non-optional on
|
|
589
|
+
`OuterJoynContextValue` and `useOuterJoyn()` throws outside a
|
|
590
|
+
provider, so there is always a way to link. The former
|
|
591
|
+
`(onLinkAnother || ctx.openConnect) &&` guard could never be false —
|
|
592
|
+
`tsc` flagged it as TS2774 — and the `?.` below was dead for the same
|
|
593
|
+
reason. `onLinkAnother` still wins when a caller supplies it. */}
|
|
594
|
+
<Pressable
|
|
595
|
+
style={styles.linkMoreButton}
|
|
596
|
+
onPress={() => (onLinkAnother ? onLinkAnother() : ctx.openConnect())}
|
|
597
|
+
accessibilityRole="button"
|
|
598
|
+
accessibilityLabel="Link another loyalty program"
|
|
599
|
+
>
|
|
600
|
+
<Text style={styles.linkMorePlus}>+</Text>
|
|
601
|
+
<Text style={styles.linkMoreText}>Link another program</Text>
|
|
602
|
+
</Pressable>
|
|
537
603
|
|
|
538
604
|
<View style={styles.poweredByRow}>
|
|
539
605
|
<Text style={styles.poweredByText}>Powered by</Text>
|
package/src/core/types.ts
CHANGED
|
@@ -190,7 +190,25 @@ export interface OuterJoynContextValue {
|
|
|
190
190
|
openConnect: (opts?: { institutionId?: string }) => void;
|
|
191
191
|
openExchange: (opts?: { sourceCurrencyId?: number | string }) => void;
|
|
192
192
|
openRedeem: (opts?: { category?: string }) => void;
|
|
193
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Open the pay-with-points sheet.
|
|
195
|
+
*
|
|
196
|
+
* The order breakdown is what the server derives the REDEEMABLE BASIS from.
|
|
197
|
+
* Without it the reserve fails closed on every storefront basis except tender
|
|
198
|
+
* with both redeem_include_tax and redeem_include_shipping on — 422
|
|
199
|
+
* `merchandise_subtotal_required` / `tax_amount_required` /
|
|
200
|
+
* `shipping_amount_required`. `absent` is NOT `0`: the gateway's guard is
|
|
201
|
+
* `== null`, so passing 0 asserts a zero subtotal and caps redemption at
|
|
202
|
+
* nothing. Omit what you don't have.
|
|
203
|
+
*/
|
|
204
|
+
openPay: (opts: {
|
|
205
|
+
orderTotalCents: number;
|
|
206
|
+
merchantOrderId?: string;
|
|
207
|
+
currencyCode?: string;
|
|
208
|
+
merchandiseSubtotalCents?: number;
|
|
209
|
+
taxCents?: number;
|
|
210
|
+
shippingCents?: number;
|
|
211
|
+
}) => void;
|
|
194
212
|
openAccount: () => void;
|
|
195
213
|
closeSheet: () => void;
|
|
196
214
|
unlinkProgram: (programId: string) => void;
|
package/src/core/version.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for SDK version. Imported by api-client and analytics.
|
|
3
|
+
*
|
|
4
|
+
* This MUST equal the `version` in package.json. It ships on every request as
|
|
5
|
+
* `X-SDK-Version` and stamps every analytics event as `sdk_version`, which is
|
|
6
|
+
* what the SDK-version-adoption breakdown groups by — so a stale value here
|
|
7
|
+
* does not fail loudly, it silently mislabels all telemetry as an old release.
|
|
8
|
+
*
|
|
9
|
+
* It drifted to 1.0.0 across five releases exactly that way. Do not hand-edit
|
|
10
|
+
* it on its own: `npm version` runs the `version` script, which rewrites this
|
|
11
|
+
* file from package.json and stages it. `npm run check:version` fails the build
|
|
12
|
+
* if the two ever disagree.
|
|
13
|
+
*
|
|
14
|
+
* (It is not imported from package.json because that inlines the entire
|
|
15
|
+
* manifest — repo URLs, scripts, devDependencies — into consumer bundles.)
|
|
16
|
+
*/
|
|
17
|
+
export const SDK_VERSION = '1.5.0';
|
package/src/index.ts
CHANGED
|
@@ -15,9 +15,20 @@
|
|
|
15
15
|
* // Show a banner on any screen
|
|
16
16
|
* <LoyaltyBanner />
|
|
17
17
|
*
|
|
18
|
-
* // Pay with points at checkout
|
|
18
|
+
* // Pay with points at checkout. Send the order breakdown — the server derives
|
|
19
|
+
* // the redeemable basis from it and 422s without it on most storefronts.
|
|
19
20
|
* const { openPay } = useOuterJoyn();
|
|
20
|
-
* <Button
|
|
21
|
+
* <Button
|
|
22
|
+
* onPress={() =>
|
|
23
|
+
* openPay({
|
|
24
|
+
* orderTotalCents: 4999,
|
|
25
|
+
* merchandiseSubtotalCents: 4200,
|
|
26
|
+
* taxCents: 399,
|
|
27
|
+
* shippingCents: 400,
|
|
28
|
+
* })
|
|
29
|
+
* }
|
|
30
|
+
* title="Pay with Points"
|
|
31
|
+
* />
|
|
21
32
|
* ```
|
|
22
33
|
*/
|
|
23
34
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient shim for `react-native/Libraries/Types/CodegenTypes`.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS — this is the reason `npm publish` was broken.
|
|
5
|
+
*
|
|
6
|
+
* `react-native-webview`'s own `lib/RNCWebViewNativeComponent.d.ts` imports
|
|
7
|
+
* `DirectEventHandler`, `Double`, `Int32` and `WithDefault` from
|
|
8
|
+
* `react-native/Libraries/Types/CodegenTypes`. React Native 0.73 ships that
|
|
9
|
+
* module as **`CodegenTypes.js` only — there is no `CodegenTypes.d.ts`**, so
|
|
10
|
+
* TypeScript cannot resolve the specifier.
|
|
11
|
+
*
|
|
12
|
+
* The failure is silent and non-local, which is what made it hard to place:
|
|
13
|
+
* the unresolved import degrades `WebViewNativeEvent` & co, which degrades
|
|
14
|
+
* `IOSWebViewProps & AndroidWebViewProps & WindowsWebViewProps`, so the
|
|
15
|
+
* exported `WebViewProps` intersection collapses to `never`. Every single prop
|
|
16
|
+
* we pass in `OuterJoynSheet.tsx` then reports "Type X is not assignable to
|
|
17
|
+
* type 'never'" — ten errors that look like OUR bug and are not. `tsc` reports
|
|
18
|
+
* them against our source, and `skipLibCheck` cannot help because the `never`
|
|
19
|
+
* leaks out of the declaration file into our code.
|
|
20
|
+
*
|
|
21
|
+
* Because `prepublishOnly` runs `typecheck`, this blocked EVERY publish of this
|
|
22
|
+
* package — which is why `@outerjoyn/react-native` 1.5.0 could not ship.
|
|
23
|
+
*
|
|
24
|
+
* Verified (2026-08-21): every published `react-native-webview` 13.x — from the
|
|
25
|
+
* declared floor 13.6.0 through 13.17.0 — imports these same types, so there is
|
|
26
|
+
* no version to pin to. It is fixed upstream by RN shipping the declarations.
|
|
27
|
+
* DELETE THIS FILE once `react-native/Libraries/Types/CodegenTypes.d.ts` exists
|
|
28
|
+
* in the installed RN version.
|
|
29
|
+
*
|
|
30
|
+
* The definitions mirror React Native's own codegen types.
|
|
31
|
+
*/
|
|
32
|
+
declare module 'react-native/Libraries/Types/CodegenTypes' {
|
|
33
|
+
/** A double-precision number at the native bridge. */
|
|
34
|
+
export type Double = number;
|
|
35
|
+
/** A 32-bit integer at the native bridge. */
|
|
36
|
+
export type Int32 = number;
|
|
37
|
+
/** A float at the native bridge. */
|
|
38
|
+
export type Float = number;
|
|
39
|
+
|
|
40
|
+
/** A prop with a codegen-declared default value. */
|
|
41
|
+
export type WithDefault<Type, Value extends Type | string | undefined = undefined> =
|
|
42
|
+
Type | undefined;
|
|
43
|
+
|
|
44
|
+
/** Handler for an event emitted directly by the native component. */
|
|
45
|
+
export type DirectEventHandler<
|
|
46
|
+
Event,
|
|
47
|
+
Name extends string | undefined = string,
|
|
48
|
+
> = (event: { nativeEvent: Event }) => void;
|
|
49
|
+
|
|
50
|
+
/** Handler for an event that bubbles through the view hierarchy. */
|
|
51
|
+
export type BubblingEventHandler<
|
|
52
|
+
Event,
|
|
53
|
+
Name extends string | undefined = string,
|
|
54
|
+
> = (event: { nativeEvent: Event }) => void;
|
|
55
|
+
|
|
56
|
+
export type UnsafeObject = object;
|
|
57
|
+
export type UnsafeMixed = unknown;
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient declaration for `react-native-sse`.
|
|
3
|
+
*
|
|
4
|
+
* This package is an OPTIONAL peer: `core/event-stream.ts` reaches it through a
|
|
5
|
+
* dynamic `import()` inside a try/catch and degrades to "real-time updates
|
|
6
|
+
* disabled" when it is absent. That runtime posture is deliberate — consumers
|
|
7
|
+
* who do not want SSE should not have to install it, so it is intentionally
|
|
8
|
+
* absent from `dependencies`, `peerDependencies` and `devDependencies`.
|
|
9
|
+
*
|
|
10
|
+
* TypeScript still has to resolve the module specifier at compile time, though,
|
|
11
|
+
* and without this shim `tsc --noEmit` fails with TS2307. Because
|
|
12
|
+
* `prepublishOnly` runs `typecheck`, that failure blocked EVERY publish of this
|
|
13
|
+
* package — the real reason 1.5.0 could not ship.
|
|
14
|
+
*
|
|
15
|
+
* Do not "fix" this by adding the package as a dependency: that would make an
|
|
16
|
+
* optional feature mandatory for every consumer. If the real types are ever
|
|
17
|
+
* wanted, add `react-native-sse` to devDependencies and delete this file — the
|
|
18
|
+
* shape below is intentionally minimal and covers only what event-stream.ts
|
|
19
|
+
* uses.
|
|
20
|
+
*/
|
|
21
|
+
declare module 'react-native-sse' {
|
|
22
|
+
export interface EventSourceOptions {
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface EventSourceEvent {
|
|
28
|
+
/** Raw SSE payload; event-stream.ts JSON.parses this. */
|
|
29
|
+
data?: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default class EventSource {
|
|
34
|
+
constructor(url: string, options?: EventSourceOptions);
|
|
35
|
+
addEventListener(type: string, listener: (event: EventSourceEvent) => void): void;
|
|
36
|
+
removeAllEventListeners?(): void;
|
|
37
|
+
close(): void;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -30,6 +30,21 @@ export interface PaySheetProps extends OuterJoynConfig {
|
|
|
30
30
|
orderTotal?: number;
|
|
31
31
|
/** ISO 4217 currency code (default: USD) */
|
|
32
32
|
currencyCode?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Order breakdown (minor units). The server derives the REDEEMABLE BASIS from
|
|
35
|
+
* these and fails closed without them: every storefront basis except tender
|
|
36
|
+
* with both redeem_include_tax and redeem_include_shipping on rejects the
|
|
37
|
+
* reserve with 422 `merchandise_subtotal_required` / `tax_amount_required` /
|
|
38
|
+
* `shipping_amount_required`.
|
|
39
|
+
*
|
|
40
|
+
* `absent` is NOT `0` — the gateway's guard is `== null`, so a 0 asserts a
|
|
41
|
+
* zero subtotal and caps redemption at nothing. Omit what you don't have.
|
|
42
|
+
*/
|
|
43
|
+
merchandiseSubtotalCents?: number;
|
|
44
|
+
/** Tax in cents. Required when the storefront sets redeem_include_tax. */
|
|
45
|
+
taxCents?: number;
|
|
46
|
+
/** Shipping in cents. Required when the storefront sets redeem_include_shipping. */
|
|
47
|
+
shippingCents?: number;
|
|
33
48
|
/** Called when payment completes successfully */
|
|
34
49
|
onSuccess?: (result: PayResult) => void;
|
|
35
50
|
/** Called when an error occurs */
|
package/src/useOuterJoyn.ts
CHANGED
|
@@ -14,7 +14,16 @@
|
|
|
14
14
|
* return (
|
|
15
15
|
* <Button
|
|
16
16
|
* title={`Pay with ${totalAvailableValue}c in points`}
|
|
17
|
-
* onPress={() =>
|
|
17
|
+
* onPress={() =>
|
|
18
|
+
* // The breakdown decides how much of the order points may cover.
|
|
19
|
+
* // Omit a field you don't have — `absent` is NOT `0`.
|
|
20
|
+
* openPay({
|
|
21
|
+
* orderTotalCents: 2499,
|
|
22
|
+
* merchandiseSubtotalCents: 2100,
|
|
23
|
+
* taxCents: 199,
|
|
24
|
+
* shippingCents: 200,
|
|
25
|
+
* })
|
|
26
|
+
* }
|
|
18
27
|
* />
|
|
19
28
|
* );
|
|
20
29
|
* }
|
package/src/widgets.tsx
CHANGED
|
@@ -47,6 +47,9 @@ export function PaySheet({
|
|
|
47
47
|
theme,
|
|
48
48
|
orderTotal,
|
|
49
49
|
currencyCode,
|
|
50
|
+
merchandiseSubtotalCents,
|
|
51
|
+
taxCents,
|
|
52
|
+
shippingCents,
|
|
50
53
|
onSuccess,
|
|
51
54
|
onError,
|
|
52
55
|
onClose,
|
|
@@ -74,6 +77,12 @@ export function PaySheet({
|
|
|
74
77
|
widgetOptions={{
|
|
75
78
|
...(orderTotal !== undefined ? { orderTotal } : {}),
|
|
76
79
|
...(currencyCode !== undefined ? { currencyCode } : {}),
|
|
80
|
+
// Order breakdown — forwarded verbatim to the hosted widget's
|
|
81
|
+
// pay.open(). `absent` is NOT `0` (the gateway guards on `== null`),
|
|
82
|
+
// so an undefined field must stay off the wire entirely.
|
|
83
|
+
...(merchandiseSubtotalCents !== undefined ? { merchandiseSubtotalCents } : {}),
|
|
84
|
+
...(taxCents !== undefined ? { taxCents } : {}),
|
|
85
|
+
...(shippingCents !== undefined ? { shippingCents } : {}),
|
|
77
86
|
...(onPointsChanged ? { onPointsChanged } : {}),
|
|
78
87
|
}}
|
|
79
88
|
/>
|
|
@@ -197,6 +206,7 @@ export function AccountSheet({
|
|
|
197
206
|
sessionToken,
|
|
198
207
|
apiBaseUrl,
|
|
199
208
|
theme,
|
|
209
|
+
onSuccess,
|
|
200
210
|
onClose,
|
|
201
211
|
onError,
|
|
202
212
|
}: {
|
|
@@ -204,6 +214,12 @@ export function AccountSheet({
|
|
|
204
214
|
sessionToken?: string;
|
|
205
215
|
apiBaseUrl?: string;
|
|
206
216
|
theme?: any;
|
|
217
|
+
// Declared AND forwarded below. Omitting it here made
|
|
218
|
+
// `OuterJoynSDK.present('account')` unresolvable: the imperative bridge
|
|
219
|
+
// passes `onSuccess` to settle its promise, the prop was silently dropped,
|
|
220
|
+
// and the only remaining settle path was `dismiss()` — which *rejects*.
|
|
221
|
+
// A completed account flow therefore threw "Dismissed by user".
|
|
222
|
+
onSuccess?: () => void;
|
|
207
223
|
onClose?: () => void;
|
|
208
224
|
onError?: (error: any) => void;
|
|
209
225
|
}) {
|
|
@@ -220,6 +236,7 @@ export function AccountSheet({
|
|
|
220
236
|
theme={resolvedTheme}
|
|
221
237
|
module="account"
|
|
222
238
|
title="My Account"
|
|
239
|
+
onSuccess={onSuccess}
|
|
223
240
|
onClose={onClose}
|
|
224
241
|
onError={onError}
|
|
225
242
|
/>
|