Skip to content

Commit 447614a

Browse files
committed
implemented payment cancellation. Clicking on the 'Cancel Payment' on the Paystack payment page now closes the Payment webview.
1 parent 7a6c227 commit 447614a

File tree

10 files changed

+39
-10
lines changed

10 files changed

+39
-10
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-
'sk_test_4daeaa768f986a546516cd9a5d101f657ea4f1d3', // 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:

example/pubspec.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ packages:
166166
paystack_for_flutter:
167167
dependency: "direct main"
168168
description:
169-
name: paystack_for_flutter
170-
sha256: c232fd73995a8a6d842d696bf849f514078f36ab825b1e85577dc0a046cdf40f
171-
url: "https://pub.dev"
172-
source: hosted
169+
path: ".."
170+
relative: true
171+
source: path
173172
version: "1.0.1"
174173
plugin_platform_interface:
175174
dependency: transitive

example/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ environment:
3030
dependencies:
3131
flutter:
3232
sdk: flutter
33-
#paystack_for_flutter: ^1.0.1
3433
paystack_for_flutter:
3534
path: ../
3635

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_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)