diff --git a/.github/workflows/rn-test-ios.yml b/.github/workflows/rn-test-ios.yml index fd085418..6d098f59 100644 --- a/.github/workflows/rn-test-ios.yml +++ b/.github/workflows/rn-test-ios.yml @@ -24,6 +24,9 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Switch to Xcode 26.2 + run: sudo xcode-select --switch /Applications/Xcode_26.2.app + - name: Display Xcode info run: | echo "Xcode Path: $(xcode-select -p)" diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/RNShopifyCheckoutKit.podspec b/platforms/react-native/modules/@shopify/checkout-kit-react-native/RNShopifyCheckoutKit.podspec index e396d57c..dc5c1b7f 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/RNShopifyCheckoutKit.podspec +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/RNShopifyCheckoutKit.podspec @@ -23,8 +23,8 @@ Pod::Spec.new do |s| s.dependency "ShopifyCheckoutKit" s.dependency "ShopifyCheckoutKit/AcceleratedCheckouts" else - s.dependency "ShopifyCheckoutSheetKit", "~> 3.8.0" - s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.8.0" + s.dependency "ShopifyCheckoutKit", "~> 0.0.0" + s.dependency "ShopifyCheckoutKit/AcceleratedCheckouts", "~> 0.0.0" end install_modules_dependencies(s) diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/build.gradle b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/build.gradle index 195a8342..cc2dc2a3 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/build.gradle +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/build.gradle @@ -85,7 +85,7 @@ repositories { def useLocalSdk = (System.getenv("USE_LOCAL_SDK") ?: "0") == "1" def shopifySdkArtifact = useLocalSdk ? "com.shopify:checkout-kit:1.0.0" - : "com.shopify:checkout-sheet-kit:3.5.3" + : "com.shopify:checkout-kit:0.0.0" dependencies { // For < 0.71, this will be from the local maven repo diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/proguard-rules.pro b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/proguard-rules.pro index afeede94..e870977f 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/proguard-rules.pro +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/proguard-rules.pro @@ -1,2 +1,2 @@ -# Keep Checkout Sheet Kit classes --keep class com.shopify.checkoutsheetkit.** { *; } +# Keep Checkout Kit classes +-keep class com.shopify.checkoutkit.** { *; } diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutEventProcessor.java b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutEventProcessor.java index 557a329e..6bbd2ebb 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutEventProcessor.java +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/CustomCheckoutEventProcessor.java @@ -30,11 +30,11 @@ of this software and associated documentation files (the "Software"), to deal import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.shopify.checkoutsheetkit.*; +import com.shopify.checkoutkit.*; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.ReactApplicationContext; -import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutCompletedEvent; +import com.shopify.checkoutkit.lifecycleevents.CheckoutCompletedEvent; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.HashMap; @@ -93,7 +93,7 @@ public void onGeolocationPermissionsShowPrompt(@NonNull String origin, event.put("origin", origin); sendEventWithStringData("geolocationRequest", mapper.writeValueAsString(event)); } catch (IOException e) { - Log.e("ShopifyCheckoutSheetKit", "Error emitting \"geolocationRequest\" event", e); + Log.e("ShopifyCheckoutKit", "Error emitting \"geolocationRequest\" event", e); } } @@ -112,7 +112,7 @@ public void onCheckoutFailed(CheckoutException checkoutError) { String data = mapper.writeValueAsString(populateErrorDetails(checkoutError)); sendEventWithStringData("error", data); } catch (IOException e) { - Log.e("ShopifyCheckoutSheetKit", "Error processing checkout failed event", e); + Log.e("ShopifyCheckoutKit", "Error processing checkout failed event", e); } } @@ -127,7 +127,7 @@ public void onCheckoutCompleted(@NonNull CheckoutCompletedEvent event) { String data = mapper.writeValueAsString(event); sendEventWithStringData("completed", data); } catch (IOException e) { - Log.e("ShopifyCheckoutSheetKit", "Error processing completed event", e); + Log.e("ShopifyCheckoutKit", "Error processing completed event", e); } } @@ -156,7 +156,7 @@ private String getErrorTypeName(CheckoutException error) { return "CheckoutHTTPError"; } else if (error instanceof ConfigurationException) { return "ConfigurationError"; - } else if (error instanceof CheckoutSheetKitException) { + } else if (error instanceof CheckoutKitException) { return "InternalError"; } else { return "UnknownError"; diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java index 4061d0a3..968e7ab5 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java @@ -35,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.shopify.checkoutkit.NativeShopifyCheckoutKitSpec; -import com.shopify.checkoutsheetkit.*; +import com.shopify.checkoutkit.*; import java.util.HashMap; import java.util.Map; @@ -47,7 +47,7 @@ public class ShopifyCheckoutKitModule extends NativeShopifyCheckoutKitSpec { private final ReactApplicationContext reactContext; - private CheckoutSheetKitDialog checkoutSheet; + private CheckoutKitDialog checkoutSheet; private CustomCheckoutEventProcessor checkoutEventProcessor; @@ -56,8 +56,8 @@ public ShopifyCheckoutKitModule(ReactApplicationContext reactContext) { this.reactContext = reactContext; - ShopifyCheckoutSheetKit.configure(configuration -> { - configuration.setPlatform(Platform.REACT_NATIVE); + ShopifyCheckoutKit.configure(configuration -> { + configuration.setPlatform(new Platform.ReactNative()); checkoutConfig = configuration; }); } @@ -65,7 +65,7 @@ public ShopifyCheckoutKitModule(ReactApplicationContext reactContext) { @Override protected Map getTypedExportedConstants() { final Map constants = new HashMap<>(); - constants.put("version", ShopifyCheckoutSheetKit.version); + constants.put("version", ShopifyCheckoutKit.version); return constants; } @@ -85,7 +85,7 @@ public void present(String checkoutURL) { if (currentActivity instanceof ComponentActivity) { checkoutEventProcessor = new CustomCheckoutEventProcessor(currentActivity, this.reactContext); currentActivity.runOnUiThread(() -> { - checkoutSheet = ShopifyCheckoutSheetKit.present(checkoutURL, (ComponentActivity) currentActivity, + checkoutSheet = ShopifyCheckoutKit.present(checkoutURL, (ComponentActivity) currentActivity, checkoutEventProcessor); }); } @@ -104,13 +104,13 @@ public void preload(String checkoutURL) { Activity currentActivity = getCurrentActivity(); if (currentActivity instanceof ComponentActivity) { - ShopifyCheckoutSheetKit.preload(checkoutURL, (ComponentActivity) currentActivity); + ShopifyCheckoutKit.preload(checkoutURL, (ComponentActivity) currentActivity); } } @ReactMethod public void invalidateCache() { - ShopifyCheckoutSheetKit.invalidate(); + ShopifyCheckoutKit.invalidate(); } @ReactMethod(isBlockingSynchronousMethod = true) @@ -128,7 +128,7 @@ public WritableMap getConfig() { public void setConfig(ReadableMap config) { Context context = getReactApplicationContext(); - ShopifyCheckoutSheetKit.configure(configuration -> { + ShopifyCheckoutKit.configure(configuration -> { if (config.hasKey("preloading")) { configuration.setPreloading(new Preloading(config.getBoolean("preloading"))); } diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift index 6d152b69..31f03ccc 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/AcceleratedCheckoutButtons.swift @@ -24,7 +24,7 @@ import Foundation import PassKit import React -import ShopifyCheckoutSheetKit +import ShopifyCheckoutKit import SwiftUI import UIKit @@ -127,7 +127,6 @@ class RCTAcceleratedCheckoutButtonsView: UIView { } @objc var onFail: RCTBubblingEventBlock? - @objc var onComplete: RCTBubblingEventBlock? @objc var onCancel: RCTBubblingEventBlock? @objc var onRenderStateChange: RCTBubblingEventBlock? @objc var onShouldRecoverFromError: RCTDirectEventBlock? @@ -253,9 +252,6 @@ class RCTAcceleratedCheckoutButtonsView: UIView { private func attachEventListeners(to buttons: AcceleratedCheckoutButtons) -> AcceleratedCheckoutButtons { return buttons - .onComplete { [weak self] event in - self?.handleCheckoutCompleted(event) - } .onFail { [weak self] error in self?.handleCheckoutFailed(error) } @@ -265,9 +261,6 @@ class RCTAcceleratedCheckoutButtonsView: UIView { .onRenderStateChange { [weak self] state in self?.handleRenderStateChange(state) } - .onClickLink { [weak self] url in - self?.handleClickLink(url) - } } private func updateView() { @@ -347,10 +340,6 @@ class RCTAcceleratedCheckoutButtonsView: UIView { // MARK: - Event Handlers - private func handleCheckoutCompleted(_ event: CheckoutCompletedEvent) { - onComplete?(ShopifyEventSerialization.serialize(checkoutCompletedEvent: event)) - } - private func handleCheckoutFailed(_ error: CheckoutError) { onFail?(ShopifyEventSerialization.serialize(checkoutError: error)) } diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit+EventSerialization.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit+EventSerialization.swift index e7cb27ef..1944e368 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit+EventSerialization.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit+EventSerialization.swift @@ -22,10 +22,10 @@ */ import Foundation -import ShopifyCheckoutSheetKit +import ShopifyCheckoutKit /** - * Shared event serialization utilities for converting ShopifyCheckoutSheetKit events + * Shared event serialization utilities for converting ShopifyCheckoutKit events * to React Native compatible dictionaries. */ internal enum ShopifyEventSerialization { @@ -59,13 +59,6 @@ internal enum ShopifyEventSerialization { } } - /** - * Converts a CheckoutCompletedEvent to a React Native compatible dictionary. - */ - static func serialize(checkoutCompletedEvent event: CheckoutCompletedEvent) -> [String: Any] { - return encodeToJSON(from: event) - } - static func serialize(clickEvent url: URL) -> [String: URL] { return ["url": url] } @@ -103,14 +96,6 @@ internal enum ShopifyEventSerialization { ] } - case let .configurationError(message, code, recoverable): - return [ - "__typename": "ConfigurationError", - "message": message, - "code": code.rawValue, - "recoverable": recoverable - ] - case let .sdkError(underlying, recoverable): return [ "__typename": "InternalError", diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.mm b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.mm index 1efaed39..ba49f172 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.mm +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.mm @@ -99,11 +99,6 @@ @interface RCT_EXTERN_MODULE (RCTAcceleratedCheckoutButtonsManager, RCTViewManag */ RCT_EXPORT_VIEW_PROPERTY(onFail, RCTBubblingEventBlock) -/** - * Emitted when checkout completes successfully. Payload contains order details. - */ -RCT_EXPORT_VIEW_PROPERTY(onComplete, RCTBubblingEventBlock) - /** * Emitted when checkout is cancelled by the buyer. */ diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift index f24fba21..2b41b10b 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift @@ -24,12 +24,12 @@ import Foundation import PassKit import React -import ShopifyCheckoutSheetKit +import ShopifyCheckoutKit import SwiftUI import UIKit @objc(RCTShopifyCheckoutKit) -class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { +class RCTShopifyCheckoutKit: RCTEventEmitter { private var hasListeners = false internal var checkoutSheet: UIViewController? @@ -46,15 +46,15 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { } override init() { - ShopifyCheckoutSheetKit.configure { - $0.platform = ShopifyCheckoutSheetKit.Platform.reactNative + configure { + $0.platform = Platform.reactNative } super.init() } override func supportedEvents() -> [String]! { - return ["close", "completed", "error"] + return ["close", "error"] } override func startObserving() { @@ -65,17 +65,17 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { hasListeners = false } - func checkoutDidComplete(event: CheckoutCompletedEvent) { - if hasListeners { - sendEvent(withName: "completed", body: ShopifyEventSerialization.serialize(checkoutCompletedEvent: event)) - } - } + // TODO: re-enable when iOS CheckoutDelegate (or equivalent) lands upstream — + // parallels Android's DefaultCheckoutEventProcessor.onCheckoutCanceled / onCheckoutFailed. + // Until then, the JS "error" and "close" events stay declared in supportedEvents() + // but native never emits them. + /* func shouldRecoverFromError(error: CheckoutError) -> Bool { return error.isRecoverable } - func checkoutDidFail(error: ShopifyCheckoutSheetKit.CheckoutError) { + func checkoutDidFail(error: CheckoutError) { guard hasListeners else { return } sendEvent(withName: "error", body: ShopifyEventSerialization.serialize(checkoutError: error)) @@ -91,14 +91,12 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { } } - // TODO: remove when wrapper migrates off ShopifyCheckoutSheetKit. - // Required by CSK's CheckoutDelegate; intentionally no-ops since pixel events - // are no longer forwarded to JS. - func checkoutDidEmitWebPixelEvent(event _: ShopifyCheckoutSheetKit.PixelEvent) {} + func checkoutDidEmitWebPixelEvent(event _: PixelEvent) {} + */ @objc override func constantsToExport() -> [AnyHashable: Any]! { return [ - "version": ShopifyCheckoutSheetKit.version + "version": ShopifyCheckoutKit.version ] } @@ -139,13 +137,13 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { } @objc func invalidateCache() { - ShopifyCheckoutSheetKit.invalidate() + invalidate() } @objc func present(_ checkoutURL: String) { DispatchQueue.main.async { if let url = URL(string: checkoutURL), let viewController = self.getCurrentViewController() { - let view = CheckoutViewController(checkout: url, delegate: self) + let view = CheckoutViewController(checkout: url) viewController.present(view, animated: true) self.checkoutSheet = view } @@ -155,23 +153,23 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { @objc func preload(_ checkoutURL: String) { DispatchQueue.main.async { if let url = URL(string: checkoutURL) { - ShopifyCheckoutSheetKit.preload(checkout: url) + ShopifyCheckoutKit.preload(checkout: url) } } } - private func getColorScheme(_ colorScheme: String) -> ShopifyCheckoutSheetKit.Configuration.ColorScheme { + private func getColorScheme(_ colorScheme: String) -> Configuration.ColorScheme { switch colorScheme { case "web_default": - return ShopifyCheckoutSheetKit.Configuration.ColorScheme.web + return Configuration.ColorScheme.web case "automatic": - return ShopifyCheckoutSheetKit.Configuration.ColorScheme.automatic + return Configuration.ColorScheme.automatic case "light": - return ShopifyCheckoutSheetKit.Configuration.ColorScheme.light + return Configuration.ColorScheme.light case "dark": - return ShopifyCheckoutSheetKit.Configuration.ColorScheme.dark + return Configuration.ColorScheme.dark default: - return ShopifyCheckoutSheetKit.Configuration.ColorScheme.automatic + return Configuration.ColorScheme.automatic } } @@ -180,33 +178,33 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { let iosConfig = colorConfig?["ios"] as? [String: String] if let title = configuration["title"] as? String { - ShopifyCheckoutSheetKit.configuration.title = title + ShopifyCheckoutKit.configuration.title = title } if let preloading = configuration["preloading"] as? Bool { - ShopifyCheckoutSheetKit.configuration.preloading.enabled = preloading + ShopifyCheckoutKit.configuration.preloading.enabled = preloading } if let colorScheme = configuration["colorScheme"] as? String { - ShopifyCheckoutSheetKit.configuration.colorScheme = getColorScheme(colorScheme) + ShopifyCheckoutKit.configuration.colorScheme = getColorScheme(colorScheme) } if let tintColorHex = iosConfig?["tintColor"] as? String { - ShopifyCheckoutSheetKit.configuration.tintColor = UIColor(hex: tintColorHex) + ShopifyCheckoutKit.configuration.tintColor = UIColor(hex: tintColorHex) } if let backgroundColorHex = iosConfig?["backgroundColor"] as? String { - ShopifyCheckoutSheetKit.configuration.backgroundColor = UIColor(hex: backgroundColorHex) + ShopifyCheckoutKit.configuration.backgroundColor = UIColor(hex: backgroundColorHex) } if let closeButtonColorHex = iosConfig?["closeButtonColor"] as? String { - ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = UIColor(hex: closeButtonColorHex) + ShopifyCheckoutKit.configuration.closeButtonTintColor = UIColor(hex: closeButtonColorHex) } if let logLevel = configuration["logLevel"] as? String { - ShopifyCheckoutSheetKit.configuration.logLevel = ShopifyCheckoutSheetKit.LogLevel(rawValue: logLevel.lowercased()) ?? defaultLogLevel + ShopifyCheckoutKit.configuration.logLevel = LogLevel(rawValue: logLevel.lowercased()) ?? defaultLogLevel } else { - ShopifyCheckoutSheetKit.configuration.logLevel = defaultLogLevel + ShopifyCheckoutKit.configuration.logLevel = defaultLogLevel } NotificationCenter.default.post(name: Notification.Name("CheckoutKitConfigurationUpdated"), object: nil) @@ -214,13 +212,13 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate { @objc func getConfig() -> NSDictionary { return [ - "title": ShopifyCheckoutSheetKit.configuration.title, - "preloading": ShopifyCheckoutSheetKit.configuration.preloading.enabled, - "colorScheme": ShopifyCheckoutSheetKit.configuration.colorScheme.rawValue, - "tintColor": ShopifyCheckoutSheetKit.configuration.tintColor, - "backgroundColor": ShopifyCheckoutSheetKit.configuration.backgroundColor, - "closeButtonColor": ShopifyCheckoutSheetKit.configuration.closeButtonTintColor, - "logLevel": logLevelToString(ShopifyCheckoutSheetKit.configuration.logLevel) + "title": ShopifyCheckoutKit.configuration.title, + "preloading": ShopifyCheckoutKit.configuration.preloading.enabled, + "colorScheme": ShopifyCheckoutKit.configuration.colorScheme.rawValue, + "tintColor": ShopifyCheckoutKit.configuration.tintColor, + "backgroundColor": ShopifyCheckoutKit.configuration.backgroundColor, + "closeButtonColor": ShopifyCheckoutKit.configuration.closeButtonTintColor, + "logLevel": logLevelToString(ShopifyCheckoutKit.configuration.logLevel) ] } diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/package.snapshot.json b/platforms/react-native/modules/@shopify/checkout-kit-react-native/package.snapshot.json index 7011f0d3..5c442b47 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/package.snapshot.json +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/package.snapshot.json @@ -20,8 +20,6 @@ "lib/commonjs/context.js.map", "lib/commonjs/errors.d.js", "lib/commonjs/errors.d.js.map", - "lib/commonjs/events.d.js", - "lib/commonjs/events.d.js.map", "lib/commonjs/index.d.js", "lib/commonjs/index.d.js.map", "lib/commonjs/index.js", @@ -36,8 +34,6 @@ "lib/module/context.js.map", "lib/module/errors.d.js", "lib/module/errors.d.js.map", - "lib/module/events.d.js", - "lib/module/events.d.js.map", "lib/module/index.d.js", "lib/module/index.d.js.map", "lib/module/index.js", @@ -62,7 +58,6 @@ "src/components/AcceleratedCheckoutButtons.tsx", "src/context.tsx", "src/errors.d.ts", - "src/events.d.ts", "src/index.d.ts", "src/index.ts", "src/specs/NativeShopifyCheckoutKit.ts", diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/components/AcceleratedCheckoutButtons.tsx b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/components/AcceleratedCheckoutButtons.tsx index 8b71755e..f7bfafe1 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/components/AcceleratedCheckoutButtons.tsx +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/components/AcceleratedCheckoutButtons.tsx @@ -23,11 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO import React, {useCallback, useMemo, useState} from 'react'; import {Platform} from 'react-native'; -import type { - AcceleratedCheckoutWallet, - CheckoutCompletedEvent, - CheckoutException, -} from '..'; +import type {AcceleratedCheckoutWallet, CheckoutException} from '..'; import RCTAcceleratedCheckoutButtons from '../specs/RCTAcceleratedCheckoutButtonsNativeComponent'; export enum RenderState { @@ -104,11 +100,6 @@ interface CommonAcceleratedCheckoutButtonsProps { */ onFail?: (error: CheckoutException) => void; - /** - * Called when checkout is completed successfully - */ - onComplete?: (event: CheckoutCompletedEvent) => void; - /** * Called when checkout is cancelled */ @@ -160,7 +151,6 @@ export type AcceleratedCheckoutButtonsProps = (CartProps | VariantProps) & * @example Cart-based checkout * console.log('Checkout completed!', event.orderDetails)} * onFail={(error) => console.error('Checkout failed:', error.message)} * /> * @@ -168,7 +158,6 @@ export type AcceleratedCheckoutButtonsProps = (CartProps | VariantProps) & * console.log('Checkout completed!', event.orderDetails)} * /> */ @@ -182,7 +171,6 @@ export const AcceleratedCheckoutButtons: React.FC< cornerRadius, wallets, onFail, - onComplete, onCancel, onRenderStateChange, onClickLink, @@ -201,13 +189,6 @@ export const AcceleratedCheckoutButtons: React.FC< [onFail], ); - const handleComplete = useCallback( - (event: {nativeEvent: unknown}) => { - onComplete?.(event.nativeEvent as CheckoutCompletedEvent); - }, - [onComplete], - ); - const handleCancel = useCallback(() => { onCancel?.(); }, [onCancel]); @@ -297,7 +278,6 @@ export const AcceleratedCheckoutButtons: React.FC< cornerRadius={cornerRadius} wallets={wallets} onFail={handleFail} - onComplete={handleComplete} onCancel={handleCancel} onRenderStateChange={handleRenderStateChange} onClickLink={handleClickLink} diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/events.d.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/events.d.ts deleted file mode 100644 index 325596d4..00000000 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/events.d.ts +++ /dev/null @@ -1,112 +0,0 @@ -/* -MIT License - -Copyright 2023 - Present, Shopify Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -namespace CheckoutCompletedEvent { - interface Address { - address1?: string; - address2?: string; - city?: string; - countryCode?: string; - firstName?: string; - lastName?: string; - name?: string; - phone?: string; - postalCode?: string; - referenceId?: string; - zoneCode?: string; - } - - interface CartInfo { - lines: CartLine[]; - price: Price; - token: string; - } - - interface CartLineImage { - altText?: string; - lg: string; - md: string; - sm: string; - } - - interface CartLine { - discounts?: Discount[]; - image?: CartLineImage; - merchandiseId?: string; - price: Money; - productId?: string; - quantity: number; - title: string; - } - - interface DeliveryDetails { - additionalInfo?: string; - location?: Address; - name?: string; - } - - interface DeliveryInfo { - details: DeliveryDetails; - method: string; - } - - interface Discount { - amount?: Money; - applicationType?: string; - title?: string; - value?: number; - valueType?: string; - } - - export interface OrderDetails { - billingAddress?: Address; - cart: CartInfo; - deliveries?: DeliveryInfo[]; - email?: string; - id: string; - paymentMethods?: PaymentMethod[]; - phone?: string; - } - - interface PaymentMethod { - details: {[key: string]: string | null}; - type: string; - } - - interface Price { - discounts?: Discount[]; - shipping?: Money; - subtotal?: Money; - taxes?: Money; - total?: Money; - } - - interface Money { - amount?: number; - currencyCode?: string; - } -} - -export interface CheckoutCompletedEvent { - orderDetails: CheckoutCompletedEvent.OrderDetails; -} diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts index d2b166d3..67d7d460 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts @@ -22,7 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO */ import type {EmitterSubscription} from 'react-native'; -import type {CheckoutCompletedEvent} from './events'; import type {CheckoutException} from './errors'; export type Maybe = T | undefined; @@ -170,11 +169,7 @@ export type Configuration = CommonConfiguration & { } ); -export type CheckoutEvent = - | 'close' - | 'completed' - | 'error' - | 'geolocationRequest'; +export type CheckoutEvent = 'close' | 'error' | 'geolocationRequest'; export interface GeolocationRequestEvent { origin: string; @@ -185,14 +180,10 @@ export type GeolocationRequestEventCallback = ( event: GeolocationRequestEvent, ) => void; export type CheckoutExceptionCallback = (error: CheckoutException) => void; -export type CheckoutCompletedEventCallback = ( - event: CheckoutCompletedEvent, -) => void; export type CheckoutEventCallback = | CloseEventCallback | CheckoutExceptionCallback - | CheckoutCompletedEventCallback | GeolocationRequestEventCallback; /** @@ -271,11 +262,6 @@ function addEventListener( callback: () => void, ): Maybe; -function addEventListener( - event: 'completed', - callback: CheckoutCompletedEventCallback, -): Maybe; - function addEventListener( event: 'error', callback: CheckoutExceptionCallback, diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts index 76d94f49..dd7a8f94 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.ts @@ -52,7 +52,6 @@ import { GenericError, } from './errors.d'; import {CheckoutErrorCode} from './errors.d'; -import type {CheckoutCompletedEvent} from './events.d'; import {ApplePayLabel, ApplePayStyle} from './components/AcceleratedCheckoutButtons'; import type { AcceleratedCheckoutButtonsProps, @@ -182,9 +181,6 @@ class ShopifyCheckout implements ShopifyCheckoutKit { let eventCallback; switch (event) { - case 'completed': - eventCallback = this.interceptEventEmission('completed', callback); - break; case 'error': eventCallback = this.interceptEventEmission( 'error', @@ -540,7 +536,6 @@ export { export type { AcceleratedCheckoutButtonsProps, AcceleratedCheckoutConfiguration, - CheckoutCompletedEvent, CheckoutEvent, CheckoutEventCallback, CheckoutException, diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts index 189e1ffc..2ee5bc95 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts @@ -27,7 +27,6 @@ import type { DirectEventHandler, Double, Float, - UnsafeMixed, // eslint-disable-next-line @react-native/no-deep-imports -- codegen parser requires these type names to be imported directly (not via aliases) so it can match them statically during AST traversal } from 'react-native/Libraries/Types/CodegenTypes'; @@ -38,16 +37,6 @@ type FailEvent = Readonly<{ recoverable?: boolean; }>; -type CompleteEvent = Readonly<{ - orderDetails: Readonly<{ - id: string; - cart?: UnsafeMixed; - email?: string; - paymentMethods?: UnsafeMixed; - phone?: string; - }>; -}>; - type RenderStateChangeEvent = Readonly<{ state: string; reason?: string; @@ -69,7 +58,6 @@ interface NativeProps extends ViewProps { applePayLabel?: string; applePayStyle?: string; onFail?: BubblingEventHandler; - onComplete?: BubblingEventHandler; onCancel?: BubblingEventHandler; onRenderStateChange?: BubblingEventHandler; onClickLink?: BubblingEventHandler; diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/AcceleratedCheckoutButtons.test.tsx b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/AcceleratedCheckoutButtons.test.tsx index a29ca4fc..d27ebdeb 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/AcceleratedCheckoutButtons.test.tsx +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/AcceleratedCheckoutButtons.test.tsx @@ -190,21 +190,6 @@ describe('AcceleratedCheckoutButtons', () => { expect(onFail).toHaveBeenCalledWith(error); }); - it('forwards native complete event to onComplete prop', () => { - const onComplete = jest.fn(); - const {getByTestId} = render( - , - ); - - const nativeComponent = getByTestId('accelerated-checkout-buttons'); - const details = {orderDetails: {id: '1'}} as any; - nativeComponent.props.onComplete({nativeEvent: details}); - expect(onComplete).toHaveBeenCalledWith(details); - }); - it('calls onCancel when native cancel is invoked', () => { const onCancel = jest.fn(); const {getByTestId} = render( @@ -313,7 +298,6 @@ describe('AcceleratedCheckoutButtons', () => { it('handles callbacks without throwing', () => { const mockCallbacks = { onFail: jest.fn(), - onComplete: jest.fn(), onCancel: jest.fn(), onRenderStateChange: jest.fn(), onClickLink: jest.fn(), diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts index 5ceab2af..ad9787f0 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts @@ -185,67 +185,6 @@ describe('ShopifyCheckoutKit', () => { ); }); - describe('Completed Event', () => { - it('parses completed event string data as JSON', () => { - const instance = new ShopifyCheckout(); - const eventName = 'completed'; - const callback = jest.fn(); - instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); - expect(eventEmitter.addListener).toHaveBeenCalledWith( - 'completed', - expect.any(Function), - ); - eventEmitter.emit( - 'completed', - JSON.stringify({orderDetails: {id: 'test-id'}}), - ); - expect(callback).toHaveBeenCalledWith({orderDetails: {id: 'test-id'}}); - }); - - it('parses completed event JSON data', () => { - const instance = new ShopifyCheckout(); - const eventName = 'completed'; - const callback = jest.fn(); - instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); - expect(eventEmitter.addListener).toHaveBeenCalledWith( - 'completed', - expect.any(Function), - ); - eventEmitter.emit('completed', {orderDetails: {id: 'test-id'}}); - expect(callback).toHaveBeenCalledWith({orderDetails: {id: 'test-id'}}); - }); - - it('prints an error if the completed event data cannot be parsed', () => { - const mock = jest.spyOn(global.console, 'error'); - const instance = new ShopifyCheckout(); - const eventName = 'completed'; - const callback = jest.fn(); - instance.addEventListener(eventName, callback); - NativeModule.addEventListener( - eventName, - callback, - ); - expect(eventEmitter.addListener).toHaveBeenCalledWith( - 'completed', - expect.any(Function), - ); - const invalidData = 'INVALID JSON'; - eventEmitter.emit('completed', invalidData); - expect(mock).toHaveBeenCalledWith( - expect.any(LifecycleEventParseError), - invalidData, - ); - }); - }); - describe('Error Event', () => { const internalError = { __typename: CheckoutNativeErrorType.InternalError, diff --git a/platforms/react-native/sample/android/app/build.gradle b/platforms/react-native/sample/android/app/build.gradle index c24be224..1080dd0b 100644 --- a/platforms/react-native/sample/android/app/build.gradle +++ b/platforms/react-native/sample/android/app/build.gradle @@ -156,7 +156,7 @@ android { def useLocalSdk = (System.getenv("USE_LOCAL_SDK") ?: "0") == "1" def shopifySdkArtifact = useLocalSdk ? "com.shopify:checkout-kit:1.0.0" - : "com.shopify:checkout-sheet-kit:3.5.3" + : "com.shopify:checkout-kit:0.0.0" dependencies { // The version of react-native is set by the React Native Gradle Plugin diff --git a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java index e6348002..95973128 100644 --- a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java +++ b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkitreactnative/ShopifyCheckoutKitModuleTest.java @@ -8,20 +8,20 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; -import com.shopify.checkoutsheetkit.CheckoutException; -import com.shopify.checkoutsheetkit.CheckoutExpiredException; -import com.shopify.checkoutsheetkit.CheckoutSheetKitException; -import com.shopify.checkoutsheetkit.ClientException; -import com.shopify.checkoutsheetkit.ConfigurationException; -import com.shopify.checkoutsheetkit.HttpException; -import com.shopify.checkoutsheetkit.ShopifyCheckoutSheetKit; -import com.shopify.checkoutsheetkit.Preloading; -import com.shopify.checkoutsheetkit.ColorScheme; -import com.shopify.checkoutsheetkit.LogLevel; -import com.shopify.checkoutsheetkit.lifecycleevents.CheckoutCompletedEvent; -import com.shopify.checkoutsheetkit.lifecycleevents.OrderDetails; -import com.shopify.checkoutsheetkit.lifecycleevents.CartInfo; -import com.shopify.checkoutsheetkit.lifecycleevents.Price; +import com.shopify.checkoutkit.CheckoutException; +import com.shopify.checkoutkit.CheckoutExpiredException; +import com.shopify.checkoutkit.CheckoutKitException; +import com.shopify.checkoutkit.ClientException; +import com.shopify.checkoutkit.ConfigurationException; +import com.shopify.checkoutkit.HttpException; +import com.shopify.checkoutkit.ShopifyCheckoutKit; +import com.shopify.checkoutkit.Preloading; +import com.shopify.checkoutkit.ColorScheme; +import com.shopify.checkoutkit.LogLevel; +import com.shopify.checkoutkit.lifecycleevents.CheckoutCompletedEvent; +import com.shopify.checkoutkit.lifecycleevents.OrderDetails; +import com.shopify.checkoutkit.lifecycleevents.CartInfo; +import com.shopify.checkoutkit.lifecycleevents.Price; import com.shopify.reactnative.checkoutkit.ShopifyCheckoutKitModule; import com.shopify.reactnative.checkoutkit.CustomCheckoutEventProcessor; @@ -106,7 +106,7 @@ public void tearDown() { } // Reset configuration to initial state after each test - ShopifyCheckoutSheetKit.configure(configuration -> { + ShopifyCheckoutKit.configure(configuration -> { configuration.setPreloading(initialPreloading); configuration.setColorScheme(initialColorScheme); configuration.setLogLevel(initialLogLevel); @@ -120,8 +120,8 @@ public void tearDown() { @Test public void testCanPresentCheckout() { - try (MockedStatic mockedShopifyCheckoutKit = Mockito - .mockStatic(ShopifyCheckoutSheetKit.class)) { + try (MockedStatic mockedShopifyCheckoutKit = Mockito + .mockStatic(ShopifyCheckoutKit.class)) { String checkoutUrl = "https://shopify.com"; shopifyCheckoutKitModule.present(checkoutUrl); @@ -129,20 +129,20 @@ public void testCanPresentCheckout() { runnableCaptor.getValue().run(); mockedShopifyCheckoutKit.verify(() -> { - ShopifyCheckoutSheetKit.present(eq(checkoutUrl), any(), any()); + ShopifyCheckoutKit.present(eq(checkoutUrl), any(), any()); }); } } @Test public void testCanPreloadCheckout() { - try (MockedStatic mockedShopifyCheckoutKit = Mockito - .mockStatic(ShopifyCheckoutSheetKit.class)) { + try (MockedStatic mockedShopifyCheckoutKit = Mockito + .mockStatic(ShopifyCheckoutKit.class)) { String checkoutUrl = "https://shopify.com"; shopifyCheckoutKitModule.preload(checkoutUrl); mockedShopifyCheckoutKit.verify(() -> { - ShopifyCheckoutSheetKit.preload(eq(checkoutUrl), any()); + ShopifyCheckoutKit.preload(eq(checkoutUrl), any()); }); } } diff --git a/platforms/react-native/sample/ios/ReactNative.xcodeproj/project.pbxproj b/platforms/react-native/sample/ios/ReactNative.xcodeproj/project.pbxproj index bbe3425d..f36e4308 100644 --- a/platforms/react-native/sample/ios/ReactNative.xcodeproj/project.pbxproj +++ b/platforms/react-native/sample/ios/ReactNative.xcodeproj/project.pbxproj @@ -51,7 +51,7 @@ 6AF1E0022C00010100E5EE1B /* EventSerializationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventSerializationTests.swift; sourceTree = ""; }; 6AF2B3762B0BCA6600C6CE4F /* ReactNative-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ReactNative-Bridging-Header.h"; sourceTree = ""; }; 6AFAD2D12BA9DEF8001F9644 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; name = Localizable.xcstrings; path = ReactNative/Localizable.xcstrings; sourceTree = ""; }; - 6AFC2CB62B0D5814003B5A63 /* libShopifyCheckoutSheetKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libShopifyCheckoutSheetKit.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AFC2CB62B0D5814003B5A63 /* libShopifyCheckoutKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libShopifyCheckoutKit.a; sourceTree = BUILT_PRODUCTS_DIR; }; 7959053DABE1E06BE5CF1255 /* Pods-ReactNative-ReactNativeTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNative-ReactNativeTests.release.xcconfig"; path = "Target Support Files/Pods-ReactNative-ReactNativeTests/Pods-ReactNative-ReactNativeTests.release.xcconfig"; sourceTree = ""; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = ReactNative/LaunchScreen.storyboard; sourceTree = ""; }; 9E0AC43398437CA0E3D05DDF /* libPods-ReactNative.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNative.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -120,7 +120,7 @@ isa = PBXGroup; children = ( 6AABC1942B17417E008240EB /* OpenSSL.xcframework */, - 6AFC2CB62B0D5814003B5A63 /* libShopifyCheckoutSheetKit.a */, + 6AFC2CB62B0D5814003B5A63 /* libShopifyCheckoutKit.a */, 9E0AC43398437CA0E3D05DDF /* libPods-ReactNative.a */, 591887D86C91BE07EFFC9303 /* libPods-ReactNativeTests.a */, ); @@ -520,7 +520,7 @@ "\"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimescheduler\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/React-utils\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon\"", - "\"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutSheetKit\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutKit\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/Yoga\"", "\"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit\"", @@ -539,7 +539,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.shopify.example.CheckoutKitReactNative; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_INCLUDE_PATHS = "$(inherited) \"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutSheetKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/RNShopifyCheckoutKit\"/**"; + SWIFT_INCLUDE_PATHS = "$(inherited) \"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/RNShopifyCheckoutKit\"/**"; SWIFT_OBJC_BRIDGING_HEADER = "ReactNativeTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -625,7 +625,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.shopify.example.CheckoutKitReactNative; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_INCLUDE_PATHS = "$(inherited) \"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutSheetKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/RNShopifyCheckoutKit\"/**"; + SWIFT_INCLUDE_PATHS = "$(inherited) \"${PODS_CONFIGURATION_BUILD_DIR}/ShopifyCheckoutKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/YogaKit\" \"${PODS_CONFIGURATION_BUILD_DIR}/RNShopifyCheckoutKit\"/**"; SWIFT_OBJC_BRIDGING_HEADER = "ReactNativeTests-Bridging-Header.h"; SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReactNative.app/ReactNative"; @@ -660,7 +660,7 @@ "\"${PODS_ROOT}/Headers/Public/React-Core\"", "\"${PODS_ROOT}/Headers/Public/React-NativeModulesApple\"", "\"${PODS_ROOT}/Headers/Public/React-RCTAnimation\"", - "\"$(SRCROOT)/Pods/ShopifyCheckoutSheetKit\"/**", + "\"$(SRCROOT)/Pods/ShopifyCheckoutKit\"/**", "\"${PODS_ROOT}/Headers/Public/React-RCTAppDelegate\"", "\"${PODS_ROOT}/Headers/Public/React-RCTBlob\"", "\"${PODS_ROOT}/Headers/Public/React-RCTText\"", @@ -750,7 +750,7 @@ "\"${PODS_ROOT}/Headers/Public/React-Core\"", "\"${PODS_ROOT}/Headers/Public/React-NativeModulesApple\"", "\"${PODS_ROOT}/Headers/Public/React-RCTAnimation\"", - "\"$(SRCROOT)/Pods/ShopifyCheckoutSheetKit\"/**", + "\"$(SRCROOT)/Pods/ShopifyCheckoutKit\"/**", "\"${PODS_ROOT}/Headers/Public/React-RCTAppDelegate\"", "\"${PODS_ROOT}/Headers/Public/React-RCTBlob\"", "\"${PODS_ROOT}/Headers/Public/React-RCTText\"", diff --git a/platforms/react-native/sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift b/platforms/react-native/sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift index c623e8f6..37c1545d 100644 --- a/platforms/react-native/sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift +++ b/platforms/react-native/sample/ios/ReactNativeTests/AcceleratedCheckouts_SupportedTests.swift @@ -25,7 +25,7 @@ import Foundation import PassKit import SwiftUI @testable import RNShopifyCheckoutKit -@testable import ShopifyCheckoutSheetKit +@testable import ShopifyCheckoutKit import XCTest struct WalletButtons { @@ -57,9 +57,9 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase { } private func resetCheckoutKitDefaults() { - ShopifyCheckoutSheetKit.configuration.preloading = Configuration.Preloading(enabled: true) - ShopifyCheckoutSheetKit.configuration.colorScheme = .automatic - ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = nil + ShopifyCheckoutKit.configuration.preloading = Configuration.Preloading(enabled: true) + ShopifyCheckoutKit.configuration.colorScheme = .automatic + ShopifyCheckoutKit.configuration.closeButtonTintColor = nil } @discardableResult diff --git a/platforms/react-native/sample/ios/ReactNativeTests/CheckoutDidFailTests.swift b/platforms/react-native/sample/ios/ReactNativeTests/CheckoutDidFailTests.swift index 4fcf4cb0..1260ef5a 100644 --- a/platforms/react-native/sample/ios/ReactNativeTests/CheckoutDidFailTests.swift +++ b/platforms/react-native/sample/ios/ReactNativeTests/CheckoutDidFailTests.swift @@ -23,9 +23,13 @@ import Foundation @testable import RNShopifyCheckoutKit -@testable import ShopifyCheckoutSheetKit import XCTest +// TODO: re-enable when iOS CheckoutDelegate (or equivalent) lands upstream — +// parallels Android's DefaultCheckoutEventProcessor.onCheckoutCanceled / onCheckoutFailed. +class CheckoutDidFailTests: XCTestCase {} + +/* class CheckoutDidFailTests: XCTestCase { private var shopifyCheckoutKit: RCTShopifyCheckoutKit! @@ -199,3 +203,4 @@ class CheckoutDidFailTests: XCTestCase { return mock } } +*/ diff --git a/platforms/react-native/sample/ios/ReactNativeTests/EventSerializationTests.swift b/platforms/react-native/sample/ios/ReactNativeTests/EventSerializationTests.swift index 0bd88db4..d454729b 100644 --- a/platforms/react-native/sample/ios/ReactNativeTests/EventSerializationTests.swift +++ b/platforms/react-native/sample/ios/ReactNativeTests/EventSerializationTests.swift @@ -23,7 +23,7 @@ import Foundation @testable import RNShopifyCheckoutKit -import ShopifyCheckoutSheetKit +import ShopifyCheckoutKit import XCTest @available(iOS 16.0, *) diff --git a/platforms/react-native/sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift b/platforms/react-native/sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift index 39e72b34..603cef36 100644 --- a/platforms/react-native/sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift +++ b/platforms/react-native/sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift @@ -23,7 +23,7 @@ import Foundation @testable import RNShopifyCheckoutKit -@testable import ShopifyCheckoutSheetKit +import ShopifyCheckoutKit import XCTest class ShopifyCheckoutKitTests: XCTestCase { @@ -41,10 +41,10 @@ class ShopifyCheckoutKitTests: XCTestCase { } private func resetShopifyCheckoutKitDefaults() { - ShopifyCheckoutSheetKit.configuration.preloading = Configuration.Preloading(enabled: true) - ShopifyCheckoutSheetKit.configuration.colorScheme = .automatic - ShopifyCheckoutSheetKit.configuration.closeButtonTintColor = nil - ShopifyCheckoutSheetKit.configuration.logLevel = LogLevel.error + ShopifyCheckoutKit.configuration.preloading.enabled = true + ShopifyCheckoutKit.configuration.colorScheme = .automatic + ShopifyCheckoutKit.configuration.closeButtonTintColor = nil + ShopifyCheckoutKit.configuration.logLevel = LogLevel.error } private func getShopifyCheckoutKit() -> RCTShopifyCheckoutKit { @@ -76,10 +76,10 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertTrue(ShopifyCheckoutSheetKit.configuration.preloading.enabled) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.colorScheme, .dark) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.tintColor, UIColor(hex: "#FF0000")) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.backgroundColor, UIColor(hex: "#0000FF")) + XCTAssertTrue(ShopifyCheckoutKit.configuration.preloading.enabled) + XCTAssertEqual(ShopifyCheckoutKit.configuration.colorScheme, .dark) + XCTAssertEqual(ShopifyCheckoutKit.configuration.tintColor, UIColor(hex: "#FF0000")) + XCTAssertEqual(ShopifyCheckoutKit.configuration.backgroundColor, UIColor(hex: "#0000FF")) } func testConfigureWithPartialConfig() { @@ -89,7 +89,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertFalse(ShopifyCheckoutSheetKit.configuration.preloading.enabled) + XCTAssertFalse(ShopifyCheckoutKit.configuration.preloading.enabled) } func testConfigureWithInvalidColors() { @@ -104,7 +104,7 @@ class ShopifyCheckoutKitTests: XCTestCase { let defaultColorFallback = UIColor(red: 0, green: 0, blue: 0, alpha: 1) shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.tintColor, defaultColorFallback) + XCTAssertEqual(ShopifyCheckoutKit.configuration.tintColor, defaultColorFallback) } func testConfigureWithCloseButtonColor() { @@ -118,7 +118,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.closeButtonTintColor, UIColor(hex: "#FF0000")) + XCTAssertEqual(ShopifyCheckoutKit.configuration.closeButtonTintColor, UIColor(hex: "#FF0000")) } func testConfigureWithInvalidCloseButtonColor() { @@ -133,7 +133,7 @@ class ShopifyCheckoutKitTests: XCTestCase { let defaultColorFallback = UIColor(red: 0, green: 0, blue: 0, alpha: 1) shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.closeButtonTintColor, defaultColorFallback) + XCTAssertEqual(ShopifyCheckoutKit.configuration.closeButtonTintColor, defaultColorFallback) } func testConfigureWithoutCloseButtonColor() { @@ -148,7 +148,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) // closeButtonTintColor should remain nil when not specified (uses system default) - XCTAssertNil(ShopifyCheckoutSheetKit.configuration.closeButtonTintColor) + XCTAssertNil(ShopifyCheckoutKit.configuration.closeButtonTintColor) } func testGetConfigIncludesCloseButtonColor() { @@ -179,7 +179,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.debug) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.debug) } func testConfigureWithLogLevelError() { @@ -189,7 +189,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.error) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.error) } func testConfigureWithLogLevelNone() { @@ -199,7 +199,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.none) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.none) } func testConfigureWithInvalidLogLevelDefaultsToError() { @@ -209,7 +209,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.error) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.error) } func testLogLevelHandlesUppercaseDebug() { @@ -219,7 +219,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.debug) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.debug) } func testLogLevelHandlesMixedCaseDebug() { @@ -229,7 +229,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.debug) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.debug) } func testLogLevelHandlesUppercaseError() { @@ -239,7 +239,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.error) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.error) } func testSetConfigWithoutLogLevelDefaultsToError() { @@ -249,7 +249,7 @@ class ShopifyCheckoutKitTests: XCTestCase { shopifyCheckoutKit.setConfig(configuration) - XCTAssertEqual(ShopifyCheckoutSheetKit.configuration.logLevel, LogLevel.error) + XCTAssertEqual(ShopifyCheckoutKit.configuration.logLevel, LogLevel.error) } func testGetConfigIncludesLogLevel() { @@ -319,6 +319,9 @@ class ShopifyCheckoutKitTests: XCTestCase { XCTAssertEqual(result?["logLevel"] as? String, "error") } + // TODO: re-enable when iOS CheckoutDelegate (or equivalent) lands upstream — + // parallels Android's DefaultCheckoutEventProcessor.onCheckoutCanceled / onCheckoutFailed. + /* /// checkoutDidComplete func testCheckoutDidCompleteSendsEvent() { let event = CheckoutCompletedEvent( @@ -394,6 +397,7 @@ class ShopifyCheckoutKitTests: XCTestCase { // swiftlint:disable:next force_cast XCTAssertTrue((mock.checkoutSheet as! MockCheckout).dismissWasCalled) } + */ private func mockSendEvent(eventName: String) -> RCTShopifyCheckoutKitMock { let mock = RCTShopifyCheckoutKitMock() diff --git a/platforms/react-native/sample/src/App.tsx b/platforms/react-native/sample/src/App.tsx index 4d689ae5..60349056 100644 --- a/platforms/react-native/sample/src/App.tsx +++ b/platforms/react-native/sample/src/App.tsx @@ -47,10 +47,7 @@ import { ShopifyCheckoutProvider, useShopifyCheckout, } from '@shopify/checkout-kit-react-native'; -import type { - CheckoutCompletedEvent, - CheckoutException, -} from '@shopify/checkout-kit-react-native'; +import type {CheckoutException} from '@shopify/checkout-kit-react-native'; import {ConfigProvider, useConfig} from './context/Config'; import {BuyerIdentityMode} from './auth/types'; import { @@ -216,13 +213,6 @@ function AppWithContext({children}: PropsWithChildren) { eventHandlers.onCancel?.(); }); - const completed = shopify.addEventListener( - 'completed', - (event: CheckoutCompletedEvent) => { - eventHandlers.onComplete?.(event); - }, - ); - const error = shopify.addEventListener( 'error', (error: CheckoutException) => { @@ -231,7 +221,6 @@ function AppWithContext({children}: PropsWithChildren) { ); return () => { - completed?.remove(); close?.remove(); error?.remove(); }; diff --git a/platforms/react-native/sample/src/context/Cart.tsx b/platforms/react-native/sample/src/context/Cart.tsx index bdf6990c..787f343d 100644 --- a/platforms/react-native/sample/src/context/Cart.tsx +++ b/platforms/react-native/sample/src/context/Cart.tsx @@ -91,14 +91,6 @@ export const CartProvider: React.FC = ({children}) => { clearCart(); }, [appConfig.buyerIdentityMode, clearCart]); - useEffect(() => { - const subscription = shopify.addEventListener('completed', () => { - clearCart(); - }); - - return subscription?.remove; - }, [shopify, clearCart, setCartId, setCheckoutURL, setTotalQuantity]); - useEffect(() => { async function getCart() { try { diff --git a/platforms/react-native/sample/src/hooks/useCheckoutEventHandlers.ts b/platforms/react-native/sample/src/hooks/useCheckoutEventHandlers.ts index d1656536..32f61477 100644 --- a/platforms/react-native/sample/src/hooks/useCheckoutEventHandlers.ts +++ b/platforms/react-native/sample/src/hooks/useCheckoutEventHandlers.ts @@ -2,9 +2,7 @@ import {useMemo} from 'react'; import {createDebugLogger} from '../utils'; -import {useCart} from '../context/Cart'; import type { - CheckoutCompletedEvent, CheckoutException, RenderStateChangeEvent, } from '@shopify/checkout-kit-react-native'; @@ -12,26 +10,18 @@ import {Linking} from 'react-native'; interface EventHandlers { onFail?: (error: CheckoutException) => void; - onComplete?: (event: CheckoutCompletedEvent) => void; onCancel?: () => void; onRenderStateChange?: (event: RenderStateChangeEvent) => void; - onShouldRecoverFromError?: (error: {message: string}) => boolean; onClickLink?: (url: string) => void; } export function useShopifyEventHandlers(name?: string): EventHandlers { - const {clearCart} = useCart(); - return useMemo(() => { const log = createDebugLogger(name ?? ''); return { onFail: error => { log('onFail', error); }, - onComplete: event => { - log('onComplete', event.orderDetails.id); - clearCart(); - }, onCancel: () => { log('onCancel'); }, @@ -46,5 +36,5 @@ export function useShopifyEventHandlers(name?: string): EventHandlers { } }, }; - }, [clearCart, name]); + }, [name]); }