Coder Social home page Coder Social logo

aolmez / flutter-bkash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codeboxrcodehub/flutter-bkash

0.0 0.0 0.0 820 KB

Flutter/dart package for payment gateway bKash (Bangladesh)

Home Page: https://pub.dev/packages/flutter_bkash

License: BSD 3-Clause "New" or "Revised" License

Objective-C 0.13% Kotlin 0.43% Dart 61.07% CSS 3.79% Swift 1.39% HTML 33.20%

flutter-bkash's Introduction

bKash(BD) Mobile Finance Payment Gateway Flutter Package

Pub License PRs Welcome Maintenance Open Source Love svg1

This is a Flutter package for bKash BD Payment Gateway. This package can be used in flutter project. We created this package while working for a project and thought to release for all so that it helps.

โš ๏ธ Please note that, you have to contact with bKash sales team for any kind of dev or production access keys or tokens. We don't provide any test account or access keys or don't contact us for such

Check the package in github and also available in flutter/dart package

How to use:

Depend on it, Run this command With Flutter:

$ flutter pub add flutter_bkash

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
    flutter_bkash: ^0.1.3

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

Now in your Dart code, you can use:

import 'package:flutter_bkash/flutter_bkash.dart';

Usage

Official Link for API documentation and demo checkout

Examples for see the /example folder.

Here is the example code

BkashPayment(  
    // depend isSandbox (true/false)
    isSandbox: true,
    // amount of your bkash payment
    amount: '20',
    /// intent would be (sale / authorization)
    intent: 'sale',
    // accessToken: '', /// if the user have own access token for verify payment
    // currency: 'BDT',
    /// bkash url for create payment, when you implement on you project then it be change as your production create url, [when you send it on sandbox mode, send it as empty string '' or anything]
    createBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/create',
    /// bkash url for execute payment, , when you implement on you project then it be change as your production create url, [when you send it on sandbox mode, send it as empty string '' or anything]
    executeBKashUrl: 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute',
    /// for script url, when you implement on production the set it live script js (https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-pay.js)
    scriptUrl: 'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js',
    /// the return value from the package
    /// status => 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose'
    /// data => return value of response
     
    paymentStatus: (status, data) {
    dev.log('return status => $status');  
    dev.log('return data => $data');

    /// when payment success  
    if (status == 'paymentSuccess') {
        if (data['transactionStatus'] == 'Completed') {
            Style.basicToast('Payment Success');  
        }
    }  
      
    /// when payment failed  
    else if (status == 'paymentFailed') {
        if (data.isEmpty) {
            Style.errorToast('Payment Failed');
        } else if (data[0]['errorMessage'].toString() != 'null'){
            Style.errorToast("Payment Failed ${data[0]['errorMessage']}");
        } else {  
            Style.errorToast("Payment Failed");
        }
    }  
      
    /// when payment on error  
    else if (status == 'paymentError') {
        Style.errorToast(jsonDecode(data['responseText'])['error']);
    }  
      
    /// when payment close on demand closed the windows  
    else if (status == 'paymentClose') {
        if (data == 'closedWindow') {
            Style.errorToast('Failed to payment, closed screen');
        } else if (data == 'scriptLoadedFailed') {
            Style.errorToast('Payment screen loading failed');
        }
    }
    /// back to screen to pop()
    Navigator.of(context).pop();
    },
)

Importance Notes

  • Read the comments in the example of code
  • See the documents and demo checkout bKash API Specifications, bKash Payment Checkout Demo
  • intent - it would be 'sale' or 'authorization'
  • Payment status return as 'paymentSuccess', 'paymentFailed', 'paymentError', 'paymentClose', find on this keyword of the payment status, then you get the data of response on specific status.

Contributing

Contributions to the flutter_bkash package are welcome. Please note the following guidelines before submitting your pull request.

  • Follow Effective Dart: Style coding standards.
  • Read bKash API documentations first.Please contact with bKash for their api documentation and sandbox access.

License

flutter_bkash package is licensed under the BSD 3-Clause License.

Copyright 2022 Codeboxr.com Team. We are not affiliated with bKash and don't give any guarantee.

flutter-bkash's People

Contributors

manchumahara avatar rdnasim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.