vinidpay_sdk 0.0.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

VinIDPay SDK #

pub package

VinIDPay SDK helps you handle payments with VinID iOS and Android app using Flutter.

Android SDK

iOS SDK

Requirements #

Android #

  • Minimum SDK version: 16
  • Recommend SDK version: 21 // Current minimum SDK version of VinID App
  • Minimum VinID App's version: // TBD

iOS #

  • Xcode 10+ and iOS 9.0+ Base SDK
  • iOS 9.0+ deployment target

How to install #

Android #

  • No configuration required

iOS #

Setup for app switch #

Update query scheme

To redirect users from your app to VinID App to start payment process, you must update your Info.plist file to support querying VinID App's scheme. The scheme is the app bundle ID, so if you use sandbox mode, make sure to add bundle ID of VinID UAT app also:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>com.vingroup.VinIDApp</string>
    <string>com.vingroup.VinIDApp.UAT</string>
</array>

Register a URL type

To redirect users from VinID app to your app during payment process, you must register a URL type and configure your app to handle return URLs.

  1. In Xcode, click on your project in the Project Navigator and navigate to App Target > Info > URL Types
  2. Click [+] to add a new URL type
  3. Under URL Schemes, enter your app switch return URL scheme. This scheme must start with your app's Bundle ID and be dedicated to VinID app switch returns. For example, if the app bundle ID is com.your-company.Your-App, then your URL scheme could be com.your-company.Your-App.vinidpay.

IMPORTANT: If you have multiple app targets, be sure to add the return URL type for all of the targets.

Then in your AppDelegate's application:didFinishLaunchingWithOptions: implementation, use setReturnURLScheme: with the URL type you set above.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    VinIDPay.sharedInstance.returnURLScheme = "com.your-company.Your-App.vinidpay"
    return true
}

Forward payment results

In your AppDelegate, make sure to pass the return URL to VinIDPay to handle payment results:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    VinIDPay.sharedInstance.handleReturnURL(url)
    return true
}

If your app uses SceneDelegate, you must update the delegate to handle return URL:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    for context in URLContexts {
        VinIDPay.sharedInstance.handleReturnURL(context.url)
    }
}

Usage #

PropertyDescriptionType
orderIdYour Order IDString
signatureYour SignatureString
sandboxModeSandbox Modebool

Utilities #

We support some utility methods to help you work better with VinIDPay SDK:

  • Validate if VinID App is installed or not.
Future<void> isVinIdAppInstalled(bool sandboxMode) async {
  bool _status;
  _status = await VinidpaySdk.isVinIdAppInstalled(sandboxMode);
  print(_status);
}
  • Open VinID App on Store:
void openVinIDInstallPage(bool sandboxMode) {
  VinidpaySdk.openVinIDInstallPage(sandboxMode);
}

Example #


import 'package:vinidpay_sdk/vinidpay_sdk.dart';

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> proceedPayment(
  String orderId,
  String signature,
  bool sandboxMode,
) async {
  VinidpaySdkStatus _status;
  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
    _status = await VinidpaySdk.proceedPayment(
      orderId,
      signature,
      sandboxMode,
    );
  } on PlatformException {
    _status = VinidpaySdkStatus.UNKNOW;
  }

  // If the widget was removed from the tree while the asynchronous platform
  // message was in flight, we want to discard the reply rather than calling
  // setState to update our non-existent appearance.
  if (!mounted) return;

  //Doing something
  switch (_status) {
    case VinidpaySdkStatus.SUCCESS:
  
    case VinidpaySdkStatus.ABORT:
  
    case VinidpaySdkStatus.FAIL:
  
    case VinidpaySdkStatus.UNKNOW:
  
    default:
  
  }

}

Future<void> isVinIdAppInstalled(bool sandboxMode) async {
  bool _status;
  _status = await VinidpaySdk.isVinIdAppInstalled(sandboxMode);
  print(_status);
}

openVinIDInstallPage(bool sandboxMode) {
  VinidpaySdk.openVinIDInstallPage(sandboxMode);
}
    

0.0.2 #

  • Update README.

0.0.1+1 #

  • Update README.

0.0.1 #

  • Initial release of VinIDPay SDK.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:vinidpay_sdk/vinidpay_sdk.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _paymentStatus = 'Unknown';
  bool _sandboxMode = true;
  final _orderIdController = TextEditingController();
  final _signatureController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('VinIDPay SDK'),
        ),
        body: Padding(
          padding: EdgeInsets.all(16),
          child: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                TextField(
                  controller: _orderIdController,
                  decoration: InputDecoration(
                    labelText: 'Order ID',
                  ),
                ),
                TextField(
                  controller: _signatureController,
                  decoration: InputDecoration(
                    labelText: 'Signature',
                  ),
                ),
                FlatButton(
                  color: Colors.red,
                  onPressed: () {
                    if (_orderIdController.text == '' ||
                        _signatureController.text == '') {
                      return;
                    }

                    final String _orderId = _orderIdController.text;
                    final String _signature = _signatureController.text;

                    proceedPayment(
                      _orderId,
                      _signature,
                      _sandboxMode,
                    );
                  },
                  child: Text(
                    'Proceed Payment',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                FlatButton(
                  color: Colors.red,
                  onPressed: () {
                    isVinIdAppInstalled(_sandboxMode);
                  },
                  child: Text(
                    'isVinIdAppInstalled ',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                FlatButton(
                  color: Colors.red,
                  onPressed: () {
                    openVinIDInstallPage(_sandboxMode);
                  },
                  child: Text(
                    'openVinIDInstallPage',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                SizedBox(height: 8),
                Text('Sandbox Mode: $_sandboxMode'),
                SizedBox(height: 8),
                Text('Payment Status: $_paymentStatus'),
              ],
            ),
          ),
        ),
      ),
    );
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> proceedPayment(
    String orderId,
    String signature,
    bool sandboxMode,
  ) async {
    VinidpaySdkStatus _status;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      _status = await VinidpaySdk.proceedPayment(
        orderId,
        signature,
        sandboxMode,
      );
    } on PlatformException {
      _status = VinidpaySdkStatus.UNKNOW;
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

//    switch (_status) {
//      case VinidpaySdkStatus.SUCCESS:
//
//      case VinidpaySdkStatus.ABORT:
//
//      case VinidpaySdkStatus.FAIL:
//
//      case VinidpaySdkStatus.UNKNOW:
//
//      default:
//
//    }

    setState(() {
      _paymentStatus = _status.toString();
    });
  }

  Future<void> isVinIdAppInstalled(bool sandboxMode) async {
    bool _status;
    _status = await VinidpaySdk.isVinIdAppInstalled(sandboxMode);
    print(_status);
  }

  void openVinIDInstallPage(bool sandboxMode) {
    VinidpaySdk.openVinIDInstallPage(sandboxMode);
  }

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  vinidpay_sdk: ^0.0.2+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:vinidpay_sdk/vinidpay_sdk.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:vinidpay_sdk/vinidpay_sdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:vinidpay_sdk/vinidpay_sdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:vinidpay_sdk/vinidpay_sdk.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:vinidpay_sdk/vinidpay_sdk.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [vinidpay_sdk] that is in a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test