Skip to content

DevCrew-io/2checkout-flutter

Repository files navigation

2Checkout Flutter SDK

pub package license

The 2Checkout Flutter SDK wrapper for 2checkout-android-sdk and 2checkout-ios-sdk allows you to build delightful payment experiences in your native Android and iOS. We provide powerful and customizable UI screens, widget, and method channels for native functions access that can be used out-of-the-box to collect your users' payment details.

The 2Checkout Flutter SDK is designed to be easy to integrate into your application. With the 2Checkout Flutter SDK, you can easily tokenize card details, handle 3D Secure verification, and authorize PayPal payments.

Alt Text

Features

  • Simplified Security: We make it simple for you to collect sensitive data such as credit card numbers and remain PCI compliant. This means the sensitive data is sent directly to 2Checkout (Now Verifone) instead of passing through your server. For more information, see our Integration Security Guide.
  • Payment methods: Accepting more payment methods helps your business expand its global reach and improve checkout conversion.
  • SCA-Ready: The SDK automatically performs native 3D Secure authentication if needed to comply with Strong Customer Authentication.
  • Native UI: We provide native screens and elements to securely collect payment details on Android and iOS.
  • Pre-built payments UI: Learn how to integrate Payment Sheet, the new pre-built payments UI for mobile apps. This pre-built UI lets you accept cards and Paypal out of the box.

Supported Payment Methods

  • Credit Card Tokenization
  • 3D Secure Authorization
  • Paypal Payment Authorization

Recommended usage

If you're selling digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store's in-app purchase APIs. See Apple's and Google's guidelines for more information. For all other scenarios you can use this SDK to process payments via 2checkout.

Requirements

Android Requirements

  • Use Android 4.0 (API level 19) and above.
  • Utilize Kotlin version 1.7.0 and above.
  • Ensure you are using an up-to-date Android Gradle build tools version.
  • Use an up-to-date Gradle version accordingly.
  • Remember to rebuild the app after making the above changes, as these changes may not take effect with hot reload.

iOS Requirements

  • Xcode 10.2 or higher
  • Swift 5.0 or higher
  • iOS 12 or higher

If you encounter difficulties while setting up the package on Android, join the discussion for support.

Installation

To install the 2Checkout Flutter plugin, use the following Dart package command:

dart pub add twocheckout_flutter

Dart API

The library offers several methods for handling 2Checkout-related actions:

Callback when payment form will show.

 void paymentFormWillShow();

Callback when payment form will close.

  void paymentFormWillClose();

Callback when a payment method did selected.

  void paymentMethodSelected(PaymentMethodType paymentMethod);

Callback when the payment process failed with error.

  void paymentFailedWithError(String message);

Callback when card input form is completed and call 2Checkout API here for post order with the received token.

  void onPaymentFormComplete(PaymentFormResult paymentFormResult);

Callback when payment is canceled.

  void authorizePaymentDidCancel();

Callback when 3D auth will be completed and here you can call 2Checkout order status ("orders/(refNo)") API here to check the payment transactio status.

   void authorizePaymentDidCompleteAuthorizing(Map<dynamic, dynamic> result);

Usage

Initialization of 2Checkout SDK

  _twoCheckoutFlutterPlugin.setTwoCheckoutCredentials(secretKey: "Your_Key", merchantCode: "Your_Code");

Start 2Checkout Payment Flow

  _twoCheckoutFlutterPlugin.showPaymentMethods(price: 10.5, currency: "USD", local: "en");

Authorize the Card 3DS or PayPal payment using the authorizePaymentWithOrderResponse method.

  /// Authorizes a payment with the post order response.
  /// If need to authorized payment depending on the following key contain in post order api response
  /// Credit Card: response -> PaymentDetails -> PaymentMethod -> Authorize3DS exist
  /// Paypal: response -> PaymentDetails -> PaymentMethod -> RedirectURL exist
  ///
  /// @param url The Redirect URL for payment authorization. --> Credit Card: Authorize3DS.getString("Href"),  Paypal: PaymentMethod.getString("RedirectURL")
  /// @param parameters --> Credit Card: ['avng8apitoken' : 'Authorize3DS -> Params -> avng8apitoken'],  Paypal: [:] none optional
  /// @param successReturnUrl The URL to redirect to on successful payment (default is an empty string).
  /// @param cancelReturnUrl The URL to redirect to if the payment is canceled (default is an empty string).
  ///
  _twoCheckoutFlutterPlugin.authorizePaymentWithOrderResponse(
      String url, Map<dynamic, dynamic> parameters,
      {String successReturnUrl = "", String cancelReturnUrl = ""});

Card tokenisation without UI

A method that can be used to generate a payment token based on provided card data.

    TokenResult result = await _twoCheckoutFlutterPlugin.createToken(name: "CARD_HOLDER_NAME", creditNumber: "CARD_NUMBER", cvv: "xxx", expiryDate: "xx/xx");

Running the Example App

To run the example app, follow these steps:

  1. Navigate to the example folder: cd example.
  2. Install the dependencies: flutter pub get.
  3. Set up environment variables for the Flutter app and a local backend.
  4. Obtain your secret and Merchant key from the 2Checkout dashboard.
  5. Set the keys in the function called _twoCheckoutFlutterPlugin.setTwoCheckoutCredentials("secretKey", "merchant_key").

Here is the list of test cards on the official 2Checkout platform.

  1. Run Flutter: flutter run.

Contributing

You can help us make this project better by contributing. Feel free to open a new issue or submit a pull request.

Author

DevCrew I/O

Connect with Us:

devcrew.io mycompany DevCrew-io

About

A flutter plugin for 2Checkout payment gateway

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •