Skip to content

Commit

Permalink
Check if venmo available function
Browse files Browse the repository at this point in the history
  • Loading branch information
tvergho committed May 12, 2021
1 parent 348c6bf commit 24c1214
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
React Native integration for BrainTree Venmo payments. Currently only has Venmo enabled and only tested with iOS.

## Installation
### Podfile
Before running `pod install`, add the following lines **before** `use_native_modules!` in the Podfile.

```
pod 'Braintree', :modular_headers => true
pod 'BraintreeDropIn', '~> 8.1.4', :modular_headers => true
pod 'react-native-braintree', :podspec => '../node_modules/@dali-lab/react-native-braintree', :modular_headers => true
```

### info.plist
You must add the following to the queries schemes allowlist in your app's `info.plist`:
Expand Down Expand Up @@ -67,7 +75,7 @@ API_AVAILABLE(ios(13.0)){
## Usage
```js
import Braintree from "react-native-braintree";
import Braintree from "@dali-lab/react-native-braintree";
Braintree.config({ clientToken: YOUR_TOKEN_HERE });
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ PODS:
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- React-jsinspector (0.63.4)
- react-native-braintree (0.1.0):
- react-native-braintree (0.1.11):
- Braintree
- Braintree/Venmo
- BraintreeDropIn (~> 8.1.4)
Expand Down Expand Up @@ -406,7 +406,7 @@ SPEC CHECKSUMS:
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
react-native-braintree: b99f51e8c9d7101b686fe3903dcf98088b236983
react-native-braintree: e251cba68f7d2f8cb061ec6fb9eac95f3ceb2261
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
Expand Down
3 changes: 2 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from 'react';

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

const token = 'sandbox_d5ytzvpc_vb9254p26ccr5hk6';

Expand All @@ -14,6 +14,7 @@ export default function App() {
setInterval(() => {
setIsShown(true);
}, 2000);
Braintree.getIsVenmoInstalled().then((result) => console.log(result));
}, []);

const onComplete = (result: BTDropInResult | Error) => {
Expand Down
8 changes: 8 additions & 0 deletions ios/Braintree.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ @interface RCT_EXTERN_MODULE(BraintreeViewManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(onCompleteTransaction, RCTDirectEventBlock)

@end

@interface RCT_EXTERN_MODULE(BraintreeMethods, NSObject)

RCT_EXTERN_METHOD(getIsVenmoInstalled:(NSString)token
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

@end
20 changes: 20 additions & 0 deletions ios/Braintree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ class BraintreeView : UIView {
self.viewController?.present(dropIn!, animated: true, completion: nil)
}
}

@objc(BraintreeMethods)
class BraintreeMethods: NSObject {
@objc(getIsVenmoInstalled:withResolver:withRejecter:)
func getIsVenmoInstalled(token: String, resolve:@escaping RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
if (token.count == 0) {
resolve(false);
}
let apiClient = BTAPIClient(authorization: token)
if let apiClient = apiClient {
let venmo = BTVenmoDriver(apiClient: apiClient)
DispatchQueue.main.async {
let isAvailable = venmo.isiOSAppAvailableForAppSwitch()
resolve(isAvailable)
}
} else {
resolve(false);
}
}
}
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { SyntheticEvent } from 'react';
import { requireNativeComponent, ViewStyle } from 'react-native';
import { requireNativeComponent, ViewStyle, NativeModules } from 'react-native';

const { BraintreeMethods } = NativeModules;

export type BTDropInResult = {
isCancelled: boolean;
Expand Down Expand Up @@ -53,6 +55,11 @@ Braintree.config = ({ clientToken }: configProps): void => {
if (clientToken) token = clientToken;
};

Braintree.getIsVenmoInstalled = async (): Promise<boolean> => {
if (!token) return false;
return await BraintreeMethods.getIsVenmoInstalled(token);
};

type BraintreeViewProps = {
style?: ViewStyle;
isShown?: boolean;
Expand Down

0 comments on commit 24c1214

Please sign in to comment.