flutter_braintree 0.5.0 copy "flutter_braintree: ^0.5.0" to clipboard
flutter_braintree: ^0.5.0 copied to clipboard

outdated

Flutter plugin that wraps the native Braintree SDKs. Enables payments with credit cards, PayPal, Google Pay and more.

Braintree for Flutter #

A Flutter plugin that wraps the native Braintree SDKs. Unlike other plugins, this plugin not only lets you start Braintree's native Drop-in UI, but also allows you to create your own custom Flutter UI with Braintree functionality.

Custom UI is still early in development and does not yet work on iOS!

Installation #

Add flutter_braintree to your pubspec.yaml file:

dependencies:
  ...
  flutter_braintree: ^0.5.0

Android #

You must migrate to AndroidX.
In /app/build.gradle, set your minSdkVersion to at least 21.

PayPal / Venmo / 3D Secure

In order for this plugin to support PayPal, Venmo or 3D Secure payments, you must allow for the browser switch by adding an intent filter to your AndroidManifest.xml (inside the <application> body):

<activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <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" />
    </intent-filter>
</activity>

Important: Your app's URL scheme must begin with your app's package ID and end with .braintree. For example, if the Package ID is com.your-company.your-app, then your URL scheme should be com.your-company.your-app.braintree. ${applicationId} is automatically applied with your app's package when using Gradle. Note: The scheme you define must use all lowercase letters. If your package contains underscores, the underscores should be removed when specifying the scheme in your Android Manifest.

Google Pay

Add the wallet enabled meta-data tag to your AndroidManifest.xml (inside the <application> body):

<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>

iOS #

Warning: Device data collection is not yet supported for iOS.

PayPal / Venmo / 3D Secure

In your App Delegate or your Runner project, you need to specify the URL scheme for redirecting payments as following:

BTAppSwitch.setReturnURLScheme("com.your-company.your-app.braintree")

Moreover, you need to specify the same URL scheme in your Info.plist:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLName</key>
        <string>com.your-company.your-app.braintree</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>com.your-company.your-app.braintree</string>
        </array>
    </dict>
</array>

See the official Braintree documentation for a more detailed explanation.

Usage #

First, import the plugin:

import 'package:flutter_braintree/flutter_braintree.dart';

Your own custom UI #

Warning: This feature is only implemented for Android.

Credit cards

Create a credit card request object:

final request = BraintreeCreditCardRequest(
  cardNumber: '4111111111111111',
  expirationMonth: '12',
  expirationYear: '2021',
);

Then ask Braintree to tokenize the credit card:

BraintreePaymentMethodNonce result = await Braintree.tokenizeCreditCard(
   '<Insert your tokenization key or client token here>',
   request,
);
print(result.nonce);

PayPal

Create a PayPal request object:

final request = BraintreePayPalRequest(amount: '13.37');

Or, for the Vault flow:

final request = BraintreePayPalRequest(
  billingAgreementDescription: 'I hearby agree that flutter_braintree is great.',
);

Then launch the PayPal request:

BraintreePaymentMethodNonce result = await Braintree.requestPaypalNonce(
   '<Insert your tokenization key or client token here>',
   request,
);
print(result.nonce);

Braintree's native drop-in #

Create a drop-in request object:

final request = BraintreeDropInRequest(
  clientToken: '<Insert your client token here>',
  collectDeviceData: true,
  googlePaymentRequest: BraintreeGooglePaymentRequest(
    totalPrice: '4.20',
    currencyCode: 'USD',
    billingAddressRequired: false,
  ),
  paypalRequest: BraintreePayPalRequest(
    amount: '4.20',
    displayName: 'Example company',
  ),
);

Then launch the drop-in:

BraintreeDropInResult result = await BraintreeDropIn.start(request);

Access the payment nonce:

if (result != null) {
  print('Nonce: ${result.paymentMethodNonce.nonce}');
} else {
  print('Selection was canceled.');
}

See BraintreeDropInRequest and BraintreeDropInResult for more documentation.

184
likes
0
pub points
96%
popularity

Publisher

verified publisherbyte-sapling.io

Flutter plugin that wraps the native Braintree SDKs. Enables payments with credit cards, PayPal, Google Pay and more.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, meta

More

Packages that depend on flutter_braintree