Skip to content

Commit 24c1214

Browse files
committed
Check if venmo available function
1 parent 348c6bf commit 24c1214

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
React Native integration for BrainTree Venmo payments. Currently only has Venmo enabled and only tested with iOS.
44

55
## Installation
6+
### Podfile
7+
Before running `pod install`, add the following lines **before** `use_native_modules!` in the Podfile.
8+
9+
```
10+
pod 'Braintree', :modular_headers => true
11+
pod 'BraintreeDropIn', '~> 8.1.4', :modular_headers => true
12+
pod 'react-native-braintree', :podspec => '../node_modules/@dali-lab/react-native-braintree', :modular_headers => true
13+
```
614

715
### info.plist
816
You must add the following to the queries schemes allowlist in your app's `info.plist`:
@@ -67,7 +75,7 @@ API_AVAILABLE(ios(13.0)){
6775
## Usage
6876
6977
```js
70-
import Braintree from "react-native-braintree";
78+
import Braintree from "@dali-lab/react-native-braintree";
7179
7280
Braintree.config({ clientToken: YOUR_TOKEN_HERE });
7381

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ PODS:
227227
- React-cxxreact (= 0.63.4)
228228
- React-jsi (= 0.63.4)
229229
- React-jsinspector (0.63.4)
230-
- react-native-braintree (0.1.0):
230+
- react-native-braintree (0.1.11):
231231
- Braintree
232232
- Braintree/Venmo
233233
- BraintreeDropIn (~> 8.1.4)
@@ -406,7 +406,7 @@ SPEC CHECKSUMS:
406406
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
407407
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
408408
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
409-
react-native-braintree: b99f51e8c9d7101b686fe3903dcf98088b236983
409+
react-native-braintree: e251cba68f7d2f8cb061ec6fb9eac95f3ceb2261
410410
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
411411
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
412412
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0

example/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22

33
import { StyleSheet, View } from 'react-native';
4-
import Braintree, { BTDropInResult } from 'react-native-braintree';
4+
import Braintree, { BTDropInResult } from '@dali-lab/react-native-braintree';
55

66
const token = 'sandbox_d5ytzvpc_vb9254p26ccr5hk6';
77

@@ -14,6 +14,7 @@ export default function App() {
1414
setInterval(() => {
1515
setIsShown(true);
1616
}, 2000);
17+
Braintree.getIsVenmoInstalled().then((result) => console.log(result));
1718
}, []);
1819

1920
const onComplete = (result: BTDropInResult | Error) => {

ios/Braintree.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ @interface RCT_EXTERN_MODULE(BraintreeViewManager, RCTViewManager)
77
RCT_EXPORT_VIEW_PROPERTY(onCompleteTransaction, RCTDirectEventBlock)
88

99
@end
10+
11+
@interface RCT_EXTERN_MODULE(BraintreeMethods, NSObject)
12+
13+
RCT_EXTERN_METHOD(getIsVenmoInstalled:(NSString)token
14+
withResolver:(RCTPromiseResolveBlock)resolve
15+
withRejecter:(RCTPromiseRejectBlock)reject)
16+
17+
@end

ios/Braintree.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,23 @@ class BraintreeView : UIView {
7373
self.viewController?.present(dropIn!, animated: true, completion: nil)
7474
}
7575
}
76+
77+
@objc(BraintreeMethods)
78+
class BraintreeMethods: NSObject {
79+
@objc(getIsVenmoInstalled:withResolver:withRejecter:)
80+
func getIsVenmoInstalled(token: String, resolve:@escaping RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
81+
if (token.count == 0) {
82+
resolve(false);
83+
}
84+
let apiClient = BTAPIClient(authorization: token)
85+
if let apiClient = apiClient {
86+
let venmo = BTVenmoDriver(apiClient: apiClient)
87+
DispatchQueue.main.async {
88+
let isAvailable = venmo.isiOSAppAvailableForAppSwitch()
89+
resolve(isAvailable)
90+
}
91+
} else {
92+
resolve(false);
93+
}
94+
}
95+
}

src/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { SyntheticEvent } from 'react';
2-
import { requireNativeComponent, ViewStyle } from 'react-native';
2+
import { requireNativeComponent, ViewStyle, NativeModules } from 'react-native';
3+
4+
const { BraintreeMethods } = NativeModules;
35

46
export type BTDropInResult = {
57
isCancelled: boolean;
@@ -53,6 +55,11 @@ Braintree.config = ({ clientToken }: configProps): void => {
5355
if (clientToken) token = clientToken;
5456
};
5557

58+
Braintree.getIsVenmoInstalled = async (): Promise<boolean> => {
59+
if (!token) return false;
60+
return await BraintreeMethods.getIsVenmoInstalled(token);
61+
};
62+
5663
type BraintreeViewProps = {
5764
style?: ViewStyle;
5865
isShown?: boolean;

0 commit comments

Comments
 (0)