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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ experiences.

## Platform Requirements

- **React Native** - Minimum version `0.76` (v4+) / `0.70` (v3 and earlier)
- **React Native** - Minimum version `0.76` (`3.9.0+`) / `0.70` (`<=3.8.x`)
- **iOS** - Minimum version iOS 13
- **Android** - Minimum Java 11 & Android SDK version `23`

## Version Compatibility

Starting with **v4.0.0**, `@shopify/checkout-sheet-kit` requires the React Native
**New Architecture** (TurboModules + Fabric). Apps on the old architecture must
stay on the `v3.x` line until they migrate.
The **v3.9.x** line keeps the v3 public async API while supporting both React
Native architectures. Starting with **v4.0.0**, `@shopify/checkout-sheet-kit`
requires the React Native **New Architecture** (TurboModules + Fabric).

| Package version | React Native | Architecture |
| --------------- | -------------- | ------------------ |
| `4.x` | `>= 0.76` | New Architecture |
| `3.x` | `>= 0.70` | Old Architecture |
| `3.9.x` | `>= 0.76` | Old + New |
| `<=3.8.x` | `>= 0.70` | Old Architecture |

See the [React Native upgrade guide](https://reactnative.dev/docs/the-new-architecture/use-the-new-architecture)
for help enabling the New Architecture in your app.
Expand Down
6 changes: 6 additions & 0 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ module.exports = {
requireNativeComponent,
codegenNativeComponent,
TurboModuleRegistry: {
get: jest.fn((name: string) => {
if (name === 'ShopifyCheckoutSheetKit') {
return ShopifyCheckoutSheetKit;
}
return null;
}),
getEnforcing: jest.fn((name: string) => {
if (name === 'ShopifyCheckoutSheetKit') {
return ShopifyCheckoutSheetKit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"

Pod::Spec.new do |s|
s.name = "RNShopifyCheckoutSheetKit"
s.version = package["version"]
Expand All @@ -19,5 +23,23 @@ Pod::Spec.new do |s|
s.dependency "ShopifyCheckoutSheetKit", "~> 3.8.0"
s.dependency "ShopifyCheckoutSheetKit/AcceleratedCheckouts", "~> 3.8.0"

install_modules_dependencies(s)
if new_arch_enabled
if defined?(install_modules_dependencies)
install_modules_dependencies(s)
else
s.dependency "React-Codegen"
s.dependency "RCT-Folly", :modular_headers => true
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end

s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"

s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
end
end
21 changes: 19 additions & 2 deletions modules/@shopify/checkout-sheet-kit/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ buildscript {
}

apply plugin: "com.android.library"
apply plugin: "com.facebook.react"

def isNewArchitectureEnabled() {
def newArchEnabled = project.hasProperty("newArchEnabled")
? project.property("newArchEnabled")
: rootProject.hasProperty("newArchEnabled")
? rootProject.property("newArchEnabled")
: "false"

return newArchEnabled.toString() == "true"
}

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[name]).toInteger()
Expand All @@ -37,6 +50,10 @@ android {
if (supportsNamespace()) {
namespace "com.shopify.reactnative.checkoutsheetkit"

buildFeatures {
buildConfig true
}

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
Expand All @@ -50,6 +67,7 @@ android {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}

buildTypes {
Expand Down Expand Up @@ -93,4 +111,3 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.5")
debugImplementation("com.shopify:checkout-sheet-kit:${SHOPIFY_CHECKOUT_SDK_VERSION}")
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@ of this software and associated documentation files (the "Software"), to deal
import android.content.Context;
import androidx.activity.ComponentActivity;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.shopify.checkoutsheetkit.NativeShopifyCheckoutSheetKitSpec;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import com.shopify.checkoutsheetkit.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class ShopifyCheckoutSheetKitModule extends NativeShopifyCheckoutSheetKitSpec {
@ReactModule(name = ShopifyCheckoutSheetKitModule.NAME)
public class ShopifyCheckoutSheetKitModule extends ReactContextBaseJavaModule implements TurboModule {

public static final String NAME = "ShopifyCheckoutSheetKit";

public static Configuration checkoutConfig = new Configuration();

Expand All @@ -62,8 +66,14 @@ public ShopifyCheckoutSheetKitModule(ReactApplicationContext reactContext) {
});
}

@NonNull
@Override
public String getName() {
return NAME;
}

@Override
protected Map<String, Object> getTypedExportedConstants() {
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("version", ShopifyCheckoutSheetKit.version);
return constants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.TurboReactPackage;
import com.facebook.react.BaseReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
Expand All @@ -38,7 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.List;
import java.util.Map;

public class ShopifyCheckoutSheetKitPackage extends TurboReactPackage {
public class ShopifyCheckoutSheetKitPackage extends BaseReactPackage {

@NonNull
@Override
Expand Down Expand Up @@ -67,7 +67,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
false, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
true // isTurboModule
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED // isTurboModule
));
return moduleInfos;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ of this software and associated documentation files (the "Software"), to deal

#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>

#if RCT_NEW_ARCH_ENABLED
#import <RNShopifyCheckoutSheetKitSpec/RNShopifyCheckoutSheetKitSpec.h>

// Registers the Swift module class (ShopifyCheckoutSheetKit.swift) with the RN
Expand Down Expand Up @@ -61,6 +63,61 @@ @implementation RCTShopifyCheckoutSheetKit (TurboModule)
params);
}
@end
#else
@interface RCT_EXTERN_MODULE (RCTShopifyCheckoutSheetKit, NSObject)

/**
* Present checkout
*/
RCT_EXTERN_METHOD(present : (NSString*)checkoutURLString);

/**
* Preload checkout
*/
RCT_EXTERN_METHOD(preload : (NSString*)checkoutURLString);

/**
* Dismiss checkout
*/
RCT_EXTERN_METHOD(dismiss);

/**
* Invalidate preload cache
*/
RCT_EXTERN_METHOD(invalidateCache);

/**
* Set configuration for checkout
*/
RCT_EXTERN_METHOD(setConfig : (NSDictionary*)configuration);

/**
* Return configuration for checkout
*/
RCT_EXTERN_METHOD(getConfig : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);

/**
* Configure AcceleratedCheckouts
*/
RCT_EXTERN_METHOD(configureAcceleratedCheckouts : (NSString*)storefrontDomain storefrontAccessToken : (
NSString*)storefrontAccessToken customerEmail : (NSString*)customerEmail customerPhoneNumber : (NSString*)
customerPhoneNumber customerAccessToken : (NSString*)customerAccessToken applePayMerchantIdentifier : (NSString*)
applePayMerchantIdentifier applyPayContactFields : (NSArray*)applyPayContactFields supportedShippingCountries : (NSArray*)supportedShippingCountries resolve : (
RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);

/**
* Check if accelerated checkout is available
*/
RCT_EXTERN_METHOD(
isAcceleratedCheckoutAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);

/**
* Check if Apple Pay is available
*/
RCT_EXTERN_METHOD(isApplePayAvailable : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)reject);

@end
#endif

/**
* AcceleratedCheckoutButtons View Manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
]
}

@objc func getConfig(
_ resolve: @escaping RCTPromiseResolveBlock,
reject _: @escaping RCTPromiseRejectBlock
) {
resolve(getConfig())
}

@objc func configureAcceleratedCheckouts(
_ storefrontDomain: String,
storefrontAccessToken: String,
Expand Down Expand Up @@ -274,6 +281,30 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
return NSNumber(value: true)
}

@objc func configureAcceleratedCheckouts(
_ storefrontDomain: String,
storefrontAccessToken: String,
customerEmail: String?,
customerPhoneNumber: String?,
customerAccessToken: String?,
applePayMerchantIdentifier: String?,
applyPayContactFields: [String]?,
supportedShippingCountries: [String]?,
resolve: @escaping RCTPromiseResolveBlock,
reject _: @escaping RCTPromiseRejectBlock
) {
resolve(configureAcceleratedCheckouts(
storefrontDomain,
storefrontAccessToken: storefrontAccessToken,
customerEmail: customerEmail,
customerPhoneNumber: customerPhoneNumber,
customerAccessToken: customerAccessToken,
applePayMerchantIdentifier: applePayMerchantIdentifier,
applyPayContactFields: applyPayContactFields,
supportedShippingCountries: supportedShippingCountries
))
}

@objc func isAcceleratedCheckoutAvailable() -> NSNumber {
guard #available(iOS 16.0, *) else {
return NSNumber(value: false)
Expand All @@ -282,6 +313,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
return NSNumber(value: AcceleratedCheckoutConfiguration.shared.available)
}

@objc func isAcceleratedCheckoutAvailable(
_ resolve: @escaping RCTPromiseResolveBlock,
reject _: @escaping RCTPromiseRejectBlock
) {
resolve(isAcceleratedCheckoutAvailable())
}

@objc func isApplePayAvailable() -> NSNumber {
guard #available(iOS 16.0, *) else {
return NSNumber(value: false)
Expand All @@ -292,6 +330,13 @@ class RCTShopifyCheckoutSheetKit: RCTEventEmitter, CheckoutDelegate {
return NSNumber(value: available)
}

@objc func isApplePayAvailable(
_ resolve: @escaping RCTPromiseResolveBlock,
reject _: @escaping RCTPromiseRejectBlock
) {
resolve(isApplePayAvailable())
}

@objc func initiateGeolocationRequest(_ allow: Bool) {
// No-op on iOS — geolocation permission is handled natively
}
Expand Down
2 changes: 1 addition & 1 deletion modules/@shopify/checkout-sheet-kit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shopify/checkout-sheet-kit",
"license": "MIT",
"version": "4.0.0",
"version": "3.9.0",
"main": "lib/commonjs/index.js",
"types": "src/index.ts",
"source": "src/index.ts",
Expand Down
Loading
Loading