@outerjoyn/react-native 1.6.1 → 1.7.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/package.json +1 -1
- package/src/OuterJoynProvider.tsx +6 -0
- package/src/components/CheckoutPointsApply.tsx +63 -12
- package/src/core/redemptionRules.ts +168 -0
- package/src/core/types.ts +7 -0
- package/src/core/version.ts +1 -1
- package/src/index.ts +1 -0
- package/src/screens/ConnectScreen.tsx +3 -2
- package/src/screens/ExchangeScreen.tsx +16 -15
- package/src/screens/RedeemScreen.tsx +5 -5
package/package.json
CHANGED
|
@@ -35,6 +35,7 @@ import { PaySheet, ConnectSheet, ExchangeSheet, RedeemSheet, _setContextRef } fr
|
|
|
35
35
|
import { OuterJoynSheet } from './OuterJoynSheet';
|
|
36
36
|
|
|
37
37
|
import { OJ_COLORS } from './core/colors';
|
|
38
|
+
import { parseRedemptionRules, type RedemptionRules } from './core/redemptionRules';
|
|
38
39
|
import type {
|
|
39
40
|
OuterJoynProviderProps,
|
|
40
41
|
OuterJoynContextValue,
|
|
@@ -216,6 +217,7 @@ export function OuterJoynProvider({
|
|
|
216
217
|
const [demoMode, setDemoMode] = useState(false);
|
|
217
218
|
const [linkedPrograms, setLinkedPrograms] = useState<LinkedProgram[]>([]);
|
|
218
219
|
const [brandConfig, setBrandConfig] = useState<BrandConfig | null>(null);
|
|
220
|
+
const [redemptionRules, setRedemptionRules] = useState<RedemptionRules | null>(null);
|
|
219
221
|
const [sessionStatus, setSessionStatus] = useState<
|
|
220
222
|
'idle' | 'loading' | 'ready' | 'link_required' | 'error'
|
|
221
223
|
>('idle');
|
|
@@ -355,6 +357,7 @@ export function OuterJoynProvider({
|
|
|
355
357
|
if (ctx.brand_config) {
|
|
356
358
|
setBrandConfig(ctx.brand_config);
|
|
357
359
|
}
|
|
360
|
+
setRedemptionRules(parseRedemptionRules(ctx.redemption_rules));
|
|
358
361
|
|
|
359
362
|
if (ctx.expires_at) {
|
|
360
363
|
scheduleRefresh(ctx.expires_at);
|
|
@@ -430,6 +433,7 @@ export function OuterJoynProvider({
|
|
|
430
433
|
|
|
431
434
|
setLinkedPrograms(programs);
|
|
432
435
|
setBrandConfig(ctx.brand_config ?? null);
|
|
436
|
+
setRedemptionRules(parseRedemptionRules(ctx.redemption_rules));
|
|
433
437
|
|
|
434
438
|
// Persist to offline cache
|
|
435
439
|
if (offlineCacheRef.current) {
|
|
@@ -697,6 +701,7 @@ export function OuterJoynProvider({
|
|
|
697
701
|
error,
|
|
698
702
|
demoMode,
|
|
699
703
|
brandConfig,
|
|
704
|
+
redemptionRules,
|
|
700
705
|
|
|
701
706
|
// Actions
|
|
702
707
|
refreshBalances,
|
|
@@ -732,6 +737,7 @@ export function OuterJoynProvider({
|
|
|
732
737
|
error,
|
|
733
738
|
demoMode,
|
|
734
739
|
brandConfig,
|
|
740
|
+
redemptionRules,
|
|
735
741
|
refreshBalances,
|
|
736
742
|
openConnect,
|
|
737
743
|
openExchange,
|
|
@@ -43,6 +43,15 @@ import {
|
|
|
43
43
|
import Slider from '@react-native-community/slider';
|
|
44
44
|
import { useOuterJoyn } from '../useOuterJoyn';
|
|
45
45
|
import { OJ_COLORS } from '../core/colors';
|
|
46
|
+
import {
|
|
47
|
+
amountError,
|
|
48
|
+
blockedReason,
|
|
49
|
+
ceilingCents,
|
|
50
|
+
fewestPointsForValue,
|
|
51
|
+
floorToIncrement,
|
|
52
|
+
rulesSummary,
|
|
53
|
+
uncappedCeilingCents,
|
|
54
|
+
} from '../core/redemptionRules';
|
|
46
55
|
|
|
47
56
|
const OJ_LOGO_URL = 'https://app.outerjoyn.com/outerjoyn-logo.png';
|
|
48
57
|
const PRIMARY = OJ_COLORS.primary;
|
|
@@ -125,7 +134,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
125
134
|
style,
|
|
126
135
|
}: CheckoutPointsApplyProps, ref) {
|
|
127
136
|
const ctx = useOuterJoyn();
|
|
128
|
-
const { isReady, isLinked, linkedPrograms, loading, demoMode, apiClient, t } = ctx;
|
|
137
|
+
const { isReady, isLinked, linkedPrograms, loading, demoMode, apiClient, redemptionRules, t } = ctx;
|
|
129
138
|
|
|
130
139
|
const [sliderValues, setSliderValues] = useState<Record<string, number>>({});
|
|
131
140
|
const [confirmedPrograms, setConfirmedPrograms] = useState<Set<string>>(new Set());
|
|
@@ -185,6 +194,18 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
185
194
|
|
|
186
195
|
const selectedPoints = sliderValues[progId] ?? 0;
|
|
187
196
|
if (selectedPoints <= 0) return;
|
|
197
|
+
// The store's minimum and step, and points that would buy nothing,
|
|
198
|
+
// checked here so the shopper gets the refusal (with a figure that
|
|
199
|
+
// works) before the server's.
|
|
200
|
+
const fewest = fewestPointsForValue(selectedPoints, prog.pointValueAmount, redemptionRules);
|
|
201
|
+
const ruleError = amountError(selectedPoints, redemptionRules)
|
|
202
|
+
?? (fewest < selectedPoints
|
|
203
|
+
? `${selectedPoints.toLocaleString()} points pay the same as ${fewest.toLocaleString()} here. Use ${fewest.toLocaleString()}.`
|
|
204
|
+
: null);
|
|
205
|
+
if (ruleError) {
|
|
206
|
+
setApiError((prev) => ({ ...prev, [progId]: ruleError }));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
188
209
|
|
|
189
210
|
// Validate orderTotalCents inside callback scope
|
|
190
211
|
const validOrderTotal = (typeof orderTotalCents === 'number' && !Number.isNaN(orderTotalCents))
|
|
@@ -282,7 +303,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
282
303
|
setApiLoading((prev) => ({ ...prev, [progId]: false }));
|
|
283
304
|
}
|
|
284
305
|
},
|
|
285
|
-
[programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, buildPayload, onPointsChanged, redemptionTokens],
|
|
306
|
+
[programs, sliderValues, demoMode, apiClient, orderTotalCents, merchandiseSubtotalCents, taxCents, shippingCents, currencyCode, buildPayload, onPointsChanged, redemptionTokens, redemptionRules],
|
|
286
307
|
);
|
|
287
308
|
|
|
288
309
|
const handleRemove = useCallback(
|
|
@@ -386,6 +407,17 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
386
407
|
if (!isReady && !loading) return null;
|
|
387
408
|
if (!isLinked || programs.length === 0) return null;
|
|
388
409
|
|
|
410
|
+
const order = {
|
|
411
|
+
orderTotalCents: safeOrderTotalCents,
|
|
412
|
+
merchandiseSubtotalCents: Number.isFinite(merchandiseSubtotalCents) ? merchandiseSubtotalCents : undefined,
|
|
413
|
+
taxCents: Number.isFinite(taxCents) ? taxCents : undefined,
|
|
414
|
+
shippingCents: Number.isFinite(shippingCents) ? shippingCents : undefined,
|
|
415
|
+
};
|
|
416
|
+
// The most points value this order can take: before and after the store's percent cap.
|
|
417
|
+
const orderCeilingCents = ceilingCents(order, redemptionRules);
|
|
418
|
+
const orderUncappedCents = uncappedCeilingCents(order);
|
|
419
|
+
const rulesLine = rulesSummary(redemptionRules);
|
|
420
|
+
|
|
389
421
|
// Calculate already-confirmed total to cap remaining programs
|
|
390
422
|
const confirmedTotalCents = programs.reduce((sum, prog) => {
|
|
391
423
|
if (confirmedPrograms.has(prog.id)) {
|
|
@@ -397,6 +429,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
397
429
|
return (
|
|
398
430
|
<View style={[styles.container, style]}>
|
|
399
431
|
<Text style={styles.sectionLabel}>{t('banner.pay_with_points')}</Text>
|
|
432
|
+
{rulesLine && <Text style={styles.rulesText}>{rulesLine}</Text>}
|
|
400
433
|
|
|
401
434
|
{programs.map((prog) => {
|
|
402
435
|
const isConfirmed = confirmedPrograms.has(prog.id);
|
|
@@ -404,15 +437,17 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
404
437
|
const previewValueAmount = Math.round(currentPts * prog.pointValueAmount);
|
|
405
438
|
const previewDollars = (previewValueAmount / 100).toFixed(2);
|
|
406
439
|
|
|
407
|
-
// Cap slider
|
|
440
|
+
// Cap the slider at what this order can still take, in the store's steps.
|
|
408
441
|
const otherConfirmedCents = confirmedTotalCents - (isConfirmed ? previewValueAmount : 0);
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
prog.pointValueAmount > 0
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const maxSlider =
|
|
415
|
-
const
|
|
442
|
+
const maxPointsFor = (ceiling: number) => {
|
|
443
|
+
const remaining = Math.max(0, ceiling - otherConfirmedCents);
|
|
444
|
+
const pts = prog.pointValueAmount > 0 ? Math.floor(remaining / prog.pointValueAmount) : prog.pointsBalance;
|
|
445
|
+
return fewestPointsForValue(floorToIncrement(Math.min(prog.pointsBalance, pts), redemptionRules), prog.pointValueAmount, redemptionRules);
|
|
446
|
+
};
|
|
447
|
+
const maxSlider = maxPointsFor(orderCeilingCents);
|
|
448
|
+
const blocked = blockedReason(prog.pointsBalance, maxSlider, maxPointsFor(orderUncappedCents), redemptionRules);
|
|
449
|
+
const increment = redemptionRules?.pointsIncrement ?? 0;
|
|
450
|
+
const sliderStep = increment > 1 ? increment : Math.max(1, Math.floor(maxSlider / 100));
|
|
416
451
|
|
|
417
452
|
const isLoading = apiLoading[prog.id] ?? false;
|
|
418
453
|
const errorMsg = apiError[prog.id];
|
|
@@ -420,7 +455,7 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
420
455
|
return (
|
|
421
456
|
<View
|
|
422
457
|
key={prog.id}
|
|
423
|
-
style={[styles.programCard, isConfirmed && styles.programCardApplied]}
|
|
458
|
+
style={[styles.programCard, isConfirmed && styles.programCardApplied, !isConfirmed && blocked ? styles.programCardBlocked : null]}
|
|
424
459
|
>
|
|
425
460
|
{/* Header */}
|
|
426
461
|
<View style={styles.programHeader}>
|
|
@@ -469,7 +504,9 @@ export const CheckoutPointsApply = forwardRef<CheckoutPointsApplyHandle, Checkou
|
|
|
469
504
|
)}
|
|
470
505
|
|
|
471
506
|
{/* Applied state */}
|
|
472
|
-
{isConfirmed ? (
|
|
507
|
+
{!isConfirmed && blocked ? (
|
|
508
|
+
<Text style={styles.blockedText}>{blocked}</Text>
|
|
509
|
+
) : isConfirmed ? (
|
|
473
510
|
<View style={styles.appliedRow}>
|
|
474
511
|
<Text style={[styles.checkmark, { color: SUCCESS }]}>{'\u2714'}</Text>
|
|
475
512
|
<Text style={styles.appliedLabel}>
|
|
@@ -634,6 +671,9 @@ const styles = StyleSheet.create({
|
|
|
634
671
|
borderColor: SUCCESS,
|
|
635
672
|
backgroundColor: '#F0FDF4',
|
|
636
673
|
},
|
|
674
|
+
programCardBlocked: {
|
|
675
|
+
opacity: 0.6,
|
|
676
|
+
},
|
|
637
677
|
programHeader: {
|
|
638
678
|
flexDirection: 'row',
|
|
639
679
|
alignItems: 'center',
|
|
@@ -679,6 +719,17 @@ const styles = StyleSheet.create({
|
|
|
679
719
|
fontWeight: '600',
|
|
680
720
|
padding: 4,
|
|
681
721
|
},
|
|
722
|
+
rulesText: {
|
|
723
|
+
fontSize: 12,
|
|
724
|
+
color: '#6B7280',
|
|
725
|
+
marginTop: -6,
|
|
726
|
+
marginBottom: 10,
|
|
727
|
+
},
|
|
728
|
+
blockedText: {
|
|
729
|
+
fontSize: 12,
|
|
730
|
+
color: '#6B7280',
|
|
731
|
+
marginTop: 8,
|
|
732
|
+
},
|
|
682
733
|
errorText: {
|
|
683
734
|
fontSize: 12,
|
|
684
735
|
color: '#DC2626',
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The store's pay-with-points rules, as served on /api/sdk/sessions/context
|
|
3
|
+
* (`redemption_rules`): a minimum, a step size, and a cap on how much of an
|
|
4
|
+
* order points may pay. The server enforces them at reserve; this module only
|
|
5
|
+
* shapes the input so the shopper meets a rule here instead of as an error
|
|
6
|
+
* after Apply. Same semantics as the web pay widget.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface RedemptionRules {
|
|
10
|
+
/** 0 = no cap; 1..99 = points may pay at most this percent of the order's redeemable amount. */
|
|
11
|
+
maxPercent: number;
|
|
12
|
+
/** 0 = no minimum; else the fewest points one program may apply. */
|
|
13
|
+
minPoints: number;
|
|
14
|
+
/** 0 = none; else points must be a whole multiple of this. */
|
|
15
|
+
pointsIncrement: number;
|
|
16
|
+
allowRewardStacking: boolean;
|
|
17
|
+
/** 'discount' | 'tender' | 'coupon' | '' (unset). */
|
|
18
|
+
applicationMode: string;
|
|
19
|
+
includeTax: boolean;
|
|
20
|
+
includeShipping: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Wrong type or out of range reads as "no rule", never a lockout. */
|
|
24
|
+
export function parseRedemptionRules(raw: unknown): RedemptionRules | null {
|
|
25
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
26
|
+
const rr = raw as Record<string, unknown>;
|
|
27
|
+
const intOr0 = (v: unknown, lo: number, hi: number) => {
|
|
28
|
+
const n = typeof v === 'number' && Number.isFinite(v) ? Math.floor(v) : 0;
|
|
29
|
+
return n >= lo && n <= hi ? n : 0;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
maxPercent: intOr0(rr.max_percent, 1, 99),
|
|
33
|
+
minPoints: intOr0(rr.min_points, 1, Number.MAX_SAFE_INTEGER),
|
|
34
|
+
pointsIncrement: intOr0(rr.points_increment, 2, Number.MAX_SAFE_INTEGER),
|
|
35
|
+
allowRewardStacking: rr.allow_reward_stacking !== false,
|
|
36
|
+
applicationMode: typeof rr.application_mode === 'string' ? rr.application_mode : '',
|
|
37
|
+
includeTax: rr.redeem_include_tax === true,
|
|
38
|
+
includeShipping: rr.redeem_include_shipping === true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Round DOWN to the step (identity when none): never more points than asked. */
|
|
43
|
+
export function floorToIncrement(points: number, rules: RedemptionRules | null): number {
|
|
44
|
+
const inc = rules?.pointsIncrement ?? 0;
|
|
45
|
+
return inc > 1 ? Math.floor(points / inc) * inc : points;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The fewest points, in the store's steps, worth what `points` are worth at
|
|
50
|
+
* `pointValue` cents a point. Checkout values points at floor(points × value),
|
|
51
|
+
* so below a cent a point the last points can buy nothing (51 at 0.5 cents pay
|
|
52
|
+
* what 50 do) and it refuses such an amount (points_buy_nothing). Down only.
|
|
53
|
+
*/
|
|
54
|
+
export function fewestPointsForValue(points: number, pointValue: number, rules: RedemptionRules | null): number {
|
|
55
|
+
const inc = rules?.pointsIncrement ?? 0;
|
|
56
|
+
const step = inc > 1 ? inc : 1;
|
|
57
|
+
const lowest = Math.max(1, smallestValidPoints(rules));
|
|
58
|
+
const value = Math.floor(points * pointValue);
|
|
59
|
+
let fewest = points;
|
|
60
|
+
while (fewest - step >= lowest && Math.floor((fewest - step) * pointValue) === value) fewest -= step;
|
|
61
|
+
return fewest;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The smallest amount that meets BOTH the minimum and the step (min 450, step 100 -> 500). */
|
|
65
|
+
export function smallestValidPoints(rules: RedemptionRules | null): number {
|
|
66
|
+
const min = rules?.minPoints ?? 0;
|
|
67
|
+
const inc = rules?.pointsIncrement ?? 0;
|
|
68
|
+
const lowest = min > 0 ? min : 1;
|
|
69
|
+
if (inc <= 1) return min > 0 ? min : 0;
|
|
70
|
+
return Math.max(inc, Math.ceil(lowest / inc) * inc);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface OrderBreakdown {
|
|
74
|
+
orderTotalCents: number;
|
|
75
|
+
merchandiseSubtotalCents?: number;
|
|
76
|
+
taxCents?: number;
|
|
77
|
+
shippingCents?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The most points value this order can take before the percent cap. */
|
|
81
|
+
export function uncappedCeilingCents(order: OrderBreakdown): number {
|
|
82
|
+
return order.merchandiseSubtotalCents != null
|
|
83
|
+
? Math.min(order.orderTotalCents, order.merchandiseSubtotalCents)
|
|
84
|
+
: order.orderTotalCents;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The most points value this order can take, with the store's percent cap
|
|
89
|
+
* applied to the same amount the server caps (in tender mode the tax/shipping
|
|
90
|
+
* settings widen it). A missing component falls back to merchandise only:
|
|
91
|
+
* offering less is safe, offering more on a guess is not. Floors, so "Use Max"
|
|
92
|
+
* always stages a figure the server accepts.
|
|
93
|
+
*/
|
|
94
|
+
export function ceilingCents(order: OrderBreakdown, rules: RedemptionRules | null): number {
|
|
95
|
+
const uncapped = uncappedCeilingCents(order);
|
|
96
|
+
const pct = rules?.maxPercent ?? 0;
|
|
97
|
+
// 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 uncapped;
|
|
99
|
+
let basis = uncapped;
|
|
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));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Why a program can't be used on this order, as shopper copy, or null.
|
|
115
|
+
* `maxPoints` is the most this program may apply (already capped and stepped);
|
|
116
|
+
* `uncappedMaxPoints` is the same figure without the percent cap, so the reason
|
|
117
|
+
* can name the cap when it is the cause.
|
|
118
|
+
*/
|
|
119
|
+
export function blockedReason(
|
|
120
|
+
balance: number,
|
|
121
|
+
maxPoints: number,
|
|
122
|
+
uncappedMaxPoints: number,
|
|
123
|
+
rules: RedemptionRules | null,
|
|
124
|
+
): string | null {
|
|
125
|
+
const floor = rules?.minPoints ?? 0;
|
|
126
|
+
if (floor <= 0 || maxPoints >= floor) return null;
|
|
127
|
+
const pts = floor.toLocaleString();
|
|
128
|
+
if (balance < floor) return `You need at least ${pts} points to redeem from this program.`;
|
|
129
|
+
if (uncappedMaxPoints > maxPoints && uncappedMaxPoints >= floor) {
|
|
130
|
+
return `Points can pay up to ${rules!.maxPercent}% of this order — less than the ${pts}-point minimum.`;
|
|
131
|
+
}
|
|
132
|
+
return `This order is too small to use the ${pts}-point minimum.`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The refusal for an amount the server would turn down, as shopper copy, or null. */
|
|
136
|
+
export function amountError(points: number, rules: RedemptionRules | null): string | null {
|
|
137
|
+
const floor = rules?.minPoints ?? 0;
|
|
138
|
+
const inc = rules?.pointsIncrement ?? 0;
|
|
139
|
+
if (inc > 1 && points % inc !== 0) {
|
|
140
|
+
const snapped = floorToIncrement(points, rules);
|
|
141
|
+
if (floor > 0 && snapped < floor) {
|
|
142
|
+
return `You need to use at least ${smallestValidPoints(rules).toLocaleString()} points at a time.`;
|
|
143
|
+
}
|
|
144
|
+
if (snapped <= 0) return `Points can only be used in multiples of ${inc.toLocaleString()}.`;
|
|
145
|
+
return `Points can only be used in multiples of ${inc.toLocaleString()} — try ${snapped.toLocaleString()}.`;
|
|
146
|
+
}
|
|
147
|
+
if (floor > 0 && points < floor) {
|
|
148
|
+
return `You need to use at least ${floor.toLocaleString()} points at a time.`;
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** One plain line naming the store's rules, or null when there are none. */
|
|
154
|
+
export function rulesSummary(rules: RedemptionRules | null): string | null {
|
|
155
|
+
if (!rules) return null;
|
|
156
|
+
const parts: string[] = [];
|
|
157
|
+
if (rules.minPoints > 0 && rules.pointsIncrement > 1) {
|
|
158
|
+
parts.push(`Use at least ${rules.minPoints.toLocaleString()} points, in steps of ${rules.pointsIncrement.toLocaleString()}.`);
|
|
159
|
+
} else if (rules.minPoints > 0) {
|
|
160
|
+
parts.push(`Use at least ${rules.minPoints.toLocaleString()} points.`);
|
|
161
|
+
} else if (rules.pointsIncrement > 1) {
|
|
162
|
+
parts.push(`Points are used in steps of ${rules.pointsIncrement.toLocaleString()}.`);
|
|
163
|
+
}
|
|
164
|
+
if (rules.maxPercent > 0 && rules.applicationMode !== 'coupon') {
|
|
165
|
+
parts.push(`Points can pay up to ${rules.maxPercent}% of this order.`);
|
|
166
|
+
}
|
|
167
|
+
return parts.length ? parts.join(' ') : null;
|
|
168
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface SessionContextResponse {
|
|
|
33
33
|
payable_balances?: PayableBalance[];
|
|
34
34
|
brand_config?: BrandConfig;
|
|
35
35
|
returning_user?: boolean;
|
|
36
|
+
/** The store's pay-with-points rules; absent when the key has no storefront. */
|
|
37
|
+
redemption_rules?: Record<string, unknown>;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface PayableBalance {
|
|
@@ -188,6 +190,11 @@ export interface OuterJoynContextValue {
|
|
|
188
190
|
error: Error | null;
|
|
189
191
|
demoMode: boolean;
|
|
190
192
|
brandConfig: BrandConfig | null;
|
|
193
|
+
/**
|
|
194
|
+
* The store's pay-with-points rules (minimum, step, percent cap), or null
|
|
195
|
+
* when the store sets none. Display only: the server enforces them.
|
|
196
|
+
*/
|
|
197
|
+
redemptionRules: import('./redemptionRules').RedemptionRules | null;
|
|
191
198
|
|
|
192
199
|
// Actions
|
|
193
200
|
refreshBalances: () => Promise<void>;
|
package/src/core/version.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -500,9 +500,10 @@ export const ConnectScreen: React.FC<ConnectScreenProps> = ({
|
|
|
500
500
|
const publicToken = params.get('public_token'); // legacy
|
|
501
501
|
|
|
502
502
|
if (error || status === 'error') {
|
|
503
|
-
|
|
503
|
+
const message = params.get('error_description') ?? error ?? 'Authorization failed';
|
|
504
|
+
setErrorMessage(message);
|
|
504
505
|
setStep('error');
|
|
505
|
-
onError?.(new Error(
|
|
506
|
+
onError?.(new Error(message));
|
|
506
507
|
return;
|
|
507
508
|
}
|
|
508
509
|
|
|
@@ -190,17 +190,18 @@ export function ExchangeScreen({
|
|
|
190
190
|
|
|
191
191
|
if (!isDemo && clientRef.current) {
|
|
192
192
|
clientRef.current
|
|
193
|
-
.get<any>('/api/
|
|
193
|
+
.get<any>('/api/v1/exchange/rates', {
|
|
194
194
|
source_currency_id: String(source.currencyId),
|
|
195
195
|
target_currency_id: String(target.currencyId),
|
|
196
|
-
amount: String(amountNum),
|
|
197
196
|
})
|
|
198
197
|
.then((data) => {
|
|
198
|
+
const found = data.rates?.[0];
|
|
199
|
+
if (!found) return;
|
|
199
200
|
setRate({
|
|
200
|
-
rate:
|
|
201
|
-
sourceValueAmount:
|
|
202
|
-
targetValueAmount:
|
|
203
|
-
fee:
|
|
201
|
+
rate: found.rate,
|
|
202
|
+
sourceValueAmount: amountNum * source.pointValueAmount,
|
|
203
|
+
targetValueAmount: Math.floor(amountNum * found.rate) * target.pointValueAmount,
|
|
204
|
+
fee: 0,
|
|
204
205
|
});
|
|
205
206
|
})
|
|
206
207
|
.catch(() => {
|
|
@@ -237,21 +238,21 @@ export function ExchangeScreen({
|
|
|
237
238
|
return;
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
// Fix #8: add idempotency_key to mutation POST
|
|
241
241
|
if (!clientRef.current) {
|
|
242
242
|
throw new Error('API client not available');
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
// The key travels in the body so the client's network retry replays it.
|
|
245
|
+
const data = await clientRef.current.post<any>('/api/v1/exchange', {
|
|
246
|
+
sourceCurrencyId: String(source.currencyId),
|
|
247
|
+
targetCurrencyId: String(target.currencyId),
|
|
248
|
+
sourceAmount: amountNum,
|
|
249
|
+
idempotencyKey: Date.now() + '_' + Math.random().toString(36).slice(2),
|
|
249
250
|
});
|
|
250
251
|
|
|
251
252
|
const res: ExchangeResult = {
|
|
252
|
-
transactionId: data.
|
|
253
|
-
sourceAmount:
|
|
254
|
-
targetAmount: data.
|
|
253
|
+
transactionId: String(data.transactionId),
|
|
254
|
+
sourceAmount: data.sourceAmount,
|
|
255
|
+
targetAmount: data.targetAmount,
|
|
255
256
|
sourceCurrency: source.currencyName,
|
|
256
257
|
targetCurrency: target.currencyName,
|
|
257
258
|
status: data.status ?? 'completed',
|
|
@@ -161,7 +161,7 @@ export function RedeemScreen({
|
|
|
161
161
|
// Category chip filter ('' = All) — Plaid-grade redesign 2026-07-21.
|
|
162
162
|
const [categoryFilter, setCategoryFilter] = useState('');
|
|
163
163
|
|
|
164
|
-
// "Available to spend":
|
|
164
|
+
// "Available to spend": the account's points_balance only reads the single brand
|
|
165
165
|
// Member.points_balance, which is 0 for cross-program demo members even
|
|
166
166
|
// when the provider holds six-figure payable balances — the infamous
|
|
167
167
|
// "Total Available Value: 0 pts" header. Prefer the provider's
|
|
@@ -226,8 +226,8 @@ export function RedeemScreen({
|
|
|
226
226
|
.finally(() => setLoading(false));
|
|
227
227
|
|
|
228
228
|
clientRef.current
|
|
229
|
-
.get<any>('/api/sdk/
|
|
230
|
-
.then((data) => setBalance(data?.points_balance ??
|
|
229
|
+
.get<any>('/api/sdk/account')
|
|
230
|
+
.then((data) => setBalance(data?.member?.points_balance ?? 0))
|
|
231
231
|
.catch(() => {});
|
|
232
232
|
}, [visible, isDemo, ctx.apiClient, reloadKey]);
|
|
233
233
|
|
|
@@ -371,7 +371,7 @@ export function RedeemScreen({
|
|
|
371
371
|
// DEPS: balance, tenderRows and ctx are READ in this callback and MUST be
|
|
372
372
|
// listed. They were omitted once, which froze the callback at its
|
|
373
373
|
// mount-time values (balance 0, tenderRows []) — both are populated
|
|
374
|
-
// asynchronously (/api/sdk/
|
|
374
|
+
// asynchronously (/api/sdk/account and /sessions/context). planRedeemTender
|
|
375
375
|
// then returned null on every real redemption, and the old
|
|
376
376
|
// `?? {method:'points'}` fallback submitted a points tender against a
|
|
377
377
|
// scalar of 0: a guaranteed 400 insufficient_balance for exactly the
|
|
@@ -467,7 +467,7 @@ export function RedeemScreen({
|
|
|
467
467
|
const renderCatalog = () => (
|
|
468
468
|
<View style={styles.content}>
|
|
469
469
|
{/* Available-to-spend chip — cross-program totals from the provider
|
|
470
|
-
(the old header read
|
|
470
|
+
(the old header read the account's single-brand
|
|
471
471
|
Member.points_balance, which rendered "0 pts" for cross-program
|
|
472
472
|
demo members). */}
|
|
473
473
|
<View style={styles.balanceChip}>
|