Skip to content

Commit

Permalink
modified the changlog, readme and format of the code of flutter format .
Browse files Browse the repository at this point in the history
  • Loading branch information
rdnasim committed Sep 23, 2022
1 parent fb78350 commit d74091a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 74 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
* Changed the parameter of BkashPayment
* Added to as isSandbox is true/false
* Modified the README.md and example of code more comment also style of formatting.

## 0.1.2
* Modified the README.md
* Flutter formats the code [flutter format .]
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<h1 align="center">bKash(BD) Mobile Finance Payment Gateway Flutter Package</h1>
<p align="center" >

[//]: # (<img src="#" />)
[//]: # (<img src="#" />)

</p>

[![Pub](https://img.shields.io/pub/v/flutter_bkash.svg)](https://pub.dartlang.org/packages/flutter_bkash)
Expand All @@ -29,7 +26,7 @@ This will add a line like this to your package's `pubspec.yaml` (and run an impl

```
dependencies:
flutter_bkash: ^0.1.2
flutter_bkash: ^0.1.3
```

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Expand Down
141 changes: 80 additions & 61 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ class HomePageState extends State<HomePage> {
controller: _amountController,
decoration: const InputDecoration(
hintText: "1240",
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(5)), borderSide: BorderSide(color: Colors.grey)),
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(5)),
borderSide: BorderSide(color: Colors.grey)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.pink, width: 2.0),
),
Expand Down Expand Up @@ -131,74 +134,90 @@ class HomePageState extends State<HomePage> {
),
onPressed: () {
String amount = _amountController.text.trim();
String intent = _intent == Intent.sale ? "sale" : "authorization";
String intent =
_intent == Intent.sale ? "sale" : "authorization";

if (amount.isEmpty) {
// if the amount is empty then show the snack-bar
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text("Amount is empty. Without amount you can't pay. Try again")));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text(
"Amount is empty. Without amount you can't pay. Try again")));
return;
}
// remove focus from TextField to hide keyboard
focusNode!.unfocus();
// Goto BkashPayment page & pass the params
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => BkashPayment(
/// depend isSandbox (true/false)
isSandbox: true,
/// amount of your bkash payment
amount: amount,
/// intent would be (sale / authorization)
intent: intent,
// 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();
},
)));
/// depend isSandbox (true/false)
isSandbox: true,

/// amount of your bkash payment
amount: amount,

/// intent would be (sale / authorization)
intent: intent,
// 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();
},
)));
},
),
)
Expand All @@ -207,4 +226,4 @@ class HomePageState extends State<HomePage> {
),
);
}
}
}
2 changes: 0 additions & 2 deletions example/lib/utils/style.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';


class Style {

static basicToast(String toast) {
return Fluttertoast.showToast(
msg: toast,
Expand Down
18 changes: 15 additions & 3 deletions lib/flutter_bkash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
typedef PaymentStatus<A, B> = void Function(A status, B data);

class BkashPayment extends StatefulWidget {

/// default the sandbox is true
final bool isSandbox;

/// amount of the payment through bKash
final String amount;

/// intent as sale or authorization
final String intent;

/// reference no is order no or any other unique string for payment
final String? refNo;

/// BDT
final String? currency;

/// if the user have own access token for verify payment
final String? accessToken;

/// create bkash url based on sandbox or production
final String createBKashUrl;

/// execute bkash url based on sandbox or production
final String executeBKashUrl;

/// javascript script url for load modal window for bkash payment
final String scriptUrl;

/// return the payment status
final PaymentStatus<String, dynamic> paymentStatus;

Expand Down Expand Up @@ -74,8 +82,12 @@ class BkashPaymentState extends State<BkashPayment> {
},
'paymentConfig': {
/// sandbox is sandbox or live mode, change the value depend on it
'createCheckoutURL': widget.isSandbox ? BkashConstants.sandboxCreateUrlBKash : widget.createBKashUrl,
'executeCheckoutURL': widget.isSandbox? BkashConstants.sandboxExecuteUrlBKash : widget.executeBKashUrl,
'createCheckoutURL': widget.isSandbox
? BkashConstants.sandboxCreateUrlBKash
: widget.createBKashUrl,
'executeCheckoutURL': widget.isSandbox
? BkashConstants.sandboxExecuteUrlBKash
: widget.executeBKashUrl,
'scriptUrl': widget.scriptUrl,
},
'accessToken': widget.accessToken ?? '',
Expand Down
12 changes: 8 additions & 4 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class BkashConstants {
static const sandboxCreateUrlBKash = 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/create';
static const sandboxExecuteUrlBKash = 'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute';
static const sandboxScriptUrl = 'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js';
static const productionScriptUrl = 'https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-pay.js';
static const sandboxCreateUrlBKash =
'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/create';
static const sandboxExecuteUrlBKash =
'https://merchantserver.sandbox.bka.sh/api/checkout/v1.2.0-beta/payment/execute';
static const sandboxScriptUrl =
'https://scripts.sandbox.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-sandbox.js';
static const productionScriptUrl =
'https://scripts.pay.bka.sh/versions/1.2.0-beta/checkout/bKash-checkout-pay.js';
}

0 comments on commit d74091a

Please sign in to comment.