@outerjoyn/react-native 1.7.1 → 1.8.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 +1 -1
- package/package.json +1 -1
- package/src/components/CheckoutPointsApply.tsx +11 -3
- package/src/core/portabilityHandoff.ts +6 -0
- package/src/core/redemptionRules.ts +30 -23
- package/src/core/tender.ts +11 -0
- package/src/core/version.ts +1 -1
- package/src/index.ts +1 -1
- package/src/screens/ConnectScreen.tsx +27 -10
- package/src/screens/RedeemScreen.tsx +14 -2
package/README.md
CHANGED
|
@@ -133,7 +133,7 @@ zero-point checkout.
|
|
|
133
133
|
|-----------|-------------|
|
|
134
134
|
| `<LoyaltyBanner>` | Home/product page banner. Brand logos + balance. |
|
|
135
135
|
| `<BalanceSummary>` | Balance display: `compact`, `card`, or `inline` layout. |
|
|
136
|
-
| `<CheckoutPointsApply>` | Per-program sliders at checkout. Brand-colored tracks. |
|
|
136
|
+
| `<CheckoutPointsApply>` | Per-program sliders at checkout. Brand-colored tracks. Pass your order number as `merchantOrderId`, and the same number to `POST /api/sdk/earn/submit` when the order completes. |
|
|
137
137
|
| `<LoyaltyProfileSection>` | Profile card with linked programs + unlink. |
|
|
138
138
|
| `<PostCheckoutSavePrompt>` | Post-checkout phone OTP to save programs. |
|
|
139
139
|
|
package/package.json
CHANGED
|
@@ -84,6 +84,13 @@ export interface CheckoutPointsApplyHandle {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export interface CheckoutPointsApplyProps {
|
|
87
|
+
/**
|
|
88
|
+
* The store's own order number (required). Every program the shopper applies
|
|
89
|
+
* is held under it, so the purchase you record afterwards (POST
|
|
90
|
+
* /api/sdk/earn/submit with the same merchantOrderId) knows what points paid
|
|
91
|
+
* and earns only on the rest.
|
|
92
|
+
*/
|
|
93
|
+
merchantOrderId: string;
|
|
87
94
|
/** Order total in integer MINOR UNITS of the order currency (required) —
|
|
88
95
|
* cents for USD ($50.00 = 5000), whole yen for JPY (¥1,850 = 1850). */
|
|
89
96
|
orderTotalCents: number;
|
|
@@ -132,6 +139,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
132
139
|
onPointsChanged,
|
|
133
140
|
onLinkAnother,
|
|
134
141
|
style,
|
|
142
|
+
merchantOrderId,
|
|
135
143
|
}: CheckoutPointsApplyProps, ref) {
|
|
136
144
|
const ctx = useOuterJoyn();
|
|
137
145
|
const { isReady, isLinked, linkedPrograms, loading, demoMode, apiClient, redemptionRules, t } = ctx;
|
|
@@ -260,7 +268,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
260
268
|
valueAmount?: number;
|
|
261
269
|
}>;
|
|
262
270
|
}>('/api/sdk/pay/checkout', {
|
|
263
|
-
merchantOrderId
|
|
271
|
+
merchantOrderId,
|
|
264
272
|
orderTotalCents: validOrderTotal,
|
|
265
273
|
currencyCode: orderCurrency,
|
|
266
274
|
...breakdown,
|
|
@@ -303,7 +311,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
303
311
|
setApiLoading((prev) => ({ ...prev, [progId]: false }));
|
|
304
312
|
}
|
|
305
313
|
},
|
|
306
|
-
[programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, buildPayload, onPointsChanged, redemptionTokens, redemptionRules],
|
|
314
|
+
[programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, merchantOrderId, buildPayload, onPointsChanged, redemptionTokens, redemptionRules],
|
|
307
315
|
);
|
|
308
316
|
|
|
309
317
|
const handleRemove = useCallback(
|
|
@@ -415,7 +423,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
415
423
|
};
|
|
416
424
|
// The most points value this order can take: before and after the store's percent cap.
|
|
417
425
|
const orderCeilingCents = ceilingCents(order, redemptionRules);
|
|
418
|
-
const orderUncappedCents = uncappedCeilingCents(order);
|
|
426
|
+
const orderUncappedCents = uncappedCeilingCents(order, redemptionRules);
|
|
419
427
|
const rulesLine = rulesSummary(redemptionRules);
|
|
420
428
|
|
|
421
429
|
// Calculate already-confirmed total to cap remaining programs
|
|
@@ -18,6 +18,12 @@ export interface PortabilityHandoff {
|
|
|
18
18
|
expires_at: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** True only when the server says the hosted page could finish (programs to share, a verified email or phone). */
|
|
22
|
+
export async function getPortabilityHandoffAvailable(client: APIClient): Promise<boolean> {
|
|
23
|
+
const r = await client.get<{ available?: unknown }>('/api/connect/identity/portability/availability');
|
|
24
|
+
return r?.available === true;
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
export function createPortabilityHandoff(client: APIClient): Promise<PortabilityHandoff> {
|
|
22
28
|
return client.post<PortabilityHandoff>('/api/connect/identity/portability/requests', {});
|
|
23
29
|
}
|
|
@@ -77,37 +77,44 @@ export interface OrderBreakdown {
|
|
|
77
77
|
shippingCents?: number;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The most points value this order can take before the percent cap: the same
|
|
82
|
+
* amount the checkout accepts. In tender mode the store's tax/shipping settings
|
|
83
|
+
* let points pay those too. Discount,
|
|
84
|
+
* coupon, an unset mode or a missing component keep the merchandise ceiling;
|
|
85
|
+
* the server names what is missing.
|
|
86
|
+
*/
|
|
87
|
+
export function uncappedCeilingCents(order: OrderBreakdown, rules: RedemptionRules | null): number {
|
|
88
|
+
const merchandiseCeiling =
|
|
89
|
+
order.merchandiseSubtotalCents != null
|
|
90
|
+
? Math.min(order.orderTotalCents, order.merchandiseSubtotalCents)
|
|
91
|
+
: order.orderTotalCents;
|
|
92
|
+
if (rules?.applicationMode !== 'tender') return merchandiseCeiling;
|
|
93
|
+
if (rules.includeTax && rules.includeShipping) return order.orderTotalCents;
|
|
94
|
+
if (order.merchandiseSubtotalCents == null) return merchandiseCeiling;
|
|
95
|
+
let basis = order.merchandiseSubtotalCents;
|
|
96
|
+
if (rules.includeTax) {
|
|
97
|
+
if (order.taxCents == null) return merchandiseCeiling;
|
|
98
|
+
basis += order.taxCents;
|
|
99
|
+
}
|
|
100
|
+
if (rules.includeShipping) {
|
|
101
|
+
if (order.shippingCents == null) return merchandiseCeiling;
|
|
102
|
+
basis += order.shippingCents;
|
|
103
|
+
}
|
|
104
|
+
return Math.min(basis, order.orderTotalCents);
|
|
85
105
|
}
|
|
86
106
|
|
|
87
107
|
/**
|
|
88
108
|
* The most points value this order can take, with the store's percent cap
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* offering less is safe, offering more on a guess is not. Floors, so "Use Max"
|
|
92
|
-
* always stages a figure the server accepts.
|
|
109
|
+
* taken of that same basis. Floors, so "Use Max" always stages a figure the
|
|
110
|
+
* server accepts.
|
|
93
111
|
*/
|
|
94
112
|
export function ceilingCents(order: OrderBreakdown, rules: RedemptionRules | null): number {
|
|
95
|
-
const
|
|
113
|
+
const basis = uncappedCeilingCents(order, rules);
|
|
96
114
|
const pct = rules?.maxPercent ?? 0;
|
|
97
115
|
// Coupon mode has no percent cap on the server (the store's code caps instead).
|
|
98
|
-
if (!rules || pct <= 0 || pct >= 100 || rules.applicationMode === 'coupon') return
|
|
99
|
-
|
|
100
|
-
if (rules.applicationMode === 'tender') {
|
|
101
|
-
if (rules.includeTax && rules.includeShipping) {
|
|
102
|
-
basis = order.orderTotalCents;
|
|
103
|
-
} else if (order.merchandiseSubtotalCents != null) {
|
|
104
|
-
let b = order.merchandiseSubtotalCents;
|
|
105
|
-
if (rules.includeTax && order.taxCents != null) b += order.taxCents;
|
|
106
|
-
if (rules.includeShipping && order.shippingCents != null) b += order.shippingCents;
|
|
107
|
-
basis = Math.min(b, order.orderTotalCents);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return Math.min(uncapped, Math.floor((basis * pct) / 100));
|
|
116
|
+
if (!rules || pct <= 0 || pct >= 100 || rules.applicationMode === 'coupon') return basis;
|
|
117
|
+
return Math.floor((basis * pct) / 100);
|
|
111
118
|
}
|
|
112
119
|
|
|
113
120
|
/**
|
package/src/core/tender.ts
CHANGED
|
@@ -73,6 +73,17 @@ export function planRedeemTender(
|
|
|
73
73
|
return null;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** The rows that may pay for one item: a partner reward is priced in one
|
|
77
|
+
* currency (its pay_currency_id) and only that row pays for it. */
|
|
78
|
+
export function rowsPayingIn<T extends TenderRowLike>(
|
|
79
|
+
payableRows: readonly T[] | null | undefined,
|
|
80
|
+
payCurrencyId: string | null | undefined
|
|
81
|
+
): readonly T[] {
|
|
82
|
+
const rows = payableRows ?? [];
|
|
83
|
+
if (!payCurrencyId) return rows;
|
|
84
|
+
return rows.filter((r) => String(r?.currencyId ?? r?.currency_id ?? '').trim() === payCurrencyId);
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
/** Max a SINGLE tender can put toward one item (scalar or biggest row). */
|
|
77
88
|
export function maxTenderableBalance(
|
|
78
89
|
scalarPointsBalance: number | null | undefined,
|
package/src/core/version.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -85,7 +85,7 @@ export type {
|
|
|
85
85
|
|
|
86
86
|
// Core
|
|
87
87
|
export { APIClient, SDKError } from './core/api-client';
|
|
88
|
-
export { createPortabilityHandoff, getPortabilityHandoffStatus } from './core/portabilityHandoff';
|
|
88
|
+
export { createPortabilityHandoff, getPortabilityHandoffAvailable, getPortabilityHandoffStatus } from './core/portabilityHandoff';
|
|
89
89
|
export type { PortabilityHandoff, PortabilityOutcome } from './core/portabilityHandoff';
|
|
90
90
|
export { OuterJoynErrorBoundary } from './core/ErrorBoundary';
|
|
91
91
|
export { SDK_VERSION } from './core/version';
|
|
@@ -43,8 +43,8 @@ import {
|
|
|
43
43
|
} from 'react-native';
|
|
44
44
|
import * as WebBrowser from 'expo-web-browser';
|
|
45
45
|
import { OuterJoynContext } from '../OuterJoynProvider';
|
|
46
|
-
import { APIClient } from '../core/api-client';
|
|
47
|
-
import { createPortabilityHandoff, getPortabilityHandoffStatus } from '../core/portabilityHandoff';
|
|
46
|
+
import { APIClient, SDKError } from '../core/api-client';
|
|
47
|
+
import { createPortabilityHandoff, getPortabilityHandoffAvailable, getPortabilityHandoffStatus } from '../core/portabilityHandoff';
|
|
48
48
|
|
|
49
49
|
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
50
50
|
|
|
@@ -97,7 +97,9 @@ export interface ConnectScreenProps {
|
|
|
97
97
|
sessionToken?: string;
|
|
98
98
|
/** Override API base URL (reads from context if omitted) */
|
|
99
99
|
apiBaseUrl?: string;
|
|
100
|
-
/**
|
|
100
|
+
/** Open straight on this partner program's consent step (the web SDK's
|
|
101
|
+
* `preselectedBrandId`). A program this store can't link is an error
|
|
102
|
+
* (onError code `partner_not_linkable`), never the list. */
|
|
101
103
|
preselectedInstitutionId?: string;
|
|
102
104
|
}
|
|
103
105
|
|
|
@@ -317,8 +319,12 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
317
319
|
}
|
|
318
320
|
const instData = inst.data;
|
|
319
321
|
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
+
// Offer the hand-off only when the hosted page could finish it; one that
|
|
323
|
+
// can only say "we can't confirm it's you" is not offered.
|
|
324
|
+
if (
|
|
325
|
+
portableData?.consent_status === 'required' &&
|
|
326
|
+
(await getPortabilityHandoffAvailable(client).catch(() => false))
|
|
327
|
+
) {
|
|
322
328
|
setConsentRequired(true);
|
|
323
329
|
}
|
|
324
330
|
|
|
@@ -337,13 +343,24 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
337
343
|
|
|
338
344
|
setStep('search');
|
|
339
345
|
|
|
340
|
-
const activeList = list;
|
|
341
346
|
if (preselectedInstitutionId) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
// Asked of the server, which says whether this store can link it: the
|
|
348
|
+
// full list is capped, so a missing row there proves nothing.
|
|
349
|
+
const only = await client.get<{ institutions: Institution[] }>(
|
|
350
|
+
`/api/sdk/institutions?program=${encodeURIComponent(preselectedInstitutionId)}`,
|
|
351
|
+
);
|
|
352
|
+
const match = (only?.institutions || []).find(
|
|
353
|
+
(i) => i.institution_id === preselectedInstitutionId && i.is_active !== false,
|
|
354
|
+
);
|
|
355
|
+
if (!match) {
|
|
356
|
+
const message = 'This program can\u2019t be linked from this store.';
|
|
357
|
+
setErrorMessage(message);
|
|
358
|
+
setStep('error');
|
|
359
|
+
onError?.(new SDKError('partner_not_linkable', message, { param: 'preselectedInstitutionId' }));
|
|
360
|
+
return;
|
|
346
361
|
}
|
|
362
|
+
setSelectedInstitution(match);
|
|
363
|
+
setStep('consent');
|
|
347
364
|
}
|
|
348
365
|
} catch (err: any) {
|
|
349
366
|
console.warn('[OuterJoyn] ConnectScreen loadData failed:', err.message);
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
Linking,
|
|
26
26
|
} from 'react-native';
|
|
27
27
|
import { useOuterJoyn } from '../useOuterJoyn';
|
|
28
|
-
import { planRedeemTender, maxTenderableBalance } from '../core/tender';
|
|
28
|
+
import { planRedeemTender, maxTenderableBalance, rowsPayingIn } from '../core/tender';
|
|
29
29
|
import { APIClient } from '../core/api-client';
|
|
30
30
|
|
|
31
31
|
// =============================================================================
|
|
@@ -77,6 +77,10 @@ interface CatalogItem {
|
|
|
77
77
|
inventory_count?: number;
|
|
78
78
|
terms_and_conditions?: string;
|
|
79
79
|
expiry_days?: number;
|
|
80
|
+
/** Snowflake STRINGS on a partner reward: the partnership it is shared
|
|
81
|
+
* through and the one currency its price is in. */
|
|
82
|
+
partnership_id?: string;
|
|
83
|
+
pay_currency_id?: string;
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
@@ -212,6 +216,8 @@ export function RedeemScreen({
|
|
|
212
216
|
inventory_count: item.inventory_count ?? item.inventoryCount,
|
|
213
217
|
terms_and_conditions: item.terms_and_conditions ?? item.termsAndConditions,
|
|
214
218
|
expiry_days: item.expiry_days ?? item.expiryDays,
|
|
219
|
+
partnership_id: item.partnership_id ?? item.partnershipId,
|
|
220
|
+
pay_currency_id: item.pay_currency_id ?? item.payCurrencyId,
|
|
215
221
|
}));
|
|
216
222
|
// A genuinely empty catalog is a real (empty) state — render it as
|
|
217
223
|
// such via ListEmptyComponent rather than masking it with demo items.
|
|
@@ -279,7 +285,7 @@ export function RedeemScreen({
|
|
|
279
285
|
// cross-program TOTAL) — a sum no single tender can spend, so it enabled
|
|
280
286
|
// confirms the server would reject. Plan against the scalar + per-row
|
|
281
287
|
// balances instead; effectiveBalance stays display-only.
|
|
282
|
-
const
|
|
288
|
+
const allTenderRows = useMemo(
|
|
283
289
|
() =>
|
|
284
290
|
(ctx.linkedPrograms ?? []).map((p) => ({
|
|
285
291
|
balance: p.pointsBalance,
|
|
@@ -288,6 +294,11 @@ export function RedeemScreen({
|
|
|
288
294
|
})),
|
|
289
295
|
[ctx.linkedPrograms]
|
|
290
296
|
);
|
|
297
|
+
// A partner reward is paid only from the currency it is priced in.
|
|
298
|
+
const tenderRows = useMemo(
|
|
299
|
+
() => rowsPayingIn(allTenderRows, selectedItem?.pay_currency_id),
|
|
300
|
+
[allTenderRows, selectedItem]
|
|
301
|
+
);
|
|
291
302
|
|
|
292
303
|
const handleRedeem = useCallback(() => {
|
|
293
304
|
if (!selectedItem) return;
|
|
@@ -346,6 +357,7 @@ export function RedeemScreen({
|
|
|
346
357
|
const data = await clientRef.current.post<any>('/api/sdk/redeem', {
|
|
347
358
|
product_id: selectedItem.product_id,
|
|
348
359
|
payment,
|
|
360
|
+
...(selectedItem.partnership_id ? { partnershipId: selectedItem.partnership_id } : {}),
|
|
349
361
|
idempotency_key: Date.now() + '_' + Math.random().toString(36).slice(2),
|
|
350
362
|
});
|
|
351
363
|
const res: RedemptionResult = {
|