Skip to content

Commit 6c92e45

Browse files
authored
Merge pull request #4 from VhiktorBrown/cancel-payment-feat
implemented payment cancellation. Clicking on the 'Cancel Payment' on the Paystack payment page now closes the Payment webview.
2 parents 54db42a + 447614a commit 6c92e45

File tree

9 files changed

+37
-6
lines changed

9 files changed

+37
-6
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"webview_flutter_wkwebview","path":"/Users/user/.pub-cache/hosted/pub.dev/webview_flutter_wkwebview-3.14.0/","native_build":true,"dependencies":[]}],"android":[{"name":"webview_flutter_android","path":"/Users/user/.pub-cache/hosted/pub.dev/webview_flutter_android-3.16.3/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"webview_flutter","dependencies":["webview_flutter_android","webview_flutter_wkwebview"]},{"name":"webview_flutter_android","dependencies":[]},{"name":"webview_flutter_wkwebview","dependencies":[]}],"date_created":"2024-09-22 06:48:17.163407","version":"3.21.0-1.0.pre.6"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"webview_flutter_wkwebview","path":"/Users/user/.pub-cache/hosted/pub.dev/webview_flutter_wkwebview-3.14.0/","native_build":true,"dependencies":[]}],"android":[{"name":"webview_flutter_android","path":"/Users/user/.pub-cache/hosted/pub.dev/webview_flutter_android-3.16.3/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"webview_flutter","dependencies":["webview_flutter_android","webview_flutter_wkwebview"]},{"name":"webview_flutter_android","dependencies":[]},{"name":"webview_flutter_wkwebview","dependencies":[]}],"date_created":"2024-09-23 01:23:01.343186","version":"3.21.0-1.0.pre.6"}

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55

66
## 1.0.1
77

8-
* Fixed GIF and screenshots not showing in README.md
8+
* Fixed GIF and screenshots not showing in README.md
9+
10+
## 1.0.2
11+
12+
* Fixed `showProgressBar` argument not being used in implementation. Now, whatever value you set is used.
13+
* Clicking on `Cancel Payment` on Paystack payment page now cancels the payment and closes the page, calling the onCancelled callback.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ The Flutter package that makes it super easy to integrate Paystack's payment gat
1717
|:------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------:|
1818
| <img src="https://raw.githubusercontent.com/VhiktorBrown/paystack_flutter/master/screenshots/pay_with_bank.png" height="400" width="200"/> | <img src="https://raw.githubusercontent.com/VhiktorBrown/paystack_flutter/master/screenshots/payment_success.png" height="400" width="200"/> |
1919

20+
## Significant Changes:
21+
* Fixed `showProgressBar` argument not being used in implementation. Now, whatever value you set is used.
22+
* Clicking on `Cancel Payment` on Paystack payment page now cancels the payment and closes the page, calling the onCancelled callback.
23+
24+
2025
## :dart: Add dependency to pubspec.yaml:
2126
``` dart
2227
dependencies:

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class _MyHomePageState extends State<MyHomePage> {
4242
PaystackFlutter().pay(
4343
context: context,
4444
secretKey:
45-
'YOUR PAYSTACK_SECRET_KEY', // Your Paystack secret key.
45+
'YOUR_PAYSTACK_SECRET_KEY', // Your Paystack secret key.
4646
amount:
4747
60000, // The amount to be charged in the smallest currency unit. If amount is 600, multiply by 100(600*100)
4848
email:

lib/src/models/paystack_request.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PaystackRequest {
5959

6060
/// Any additional metadata you want to associate with the transaction.
6161
/// This can be a map of key-value pairs (optional).
62-
final dynamic metaData;
62+
dynamic metaData;
6363

6464
/// Creates a new PaystackRequest object.
6565
///
@@ -87,8 +87,22 @@ class PaystackRequest {
8787
this.currency,
8888
});
8989

90+
/// Updates or adds the provided key-value pair to the `metadata`.
91+
/// Ensures `metaData` is a Map before adding the data.
92+
void updateMetadata(String key, String value) {
93+
if (metaData == null) {
94+
metaData = {}; // Initialize as an empty Map if not already set
95+
} else if (metaData is! Map) {
96+
throw ArgumentError('metaData must be a Map');
97+
}
98+
metaData[key] = value;
99+
}
100+
90101
/// Converts the PaystackRequest object to a JSON map suitable for sending to the Paystack API.
91102
Map<String, dynamic> toJson() {
103+
// Call updateMetadata to ensure the "cancel_action" key-value pair is added
104+
updateMetadata("cancel_action", "https://github.com/VhiktorBrown/paystack_flutter");
105+
92106
final Map<String, dynamic> baseJson = {
93107
"amount": amount,
94108
"email": email,

lib/src/paystack_flutter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class PaystackFlutter {
9797
email: email,
9898
amount: amount,
9999
reference: reference,
100-
showProgressBar: false,
100+
showProgressBar: showProgressBar,
101101
confirmTransaction: confirmTransaction,
102102
paymentOptions: paymentOptions,
103103
currency: currency,

lib/src/paystack_webview.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ class _PaystackWebviewState extends State<PaystackWebview> {
191191
return NavigationDecision.navigate;
192192
}
193193

194+
//check if Paystack redirects to cancel_url
195+
if(uri.toString() == "https://github.com/VhiktorBrown/paystack_flutter"){
196+
Navigator.pop(context);
197+
//this means the user cancelled payment.
198+
widget.onCancelled(callback);
199+
}
200+
194201
//check if user is redirected to https://standard.paystack.co/close
195202
if (uri
196203
.toString()

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: paystack_for_flutter
2-
description: The paystack_flutter package helps you collect payment in your app with just few lines of code. Offers many payment options.
2+
description: The Flutter package that makes it super easy to integrate Paystack's payment gateway into your app with just few lines of code.
33
version: 1.0.1
44
homepage: https://github.com/VhiktorBrown/paystack_flutter
55
documentation: https://github.com/VhiktorBrown/paystack_flutter/blob/master/README.md

screenshots/pay_with_card.png

-146 KB
Loading

0 commit comments

Comments
 (0)