Skip to content

Commit ee9851f

Browse files
committed
Changes for v0.10.0
1 parent e25f344 commit ee9851f

File tree

5 files changed

+56
-32
lines changed

5 files changed

+56
-32
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.10.0 (Breaking change)
2+
3+
4+
* Security Improvement: Removed usage of the secret key in checkout
5+
* Removed support for bank payment (requires secret key)
6+
* Transaction initialization and verification is no longer being handled by the checkout function (requires secret key)
7+
* Handled Gateway timeout error
8+
* Returning last for digits instead full card number after payment
9+
110
## 0.9.3
211

312
* Fixed failure of web OTP on iOS devices

README.md

+32-22
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,45 @@
22

33
[![pub package](https://img.shields.io/pub/v/flutter_paystack.svg)](https://pub.dartlang.org/packages/flutter_paystack)
44

5-
A Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS.
5+
A Flutter plugin for making payments via Paystack Payment Gateway. Fully
6+
supports Android and iOS.
67

78
## :rocket: Installation
89
To use this plugin, add `flutter_paystack` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
910

1011
Then initialize the plugin preferably in the `initState` of your widget.
1112

1213
``` dart
13-
import 'package:flutter_paystack/flutter_paystack.dart'
14+
import 'package:flutter_paystack/flutter_paystack.dart';
1415
1516
class _PaymentPageState extends State<PaymentPage> {
16-
var paystackPublicKey = '[YOUR_PAYSTACK_PUBLIC_KEY]';
17-
var paystackSecretKey = '[YOUR_PAYSTACK_SECRET_KEY]';
17+
var publicKey = '[YOUR_PAYSTACK_PUBLIC_KEY]';
1818
1919
@override
2020
void initState() {
2121
PaystackPlugin.initialize(
22-
publicKey: paystackPublicKey, secretKey: paystackSecretKey);
23-
// secretKey is not needed if you're not using checkout as a payment method.
24-
//
22+
publicKey: publicKey);
2523
}
2624
}
2725
```
2826

29-
No other configuration required - the plugin works out of the box.
27+
No other configuration required&mdash;the plugin works out of the box.
3028

3129
## :heavy_dollar_sign: Making Payments
3230
There are two ways of making payment with the plugin.
33-
1. **Checkout**: This is the easy way; as the plugin handles all the processes involved in making a payment.
34-
2. **Charge Card**: This is a longer approach; you handle all callbacks and UI states on your own.
31+
1. **Checkout**: This is the easy way; as the plugin handles all the
32+
processes involved in making a payment (except transaction
33+
initialization and verification which should be done from your
34+
backend).
35+
2. **Charge Card**: This is a longer approach; you handle all callbacks
36+
and UI states.
3537

3638
### 1. :star2: Checkout (Recommended)
37-
You initialize a charge object with just an amount, email & accessCode or reference.
38-
Pass an `accessCode` only when you have [initialized the transaction](https://developers.paystack.co/reference#initialize-a-transaction) from your end otherwise, pass `reference`;
39+
You initialize a charge object with an amount, email & accessCode or
40+
reference. Pass an `accessCode` only when you have
41+
[initialized the transaction](https://developers.paystack.co/reference#initialize-a-transaction)
42+
from your backend. Otherwise, pass a `reference`.
3943

40-
Except you want the user to use a preferred checkout method, pass a one of your choosing.
4144

4245
```dart
4346
Charge charge = Charge()
@@ -46,20 +49,28 @@ There are two ways of making payment with the plugin.
4649
// or ..accessCode = _getAccessCodeFrmInitialization()
4750
..email = '[email protected]';
4851
CheckoutResponse response = await PaystackPlugin.checkout(
49-
context,
50-
method: _method,
52+
context context,
5153
charge: charge,
5254
);
5355
```
5456

55-
`PaystackPlugin.checkout()` returns `true` for a successful payment otherwise, it returns `false`.
57+
`PaystackPlugin.checkout()` returns the state and details of the
58+
payment in an instance of `CheckoutResponse` .
59+
60+
61+
It is recommended that when `PaystackPlugin.checkout()` returns, the
62+
payment should be
63+
[verified](https://developers.paystack.co/v2.0/reference#verify-transaction)
64+
on your backend.
5665

5766
### 2. :star: Charge Card
58-
You can choose to initialize the payment locally or via Paystack's backend.
67+
You can choose to initialize the payment locally or via your backend.
5968

60-
#### A. Initialize Via Paystack (Recommended)
69+
#### A. Initialize Via Your Backend (Recommended)
6170

62-
1.a. This starts by making a HTTP POST request to [paystack](https://developers.paystack.co/reference#initialize-a-transaction).
71+
1.a. This starts by making a HTTP POST request to
72+
[paystack](https://developers.paystack.co/reference#initialize-a-transaction)
73+
on your backend.
6374

6475
1.b If everything goes well, the initialization request returns a response with an `access_code`.
6576
You can then create a `Charge` object with the access code and card details. The `charge` is in turn passed to the ` PaystackPlugin.chargeCard()` function for payment:
@@ -96,10 +107,9 @@ You can then create a `Charge` object with the access code and card details. The
96107
// addressLine1: '90, Nnebisi Road, Asaba, Deleta State');
97108
}
98109
99-
_chargeCard(http.Response response) {
100-
Map<String, dynamic> responseBody = json.decode(response.body);
110+
_chargeCard(String accessCode) {
101111
var charge = Charge()
102-
..accessCode = responseBody['access_code']
112+
..accessCode = accessCode
103113
..card = _getCardFromUI();
104114
105115
PaystackPlugin.chargeCard(context,

lib/src/common/paystack.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ class PaystackPlugin {
139139
/// [onValidated] - Called when the payment completes with an unrecoverable error
140140
///
141141
/// [method] - The payment payment method to use(card, bank). It defaults to
142-
/// [CheckoutMethod.selectable] to allow the user to select
142+
/// [CheckoutMethod.selectable] to allow the user to select. Please note that this is
143+
/// just redundant pending when bank payment returns
143144
static Future<CheckoutResponse> checkout(
144145
BuildContext context, {
145146
@required Charge charge,

lib/src/model/card.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ class PaymentCard {
167167
if (cardCvc == null || cardCvc.trim().isEmpty) return false;
168168

169169
var cvcValue = cardCvc.trim();
170-
bool validLength = ((_type == null && cvcValue.length >= 3 && cvcValue.length <= 4) ||
171-
(CardType.americanExpress == _type && cvcValue.length == 4) ||
172-
(CardType.americanExpress != _type && cvcValue.length == 3));
170+
bool validLength =
171+
((_type == null && cvcValue.length >= 3 && cvcValue.length <= 4) ||
172+
(CardType.americanExpress == _type && cvcValue.length == 4) ||
173+
(CardType.americanExpress != _type && cvcValue.length == 3));
173174
return !(!CardUtils.isWholeNumberPositive(cvcValue) || !validLength);
174175
}
175176

@@ -182,7 +183,8 @@ class PaymentCard {
182183
if (StringUtils.isEmpty(cardNumber)) return false;
183184

184185
// Remove all non digits
185-
var formattedNumber = cardNumber.trim().replaceAll(new RegExp(r'[^0-9]'), '');
186+
var formattedNumber =
187+
cardNumber.trim().replaceAll(new RegExp(r'[^0-9]'), '');
186188

187189
// Verve card needs no other validation except it matched pattern
188190
if (CardType.fullPatternVerve.hasMatch(formattedNumber)) {
@@ -265,16 +267,18 @@ abstract class CardType {
265267
static final fullPatternDiscover = RegExp(r'^6(?:011|5[0-9]{2})[0-9]{12}$');
266268
static final fullPatternJCB = RegExp(r'^(?:2131|1800|35[0-9]{3})'
267269
r'[0-9]{11}$');
268-
static final fullPatternVerve = RegExp(r'^((506(0|1))|(507(8|9))|(6500))[0-9]{12,15}$');
270+
static final fullPatternVerve =
271+
RegExp(r'^((506(0|1))|(507(8|9))|(6500))[0-9]{12,15}$');
269272

270273
// Regular expression to match starting characters (aka issuer
271274
// identification number (IIN)) of the card
272275
// Source https://en.wikipedia.org/wiki/Payment_card_number
273276
static final startingPatternVisa = RegExp(r'[4]');
274-
static final startingPatternMasterCard =
275-
RegExp(r'((5[1-5])|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720))');
277+
static final startingPatternMasterCard = RegExp(
278+
r'((5[1-5])|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720))');
276279
static final startingPatternAmericanExpress = RegExp(r'((34)|(37))');
277-
static final startingPatternDinersClub = RegExp(r'((30[0-5])|(3[89])|(36)|(3095))');
280+
static final startingPatternDinersClub =
281+
RegExp(r'((30[0-5])|(3[89])|(36)|(3095))');
278282
static final startingPatternJCB = RegExp(r'(352[89]|35[3-8][0-9])');
279283
static final startingPatternVerve = RegExp(r'((506(0|1))|(507(8|9))|(6500))');
280284
static final startingPatternDiscover = RegExp(r'((6[45])|(6011))');

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_paystack
22
description: A Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS.
3-
version: 0.9.3
3+
version: 0.10.0
44
author: Wilberforce Uwadiegwu <[email protected]>
55
homepage: https://github.com/wilburt/flutter_paystack
66

0 commit comments

Comments
 (0)