Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,27 +305,6 @@ extension RCTCheckoutWebView: CheckoutDelegate {
])
}

func checkoutDidRequestCardChange(event: CheckoutCardChangeRequested) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally removed this?

guard let id = event.id else { return }

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

var eventData: [String: Any] = [
"id": event.id,
"type": "paymentChangeIntent",
]

// Include current card info if available
if let currentCard = event.params.currentCard {
eventData["currentCard"] = [
"last4": currentCard.last4,
"brand": currentCard.brand,
]
}

onPaymentChangeIntent?(eventData)
}

/// Called when the buyer attempts to submit the checkout.
///
/// This event is only emitted when native payment delegation is configured
Expand Down
40 changes: 20 additions & 20 deletions modules/@shopify/checkout-sheet-kit/src/components/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import type {
CheckoutSubmitStart
} from '../events';

export interface CheckoutProps {
export interface ShopifyCheckoutProps {
/**
* The checkout URL to load in the webview
*/
Expand Down Expand Up @@ -104,14 +104,14 @@ export interface CheckoutProps {
testID?: string;
}

export interface CheckoutRef {
export interface ShopifyCheckoutRef {
/**
* Reload the current checkout page
*/
reload: () => void;
}

interface NativeCheckoutWebViewProps {
interface NativeShopifyCheckoutWebViewProps {
checkoutUrl: string;
auth?: string;
style?: ViewStyle;
Expand All @@ -126,7 +126,7 @@ interface NativeCheckoutWebViewProps {
}

const RCTCheckoutWebView =
requireNativeComponent<NativeCheckoutWebViewProps>('RCTCheckoutWebView');
requireNativeComponent<NativeShopifyCheckoutWebViewProps>('RCTCheckoutWebView');

/**
* Checkout provides a native webview component for displaying
Expand All @@ -137,29 +137,29 @@ const RCTCheckoutWebView =
* including Shop Pay, Apple Pay, and other payment methods.
*
* @example Basic usage
* import {Checkout} from '@shopify/checkout-sheet-kit';
* import {ShopifyCheckout} from '@shopify/checkout-sheet-kit';
*
* <Checkout
* <ShopifyCheckout
* checkoutUrl="https://shop.example.com/checkouts/cn/123"
* onComplete={(event) => console.log('Checkout completed!', event.orderDetails)}
* onError={(error) => console.error('Checkout failed:', error.message)}
* style={{flex: 1}}
* />
*
* @example Passing an app authentication token to customize checkout and receive richer events
* <Checkout
* <ShopifyCheckout
* checkoutUrl="https://shop.example.com/checkouts/cn/123"
* auth="your_auth_token_here"
* onComplete={(event) => console.log('Checkout completed!')}
* />
*
* @example Using with ref to reload on error
* import {useRef} from 'react';
* import {Checkout, CheckoutHandle} from '@shopify/checkout-sheet-kit';
* import {ShopifyCheckout, CheckoutHandle} from '@shopify/checkout-sheet-kit';
*
* const checkoutRef = useRef<CheckoutHandle>(null);
* const checkoutRef = useRef<ShopifyCheckoutHandle>(null);
*
* <Checkout
* <ShopifyCheckout
* ref={checkoutRef}
* checkoutUrl={url}
* auth={authToken}
Expand All @@ -169,7 +169,7 @@ const RCTCheckoutWebView =
* }}
* />
*/
export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
export const ShopifyCheckout = forwardRef<ShopifyCheckoutRef, ShopifyCheckoutProps>(
(
{
checkoutUrl,
Expand Down Expand Up @@ -201,7 +201,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(


const handleStart = useCallback<
Required<NativeCheckoutWebViewProps>['onStart']
Required<NativeShopifyCheckoutWebViewProps>['onStart']
>(
(event: {nativeEvent: CheckoutStartEvent}) => {
onStart?.(event.nativeEvent);
Expand All @@ -210,7 +210,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
);

const handleError = useCallback<
Required<NativeCheckoutWebViewProps>['onError']
Required<NativeShopifyCheckoutWebViewProps>['onError']
>(
(event: {nativeEvent: CheckoutException}) => {
onError?.(event.nativeEvent);
Expand All @@ -219,7 +219,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
);

const handleComplete = useCallback<
Required<NativeCheckoutWebViewProps>['onComplete']
Required<NativeShopifyCheckoutWebViewProps>['onComplete']
>(
(event: {nativeEvent: CheckoutCompleteEvent}) => {
onComplete?.(event.nativeEvent);
Expand All @@ -228,13 +228,13 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
);

const handleCancel = useCallback<
Required<NativeCheckoutWebViewProps>['onCancel']
Required<NativeShopifyCheckoutWebViewProps>['onCancel']
>(() => {
onCancel?.();
}, [onCancel]);

const handleLinkClick = useCallback<
Required<NativeCheckoutWebViewProps>['onLinkClick']
Required<NativeShopifyCheckoutWebViewProps>['onLinkClick']
>(
(event: {nativeEvent: {url: string}}) => {
if (!event.nativeEvent.url) return;
Expand All @@ -244,7 +244,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
);

const handleAddressChangeStart = useCallback<
Required<NativeCheckoutWebViewProps>['onAddressChangeStart']
Required<NativeShopifyCheckoutWebViewProps>['onAddressChangeStart']
>(
(event: {nativeEvent: CheckoutAddressChangeStart}) => {
if (!event.nativeEvent) return;
Expand All @@ -254,7 +254,7 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
);

const handleSubmitStart = useCallback<
Required<NativeCheckoutWebViewProps>['onSubmitStart']
Required<NativeShopifyCheckoutWebViewProps>['onSubmitStart']
>(
(event: {nativeEvent: CheckoutSubmitStart}) => {
if (!event.nativeEvent) return;
Expand Down Expand Up @@ -303,6 +303,6 @@ export const Checkout = forwardRef<CheckoutRef, CheckoutProps>(
},
);

Checkout.displayName = 'Checkout';
ShopifyCheckout.displayName = 'Checkout';

export default Checkout;
export default ShopifyCheckout;
14 changes: 8 additions & 6 deletions modules/@shopify/checkout-sheet-kit/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {
RemoveEventListeners,
CheckoutEvent,
Configuration,
CheckoutOptions,
} from './index.d';

type Maybe<T> = T | undefined;
Expand All @@ -41,8 +42,8 @@ interface Context {
getConfig: () => Promise<Configuration | undefined>;
setConfig: (config: Configuration) => Promise<void>;
removeEventListeners: RemoveEventListeners;
preload: (checkoutUrl: string) => void;
present: (checkoutUrl: string) => void;
preload: (checkoutUrl: string, options?: CheckoutOptions) => void;
present: (checkoutUrl: string, options?: CheckoutOptions) => void;
dismiss: () => void;
invalidate: () => void;
version: Maybe<string>;
Expand Down Expand Up @@ -95,15 +96,16 @@ export function ShopifyCheckoutSheetProvider({
instance.current?.removeEventListeners(eventName);
}, []);

const present = useCallback((checkoutUrl: string) => {
const present = useCallback((checkoutUrl: string, options?: CheckoutOptions) => {
if (checkoutUrl) {
instance.current?.present(checkoutUrl);
instance.current?.present(checkoutUrl, options
);
}
}, []);

const preload = useCallback((checkoutUrl: string) => {
const preload = useCallback((checkoutUrl: string, options?: CheckoutOptions) => {
if (checkoutUrl) {
instance.current?.preload(checkoutUrl);
instance.current?.preload(checkoutUrl, options);
}
}, []);

Expand Down
4 changes: 2 additions & 2 deletions modules/@shopify/checkout-sheet-kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,15 @@ export type {
AcceleratedCheckoutButtonsProps,
RenderStateChangeEvent,
} from './components/AcceleratedCheckoutButtons';
export type {CheckoutProps, CheckoutRef} from './components/Checkout';
export type {ShopifyCheckoutProps as CheckoutProps, ShopifyCheckoutRef as CheckoutRef} from './components/Checkout';
export type {CheckoutEventProviderProps} from './CheckoutEventProvider';

// Components
export {
AcceleratedCheckoutButtons,
RenderState,
} from './components/AcceleratedCheckoutButtons';
export {Checkout} from './components/Checkout';
export {ShopifyCheckout} from './components/Checkout';
export {
CheckoutEventProvider,
useCheckoutEvents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jest.mock('react-native', () => {

import React from 'react';
import {render, act} from '@testing-library/react-native';
import {Checkout} from '../src/components/Checkout';
import {ShopifyCheckout} from '../src/components/Checkout';
import {createTestCart} from './testFixtures';

describe('Checkout Component - Address Change Events', () => {
Expand All @@ -32,7 +32,7 @@ describe('Checkout Component - Address Change Events', () => {
const onAddressChangeStart = jest.fn();

const {getByTestId} = render(
<Checkout
<ShopifyCheckout
checkoutUrl={mockCheckoutUrl}
onAddressChangeStart={onAddressChangeStart}
testID="checkout-webview"
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Checkout Component - Address Change Events', () => {

it('does not crash when onAddressChangeStart prop is not provided', () => {
const {getByTestId} = render(
<Checkout checkoutUrl={mockCheckoutUrl} testID="checkout-webview" />,
<ShopifyCheckout checkoutUrl={mockCheckoutUrl} testID="checkout-webview" />,
);

const nativeComponent = getByTestId('checkout-webview');
Expand All @@ -88,7 +88,7 @@ describe('Checkout Component - Address Change Events', () => {
const onAddressChangeStart = jest.fn();

const {getByTestId} = render(
<Checkout
<ShopifyCheckout
checkoutUrl={mockCheckoutUrl}
onAddressChangeStart={onAddressChangeStart}
testID="checkout-webview"
Expand All @@ -108,7 +108,7 @@ describe('Checkout Component - Address Change Events', () => {
const onAddressChangeStart = jest.fn();

const {getByTestId} = render(
<Checkout
<ShopifyCheckout
checkoutUrl={mockCheckoutUrl}
onAddressChangeStart={onAddressChangeStart}
testID="checkout-webview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jest.mock('react-native', () => {

import React from 'react';
import {render, act} from '@testing-library/react-native';
import {Checkout} from '../src/components/Checkout';
import {ShopifyCheckout} from '../src/components/Checkout';
import {createTestCart, createTestCheckout} from './testFixtures';

describe('Checkout Component - Submit Start Events', () => {
Expand All @@ -32,7 +32,7 @@ describe('Checkout Component - Submit Start Events', () => {
const onSubmitStart = jest.fn();

const {getByTestId} = render(
<Checkout
<ShopifyCheckout
checkoutUrl={mockCheckoutUrl}
onSubmitStart={onSubmitStart}
testID="checkout-webview"
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Checkout Component - Submit Start Events', () => {

it('does not crash when onSubmitStart prop is not provided', () => {
const {getByTestId} = render(
<Checkout checkoutUrl={mockCheckoutUrl} testID="checkout-webview" />,
<ShopifyCheckout checkoutUrl={mockCheckoutUrl} testID="checkout-webview" />,
);

const nativeComponent = getByTestId('checkout-webview');
Expand All @@ -88,7 +88,7 @@ describe('Checkout Component - Submit Start Events', () => {
const onSubmitStart = jest.fn();

const {getByTestId} = render(
<Checkout
<ShopifyCheckout
checkoutUrl={mockCheckoutUrl}
onSubmitStart={onSubmitStart}
testID="checkout-webview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static com.shopify.checkoutkitreactnative.TestFixtures.createTestCart;

import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -14,6 +16,7 @@
import com.shopify.checkoutsheetkit.Preloading;
import com.shopify.checkoutsheetkit.ColorScheme;
import com.shopify.checkoutsheetkit.Authentication;
import com.shopify.checkoutsheetkit.lifecycleevents.CartPaymentInstrument;
import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutCompleteEvent;
import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutStartEvent;
import com.shopify.checkoutsheetkit.lifecycleevents.Cart;
Expand Down Expand Up @@ -44,6 +47,11 @@
import android.content.Context;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

@RunWith(MockitoJUnitRunner.class)
public class ShopifyCheckoutSheetKitModuleTest {
Expand Down Expand Up @@ -543,18 +551,19 @@ public void testCompleteConfigurationAndEventFlow() {

private Cart buildMinimalCart(String cartId, String amount, String currencyCode) {
return new Cart(
cartId,
new ArrayList<>(), // lines
new CartCost(
new Money(amount, currencyCode),
new Money(amount, currencyCode)
),
new CartBuyerIdentity(null, null, null, null),
new ArrayList<>(), // deliveryGroups
new ArrayList<>(), // discountCodes
new ArrayList<>(), // appliedGiftCards
new ArrayList<>(), // discountAllocations
new CartDelivery(new ArrayList<>())
cartId,
new ArrayList<>(), // lines
new CartCost(
new Money(amount, currencyCode),
new Money(amount, currencyCode)
),
new CartBuyerIdentity(null, null, null, null),
new ArrayList<>(), // deliveryGroups
new ArrayList<>(), // discountCodes
new ArrayList<>(), // appliedGiftCards
new ArrayList<>(), // discountAllocations
new CartDelivery(new ArrayList<>()),
new ArrayList<>() { } // paymentInstruments
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public static Cart createTestCart(
Collections.emptyList(), // discountCodes
Collections.emptyList(), // appliedGiftCards
Collections.emptyList(), // discountAllocations
delivery
delivery,
Collections.emptyList() // paymentInstruments
);
}

Expand Down
Loading
Loading