Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android not doing Payment Controller callback #56

Closed
bhgames opened this issue Aug 9, 2017 · 1 comment
Closed

Android not doing Payment Controller callback #56

bhgames opened this issue Aug 9, 2017 · 1 comment

Comments

@bhgames
Copy link

bhgames commented Aug 9, 2017

I'm using your v1.1.1 because our project is on RN 0.25.1 and I lost 6 hours trying to upgrade it to 0.40+ and then to 0.39, to no avail. it's just too big a challenge to undertake right now. I've got your older xplat working perfectly with iOS, but in Android, it never does the callback to return the nonce. I've tried in Android Nougat and O, to no avail. It just closes the drop-in ui.

Do you have any idea why this might be happening?

My code is thus:

`
setupBraintree() {

let that = this;

let nav = this.props.navigator;

fetch(Config().apiUrl + '/api/v2/payments/get_token', {method: "GET", headers: {'Authorization': that.props.authentication_token} })
.then((response) => response.json())
.then((responseData) => {
  var clientToken = responseData.client_token;
  BTClient.setup(clientToken).then(() => {
    BTClient.showPaymentViewController().then((nonce) => {
      fetch(Config().apiUrl + '/api/v2/payments',
       {
         method: 'POST',
         headers: {
           'Accept': 'application/json',
           'Content-Type': 'application/json',
           'Authorization': that.props.authentication_token
         },
         body: JSON.stringify({
           payment_method_nonce: nonce,
           vehicle_id: that.props.vehicleId
         })
       })
       .then((response) => response.json())
       .then((responseData) => {
          if(responseData.success == true)
           {
             that.setState({
                visible: false
               });
             nav.push({ indent:'PaymentThanks' });
           } else {
             Alert.alert(
                 'Error',
                 responseData.message,
                 [
                   {text: "OK", onPress: () => nav.pop()},
                 ]
               );
           }
        }).catch(function(err) {
         Alert.alert(
             'Error',
             "An error occurred, please try again.",
           )
       }).finally(() => that.setState({visible: false}))
    }).catch(function(err) {
      if(err.message) {
         Alert.alert(
           'Error',
           "Payment failed due to: " + err.message,
         )
      }
    }).done();
  });
})

}
`

@bhgames
Copy link
Author

bhgames commented Aug 9, 2017

I went through the slow, plodding journey from 0.25.2 to 0.29 and upgraded this xplat from 1.1.1 to 2.1.0 in the process(I didnt upgrade it until 0.28 or 0.29). I did one version at a time, and took these notes on errors I came across, in case anybody can use them. A lot of them are specific to my app and they're from the README I wrote. Once I got to 0.29 the callback for the nonce began firing on Android, though it sometimes still hangs on loading the form. Working on that now.

UPGRADE NOTES

These are issues I had to ultimately correct as I went from version to version. Left here to help you debug any merge conflicts.

Generally to upgrade, I would upgrade React-Native in package.json, then npm install. It would tell me if it needed a new version of React. I would then upgrade react. Then I would check out the release notes for this RN tag to see if there were any changes
I needed to make manually.

Then I would cd into ios folder and run pod install to update the embedded CocoaPods project from which apparently Reactnative
is spawned. Though it also should be a linked project directly in Libraries. Very odd, still figuring that one out.

Then I do a clean/build and fix any code errors(mostly _refreshControl), and try to do a checkout in iOS. Then I do a Sync Gradle
Project and Build in Android Studio.

0.26

LD Flags Issue

OTHER_LDFLAGS = (
  "-ObjC",
  "-lc++",
); 

in project.pbxproj

-lc++ is important, you can do through Xcode also: Project (Not Target) Settings > Other Linker Flags

_refreshControl

Need to turn _refreshControl into refreshControl to compile

0.27

Previous Changes Required Again

  • _refreshControl Fix

New Component Source

Can't import Component from react-native anymore, must use react's component

Strict Mode Issue

Got this error on android, "Strict mode does not allow function declaration", traced to here:
facebook/react-native#11389

To fix:
In node_modules/react-native/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js

function normalizePrefix(moduleName: string) ...

REPLACE WITH:

const normalizePrefix = function(moduleName: string)

In /node_modules/react-native/Libraries/Utilities/UIManager.js:

function normalizePrefix(moduleName: string) ...

REPLACE WITH:

const normalizePrefix = function(moduleName: string)

In /node_modules/react-native/.../InitializeJavascriptAppEngine.js:

function handleError(e, isFatal) ...

REPLACE WITH:

var handleError = function(e, isFatal)

0.28

Previous Changes Required Again

  • _refreshControl Fix
  • Strict Mode Issue

CSS Changes

Note: I didn't any all of these, but if you see Flex issues, this may be it.

Updates to css-layout leading to many fixes but requiring some breaking changes:
flex styling property behavior now behaves slightly differently. If you previously used flex: 1 where not necessary this change will likely break your layout as the measuring behavior is slightly different than before due to performance optimizations. Removing that unnecessary flex: 1 will solve your layout in most cases.
Due to performance tweaks flexWrap: wrap no longer works together with alignItems: 'stretch' (the default). If you use flexWrap: wrap you probably will want to add the alignItems: 'flex-start' style as well.

New MainApplication.java

Now you need to clean the gradle cache. ./gradlew clean inside the android folder.

0.29

Previous Changes Required Again

  • Strict Mode Issue

props is undefined in _rootView call in AppDelegate

Need to remove props, place nil in there.

undefined symbol _CPLog

Get this on Xcode build for Codepush. Make sure to ensure that libPods-caradviseui.a is the first library in Link Binary with Libraries.

Replace BTAnalyticsMetaData import with Metadata

Only in iOS. Data is not supposed to be capitalized on the import of the Braintree library, so you need to make that happen.

Newer version of CodePush

Had to change CodePush to 1.17 and change it's invocations in MainApplication.java. Refer to this chart:

https://github.com/Microsoft/react-native-code-push#supported-react-native-platforms

and this link:

https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-android.md

Newer version of XPLAT/Changing of This

Also upgraded braintree xplat to 1.2.0, involved this change in MainApplication.java:

mBraintreePackage = new BraintreePackage(MainApplication.this),

Also need to use

MainApplication.this

everywhere instead of

this

@bhgames bhgames closed this as completed Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant