Skip to content

Commit bc520e6

Browse files
committed
Updated Readme
1 parent 933e32b commit bc520e6

File tree

1 file changed

+51
-64
lines changed

1 file changed

+51
-64
lines changed

README.md

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,65 @@
1-
# Paystack Plugin for Flutter
1+
# :credit_card: Paystack Plugin for Flutter
22

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

55
A Flutter plugin for making payments via Paystack Payment Gateway. Completely supports Android and iOS.
66

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

1010
Then initialize the plugin preferably in the `initState` of your widget.
1111

1212
``` dart
1313
import 'package:flutter_paystack/flutter_paystack.dart'
1414
15-
class PaymentPage extends StatefulWidget {
16-
@override
17-
State<StatefulWidget> createState() => new _PaymentPageState();
18-
}
19-
2015
class _PaymentPageState extends State<PaymentPage> {
2116
var paystackPublicKey = '[YOUR_PAYSTACK_PUBLIC_KEY]';
17+
var paystackSecretKey = '[YOUR_PAYSTACK_SECRET_KEY]';
2218
2319
@override
2420
void initState() {
25-
PaystackPlugin.initialize(publicKey: paystackPublicKey);
26-
super.initState();
27-
}
28-
29-
@override
30-
Widget build(BuildContext context) {
31-
// Return your widgets
21+
PaystackPlugin.initialize(
22+
publicKey: paystackPublicKey, secretKey: paystackSecretKey);
23+
// secretKey is not needed if you're not using checkout as a payment method.
24+
//
3225
}
3326
}
3427
```
3528

36-
No other configuration required - the plugin should work out of the box.
29+
No other configuration required - the plugin works out of the box.
30+
31+
## :heavy_dollar_sign: Making Payments
32+
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.
35+
36+
### 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+
40+
Except you want the user to use a preferred checkout method, pass a one of your choosing.
3741

38-
## Making Payments
42+
```dart
43+
Charge charge = Charge()
44+
..amount = 10000
45+
..reference = _getReference()
46+
// or ..accessCode = _getAccessCodeFrmInitialization()
47+
..email = 'customer@email.com';
48+
bool success = await PaystackPlugin.checkout(
49+
context,
50+
method: _method,
51+
charge: charge,
52+
);
53+
```
3954

55+
`PaystackPlugin.checkout()` returns `true` for a successful payment otherwise, it returns `false`.
56+
57+
### 2. :star: Charge Card
4058
You can choose to initialize the payment locally or via Paystack's backend.
4159

42-
### 1. Initialize Via Paystack (Recommended)
43-
1.a. This starts by making a HTTP POST request to `https://api.paystack.co/transaction/initialize`
44-
with the amount(in kobo), reference, etc in the request body and your paystack secret key in request header.
45-
The request looks like this:
60+
#### A. Initialize Via Paystack (Recommended)
4661

47-
``` dart
48-
// Required imports
49-
import 'dart:async';
50-
import 'dart:convert';
51-
import 'package:http/http.dart' as http;
52-
53-
initTransaction() async {
54-
var url = 'https://api.paystack.co/transaction/initialize';
55-
56-
Map<String, String> headers = {
57-
'Authorization': 'Bearer $[YOUR_PAYSTACK_SECRET_KEY]',
58-
};
59-
60-
Map<String, String> body = {
61-
'reference': '[YOUR_GENERATED_REFERENCE]',
62-
'amount': 500000.toString(), // Amount must always be in kobo
63-
'email': 'user@email.com'
64-
};
65-
66-
http.Response response =
67-
await http.post(url, body: body, headers: headers);
68-
// Charge card
69-
_chargeCard(response.body);
70-
}
71-
```
72-
Please check the [official documentation](https://developers.paystack.co/reference#initialize-a-transaction) for the full details of payment initialization.
62+
1.a. This starts by making a HTTP POST request to [paystack](https://developers.paystack.co/reference#initialize-a-transaction).
7363

7464
1.b If everything goes well, the initialization request returns a response with an `access_code`.
7565
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:
@@ -137,7 +127,7 @@ You can then create a `Charge` object with the access code and card details. The
137127

138128

139129

140-
### 2. Initialize Locally
130+
#### 2. Initialize Locally
141131
Just send the payment details to `PaystackPlugin.chargeCard`
142132
```dart
143133
// Set transaction params directly in app (note that these params
@@ -154,12 +144,14 @@ Just send the payment details to `PaystackPlugin.chargeCard`
154144
```
155145

156146

157-
## Validating Card Details
158-
You are expected to build the UI for your users to enter their payment details.
147+
## :wrench: :nut_and_bolt: Validating Card Details
148+
You are expected but not required to build the UI for your users to enter their payment details.
159149
For easier validation, wrap the **TextFormField**s inside a **Form** widget. Please check this article on
160150
[validating forms on Flutter](https://medium.freecodecamp.org/how-to-validate-forms-and-user-input-the-easy-way-using-flutter-e301a1531165)
161151
if this is new to you.
162152

153+
**NOTE:** You don't have to pass a card object to ``Charge``. The plugin will call-up a UI for the user to input their card.
154+
163155
You can validate the fields with these methods:
164156
#### card.validNumber
165157
This method helps to perform a check if the card number is valid.
@@ -178,32 +170,27 @@ Method to check if the card is valid. Always do this check, before charging the
178170
This method returns an estimate of the string representation of the card type(issuer).
179171

180172

181-
## chargeCard
182-
Charging with the **PaystackPlugin** is quite straightforward. It requires the following arguments.
183-
1. `context`: your UI **BuildContext**. It's used by the plugin for showing dialogs for the user to take a required action, e.g inputting OTP.
184-
2. `charge`: You provide the payment details (`PaymentCard`, `amount` `email` etc) to an instance of the `Charge` object.
185-
3. `beforeValidate`: Pre-validation callback.
186-
4. `onSuccess`: callbacks for a successful payment.
187-
4. `onError`: callback for when an error occurs in the transaction. Provides you with a reference to the error object.
188-
189-
190-
## Verifying Transactions
173+
## :heavy_check_mark: Verifying Transactions
191174
This is quite easy. Just send a HTTP GET request to `https://api.paystack.co/transaction/verify/$[TRANSACTION_REFERENCE]`.
192175
Please, check the [official documentaion](https://developers.paystack.co/reference#verifying-transactions) on verifying transactions.
193176

194-
## Testing your implementation
177+
## :helicopter: Testing your implementation
195178
Paystack provides tons of [payment cards](https://developers.paystack.co/docs/test-cards) for testing.
196179

197-
## Running Example project
180+
## :arrow_forward: Running Example project
198181
For help getting started with Flutter, view the online [documentation](https://flutter.io/).
199182

200183
An [example project](https://github.com/wilburt/flutter_paystack/tree/master/example) has been provided in this plugin.
201184
Clone this repo and navigate to the **example** folder. Open it with a supported IDE or execute `flutter run` from that folder in terminal.
202185

203-
## Contributing, Issues and Bug Reports
186+
## :pencil: Contributing, :disappointed: Issues and :bug: Bug Reports
204187
The project is open to public contribution. Please feel very free to contribute.
205-
Experienced an issue or want to report a bug? Please, [report it here](https://github.com/wilburt/flutter_paystack/issues). Remember to be descriptive.
188+
Experienced an issue or want to report a bug? Please, [report it here](https://github.com/wilburt/flutter_paystack/issues). Remember to be as descriptive as possible.
206189

207-
## Credits
190+
## :trophy: Credits
208191
Thanks to the authors of Paystack [iOS](https://github.com/PaystackHQ/paystack-ios) and [Android](https://github.com/PaystackHQ/paystack-android) SDKS. I leveraged on their work to bring this plugin to fruition.
209192

193+
## :fire: Apps Using this plugin
194+
1. **EasyDispatch** - [Play Store](https://play.google.com/store/apps/details?id=com.ncktech.easydispatch) | [App Store](https://itunes.apple.com/us/app/apple-store/id1413887430)
195+
196+
To to add your app here, just shoot me an email on faradaywilly(at)gmail.com.

0 commit comments

Comments
 (0)