applepay-rn 0.0.1
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/ApplepayRn.podspec +22 -0
- package/LICENSE +20 -0
- package/README.md +551 -0
- package/android/build.gradle +67 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/applepayrn/ApplepayRnPackage.kt +17 -0
- package/android/src/main/java/com/applepayrn/ApplepayRnView.kt +15 -0
- package/android/src/main/java/com/applepayrn/ApplepayRnViewManager.kt +41 -0
- package/ios/ApplePayBridge.swift +68 -0
- package/ios/ApplepayRnView.h +14 -0
- package/ios/ApplepayRnView.mm +110 -0
- package/lib/module/ApplePayView.js +70 -0
- package/lib/module/ApplePayView.js.map +1 -0
- package/lib/module/NativeApplePayView.js +7 -0
- package/lib/module/NativeApplePayView.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ApplePayView.d.ts +17 -0
- package/lib/typescript/src/ApplePayView.d.ts.map +1 -0
- package/lib/typescript/src/NativeApplePayView.d.ts +26 -0
- package/lib/typescript/src/NativeApplePayView.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +71 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +177 -0
- package/src/ApplePayView.tsx +118 -0
- package/src/NativeApplePayView.ts +20 -0
- package/src/index.tsx +16 -0
- package/src/types.ts +91 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, { useRef, useCallback } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
type StyleProp,
|
|
6
|
+
type ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import NativeApplePayView from './NativeApplePayView';
|
|
9
|
+
import type { ApplePayConfiguration } from './types';
|
|
10
|
+
|
|
11
|
+
export interface TapApplePayProps {
|
|
12
|
+
configuration: ApplePayConfiguration;
|
|
13
|
+
style?: StyleProp<ViewStyle>;
|
|
14
|
+
onReady?: () => void;
|
|
15
|
+
onClick?: () => void;
|
|
16
|
+
onSuccess?: (data: string) => void;
|
|
17
|
+
onChargeCreated?: (data: string) => void;
|
|
18
|
+
onOrderCreated?: (data: string) => void;
|
|
19
|
+
onCancel?: () => void;
|
|
20
|
+
onError?: (error: string) => void;
|
|
21
|
+
onMerchantValidation?: (data: string) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function TapApplePay({
|
|
25
|
+
configuration,
|
|
26
|
+
style,
|
|
27
|
+
onReady,
|
|
28
|
+
onClick,
|
|
29
|
+
onSuccess,
|
|
30
|
+
onChargeCreated,
|
|
31
|
+
onOrderCreated,
|
|
32
|
+
onCancel,
|
|
33
|
+
onError,
|
|
34
|
+
onMerchantValidation,
|
|
35
|
+
}: Readonly<TapApplePayProps>): React.ReactElement | null {
|
|
36
|
+
const inProgress = useRef(false);
|
|
37
|
+
|
|
38
|
+
const handleReady = useCallback(() => {
|
|
39
|
+
onReady?.();
|
|
40
|
+
}, [onReady]);
|
|
41
|
+
|
|
42
|
+
const handleClick = useCallback(
|
|
43
|
+
(_event: { nativeEvent: object }) => {
|
|
44
|
+
if (inProgress.current) return;
|
|
45
|
+
inProgress.current = true;
|
|
46
|
+
onClick?.();
|
|
47
|
+
},
|
|
48
|
+
[onClick]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const handleSuccess = useCallback(
|
|
52
|
+
(event: { nativeEvent: { data: string } }) => {
|
|
53
|
+
inProgress.current = false;
|
|
54
|
+
onSuccess?.(event.nativeEvent.data);
|
|
55
|
+
},
|
|
56
|
+
[onSuccess]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const handleChargeCreated = useCallback(
|
|
60
|
+
(event: { nativeEvent: { data: string } }) => {
|
|
61
|
+
onChargeCreated?.(event.nativeEvent.data);
|
|
62
|
+
},
|
|
63
|
+
[onChargeCreated]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const handleOrderCreated = useCallback(
|
|
67
|
+
(event: { nativeEvent: { data: string } }) => {
|
|
68
|
+
onOrderCreated?.(event.nativeEvent.data);
|
|
69
|
+
},
|
|
70
|
+
[onOrderCreated]
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const handleCancel = useCallback(
|
|
74
|
+
(_event: { nativeEvent: object }) => {
|
|
75
|
+
inProgress.current = false;
|
|
76
|
+
onCancel?.();
|
|
77
|
+
},
|
|
78
|
+
[onCancel]
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const handleError = useCallback(
|
|
82
|
+
(event: { nativeEvent: { error: string } }) => {
|
|
83
|
+
inProgress.current = false;
|
|
84
|
+
onError?.(event.nativeEvent.error);
|
|
85
|
+
},
|
|
86
|
+
[onError]
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const handleMerchantValidation = useCallback(
|
|
90
|
+
(event: { nativeEvent: { data: string } }) => {
|
|
91
|
+
onMerchantValidation?.(event.nativeEvent.data);
|
|
92
|
+
},
|
|
93
|
+
[onMerchantValidation]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
if (Platform.OS !== 'ios') {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<NativeApplePayView
|
|
102
|
+
style={[style, styles.minHeight]}
|
|
103
|
+
configuration={JSON.stringify(configuration)}
|
|
104
|
+
onApplePayReady={handleReady}
|
|
105
|
+
onApplePayClick={handleClick}
|
|
106
|
+
onApplePaySuccess={handleSuccess}
|
|
107
|
+
onApplePayChargeCreated={handleChargeCreated}
|
|
108
|
+
onApplePayOrderCreated={handleOrderCreated}
|
|
109
|
+
onApplePayCancel={handleCancel}
|
|
110
|
+
onApplePayError={handleError}
|
|
111
|
+
onApplePayMerchantValidation={handleMerchantValidation}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const styles = StyleSheet.create({
|
|
117
|
+
minHeight: { minHeight: 48 },
|
|
118
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import { codegenNativeComponent } from 'react-native';
|
|
3
|
+
// @ts-ignore – no .d.ts for this path; codegen requires this exact import
|
|
4
|
+
import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
|
|
5
|
+
|
|
6
|
+
export interface NativeApplePayViewProps extends ViewProps {
|
|
7
|
+
configuration: string;
|
|
8
|
+
onApplePayReady?: DirectEventHandler<Readonly<{}>>;
|
|
9
|
+
onApplePayClick?: DirectEventHandler<Readonly<{}>>;
|
|
10
|
+
onApplePaySuccess?: DirectEventHandler<Readonly<{ data: string }>>;
|
|
11
|
+
onApplePayChargeCreated?: DirectEventHandler<Readonly<{ data: string }>>;
|
|
12
|
+
onApplePayOrderCreated?: DirectEventHandler<Readonly<{ data: string }>>;
|
|
13
|
+
onApplePayCancel?: DirectEventHandler<Readonly<{}>>;
|
|
14
|
+
onApplePayError?: DirectEventHandler<Readonly<{ error: string }>>;
|
|
15
|
+
onApplePayMerchantValidation?: DirectEventHandler<Readonly<{ data: string }>>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default codegenNativeComponent<NativeApplePayViewProps>(
|
|
19
|
+
'NativeApplePayView'
|
|
20
|
+
);
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { TapApplePay } from './ApplePayView';
|
|
2
|
+
export type { TapApplePayProps } from './ApplePayView';
|
|
3
|
+
export type {
|
|
4
|
+
ApplePayConfiguration,
|
|
5
|
+
ApplePayMerchant,
|
|
6
|
+
ApplePayCustomer,
|
|
7
|
+
ApplePayContact,
|
|
8
|
+
ApplePayPhone,
|
|
9
|
+
ApplePayName,
|
|
10
|
+
ApplePayInterface,
|
|
11
|
+
ApplePayAcceptance,
|
|
12
|
+
ApplePayTransaction,
|
|
13
|
+
ApplePayShippingMethod,
|
|
14
|
+
ApplePayItem,
|
|
15
|
+
ApplePayFeatures,
|
|
16
|
+
} from './types';
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export interface ApplePayPhone {
|
|
2
|
+
countryCode: string;
|
|
3
|
+
number: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ApplePayContact {
|
|
7
|
+
email?: string;
|
|
8
|
+
phone?: ApplePayPhone;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ApplePayName {
|
|
12
|
+
lang: string;
|
|
13
|
+
first: string;
|
|
14
|
+
last: string;
|
|
15
|
+
middle?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ApplePayCustomer {
|
|
19
|
+
id?: string;
|
|
20
|
+
name?: ApplePayName[];
|
|
21
|
+
contact?: ApplePayContact;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ApplePayMerchant {
|
|
25
|
+
id?: string;
|
|
26
|
+
identifier?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ApplePayInterface {
|
|
30
|
+
locale?: 'en' | 'ar';
|
|
31
|
+
theme?: 'dark' | 'light';
|
|
32
|
+
edges?: 'curved' | 'straight';
|
|
33
|
+
type?: 'book' | 'buy' | 'check-out' | 'pay' | 'plain' | 'subscribe';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ApplePayShippingMethod {
|
|
37
|
+
label: string;
|
|
38
|
+
detail: string;
|
|
39
|
+
amount: string;
|
|
40
|
+
identifier: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ApplePayItem {
|
|
44
|
+
type?: 'final' | 'pending';
|
|
45
|
+
label: string;
|
|
46
|
+
amount: string;
|
|
47
|
+
paymentTiming?: 'immediate' | 'recurring' | 'deferred' | 'automaticReload';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ApplePayTransaction {
|
|
51
|
+
amount: string;
|
|
52
|
+
currency: string;
|
|
53
|
+
couponCode?: string;
|
|
54
|
+
shipping?: ApplePayShippingMethod[];
|
|
55
|
+
items?: ApplePayItem[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ApplePayAcceptance {
|
|
59
|
+
supportedBrands?: (
|
|
60
|
+
| 'amex'
|
|
61
|
+
| 'mada'
|
|
62
|
+
| 'masterCard'
|
|
63
|
+
| 'visa'
|
|
64
|
+
| 'chinaUnionPay'
|
|
65
|
+
| 'discover'
|
|
66
|
+
| 'electron'
|
|
67
|
+
| 'jcb'
|
|
68
|
+
| 'maestro'
|
|
69
|
+
)[];
|
|
70
|
+
supportedCards?: ('credit' | 'debit')[];
|
|
71
|
+
supportedRegions?: ('LOCAL' | 'REGIONAL' | 'GLOBAL')[];
|
|
72
|
+
supportedCountries?: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ApplePayFeatures {
|
|
76
|
+
supportsCouponCode?: boolean;
|
|
77
|
+
shippingContactFields?: ('name' | 'phone' | 'email')[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ApplePayConfiguration {
|
|
81
|
+
/** Tap Payments public key */
|
|
82
|
+
publicKey: string;
|
|
83
|
+
/** Type of token to generate */
|
|
84
|
+
scope: 'AppleToken' | 'TapToken';
|
|
85
|
+
merchant: ApplePayMerchant;
|
|
86
|
+
customer: ApplePayCustomer;
|
|
87
|
+
interface?: ApplePayInterface;
|
|
88
|
+
acceptance?: ApplePayAcceptance;
|
|
89
|
+
transaction?: ApplePayTransaction;
|
|
90
|
+
features?: ApplePayFeatures;
|
|
91
|
+
}
|