payment_flutter 0.0.1-alpha.1 copy "payment_flutter: ^0.0.1-alpha.1" to clipboard
payment_flutter: ^0.0.1-alpha.1 copied to clipboard

outdated

A flutter plug-in for the native Payment library (Android and iOS).

payment_flutter #

A flutter plug-in for the native Payment library (Android and iOS).

Installation #

Add dependency to your pubspec.yaml file #

Add payment_flutter as a dependency in your pubspec.yaml file.

Android #

Open the android project inside the android folder of your project in Android studio.

1. Add token to get Terra libraries

Add TekoGoogleRegistryToken to the local.properties file (contact [email protected] to get the token).

// android/local.properties

TekoGoogleRegistry.password=<your-token>

In project build.grade (android/build.gralde file). Add the following code:

// android/build.gradle
allprojects {
    repositories {
        ...

        Properties properties = new Properties()
        properties.load(project.rootProject.file('local.properties').newDataInputStream())

        maven {
            setUrl("https://asia-southeast1-maven.pkg.dev/teko-development/teko-mobile-sdks")

            authentication {
                basic(BasicAuthentication)
            }

            credentials {
                username = "_json_key_base64"
                password = properties.getProperty('TekoGoogleRegistry.password')
            }
        }
    }
}

2. Enable dataBinding and multiDex for the app module

Add some line below to the build.gradle of app module (android/app/build.gradle file).

//...

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
// add line below
apply plugin: 'kotlin-kapt'

//...

android {
  //...

  defaultConfig {
    //...

    multiDexEnabled true  // Add this line
  }

  // Add 3 lines below to enable dataBinding
  buildFeatures {
      dataBinding true
  }

  //...

}

3. Add VNPay e-wallet to app module (if your app uses VNPay e-wallet)

Please follow the instruction in this page: https://demomb.vnpay.vn:20157/sdk/sdkwallet/index.html. Please contact Terra team if you have any concerns.

iOS #

Open the ios project insdie the android folder of your project in xcode.

1. Setup github access token for accessing Teko iOS frameworks

Please contact [email protected] to get the token

Add new environment variable to your computer with the following key: GITHUB_USER_TOKEN.

2. Add UINavigation to your iOS app

  • Open the AppDelegate.swift file.
// AppDelegate.swift

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {

        TerraApp.configure(appName: "payment-flutter") { (isSuccess, terraApp) in
            print("Terra has been configured: \(isSuccess)")
            self.doLogin(terraApp: terraApp)
        }

        GeneratedPluginRegistrant.register(with: self)

        // Begin of adding a new UINavigationController
        let controller = window?.rootViewController as! FlutterViewController

        // create and then add a new UINavigationController
        let navigationController = UINavigationController(rootViewController: controller)
        self.window.rootViewController = navigationController
        navigationController.setNavigationBarHidden(true, animated: false)
        self.window.makeKeyAndVisible()
        // End of adding a new UINavigationController

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

Please contact Terra team if you have any concerns.

Library usage #

Initialize/get an TerraPayment instance #

Static Method: TerraPayment.getInstance(String appName) → Future<TerraPayment>

Should be called in initialize phase of your app and must be called after initilizing TerraApp successful.

Pay for an order with TerraPayment #

Method: TerraPayment.payWith(PaymentUIRequest request) -> Future<PaymentUIResult>

Generate payment request

Open available methods screen

final paymentRequestBuilder = PaymentUIRequestBuilder(Order(amount: 1000, orderCode: "order-code"))
    .setMainMethod(MainMethodAll(1000))
    .setExtraOptions(ExtraOptions(shouldShowPaymentResultScreen: true));

Payment directly (without available methods screen)

final paymentRequestBuilder = PaymentUIRequestBuilder(Order(amount: 1000, orderCode: "order-code"))
    .setMainMethod(MainMethodVNPayGatewayQr(1000)) // use your expected method, but not MainMethodAll
    .setExtraOptions(ExtraOptions(shouldShowPaymentResultScreen: true));

Supported payment method:

  • MainMethodAll(int amount)
  • MainMethodVNPayGatewayQr(int amount)
  • MainMethodVNPayGatewayAtm(int amount)
  • MainMethodVNPayGatewayInternationalCard(int amount)
  • MainMethodVNPayGatewayMobileBanking(int amount)
  • MainMethodVNPayQrMms(int amount)
  • MainMethodVNPayEWallet(int amount)
  • MainMethodVNPayCustomer(int amount)
  • MainMethodVNPaySposCard(int amount)
  • MainMethodMomoGateway(int amount)
  • MainMethodCod(int amount)
  • MainMethodCash(int amount)
  • MainMethodRefInput(int amount, string methodCode)
  • MainMethodBankTransfer(int amount)
  • MainMethodInstallment(int amount)

Payment methods metadata config(Optional)

There are some methods must add more config to payment, For example VNPayEWallet. So you must be passing metadata into paymentRequestBuilder before call startUI.

paymentRequestBuilder.setMetadata(
    Metadata(
        vnPayEWallet: MetadataVnPayEWallet(
            partnerId: "0912345678", // Use phone number for partnerId, this is a recommendation from the EWallet team
            phone: "0912345678",
            name: "Nguyen Van A",
            email: "[email protected]"
        ),
    ),
);

Request payment

final terraPayment = await TerraPayment.getInstance(terraAppName);
final paymentResult = await terraPayment.payWith(paymentRequestBuilder.build());

switch (paymentResult.code) {
  case PaymentUIResultCode.success:
    // TODO
    break;
  case PaymentUIResultCode.failure:
    // TODO
    break;
  case PaymentUIResultCode.cancelled:
    // TODO: maybe ignore this case
    break;
}

Open VNPay e-wallet #

Method: TerraPayment.openVnPayEWallet(VnPayEWalletUser user) -> Future<void>

final eWalletUser = VnPayEWalletUser(
  partnerId: "0912345678", // Use phone number for partnerId, this is a recommendation from the EWallet team
  phone: "0912345678",
  name: "Nguyen Van A",
  email: "[email protected]"
)

final terraPayment = await TerraPayment.getInstance(terraAppName);
final result = terraPayment.openVnPayEWallet(eWalletUser);
1
likes
0
points
10
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter plug-in for the native Payment library (Android and iOS).

Repository

License

unknown (license)

Dependencies

flutter

More

Packages that depend on payment_flutter

Packages that implement payment_flutter