Skip to content

Commit

Permalink
Working version on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgiuliani committed Mar 1, 2019
1 parent 32a62ed commit a85b924
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ android {
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

lintOptions {
disable 'InvalidPackage'
}

dependencies {
compile 'com.braintreepayments.api:drop-in:3.7.1'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import io.flutter.plugin.common.PluginRegistry.Registrar;

public class FlutterBraintreePlugin implements MethodCallHandler, PluginRegistry.ActivityResultListener {
private final Registrar mRegistrar;
private final static int REQUEST_CODE = 1;
private final Activity mActivity;
private final static int REQUEST_CODE = 11;
private Result mResult;

private FlutterBraintreePlugin(Registrar registrar) {
this.mRegistrar = registrar;
this.mRegistrar.addActivityResultListener(this);
this.mActivity = registrar.activity();
registrar.addActivityResultListener(this);
}

public static void registerWith(Registrar registrar) {
Expand All @@ -33,12 +34,10 @@ public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("showDropIn")) {
String clientToken = call.argument("clientToken");

DropInRequest dropInRequest = new DropInRequest()
.clientToken(clientToken);
DropInRequest dropInRequest = new DropInRequest().clientToken(clientToken);

mRegistrar.activity().startActivityForResult(dropInRequest.getIntent(mRegistrar.activity()), REQUEST_CODE);

result.success("OK");
mResult = result;
mActivity.startActivityForResult(dropInRequest.getIntent(mActivity), REQUEST_CODE);
} else {
result.notImplemented();
}
Expand All @@ -49,14 +48,16 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
// use the result to update your UI and send the payment method nonce to your server
mResult.success(result.getPaymentMethodNonce().getNonce());
} else if (resultCode == Activity.RESULT_CANCELED) {
// the user canceled
mResult.error("CANCELLED", "Purchase process was cancelled.", null);
} else {
// handle errors here, an exception may be available in
Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
mResult.error("ERROR", error.getMessage(), null);
}

mResult = null;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${applicationId}.braintree" />
<data android:scheme="info.keepinmind.flutterbraintreeexample.braintree" />
</intent-filter>
</activity>
</application>
Expand Down

0 comments on commit a85b924

Please sign in to comment.