framepayments-react-native 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -59
- package/android/build/intermediates/aar_main_jar/debug/syncDebugLibJars/classes.jar +0 -0
- package/android/build/intermediates/annotations_typedef_file/debug/extractDebugAnnotations/typedefs.txt +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
- package/android/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
- package/android/build/intermediates/merged_java_res/debug/mergeDebugJavaResource/feature-framepayments-react-native.jar +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/build/outputs/aar/framepayments-react-native-debug.aar +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameCheckoutActivity$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameCheckoutActivity$tryShowCheckout$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameCheckoutActivity.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameFlowActivity$CartItemDto.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameFlowActivity$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameFlowActivity$parseCartItems$type$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameFlowActivity.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameGooglePayActivity$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameGooglePayActivity.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameOnboardingActivity$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameOnboardingActivity$parseCapabilities$type$1.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameOnboardingActivity.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/framepayments/reactnativeframe/FrameSDKModule.class +0 -0
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/framepayments/reactnativeframe/FrameCheckoutActivity.kt +17 -13
- package/android/src/main/java/com/framepayments/reactnativeframe/FrameFlowActivity.kt +18 -11
- package/android/src/main/java/com/framepayments/reactnativeframe/FrameGooglePayActivity.kt +31 -8
- package/android/src/main/java/com/framepayments/reactnativeframe/FrameSDKModule.kt +28 -35
- package/ios/ApplePayPresenter.swift +53 -28
- package/ios/FrameSDKBridge.m +7 -7
- package/ios/FrameSDKBridge.swift +62 -32
- package/lib/errors.d.ts +9 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +9 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/native.d.ts +37 -7
- package/lib/native.d.ts.map +1 -1
- package/lib/native.js +61 -9
- package/lib/types.d.ts +18 -45
- package/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/native.test.ts +179 -25
- package/src/errors.ts +9 -1
- package/src/index.ts +1 -3
- package/src/native.ts +69 -17
- package/src/types.ts +19 -58
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/results.bin +0 -1
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/BuildConfig.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameCheckoutActivity$Companion.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameCheckoutActivity$tryShowCheckout$1.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameCheckoutActivity.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameFlowActivity$CartItemDto.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameFlowActivity$Companion.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameFlowActivity$parseCartItems$type$1.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameFlowActivity.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameGooglePayActivity$Companion.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameGooglePayActivity.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameOnboardingActivity$Companion.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameOnboardingActivity$parseCapabilities$type$1.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameOnboardingActivity.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameSDKModule$Companion.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameSDKModule.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/FrameSDKPackage.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/framepayments/reactnativeframe/JsonConvertersKt.dex +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameCheckoutActivity$$InternalSyntheticLambda$2$28045340ca5b91151bb937065eeb5817c0f8f911bb460e6e7ed8bb228b67ee83$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameFlowActivity$$InternalSyntheticLambda$2$467cdf1dabffeaa07b76e313efb66791f50d3ff264e427e91d1358ac5865a7a9$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameFlowActivity$$InternalSyntheticLambda$2$d15cc37cc08a853958a9c0baad49f7fce1ef84e92db9baa5103646939a0fe3e5$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameFlowActivity$$InternalSyntheticLambda$2$ee6ef8e6758d1b8e67a54e3fecfb200ac5e867541a69809ec1db49f74ffcada1$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameGooglePayActivity$$InternalSyntheticLambda$2$46cecf303f126f7c9f20b615fc49b2714ec2eb4f046ae009cfdbce53a1759f18$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameGooglePayActivity$$InternalSyntheticLambda$2$46cecf303f126f7c9f20b615fc49b2714ec2eb4f046ae009cfdbce53a1759f18$1.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameGooglePayActivity$$InternalSyntheticLambda$2$46cecf303f126f7c9f20b615fc49b2714ec2eb4f046ae009cfdbce53a1759f18$2.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameGooglePayActivity$$InternalSyntheticLambda$2$cdad629ad452b3c7f7de1310d225629dafa75285ad515d55f056371066170154$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameOnboardingActivity$$InternalSyntheticLambda$2$5d91d018c63f48735ba5e2a00b14bd815f4ce248aa924e4a58bf6addce311837$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameOnboardingActivity$$InternalSyntheticLambda$2$c9ac604bc80e3afcbfad7417717ae97568874f4e33246863c0d688abb3e89865$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameSDKModule$$InternalSyntheticLambda$2$1f479ca48bf3a1c66ff65b38aaaef67a97119b29ddce703f8104188682007f0d$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameSDKModule$$InternalSyntheticLambda$2$984ab30558bc904ed37602fa6e3ebf28f1ed69df6712b31b00c4f26fc26d3b70$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameSDKModule$$InternalSyntheticLambda$2$f4a55b70e496f422e1e03998843d62c7208f0229c2d5d080706056e98810c892$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameSDKModule$$InternalSyntheticLambda$2$f8d46f7169c404d37a1d505f19439b83090fbed62b5bdaf1e86717fdddebf622$0.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_global-synthetics/com/framepayments/reactnativeframe/FrameSDKModule$$InternalSyntheticLambda$2$f8d46f7169c404d37a1d505f19439b83090fbed62b5bdaf1e86717fdddebf622$1.globals +0 -0
- package/android/build/.transforms/5a2061641b1fc5518a336681809507bc/transformed/bundleLibRuntimeToDirDebug/desugar_graph.bin +0 -0
- package/android/build/intermediates/android_res_source_set_path_map/debug/mapDebugSourceSetPaths/file-map.txt +0 -10
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/navigation_json/debug/extractDeepLinksDebug/navigation.json +0 -1
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/META-INF/framepayments-react-native_debug.kotlin_module +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/BuildConfig.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameCheckoutActivity$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameCheckoutActivity$tryShowCheckout$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameCheckoutActivity.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameFlowActivity$CartItemDto.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameFlowActivity$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameFlowActivity$parseCartItems$type$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameFlowActivity.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameGooglePayActivity$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameGooglePayActivity.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameOnboardingActivity$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameOnboardingActivity$parseCapabilities$type$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameOnboardingActivity.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameSDKModule$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameSDKModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/FrameSDKPackage.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/framepayments/reactnativeframe/JsonConvertersKt.class +0 -0
package/lib/native.js
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { NativeModules, Platform } from 'react-native';
|
|
5
5
|
import { ErrorCodes } from './errors';
|
|
6
|
+
/**
|
|
7
|
+
* Throw a coded error from synchronous JS validation. Mirrors the `code`/`message`
|
|
8
|
+
* shape that native rejections produce so consumers can catch `e.code === 'INVALID_*'`
|
|
9
|
+
* uniformly.
|
|
10
|
+
*/
|
|
11
|
+
function throwCoded(code, message) {
|
|
12
|
+
const err = new Error(message);
|
|
13
|
+
err.code = code;
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
6
16
|
// theme is iOS-only today: frame-android does not yet have a matching theme API,
|
|
7
17
|
// so the field is accepted on both platforms but ignored on Android until it does.
|
|
8
18
|
const LINKING_ERROR = `The package 'framepayments-react-native' doesn't seem to be linked. Make sure you have run 'pod install' (iOS) or rebuilt the app (Android).`;
|
|
@@ -16,13 +26,13 @@ const FrameSDK = NativeModules.FrameSDK
|
|
|
16
26
|
let isInitialized = false;
|
|
17
27
|
export function initialize(options) {
|
|
18
28
|
if (!options?.secretKey) {
|
|
19
|
-
|
|
29
|
+
throwCoded(ErrorCodes.INIT_FAILED, 'Frame.initialize requires secretKey');
|
|
20
30
|
}
|
|
21
31
|
if (!options?.publishableKey) {
|
|
22
|
-
|
|
32
|
+
throwCoded(ErrorCodes.INIT_FAILED, 'Frame.initialize requires publishableKey');
|
|
23
33
|
}
|
|
24
34
|
if (options.theme !== undefined && (typeof options.theme !== 'object' || Array.isArray(options.theme))) {
|
|
25
|
-
|
|
35
|
+
throwCoded(ErrorCodes.INIT_FAILED, 'Frame.initialize: theme must be an object');
|
|
26
36
|
}
|
|
27
37
|
return wrapPromise(FrameSDK.initialize(options.secretKey, options.publishableKey, options.debugMode ?? false, options.theme ?? null)).then(() => {
|
|
28
38
|
isInitialized = true;
|
|
@@ -48,13 +58,34 @@ function wrapPromise(p) {
|
|
|
48
58
|
throw Object.assign(new Error(message), { code, message });
|
|
49
59
|
});
|
|
50
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Presents the Frame checkout sheet for the given account. Resolves with the
|
|
63
|
+
* created Transfer's id string on success, or rejects with `USER_CANCELED` if
|
|
64
|
+
* the user dismisses the sheet.
|
|
65
|
+
*
|
|
66
|
+
* `accountId` is required: the bundled checkout creates a `Transfer`, which is
|
|
67
|
+
* account-scoped. Callers needing a customer/ChargeIntent flow should use
|
|
68
|
+
* `presentApplePay` / `presentGooglePay` directly with a customer owner.
|
|
69
|
+
*/
|
|
51
70
|
export function presentCheckout(options) {
|
|
52
71
|
guardInitialized();
|
|
53
|
-
|
|
72
|
+
if (!options?.accountId) {
|
|
73
|
+
throwCoded(ErrorCodes.INVALID_ACCOUNT, 'Frame.presentCheckout requires accountId');
|
|
74
|
+
}
|
|
75
|
+
return wrapPromise(FrameSDK.presentCheckout(options.accountId, options.amount));
|
|
54
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Presents the Frame cart UI; tapping checkout routes through the same flow
|
|
79
|
+
* as `presentCheckout` and resolves with the created Transfer's id string.
|
|
80
|
+
*
|
|
81
|
+
* `accountId` is required for the same reason as `presentCheckout`.
|
|
82
|
+
*/
|
|
55
83
|
export function presentCart(options) {
|
|
56
84
|
guardInitialized();
|
|
57
|
-
|
|
85
|
+
if (!options?.accountId) {
|
|
86
|
+
throwCoded(ErrorCodes.INVALID_ACCOUNT, 'Frame.presentCart requires accountId');
|
|
87
|
+
}
|
|
88
|
+
return wrapPromise(FrameSDK.presentCart(options.accountId, options.items, options.shippingAmountInCents));
|
|
58
89
|
}
|
|
59
90
|
export function presentOnboarding(options) {
|
|
60
91
|
guardInitialized();
|
|
@@ -63,20 +94,41 @@ export function presentOnboarding(options) {
|
|
|
63
94
|
}
|
|
64
95
|
return wrapPromise(FrameSDK.presentOnboarding(options.accountId ?? null, options.capabilities ?? [], options.googlePayMerchantId ?? null));
|
|
65
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Presents the Apple Pay sheet and creates a charge from the resulting wallet
|
|
99
|
+
* payment method. Resolves with the created resource's id string on success,
|
|
100
|
+
* or rejects with `USER_CANCELED` if the sheet is dismissed.
|
|
101
|
+
*
|
|
102
|
+
* - `owner.type === 'customer'` → creates a `ChargeIntent`; resolves with its id.
|
|
103
|
+
* - `owner.type === 'account'` → creates a `Transfer`; resolves with its id.
|
|
104
|
+
*/
|
|
66
105
|
export function presentApplePay(options) {
|
|
67
106
|
guardInitialized();
|
|
68
107
|
if (!options?.owner || (options.owner.type !== 'customer' && options.owner.type !== 'account')) {
|
|
69
|
-
|
|
108
|
+
throwCoded(ErrorCodes.INVALID_OWNER, 'Frame.presentApplePay requires owner: { type: "customer" | "account", id: string }');
|
|
70
109
|
}
|
|
71
110
|
if (!options.owner.id) {
|
|
72
|
-
|
|
111
|
+
throwCoded(ErrorCodes.INVALID_OWNER, 'Frame.presentApplePay requires owner.id');
|
|
73
112
|
}
|
|
74
113
|
if (!options.merchantId) {
|
|
75
|
-
|
|
114
|
+
throwCoded(ErrorCodes.INVALID_MERCHANT_ID, 'Frame.presentApplePay requires merchantId');
|
|
76
115
|
}
|
|
77
116
|
return wrapPromise(FrameSDK.presentApplePay(options.owner.type, options.owner.id, options.amount, options.currency ?? 'usd', options.merchantId));
|
|
78
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Presents Google Pay and creates a charge from the resulting wallet payment method.
|
|
120
|
+
* Resolves with the created resource's id string on success.
|
|
121
|
+
*
|
|
122
|
+
* - `owner.type === 'customer'` → creates a `ChargeIntent`; resolves with its id.
|
|
123
|
+
* - `owner.type === 'account'` → creates a `Transfer`; resolves with its id.
|
|
124
|
+
*/
|
|
79
125
|
export function presentGooglePay(options) {
|
|
80
126
|
guardInitialized();
|
|
81
|
-
|
|
127
|
+
if (!options?.owner || (options.owner.type !== 'customer' && options.owner.type !== 'account')) {
|
|
128
|
+
throwCoded(ErrorCodes.INVALID_OWNER, 'Frame.presentGooglePay requires owner: { type: "customer" | "account", id: string }');
|
|
129
|
+
}
|
|
130
|
+
if (!options.owner.id) {
|
|
131
|
+
throwCoded(ErrorCodes.INVALID_OWNER, 'Frame.presentGooglePay requires owner.id');
|
|
132
|
+
}
|
|
133
|
+
return wrapPromise(FrameSDK.presentGooglePay(options.amountCents, options.owner.type, options.owner.id, options.currencyCode ?? 'USD', options.googlePayMerchantId ?? null));
|
|
82
134
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ export interface FrameCartItem {
|
|
|
9
9
|
amountInCents: number;
|
|
10
10
|
imageUrl: string;
|
|
11
11
|
}
|
|
12
|
-
export type ChargeIntentStatus = 'canceled' | 'disputed' | 'failed' | 'incomplete' | 'pending' | 'refunded' | 'reversed' | 'succeeded';
|
|
13
|
-
export type AuthorizationMode = 'automatic' | 'manual';
|
|
14
12
|
export interface BillingAddress {
|
|
15
13
|
city?: string;
|
|
16
14
|
country?: string;
|
|
@@ -46,43 +44,6 @@ export interface PaymentMethod {
|
|
|
46
44
|
ach?: BankAccount;
|
|
47
45
|
billing?: BillingAddress;
|
|
48
46
|
}
|
|
49
|
-
export interface Customer {
|
|
50
|
-
id: string;
|
|
51
|
-
object: string;
|
|
52
|
-
created: number;
|
|
53
|
-
updated: number;
|
|
54
|
-
livemode: boolean;
|
|
55
|
-
name?: string;
|
|
56
|
-
email?: string;
|
|
57
|
-
phone?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface Charge {
|
|
60
|
-
id: string;
|
|
61
|
-
object: string;
|
|
62
|
-
amount: number;
|
|
63
|
-
currency: string;
|
|
64
|
-
status: string;
|
|
65
|
-
created: number;
|
|
66
|
-
livemode: boolean;
|
|
67
|
-
}
|
|
68
|
-
/** Charge intent returned from presentCheckout / presentCart */
|
|
69
|
-
export interface ChargeIntent {
|
|
70
|
-
id: string;
|
|
71
|
-
currency: string;
|
|
72
|
-
amount: number;
|
|
73
|
-
status: ChargeIntentStatus;
|
|
74
|
-
created: number;
|
|
75
|
-
updated: number;
|
|
76
|
-
livemode: boolean;
|
|
77
|
-
object: string;
|
|
78
|
-
description?: string;
|
|
79
|
-
authorizationMode?: AuthorizationMode;
|
|
80
|
-
failureDescription?: string;
|
|
81
|
-
customer?: Customer;
|
|
82
|
-
paymentMethod?: PaymentMethod;
|
|
83
|
-
latestCharge?: Charge;
|
|
84
|
-
shipping?: BillingAddress;
|
|
85
|
-
}
|
|
86
47
|
/** Error shape when native module rejects (same as FrameErrorShape from errors.ts) */
|
|
87
48
|
export interface FrameError {
|
|
88
49
|
code: string;
|
|
@@ -98,22 +59,34 @@ export interface OnboardingResult {
|
|
|
98
59
|
/** Present when status === 'completed' and a payment method was created/verified */
|
|
99
60
|
paymentMethodId?: string;
|
|
100
61
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Identifies who the wallet payment method belongs to and which downstream
|
|
64
|
+
* resource is created when the user authorizes payment. Used by both
|
|
65
|
+
* `presentApplePay` and `presentGooglePay`.
|
|
66
|
+
*
|
|
67
|
+
* - `{ type: 'customer', id }` → creates a `ChargeIntent`; promise resolves with the ChargeIntent id.
|
|
68
|
+
* - `{ type: 'account', id }` → creates a `Transfer`; promise resolves with the Transfer id.
|
|
69
|
+
*
|
|
70
|
+
* The promise always resolves with a string id; the caller knows which resource
|
|
71
|
+
* it refers to based on the owner type they passed in.
|
|
72
|
+
*/
|
|
73
|
+
export type WalletOwner = {
|
|
103
74
|
type: 'customer';
|
|
104
75
|
id: string;
|
|
105
76
|
} | {
|
|
106
77
|
type: 'account';
|
|
107
78
|
id: string;
|
|
108
79
|
};
|
|
80
|
+
/** @deprecated Use {@link WalletOwner}. Retained as an alias for source compatibility. */
|
|
81
|
+
export type ApplePayOwner = WalletOwner;
|
|
109
82
|
/** Options for Frame.presentApplePay. */
|
|
110
83
|
export interface PresentApplePayOptions {
|
|
111
84
|
/** Payment amount in cents. */
|
|
112
85
|
amount: number;
|
|
113
86
|
/** ISO 4217 currency code. Defaults to 'usd'. */
|
|
114
87
|
currency?: string;
|
|
115
|
-
/** Customer or account that owns the resulting payment method. */
|
|
116
|
-
owner:
|
|
88
|
+
/** Customer or account that owns the resulting payment method and charge. */
|
|
89
|
+
owner: WalletOwner;
|
|
117
90
|
/** Apple Pay merchant ID configured in your Apple Developer account. */
|
|
118
91
|
merchantId: string;
|
|
119
92
|
}
|
|
@@ -121,8 +94,8 @@ export interface PresentApplePayOptions {
|
|
|
121
94
|
export interface PresentGooglePayOptions {
|
|
122
95
|
/** Payment amount in cents. */
|
|
123
96
|
amountCents: number;
|
|
124
|
-
/**
|
|
125
|
-
|
|
97
|
+
/** Customer or account that owns the resulting payment method and charge. */
|
|
98
|
+
owner: WalletOwner;
|
|
126
99
|
/** ISO 4217 currency code. Defaults to 'USD'. */
|
|
127
100
|
currencyCode?: string;
|
|
128
101
|
/** Optional override for the Google Pay merchant ID. */
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5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B,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for the native module bridge (initialize, presentCheckout, presentCart
|
|
3
|
-
* NativeModules.FrameSDK is mocked.
|
|
2
|
+
* Unit tests for the native module bridge (initialize, presentCheckout, presentCart,
|
|
3
|
+
* presentApplePay, presentGooglePay, presentOnboarding). NativeModules.FrameSDK is mocked.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const mockInitialize = jest.fn((_secretKey: string, _publishableKey: string, _debugMode: boolean) => Promise.resolve());
|
|
7
|
-
const mockPresentCheckout = jest.fn((
|
|
8
|
-
const mockPresentCart = jest.fn((
|
|
7
|
+
const mockPresentCheckout = jest.fn((_accountId: unknown, _amount: number) => Promise.resolve('tr_1'));
|
|
8
|
+
const mockPresentCart = jest.fn((_accountId: unknown, _items: unknown[], _shipping: number) => Promise.resolve('tr_2'));
|
|
9
|
+
const mockPresentApplePay = jest.fn((_ownerType: string, _ownerId: string, _amount: number, _currency: string, _merchantId: string) => Promise.resolve('tr_3'));
|
|
10
|
+
const mockPresentGooglePay = jest.fn((_amountCents: number, _ownerType: string, _ownerId: string, _currencyCode: string, _googlePayMerchantId: string | null) => Promise.resolve('tr_4'));
|
|
9
11
|
const mockPresentOnboarding = jest.fn((_accountId: unknown, _capabilities: unknown[], _merchantId: string | null) => Promise.resolve({ status: 'completed', paymentMethodId: 'pm_1' }));
|
|
10
12
|
|
|
11
13
|
const mockPlatform = { OS: 'ios' as 'ios' | 'android' };
|
|
@@ -16,6 +18,8 @@ jest.mock('react-native', () => ({
|
|
|
16
18
|
initialize: mockInitialize,
|
|
17
19
|
presentCheckout: mockPresentCheckout,
|
|
18
20
|
presentCart: mockPresentCart,
|
|
21
|
+
presentApplePay: mockPresentApplePay,
|
|
22
|
+
presentGooglePay: mockPresentGooglePay,
|
|
19
23
|
presentOnboarding: mockPresentOnboarding,
|
|
20
24
|
},
|
|
21
25
|
},
|
|
@@ -24,12 +28,14 @@ jest.mock('react-native', () => ({
|
|
|
24
28
|
|
|
25
29
|
// Re-import after mock so we get the mocked NativeModules
|
|
26
30
|
let initialize: (opts: { secretKey: string; publishableKey: string; debugMode?: boolean }) => Promise<void>;
|
|
27
|
-
let presentCheckout: (opts: {
|
|
31
|
+
let presentCheckout: (opts: { accountId: string; amount: number }) => Promise<string>;
|
|
28
32
|
let presentCart: (opts: {
|
|
29
|
-
|
|
33
|
+
accountId: string;
|
|
30
34
|
items: Array<{ id: string; title: string; amountInCents: number; imageUrl: string }>;
|
|
31
35
|
shippingAmountInCents: number;
|
|
32
|
-
}) => Promise<
|
|
36
|
+
}) => Promise<string>;
|
|
37
|
+
let presentApplePay: (opts: { amount: number; currency?: string; owner: { type: 'customer' | 'account'; id: string }; merchantId: string }) => Promise<string>;
|
|
38
|
+
let presentGooglePay: (opts: { amountCents: number; owner: { type: 'customer' | 'account'; id: string }; currencyCode?: string; googlePayMerchantId?: string }) => Promise<string>;
|
|
33
39
|
let presentOnboarding: (opts: { accountId?: string | null; capabilities?: string[]; applePayMerchantId?: string | null; googlePayMerchantId?: string | null }) => Promise<unknown>;
|
|
34
40
|
|
|
35
41
|
beforeEach(() => {
|
|
@@ -37,12 +43,16 @@ beforeEach(() => {
|
|
|
37
43
|
mockInitialize.mockClear();
|
|
38
44
|
mockPresentCheckout.mockClear();
|
|
39
45
|
mockPresentCart.mockClear();
|
|
46
|
+
mockPresentApplePay.mockClear();
|
|
47
|
+
mockPresentGooglePay.mockClear();
|
|
40
48
|
mockPresentOnboarding.mockClear();
|
|
41
49
|
mockPlatform.OS = 'ios';
|
|
42
50
|
const native = require('../native');
|
|
43
51
|
initialize = native.initialize;
|
|
44
52
|
presentCheckout = native.presentCheckout;
|
|
45
53
|
presentCart = native.presentCart;
|
|
54
|
+
presentApplePay = native.presentApplePay;
|
|
55
|
+
presentGooglePay = native.presentGooglePay;
|
|
46
56
|
presentOnboarding = native.presentOnboarding;
|
|
47
57
|
});
|
|
48
58
|
|
|
@@ -50,12 +60,12 @@ describe('initialize', () => {
|
|
|
50
60
|
it('calls native FrameSDK.initialize with secretKey, publishableKey, and debugMode', () => {
|
|
51
61
|
initialize({ secretKey: 'sk_test_xxx', publishableKey: 'pk_test_xxx', debugMode: true });
|
|
52
62
|
expect(mockInitialize).toHaveBeenCalledTimes(1);
|
|
53
|
-
expect(mockInitialize).toHaveBeenCalledWith('sk_test_xxx', 'pk_test_xxx', true);
|
|
63
|
+
expect(mockInitialize).toHaveBeenCalledWith('sk_test_xxx', 'pk_test_xxx', true, null);
|
|
54
64
|
});
|
|
55
65
|
|
|
56
66
|
it('defaults debugMode to false', () => {
|
|
57
67
|
initialize({ secretKey: 'sk_test_yyy', publishableKey: 'pk_test_yyy' });
|
|
58
|
-
expect(mockInitialize).toHaveBeenCalledWith('sk_test_yyy', 'pk_test_yyy', false);
|
|
68
|
+
expect(mockInitialize).toHaveBeenCalledWith('sk_test_yyy', 'pk_test_yyy', false, null);
|
|
59
69
|
});
|
|
60
70
|
|
|
61
71
|
it('throws if secretKey is missing', () => {
|
|
@@ -74,7 +84,7 @@ describe('initialize', () => {
|
|
|
74
84
|
describe('presentCheckout', () => {
|
|
75
85
|
it('throws NOT_INITIALIZED if initialize was not called', async () => {
|
|
76
86
|
try {
|
|
77
|
-
await presentCheckout({ amount: 10000 });
|
|
87
|
+
await presentCheckout({ accountId: 'acct_1', amount: 10000 });
|
|
78
88
|
expect(true).toBe(false);
|
|
79
89
|
} catch (e: any) {
|
|
80
90
|
expect(e.code).toBe('NOT_INITIALIZED');
|
|
@@ -83,17 +93,22 @@ describe('presentCheckout', () => {
|
|
|
83
93
|
expect(mockPresentCheckout).not.toHaveBeenCalled();
|
|
84
94
|
});
|
|
85
95
|
|
|
86
|
-
it('
|
|
96
|
+
it('throws INVALID_ACCOUNT when accountId is missing', async () => {
|
|
87
97
|
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
try {
|
|
99
|
+
await presentCheckout({ amount: 5000 } as any);
|
|
100
|
+
expect(true).toBe(false);
|
|
101
|
+
} catch (e: any) {
|
|
102
|
+
expect(e.code).toBe('INVALID_ACCOUNT');
|
|
103
|
+
}
|
|
104
|
+
expect(mockPresentCheckout).not.toHaveBeenCalled();
|
|
91
105
|
});
|
|
92
106
|
|
|
93
|
-
it('
|
|
107
|
+
it('calls native presentCheckout with accountId and amount; resolves with transfer id string', async () => {
|
|
94
108
|
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
95
|
-
await presentCheckout({ amount:
|
|
96
|
-
expect(mockPresentCheckout).toHaveBeenCalledWith(
|
|
109
|
+
const result = await presentCheckout({ accountId: 'acct_1', amount: 10000 });
|
|
110
|
+
expect(mockPresentCheckout).toHaveBeenCalledWith('acct_1', 10000);
|
|
111
|
+
expect(result).toBe('tr_1');
|
|
97
112
|
});
|
|
98
113
|
});
|
|
99
114
|
|
|
@@ -104,7 +119,7 @@ describe('presentCart', () => {
|
|
|
104
119
|
|
|
105
120
|
it('throws NOT_INITIALIZED if initialize was not called', async () => {
|
|
106
121
|
try {
|
|
107
|
-
await presentCart({ items, shippingAmountInCents: 500 });
|
|
122
|
+
await presentCart({ accountId: 'acct_1', items, shippingAmountInCents: 500 });
|
|
108
123
|
expect(true).toBe(false);
|
|
109
124
|
} catch (e: any) {
|
|
110
125
|
expect(e.code).toBe('NOT_INITIALIZED');
|
|
@@ -112,21 +127,160 @@ describe('presentCart', () => {
|
|
|
112
127
|
expect(mockPresentCart).not.toHaveBeenCalled();
|
|
113
128
|
});
|
|
114
129
|
|
|
115
|
-
it('
|
|
130
|
+
it('throws INVALID_ACCOUNT when accountId is missing', async () => {
|
|
131
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
132
|
+
try {
|
|
133
|
+
await presentCart({ items, shippingAmountInCents: 0 } as any);
|
|
134
|
+
expect(true).toBe(false);
|
|
135
|
+
} catch (e: any) {
|
|
136
|
+
expect(e.code).toBe('INVALID_ACCOUNT');
|
|
137
|
+
}
|
|
138
|
+
expect(mockPresentCart).not.toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('calls native presentCart with accountId, items, shipping; resolves with transfer id string', async () => {
|
|
116
142
|
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
117
143
|
const result = await presentCart({
|
|
118
|
-
|
|
144
|
+
accountId: 'acct_2',
|
|
119
145
|
items,
|
|
120
146
|
shippingAmountInCents: 500,
|
|
121
147
|
});
|
|
122
|
-
expect(mockPresentCart).toHaveBeenCalledWith('
|
|
123
|
-
expect(result).
|
|
148
|
+
expect(mockPresentCart).toHaveBeenCalledWith('acct_2', items, 500);
|
|
149
|
+
expect(result).toBe('tr_2');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('presentApplePay', () => {
|
|
154
|
+
it('throws NOT_INITIALIZED if initialize was not called', async () => {
|
|
155
|
+
try {
|
|
156
|
+
await presentApplePay({ amount: 100, owner: { type: 'account', id: 'acct_1' }, merchantId: 'merchant.test' });
|
|
157
|
+
expect(true).toBe(false);
|
|
158
|
+
} catch (e: any) {
|
|
159
|
+
expect(e.code).toBe('NOT_INITIALIZED');
|
|
160
|
+
}
|
|
161
|
+
expect(mockPresentApplePay).not.toHaveBeenCalled();
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('throws INVALID_OWNER when owner is missing', async () => {
|
|
165
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
166
|
+
try {
|
|
167
|
+
await presentApplePay({ amount: 100, merchantId: 'merchant.test' } as any);
|
|
168
|
+
expect(true).toBe(false);
|
|
169
|
+
} catch (e: any) {
|
|
170
|
+
expect(e.code).toBe('INVALID_OWNER');
|
|
171
|
+
}
|
|
172
|
+
expect(mockPresentApplePay).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('throws INVALID_OWNER when owner.id is empty', async () => {
|
|
176
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
177
|
+
try {
|
|
178
|
+
await presentApplePay({ amount: 100, owner: { type: 'account', id: '' }, merchantId: 'merchant.test' });
|
|
179
|
+
expect(true).toBe(false);
|
|
180
|
+
} catch (e: any) {
|
|
181
|
+
expect(e.code).toBe('INVALID_OWNER');
|
|
182
|
+
}
|
|
183
|
+
expect(mockPresentApplePay).not.toHaveBeenCalled();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('throws INVALID_MERCHANT_ID when merchantId is missing', async () => {
|
|
187
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
188
|
+
try {
|
|
189
|
+
await presentApplePay({ amount: 100, owner: { type: 'account', id: 'acct_1' } } as any);
|
|
190
|
+
expect(true).toBe(false);
|
|
191
|
+
} catch (e: any) {
|
|
192
|
+
expect(e.code).toBe('INVALID_MERCHANT_ID');
|
|
193
|
+
}
|
|
194
|
+
expect(mockPresentApplePay).not.toHaveBeenCalled();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('forwards account owner; resolves with transfer id string', async () => {
|
|
198
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
199
|
+
const result = await presentApplePay({
|
|
200
|
+
amount: 12345,
|
|
201
|
+
currency: 'usd',
|
|
202
|
+
owner: { type: 'account', id: 'acct_1' },
|
|
203
|
+
merchantId: 'merchant.test',
|
|
204
|
+
});
|
|
205
|
+
expect(mockPresentApplePay).toHaveBeenCalledWith('account', 'acct_1', 12345, 'usd', 'merchant.test');
|
|
206
|
+
expect(result).toBe('tr_3');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('forwards customer owner; resolves with charge intent id string', async () => {
|
|
210
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
211
|
+
await presentApplePay({
|
|
212
|
+
amount: 9999,
|
|
213
|
+
owner: { type: 'customer', id: 'cus_1' },
|
|
214
|
+
merchantId: 'merchant.test',
|
|
215
|
+
});
|
|
216
|
+
expect(mockPresentApplePay).toHaveBeenCalledWith('customer', 'cus_1', 9999, 'usd', 'merchant.test');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('defaults currency to usd', async () => {
|
|
220
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
221
|
+
await presentApplePay({ amount: 100, owner: { type: 'account', id: 'acct_1' }, merchantId: 'merchant.test' });
|
|
222
|
+
expect(mockPresentApplePay).toHaveBeenCalledWith('account', 'acct_1', 100, 'usd', 'merchant.test');
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('presentGooglePay', () => {
|
|
227
|
+
it('throws NOT_INITIALIZED if initialize was not called', async () => {
|
|
228
|
+
try {
|
|
229
|
+
await presentGooglePay({ amountCents: 100, owner: { type: 'account', id: 'acct_1' } });
|
|
230
|
+
expect(true).toBe(false);
|
|
231
|
+
} catch (e: any) {
|
|
232
|
+
expect(e.code).toBe('NOT_INITIALIZED');
|
|
233
|
+
}
|
|
234
|
+
expect(mockPresentGooglePay).not.toHaveBeenCalled();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('throws INVALID_OWNER when owner is missing', async () => {
|
|
238
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
239
|
+
try {
|
|
240
|
+
await presentGooglePay({ amountCents: 100 } as any);
|
|
241
|
+
expect(true).toBe(false);
|
|
242
|
+
} catch (e: any) {
|
|
243
|
+
expect(e.code).toBe('INVALID_OWNER');
|
|
244
|
+
}
|
|
245
|
+
expect(mockPresentGooglePay).not.toHaveBeenCalled();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('throws INVALID_OWNER when owner.id is empty', async () => {
|
|
249
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
250
|
+
try {
|
|
251
|
+
await presentGooglePay({ amountCents: 100, owner: { type: 'account', id: '' } });
|
|
252
|
+
expect(true).toBe(false);
|
|
253
|
+
} catch (e: any) {
|
|
254
|
+
expect(e.code).toBe('INVALID_OWNER');
|
|
255
|
+
}
|
|
256
|
+
expect(mockPresentGooglePay).not.toHaveBeenCalled();
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('forwards account owner; resolves with transfer id string', async () => {
|
|
260
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
261
|
+
const result = await presentGooglePay({
|
|
262
|
+
amountCents: 9999,
|
|
263
|
+
owner: { type: 'account', id: 'acct_1' },
|
|
264
|
+
currencyCode: 'EUR',
|
|
265
|
+
googlePayMerchantId: 'BCR2DN4T...',
|
|
266
|
+
});
|
|
267
|
+
expect(mockPresentGooglePay).toHaveBeenCalledWith(9999, 'account', 'acct_1', 'EUR', 'BCR2DN4T...');
|
|
268
|
+
expect(result).toBe('tr_4');
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('forwards customer owner; resolves with charge intent id string', async () => {
|
|
272
|
+
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
273
|
+
await presentGooglePay({
|
|
274
|
+
amountCents: 4242,
|
|
275
|
+
owner: { type: 'customer', id: 'cus_1' },
|
|
276
|
+
});
|
|
277
|
+
expect(mockPresentGooglePay).toHaveBeenCalledWith(4242, 'customer', 'cus_1', 'USD', null);
|
|
124
278
|
});
|
|
125
279
|
|
|
126
|
-
it('
|
|
280
|
+
it('defaults currencyCode to USD and merchantId to null', async () => {
|
|
127
281
|
await initialize({ secretKey: 'sk_xxx', publishableKey: 'pk_xxx' });
|
|
128
|
-
await
|
|
129
|
-
expect(
|
|
282
|
+
await presentGooglePay({ amountCents: 100, owner: { type: 'account', id: 'acct_1' } });
|
|
283
|
+
expect(mockPresentGooglePay).toHaveBeenCalledWith(100, 'account', 'acct_1', 'USD', null);
|
|
130
284
|
});
|
|
131
285
|
});
|
|
132
286
|
|
package/src/errors.ts
CHANGED
|
@@ -8,12 +8,20 @@ export const ErrorCodes = {
|
|
|
8
8
|
NO_ROOT_VC: 'NO_ROOT_VC',
|
|
9
9
|
NO_ACTIVITY: 'NO_ACTIVITY',
|
|
10
10
|
INVALID_ITEMS: 'INVALID_ITEMS',
|
|
11
|
+
INVALID_ACCOUNT: 'INVALID_ACCOUNT',
|
|
12
|
+
INVALID_OWNER: 'INVALID_OWNER',
|
|
13
|
+
INVALID_MERCHANT_ID: 'INVALID_MERCHANT_ID',
|
|
14
|
+
INVALID_AMOUNT: 'INVALID_AMOUNT',
|
|
11
15
|
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
12
16
|
API_ERROR: 'API_ERROR',
|
|
13
17
|
PARSE_ERROR: 'PARSE_ERROR',
|
|
14
18
|
NO_RESULT: 'NO_RESULT',
|
|
15
19
|
INIT_FAILED: 'INIT_FAILED',
|
|
16
|
-
|
|
20
|
+
APPLE_PAY_UNAVAILABLE: 'APPLE_PAY_UNAVAILABLE',
|
|
21
|
+
GOOGLE_PAY_UNAVAILABLE: 'GOOGLE_PAY_UNAVAILABLE',
|
|
22
|
+
NOT_ATTESTED: 'NOT_ATTESTED',
|
|
23
|
+
PAYMENT_METHOD_FAILED: 'PAYMENT_METHOD_FAILED',
|
|
24
|
+
PAYMENT_FAILED: 'PAYMENT_FAILED',
|
|
17
25
|
} as const;
|
|
18
26
|
|
|
19
27
|
export type FrameErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
package/src/index.ts
CHANGED
|
@@ -27,9 +27,6 @@ export {
|
|
|
27
27
|
} from './native';
|
|
28
28
|
export type {
|
|
29
29
|
FrameCartItem,
|
|
30
|
-
ChargeIntent,
|
|
31
|
-
ChargeIntentStatus,
|
|
32
|
-
AuthorizationMode,
|
|
33
30
|
FrameError,
|
|
34
31
|
BillingAddress,
|
|
35
32
|
PaymentCard,
|
|
@@ -38,6 +35,7 @@ export type {
|
|
|
38
35
|
OnboardingCapability,
|
|
39
36
|
OnboardingResult,
|
|
40
37
|
OnboardingResultStatus,
|
|
38
|
+
WalletOwner,
|
|
41
39
|
ApplePayOwner,
|
|
42
40
|
PresentApplePayOptions,
|
|
43
41
|
PresentGooglePayOptions,
|