This commit is contained in:
Condi
2026-02-27 00:58:05 +08:00
parent 1c49093a73
commit 9cf4fc6eda
9 changed files with 46 additions and 26 deletions

View File

@@ -71,10 +71,13 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.21"
// Braintree Dependencies - Latest versions
// Braintree
implementation 'com.braintreepayments.api:drop-in:6.16.0'
implementation 'com.braintreepayments.api:card:4.45.0'
implementation 'com.braintreepayments.api:data-collector:4.45.0'
implementation 'com.braintreepayments.api:google-pay:4.45.0'
implementation 'com.braintreepayments.api:venmo:4.45.0'
// Google Pay
implementation 'com.google.android.gms:play-services-wallet:19.2.1'
}

View File

@@ -20,7 +20,9 @@ import BraintreeDropIn, {
const BRAINTREE_CLIENT_TOKEN = 'sandbox_g42y39zw_348pk9cgf3bgyw2b';
const App = () => {
const [paymentResult, setPaymentResult] = useState<PaymentResult | null>(null);
const [paymentResult, setPaymentResult] = useState<PaymentResult | null>(
null
);
const [loading, setLoading] = useState(false);
const [deviceData, setDeviceData] = useState<string>('');
@@ -42,7 +44,10 @@ const App = () => {
const result = await BraintreeDropIn.show(options);
setPaymentResult(result);
showAlert('Success!', `Payment nonce received: ${result.nonce.substring(0, 20)}...`);
showAlert(
'Success!',
`Payment nonce received: ${result.nonce.substring(0, 20)}...`
);
console.log('Payment Result:', result);
} catch (error: any) {
if (error.message === 'USER_CANCELLATION') {
@@ -96,7 +101,10 @@ const App = () => {
// Test 3: Google Pay (Android only)
const handleGooglePay = async () => {
if (Platform.OS !== 'android') {
showAlert('Android Only', 'Google Pay is only available on Android devices');
showAlert(
'Android Only',
'Google Pay is only available on Android devices'
);
return;
}
@@ -134,10 +142,10 @@ const App = () => {
try {
const options: DropInOptions = {
clientToken: BRAINTREE_CLIENT_TOKEN,
orderTotal: 100.00,
orderTotal: 100.0,
currencyCode: 'USD',
threeDSecure: {
amount: 100.00,
amount: 100.0,
},
venmo: true,
payPal: true,
@@ -192,7 +200,9 @@ const App = () => {
const handleCollectDeviceData = async () => {
setLoading(true);
try {
const data = await BraintreeDropIn.collectDeviceData(BRAINTREE_CLIENT_TOKEN);
const data = await BraintreeDropIn.collectDeviceData(
BRAINTREE_CLIENT_TOKEN
);
setDeviceData(data);
showAlert('Device Data Collected', `Length: ${data.length} characters`);
console.log('Device Data:', data.substring(0, 100) + '...');
@@ -234,7 +244,7 @@ const App = () => {
const options: DropInOptions = {
clientToken: BRAINTREE_CLIENT_TOKEN,
vaultManager: true,
orderTotal: 25.00,
orderTotal: 25.0,
currencyCode: 'USD',
};
@@ -299,7 +309,6 @@ const App = () => {
<ScrollView
contentContainerStyle={styles.scrollContent}
showsVerticalScrollIndicator={false}>
<View style={styles.header}>
<Text style={styles.title}>Braintree Drop-In</Text>
<Text style={styles.subtitle}>React Native Turbo Module Example</Text>
@@ -314,7 +323,7 @@ const App = () => {
<View style={styles.section}>
<Text style={styles.sectionTitle}>Basic Tests</Text>
<TestButton
title="1. Show Drop-In UI"
onPress={handleBasicDropIn}
@@ -342,7 +351,7 @@ const App = () => {
<View style={styles.section}>
<Text style={styles.sectionTitle}>Platform-Specific</Text>
<TestButton
title={`5. Apple Pay (iOS Only)`}
onPress={handleApplePay}
@@ -364,7 +373,7 @@ const App = () => {
<View style={styles.section}>
<Text style={styles.sectionTitle}>Advanced Features</Text>
<TestButton
title="8. 3D Secure Authentication"
onPress={handle3DSecure}
@@ -381,7 +390,7 @@ const App = () => {
{paymentResult && (
<View style={styles.resultContainer}>
<Text style={styles.resultTitle}>Last Payment Result:</Text>
<View style={styles.resultRow}>
<Text style={styles.resultLabel}>Type:</Text>
<Text style={styles.resultValue}>{paymentResult.type}</Text>
@@ -389,7 +398,9 @@ const App = () => {
<View style={styles.resultRow}>
<Text style={styles.resultLabel}>Description:</Text>
<Text style={styles.resultValue}>{paymentResult.description}</Text>
<Text style={styles.resultValue}>
{paymentResult.description}
</Text>
</View>
<View style={styles.resultRow}>
@@ -432,7 +443,6 @@ const App = () => {
Remember to replace BRAINTREE_CLIENT_TOKEN with your actual token
</Text>
</View>
</ScrollView>
</SafeAreaView>
);

View File

@@ -1 +1 @@
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNBraintreeDropIn.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAgDpCC,gCAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNBraintreeDropIn.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAkDpCC,gCAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}

View File

@@ -1 +1 @@
{"version":3,"names":["_NativeRNBraintreeDropIn","_interopRequireDefault","require","e","__esModule","default","BraintreeDropIn","show","options","NativeRNBraintreeDropIn","fetchMostRecentPaymentMethod","clientToken","tokenizeCard","cardInfo","collectDeviceData","exports"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAgE,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAKjD,MAAMG,eAAe,CAAC;EACnC;AACF;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,OAAsB,EAA0B;IAC1D,OAAOC,gCAAuB,CAACF,IAAI,CAACC,OAAO,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOE,4BAA4BA,CACjCC,WAAmB,EACY;IAC/B,OAAOF,gCAAuB,CAACC,4BAA4B,CAACC,WAAW,CAAC;EAC1E;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,YAAYA,CACjBD,WAAmB,EACnBE,QAAkB,EACM;IACxB,OAAOJ,gCAAuB,CAACG,YAAY,CAACD,WAAW,EAAEE,QAAQ,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiBA,CAACH,WAAmB,EAAmB;IAC7D,OAAOF,gCAAuB,CAACK,iBAAiB,CAACH,WAAW,CAAC;EAC/D;AACF;AAACI,OAAA,CAAAV,OAAA,GAAAC,eAAA","ignoreList":[]}
{"version":3,"names":["_NativeRNBraintreeDropIn","_interopRequireDefault","require","e","__esModule","default","BraintreeDropIn","show","options","NativeRNBraintreeDropIn","fetchMostRecentPaymentMethod","clientToken","tokenizeCard","cardInfo","collectDeviceData","exports"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAgE,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AASjD,MAAMG,eAAe,CAAC;EACnC;AACF;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,OAAsB,EAA0B;IAC1D,OAAOC,gCAAuB,CAACF,IAAI,CAACC,OAAO,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOE,4BAA4BA,CACjCC,WAAmB,EACY;IAC/B,OAAOF,gCAAuB,CAACC,4BAA4B,CAACC,WAAW,CAAC;EAC1E;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,YAAYA,CACjBD,WAAmB,EACnBE,QAAkB,EACM;IACxB,OAAOJ,gCAAuB,CAACG,YAAY,CAACD,WAAW,EAAEE,QAAQ,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiBA,CAACH,WAAmB,EAAmB;IAC7D,OAAOF,gCAAuB,CAACK,iBAAiB,CAACH,WAAW,CAAC;EAC/D;AACF;AAACI,OAAA,CAAAV,OAAA,GAAAC,eAAA","ignoreList":[]}

View File

@@ -1 +1 @@
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNBraintreeDropIn.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAgDlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeRNBraintreeDropIn.ts"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAkDlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}

View File

@@ -1 +1 @@
{"version":3,"names":["NativeRNBraintreeDropIn","BraintreeDropIn","show","options","fetchMostRecentPaymentMethod","clientToken","tokenizeCard","cardInfo","collectDeviceData"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,uBAAuB,MAAM,2BAA2B;AAK/D,eAAe,MAAMC,eAAe,CAAC;EACnC;AACF;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,OAAsB,EAA0B;IAC1D,OAAOH,uBAAuB,CAACE,IAAI,CAACC,OAAO,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,4BAA4BA,CACjCC,WAAmB,EACY;IAC/B,OAAOL,uBAAuB,CAACI,4BAA4B,CAACC,WAAW,CAAC;EAC1E;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,YAAYA,CACjBD,WAAmB,EACnBE,QAAkB,EACM;IACxB,OAAOP,uBAAuB,CAACM,YAAY,CAACD,WAAW,EAAEE,QAAQ,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiBA,CAACH,WAAmB,EAAmB;IAC7D,OAAOL,uBAAuB,CAACQ,iBAAiB,CAACH,WAAW,CAAC;EAC/D;AACF","ignoreList":[]}
{"version":3,"names":["NativeRNBraintreeDropIn","BraintreeDropIn","show","options","fetchMostRecentPaymentMethod","clientToken","tokenizeCard","cardInfo","collectDeviceData"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,uBAAuB,MAAM,2BAA2B;AAS/D,eAAe,MAAMC,eAAe,CAAC;EACnC;AACF;AACA;AACA;AACA;EACE,OAAOC,IAAIA,CAACC,OAAsB,EAA0B;IAC1D,OAAOH,uBAAuB,CAACE,IAAI,CAACC,OAAO,CAAC;EAC9C;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,4BAA4BA,CACjCC,WAAmB,EACY;IAC/B,OAAOL,uBAAuB,CAACI,4BAA4B,CAACC,WAAW,CAAC;EAC1E;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,OAAOC,YAAYA,CACjBD,WAAmB,EACnBE,QAAkB,EACM;IACxB,OAAOP,uBAAuB,CAACM,YAAY,CAACD,WAAW,EAAEE,QAAQ,CAAC;EACpE;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiBA,CAACH,WAAmB,EAAmB;IAC7D,OAAOL,uBAAuB,CAACQ,iBAAiB,CAACH,WAAW,CAAC;EAC/D;AACF","ignoreList":[]}

View File

@@ -39,11 +39,12 @@ Pod::Spec.new do |s|
end
# Braintree Dependencies
# s.dependency 'Braintree', '~> 6.0'
# s.dependency 'BraintreeDropIn', '~> 9.0'
# s.dependency 'Braintree/DataCollector', '~> 6.0'
# s.dependency 'Braintree/ApplePay', '~> 6.0'
# s.dependency 'Braintree/Venmo', '~> 6.0'
s.dependency 'BraintreeDropIn', '9.12.2'
s.dependency 'Braintree/Core', '5.26.0'
s.dependency 'Braintree/Card', '5.26.0'
s.dependency 'Braintree/DataCollector', '5.26.0'
s.dependency 'Braintree/ApplePay', '5.26.0'
s.dependency 'Braintree/Venmo', '5.26.0'
s.swift_version = '5.0'
end

View File

@@ -42,7 +42,9 @@ export interface PaymentResult {
export interface Spec extends TurboModule {
show(options: DropInOptions): Promise<PaymentResult>;
fetchMostRecentPaymentMethod(clientToken: string): Promise<PaymentResult | null>;
fetchMostRecentPaymentMethod(
clientToken: string
): Promise<PaymentResult | null>;
tokenizeCard(clientToken: string, cardInfo: CardInfo): Promise<PaymentResult>;
collectDeviceData(clientToken: string): Promise<string>;
}

View File

@@ -1,5 +1,9 @@
import NativeRNBraintreeDropIn from './NativeRNBraintreeDropIn';
import type { DropInOptions, CardInfo, PaymentResult } from './NativeRNBraintreeDropIn';
import type {
DropInOptions,
CardInfo,
PaymentResult,
} from './NativeRNBraintreeDropIn';
export type { DropInOptions, CardInfo, PaymentResult };