You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// secretKey is not needed if you're not using checkout as a payment method.
24
+
//
32
25
}
33
26
}
34
27
```
35
28
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.
37
41
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
+
```
39
54
55
+
`PaystackPlugin.checkout()` returns `true` for a successful payment otherwise, it returns `false`.
56
+
57
+
### 2. :star: Charge Card
40
58
You can choose to initialize the payment locally or via Paystack's backend.
41
59
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)
46
61
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';
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).
73
63
74
64
1.b If everything goes well, the initialization request returns a response with an `access_code`.
75
65
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
137
127
138
128
139
129
140
-
### 2. Initialize Locally
130
+
####2. Initialize Locally
141
131
Just send the payment details to `PaystackPlugin.chargeCard`
142
132
```dart
143
133
// Set transaction params directly in app (note that these params
@@ -154,12 +144,14 @@ Just send the payment details to `PaystackPlugin.chargeCard`
154
144
```
155
145
156
146
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.
159
149
For easier validation, wrap the **TextFormField**s inside a **Form** widget. Please check this article on
160
150
[validating forms on Flutter](https://medium.freecodecamp.org/how-to-validate-forms-and-user-input-the-easy-way-using-flutter-e301a1531165)
161
151
if this is new to you.
162
152
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
+
163
155
You can validate the fields with these methods:
164
156
#### card.validNumber
165
157
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
178
170
This method returns an estimate of the string representation of the card type(issuer).
179
171
180
172
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
191
174
This is quite easy. Just send a HTTP GET request to `https://api.paystack.co/transaction/verify/$[TRANSACTION_REFERENCE]`.
192
175
Please, check the [official documentaion](https://developers.paystack.co/reference#verifying-transactions) on verifying transactions.
193
176
194
-
## Testing your implementation
177
+
## :helicopter:Testing your implementation
195
178
Paystack provides tons of [payment cards](https://developers.paystack.co/docs/test-cards) for testing.
196
179
197
-
## Running Example project
180
+
## :arrow_forward:Running Example project
198
181
For help getting started with Flutter, view the online [documentation](https://flutter.io/).
199
182
200
183
An [example project](https://github.com/wilburt/flutter_paystack/tree/master/example) has been provided in this plugin.
201
184
Clone this repo and navigate to the **example** folder. Open it with a supported IDE or execute `flutter run` from that folder in terminal.
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.
206
189
207
-
## Credits
190
+
## :trophy:Credits
208
191
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.
0 commit comments