Giter Site home page Giter Site logo

codeboxrcodehub / flutter-bkash Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 14.0 2.69 MB

Flutter/dart package for payment gateway bKash (Bangladesh)

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

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

Kotlin 0.15% Swift 0.48% Objective-C 0.05% Dart 99.33%
bangladesh bkash dart flutter payment-gateway bkash-payment-gateway payment

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.2.0

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';

Features

  • Pay using bKash without an agreement
  • Create a bKash agreement for future payments
  • Pay using bKash with an agreement

Usage

Official Link for API documentation and demo checkout

Initialize the FlutterBkash instance:

Sandbox

final flutterBkash = FlutterBkash();

Production

final flutterBkash = FlutterBkash(
	credentials: BkashCredentials(
    username: "app_username",
    password: "app_password",
    appKey: "app_key",
    appSecret: "app_secret",
    isSandbox: false,
  ),
);

Make sure to replace the provided credentials with your own bKash sandbox or production credentials depending on your development environment.

Pay without Agreement

To make a payment without an agreement, use the pay method:

Request

final result = await flutterBkash.pay(
      context: context, // BuildContext context
      amount: 100.0, // amount as double
      merchantInvoiceNumber: "invoice123",
);

Response

BkashPaymentResponse(
	trxId: AFI60BAC94, 
	payerReference:  , 
	paymentId: TR0011fd4uZMS1687062024354, 
	customerMsisdn: 01877722345, 
	merchantInvoiceNumber: tranId, 
	_executeTime: 2023-06-18T10:22:31:623 GMT+0600
)

Create Agreement

To create a new agreement, use the createAgreement method:

Request

final result = await flutterBkash.createAgreement(context: context);

Response

BkashAgreementResponse(
	payerReference:  , 
	paymentId: TR0000RCHQGmX1687063332607, 
	customerMsisdn: 01877722345, 
	agreementId: TokenizedMerchant02P1AIJ7G1687063381235, 
	_executeTime: 2023-06-18T10:43:01:235 GMT+0600
)

Pay with Agreement

To make a payment with an existing agreement, use the payWithAgreement method:

Request

final result = await flutterBkash.payWithAgreement(
  context: context, // BuildContext context
  amount: 100.0, // type as double
  agreementId: "agreement123",
  merchantInvoiceNumber: "invoice123",
);

Response

BkashPaymentResponse(
	trxId: AFI60BAC94, 
	payerReference:  , 
	paymentId: TR0011fd4uZMS1687062024354, 
	customerMsisdn: 01877722345, 
	merchantInvoiceNumber: tranId, 
	_executeTime: 2023-06-18T10:22:31:623 GMT+0600
)

Error Handling

The methods mentioned above may throw a BkashFailure exception in case of an error. You can catch and handle the exception using a try-catch block:

try {
  // Make a payment or create an agreement
} on BkashFailure catch (e) {
  // Handle the error
  print(e.message);
}

Examples for see the /example folder.

Here is the example code link

Example Video Demo

example_demo_video.mp4

Importance Notes

Contributing

Core Maintainer

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 2023 Codeboxr.com Team. We are not affiliated with bKash and don't give any guarantee.

flutter-bkash's People

Contributors

dev-masum avatar manchumahara avatar rdnasim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flutter-bkash's Issues

Create Payment Response , Execute Payment Response also needed for sandbox validation, which is absent in this package

This package only return us the response like :
BkashPaymentResponse(trxId: AGP10BWXOB, payerReference: , paymentId: TR0011hi0k0wq1690281134967, customerMsisdn: 01619777282, merchantInvoiceNumber: tranId, _executeTime: 2023-07-25T16:33:53:131 GMT+0600)

But as a merchant i need these 2 response to validate my sandbox merchant account and then i will get the live payment credentials from the pgwbkash merchant website
(1) Need the Create Payment Response like this -
{
"statusCode": "0000",
"statusMessage": "Successful",
"paymentID": "TR0011ON1565154754797",
"bkashURL": "https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=TR0011O N1565154754797&hash=Cg-Z)16.)d5E_BLhHIMmoxcm.LDMVQ.oI9o_v6qQU32nc7i2mUtDbP0_cVtIswrS-Rct1rJzJWEIPLk6cXFgRBT)rn6Q7!E.u91565154754979&mode=0011&apiVersion=v1.2.0-beta",
"callbackURL": "yourURL.com",
"successCallbackURL": "yourURL.com?paymentID=TR0011ON1565154754797&status=success",
"failureCallbackURL": "yourURL.com?paymentID=TR0011ON1565154754797&status=failure",
"cancelledCallbackURL": "yourURL.com?paymentID=TR0011ON1565154754797&status=cancel",
"amount": "15",
"intent": "sale",
"currency": "BDT",
"paymentCreateTime": "2019-08-07T11:12:34:978 GMT+0600",
"transactionStatus": "Initiated",
"merchantInvoiceNumber": "MER1231"
}
(2) Need the Execute Payment Response
like this :
{
"statusCode": "0000",
"statusMessage": "Successful",
"paymentID": "TR0011ON1565154754797",
"payerReference": "01770618575",
"customerMsisdn": "01770618575",
"trxID": "6H7801QFYM",
"amount": "15",
"transactionStatus": "Completed",
"paymentExecuteTime": "2019-08-07T11:15:56:336 GMT+0600",
"currency": "BDT",
"intent": "sale",
"merchantInvoiceNumber": "MER1231"
}

use enum instead of string for payment status

Using String

status == 'paymentSuccess'
status == 'paymentFailed'
status == 'paymentError'
status == 'paymentClose'

Enum

enum PaymentStatus {
  Success,
  Failed,
  Error,
  Close
}

Using enum

switch (status) {
    case PaymentStatus.Success:
      // do something
      break;
    case PaymentStatus.Failed:
      // do something
      break;
    case PaymentStatus.Error:
      // do something
      break;
    case PaymentStatus.Close:
      // do something
      break;
  }

No payment window popups when isSandbox is set to false.

This is where I'm stuck. Nothing is happening after this.
image
This is my code. (copy pasted from the repo)

BkashPayment(
      isSandbox: false,
      amount: '20',
      intent: 'sale',
      // accessToken: '',
      currency: 'BDT',
      createBKashUrl:
          'https://tokenized.pay.bka.sh/v1.2.0-beta/tokenized/checkout/create',
      executeBKashUrl:
          'https://tokenized.pay.bka.sh/v1.2.0-beta/tokenized/checkout/execute',
      scriptUrl: 'https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout.js',
      paymentStatus: (status, data) {
        log('return status => $status');
        log('return data => $data');
      {...}
    );

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.