Skip to content

Commit 7464de9

Browse files
refactor: remove intent from event naming
1 parent 3a7c499 commit 7464de9

File tree

5 files changed

+67
-36
lines changed

5 files changed

+67
-36
lines changed

modules/@shopify/checkout-sheet-kit/ios/RCTCheckoutWebView.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RCTCheckoutWebView: UIView {
8484
@objc var onCancel: RCTBubblingEventBlock?
8585
@objc var onLinkClick: RCTBubblingEventBlock?
8686
@objc var onAddressChangeStart: RCTBubblingEventBlock?
87-
@objc var onPaymentChangeIntent: RCTBubblingEventBlock?
87+
@objc var onPaymentMethodChangeStart: RCTBubblingEventBlock?
8888

8989
override init(frame: CGRect) {
9090
super.init(frame: frame)
@@ -304,24 +304,29 @@ extension RCTCheckoutWebView: CheckoutDelegate {
304304
])
305305
}
306306

307-
func checkoutDidRequestCardChange(event: CheckoutCardChangeRequested) {
307+
func checkoutDidStartPaymentMethodChange(event: CheckoutPaymentMethodChangeStart) {
308308
guard let id = event.id else { return }
309309

310310
self.events.set(key: id, event: event)
311311

312312
var eventData: [String: Any] = [
313313
"id": event.id,
314-
"type": "paymentChangeIntent",
314+
"type": "paymentMethodChangeStart",
315315
]
316316

317-
// Include current card info if available
318-
if let currentCard = event.params.currentCard {
319-
eventData["currentCard"] = [
320-
"last4": currentCard.last4,
321-
"brand": currentCard.brand,
322-
]
317+
// Include cart payment instruments if available
318+
if let paymentInstruments = event.params.cart?.paymentInstruments {
319+
var instruments: [[String: Any]] = []
320+
for instrument in paymentInstruments {
321+
var instrumentData: [String: Any] = ["type": instrument.type]
322+
if let details = instrument.details {
323+
instrumentData["details"] = details
324+
}
325+
instruments.append(instrumentData)
326+
}
327+
eventData["cart"] = ["paymentInstruments": instruments]
323328
}
324329

325-
onPaymentChangeIntent?(eventData)
330+
onPaymentMethodChangeStart?(eventData)
326331
}
327332
}

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ @interface RCT_EXTERN_MODULE (RCTCheckoutWebViewManager, RCTViewManager)
126126
/**
127127
* Emitted when checkout is moving to payment selection screen
128128
*/
129-
RCT_EXPORT_VIEW_PROPERTY(onPaymentChangeIntent, RCTBubblingEventBlock)
129+
RCT_EXPORT_VIEW_PROPERTY(onPaymentMethodChangeStart, RCTBubblingEventBlock)
130130

131131
/**
132132
* Emitted when a link is clicked

modules/@shopify/checkout-sheet-kit/src/components/Checkout.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ import React, {
2424
forwardRef,
2525
useEffect,
2626
} from 'react';
27-
import {
28-
requireNativeComponent,
29-
UIManager,
30-
findNodeHandle,
31-
} from 'react-native';
27+
import {requireNativeComponent, UIManager, findNodeHandle} from 'react-native';
3228
import type {ViewStyle} from 'react-native';
3329
import type {
30+
CheckoutAddressChangeStart,
3431
CheckoutCompleteEvent,
3532
CheckoutException,
33+
CheckoutStartEvent,
3634
} from '..';
3735
import {useCheckoutEvents} from '../CheckoutEventProvider';
38-
import type {CheckoutAddressChangeStart, CheckoutStartEvent} from '../events';
3936

4037
export interface CheckoutProps {
4138
/**
@@ -81,6 +78,13 @@ export interface CheckoutProps {
8178
*/
8279
onAddressChangeStart?: (event: CheckoutAddressChangeStart) => void;
8380

81+
/**
82+
* Called when checkout requests a payment method change (e.g., for native payment selector)
83+
*/
84+
onPaymentMethodChangeStart?: (
85+
event: CheckoutPaymentMethodChangeStart,
86+
) => void;
87+
8488
/**
8589
* Style for the webview container
8690
*/
@@ -109,7 +113,19 @@ interface NativeCheckoutWebViewProps {
109113
onComplete?: (event: {nativeEvent: CheckoutCompleteEvent}) => void;
110114
onCancel?: () => void;
111115
onLinkClick?: (event: {nativeEvent: {url: string}}) => void;
112-
onAddressChangeStart?: (event: {nativeEvent: CheckoutAddressChangeStart}) => void;
116+
onAddressChangeStart?: (event: {
117+
nativeEvent: CheckoutAddressChangeStart;
118+
}) => void;
119+
onPaymentMethodChangeStart?: (event: {
120+
nativeEvent: {
121+
id: string;
122+
type: string;
123+
currentCard?: {
124+
last4: string;
125+
brand: string;
126+
};
127+
};
128+
}) => void;
113129
}
114130

115131
const RCTCheckoutWebView =
@@ -167,6 +183,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
167183
onCancel,
168184
onLinkClick,
169185
onAddressChangeStart,
186+
onPaymentMethodChangeStart,
170187
style,
171188
testID,
172189
},
@@ -185,7 +202,6 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
185202
return () => eventContext.unregisterWebView();
186203
}, [eventContext]);
187204

188-
189205
const handleStart = useCallback<
190206
Required<NativeCheckoutWebViewProps>['onStart']
191207
>(
@@ -239,6 +255,22 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
239255
[onAddressChangeStart],
240256
);
241257

258+
const handlePaymentMethodChangeStart = useCallback<
259+
Required<NativeCheckoutWebViewProps>['onPaymentMethodChangeStart']
260+
>(
261+
(event: {
262+
nativeEvent: {
263+
id: string;
264+
type: string;
265+
currentCard?: {last4: string; brand: string};
266+
};
267+
}) => {
268+
if (!event.nativeEvent) return;
269+
onPaymentMethodChangeStart?.(event.nativeEvent);
270+
},
271+
[onPaymentMethodChangeStart],
272+
);
273+
242274
const reload = useCallback(() => {
243275
if (!webViewRef.current) {
244276
return;
@@ -251,11 +283,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
251283
const viewConfig = UIManager.getViewManagerConfig('RCTCheckoutWebView');
252284
const commandId = viewConfig?.Commands?.reload ?? 'reload';
253285

254-
UIManager.dispatchViewManagerCommand(
255-
handle,
256-
commandId,
257-
[],
258-
);
286+
UIManager.dispatchViewManagerCommand(handle, commandId, []);
259287
}, []);
260288

261289
useImperativeHandle(ref, () => ({reload}), [reload]);
@@ -273,6 +301,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
273301
onCancel={handleCancel}
274302
onLinkClick={handleLinkClick}
275303
onAddressChangeStart={handleAddressChangeStart}
304+
onPaymentMethodChangeStart={handlePaymentMethodChangeStart}
276305
/>
277306
);
278307
},

modules/@shopify/checkout-sheet-kit/src/events.d.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ export interface CheckoutStartEvent {
354354
cart: Cart;
355355
}
356356

357-
358357
/**
359358
* Error object returned in checkout event responses.
360359
* Used to communicate validation or processing errors back to checkout.
@@ -535,16 +534,15 @@ export interface CheckoutAddressChangeStartResponse {
535534
/**
536535
* Event emitted when the buyer intends to change their payment method.
537536
*/
538-
export interface CheckoutPaymentChangeIntent {
539-
/** Unique identifier for this event instance */
537+
/** Unique identifier for this event instance */
538+
export interface CheckoutPaymentMethodChangeStart {
540539
id: string;
541540
/** Type of payment change event */
542541
type: string;
543-
/** Current payment card information, if available */
544-
currentCard?: {
545-
/** Last 4 digits of the card number */
546-
last4: string;
547-
/** Card brand (e.g., "Visa", "Mastercard") */
548-
brand: string;
542+
cart?: {
543+
paymentInstruments?: Array<{
544+
type: string;
545+
details?: any;
546+
}>;
549547
};
550548
}

sample/src/screens/BuyNow/CheckoutScreen.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ export default function CheckoutScreen(props: {
4747
navigation.navigate('Address', {id: event.id});
4848
};
4949

50-
const onPaymentChangeIntent = (event: {id: string}) => {
51-
console.log('<CheckoutScreen /> onPaymentChangeIntent: ', event);
50+
const onPaymentMethodChangeStart = (event: {id: string}) => {
5251
navigation.navigate('Payment', {id: event.id});
5352
};
5453

@@ -75,7 +74,7 @@ export default function CheckoutScreen(props: {
7574
style={styles.container}
7675
onStart={onCheckoutStart}
7776
onAddressChangeStart={onAddressChangeStart}
78-
onPaymentChangeIntent={onPaymentChangeIntent}
77+
onPaymentMethodChangeStart={onPaymentMethodChangeStart}
7978
onCancel={onCancel}
8079
onError={onError}
8180
onComplete={onComplete}

0 commit comments

Comments
 (0)