@outerjoyn/react-native 1.7.1 → 1.7.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/package.json +1 -1
- package/src/components/CheckoutPointsApply.tsx +1 -1
- 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 +7 -3
- package/src/screens/RedeemScreen.tsx +14 -2
package/package.json
CHANGED
|
@@ -415,7 +415,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
415
415
|
};
|
|
416
416
|
// The most points value this order can take: before and after the store's percent cap.
|
|
417
417
|
const orderCeilingCents = ceilingCents(order, redemptionRules);
|
|
418
|
-
const orderUncappedCents = uncappedCeilingCents(order);
|
|
418
|
+
const orderUncappedCents = uncappedCeilingCents(order, redemptionRules);
|
|
419
419
|
const rulesLine = rulesSummary(redemptionRules);
|
|
420
420
|
|
|
421
421
|
// 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';
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
import * as WebBrowser from 'expo-web-browser';
|
|
45
45
|
import { OuterJoynContext } from '../OuterJoynProvider';
|
|
46
46
|
import { APIClient } from '../core/api-client';
|
|
47
|
-
import { createPortabilityHandoff, getPortabilityHandoffStatus } from '../core/portabilityHandoff';
|
|
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
|
|
|
@@ -317,8 +317,12 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
317
317
|
}
|
|
318
318
|
const instData = inst.data;
|
|
319
319
|
|
|
320
|
-
//
|
|
321
|
-
|
|
320
|
+
// Offer the hand-off only when the hosted page could finish it; one that
|
|
321
|
+
// can only say "we can't confirm it's you" is not offered.
|
|
322
|
+
if (
|
|
323
|
+
portableData?.consent_status === 'required' &&
|
|
324
|
+
(await getPortabilityHandoffAvailable(client).catch(() => false))
|
|
325
|
+
) {
|
|
322
326
|
setConsentRequired(true);
|
|
323
327
|
}
|
|
324
328
|
|
|
@@ -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 = {
|