Skip to content

Commit 5d25c20

Browse files
committed
Clarified access code requirement. Closes #17
1 parent 2d97db0 commit 5d25c20

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ There are two ways of making payment with the plugin.
4040
reference. Pass an `accessCode` only when you have
4141
[initialized the transaction](https://developers.paystack.co/reference#initialize-a-transaction)
4242
from your backend. Otherwise, pass a `reference`.
43-
43+
4444

4545
```dart
4646
Charge charge = Charge()
@@ -50,10 +50,14 @@ There are two ways of making payment with the plugin.
5050
..email = '[email protected]';
5151
CheckoutResponse response = await PaystackPlugin.checkout(
5252
context context,
53+
method: CheckoutMethod.card, // Defaults to CheckoutMethod.selectable
5354
charge: charge,
5455
);
5556
```
5657

58+
Please, note that an `accessCode` is required if the method is
59+
`CheckoutMethod.bank` or `CheckoutMethod.selectable`.
60+
5761
`PaystackPlugin.checkout()` returns the state and details of the
5862
payment in an instance of `CheckoutResponse` .
5963

example/lib/main.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class _HomePageState extends State<HomePage> {
128128
border: const UnderlineInputBorder(),
129129
labelText: 'Expiry Month',
130130
),
131-
onSaved: (String value) => _expiryMonth = _toInt(value),
131+
onSaved: (String value) => _expiryMonth = int.tryParse(value),
132132
),
133133
),
134134
_horizontalSizeBox,
@@ -138,7 +138,7 @@ class _HomePageState extends State<HomePage> {
138138
border: const UnderlineInputBorder(),
139139
labelText: 'Expiry Year',
140140
),
141-
onSaved: (String value) => _expiryYear = _toInt(value),
141+
onSaved: (String value) => _expiryYear = int.tryParse(value),
142142
),
143143
)
144144
],
@@ -434,16 +434,6 @@ class _HomePageState extends State<HomePage> {
434434
}
435435
}
436436

437-
int _toInt(String source) {
438-
int value;
439-
try {
440-
return int.parse(source);
441-
} catch (e) {
442-
print('Error occured while parsing $value to int. Error: $e');
443-
}
444-
return value;
445-
}
446-
447437
var banks = ['Selectable', 'Bank', 'Card'];
448438

449439
CheckoutMethod _parseStringToMethod(String string) {

lib/src/common/paystack.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,26 @@ class PaystackPlugin {
115115
/// Make payment using Paystack's checkout form. The plugin will handle the whole
116116
/// processes involved.
117117
///
118-
/// [context] - the widgets BuildContext
118+
/// [context] - the widget's BuildContext
119+
///
120+
/// [charge] - the charge object.
119121
///
120-
/// [charge] - the charge object. You must pass the amount (in kobo) to it. If you
121-
/// want to use CheckoutMethod.card/CheckoutMethod.selectable, you must also
122-
/// pass either an access code or payment reference to the charge object.
122+
/// [onSuccess] - Called when the payment completes successfully
123+
///
124+
/// [onValidated] - Called when the payment completes with an unrecoverable error
125+
///
126+
/// [method] - The payment method to use(card, bank). It defaults to
127+
/// [CheckoutMethod.selectable] to allow the user to select. For [CheckoutMethod.bank]
128+
/// or [CheckoutMethod.selectable], it is
129+
/// required that you supply an access code to the [Charge] object passed to [charge].
130+
/// For [CheckoutMethod.card], though not recommended, passing a reference to the
131+
/// [Charge] object will do just fine.
123132
///
124133
/// Notes:
125134
///
126-
/// * When you pass an access code, the plugin won't
127-
/// initialize the transaction and payment is made immediately
128-
/// * When you pass the reference, the plugin will initialize the transaction
129-
/// (via https://api.paystack.co/transaction/initialize) with the passed reference.
130135
/// * You can also pass the [PaymentCard] object and we'll use it to prepopulate the
131136
/// card fields if card payment is being used
132137
///
133-
/// [onSuccess] - Called when the payment completes successfully
134-
///
135-
/// [onValidated] - Called when the payment completes with an unrecoverable error
136-
///
137-
/// [method] - The payment payment method to use(card, bank). It defaults to
138-
/// [CheckoutMethod.selectable] to allow the user to select
139138
static Future<CheckoutResponse> checkout(
140139
BuildContext context, {
141140
@required Charge charge,

lib/src/widgets/checkout/checkout_widget.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class CheckoutWidget extends StatefulWidget {
3131

3232
class _CheckoutWidgetState extends BaseState<CheckoutWidget>
3333
with TickerProviderStateMixin {
34-
final _scaffoldKey = new GlobalKey<ScaffoldState>();
3534
static const tabBorderRadius = BorderRadius.all(Radius.circular(4.0));
3635
final Charge _charge;
3736
var _currentIndex = 0;
@@ -76,7 +75,6 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
7675
@override
7776
Widget buildChild(BuildContext context) {
7877
return new CustomAlertDialog(
79-
key: _scaffoldKey,
8078
expanded: true,
8179
fullscreen: widget.fullscreen,
8280
titlePadding: EdgeInsets.all(0.0),
@@ -98,7 +96,7 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
9896
}
9997

10098
Widget _buildTitle() {
101-
var amountAndAmount = new Column(
99+
var emailAndAmount = new Column(
102100
crossAxisAlignment: CrossAxisAlignment.end,
103101
children: <Widget>[
104102
_charge.email != null
@@ -193,7 +191,7 @@ class _CheckoutWidgetState extends BaseState<CheckoutWidget>
193191
new SizedBox(
194192
width: 50.0,
195193
),
196-
new Expanded(child: amountAndAmount),
194+
new Expanded(child: emailAndAmount),
197195
],
198196
),
199197
),

0 commit comments

Comments
 (0)