Princewil / flutter_paystack_plus

A package for Implement payment using paystack - Compatible on Android, iOS and Web
Apache License 2.0
6 stars 8 forks source link

Safe Area, Onsuccess, Onclosed Issues on Android App #3

Closed raphaeldivine3028 closed 10 months ago

raphaeldivine3028 commented 1 year ago

Firstly, thank you so much for the effort put into this app. I sincerely appreciate it.

While most things work as expected, there are a few issues:

  1. Safe Area: The payment screen is not respecting the safe area of my Android app, which includes the notification bar. See attached image.

  2. The "Cancel Payment" payment is not responding. When clicked, nothing happens.

  3. The Onsuccess/Onclosed isn't responding too. When a transaction isn't successful, the app is supposed to show a Not Successful Dialog, but this doesn't happen. That's similar to when a transaction is successful.

paystack issues

This is part of the code relevant to my app.

 Future<void> startPayment() async {
    FlutterPaystackPlus.openPaystackPopup(
      publicKey: _payStackPublicKey,
      customerEmail: _getuserEmail(),
      context: Get.context,
      secretKey: _paystackSecretKey,
      amount: _amount,
      reference: _reference,
      currency: _currency,
      onClosed: () {
        log("Transaction Not Successful!");
        Dialogs.paymentNotSuccessful(errorMessage: "");
      },
      onSuccess: () async {
        log("Transaction Successful");
        premiumController.updatePremiumStatus(true);
        Dialogs.paymentSuccessful();
      },
    );
  }
Padding(
 padding: UIParameters.screenPadding,
 child: MainButton(
 onTap: () => controller.startPayment(),
 title: 'Upgrade Now',
 ),),
Princewil commented 1 year ago

Thanks for the appreciation and also for pointing these out, I will work on them.

Princewil commented 1 year ago

Package now responses to SafeArea widget. I'm still working on the cancel button for mobile (it works well for web).

raphaeldivine3028 commented 1 year ago

Thank you so much. I'm looking forward to the cancel button fix

On Mon, Jul 17, 2023, 2:09 PM Princewil @.***> wrote:

Package now responses to SafeArea widget. I'm still working on the cancel button for mobile (it works well for web).

— Reply to this email directly, view it on GitHub https://github.com/Princewil/flutter_paystack_plus/issues/3#issuecomment-1638111034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQKHCUL3ZZPBNJB5W5BC4YDXQU2SJANCNFSM6AAAAAAZK4ANKE . You are receiving this because you authored the thread.Message ID: @.***>

Ade-Pyaar commented 1 year ago

Nicely done. I will also be on the lookout for the update concerning the onClosed and onSuccess functions. 👍

gikwegbu commented 10 months ago

For anyone still having issues with the onClosed and the onSuccess functionality, there are few things you'd need to do to make it work.

  1. onClosed Function: From the FlutterPaystackPlus.openPaystackPopup(), include the below in your metadata
...
 metadata: {
    "cancel_action": "cancelurl.com",
  },

NB: Under the hood, the package uses a Webview; hence, the NavigationDelegate will be listening for the URL you passed as the value of the cancel_action you had entered above, to run the function @Princewil had created, check below:

NB: You must use the exact cancelurl.com, as @Princewil , from his code, is using it in his package...

...
NavigationDelegate(
    onNavigationRequest: (request) async {
      if (request.url.contains('cancelurl.com')) { // here is the cancel_action value being used...
        await _checkTransactionStatus(snapshot.data!.reference)
            .then((value) {
          Navigator.of(context).pop();
        });
      }
      if (request.url.contains('paystack.co/close')) {
        await _checkTransactionStatus(snapshot.data!.reference)
            .then((value) {
          Navigator.of(context).pop();
        });
      }
      if (request.url.contains(widget.callbackUrl)) { // Your callback url here
        await _checkTransactionStatus(snapshot.data!.reference)
            .then((value) {
          Navigator.of(context).pop();
        });
      }
      return NavigationDecision.navigate;
    },
  ),
)

NB: You don't need to worry yourself about the above function.

  1. onSuccess Function: For this to work, you'd need to provide the callBackUrl, found in your Paystack Dashboard.

NB: At the time of dropping this comment (which I'll update once @Princewil merges my PR), the callBackUrl is not hitting the paystack initialize endpoint, hence the onSuccess() won't be called. But once the merge is done, hopefully, it should get the onSuccess() function working again.

NB: To the best of my knowledge about paystack, the value you provide for the callBackUrl, overrides the value in your paystack dashboard.

E.g., if you have george_is_happy.com in your paystack dashboard and you pass george_is_sad.com, the latter (sad) will override the former (happy).

Thanks. 🙏 , and thanks, @Princewill for this wonderful package.

Princewil commented 10 months ago

Thank you so much for your comment @gikwegbu and for solutions you gave🫡

I will merge PR once I test it.

Princewil commented 10 months ago

All good now!

Princewil commented 10 months ago

I've updated the package so that you no longer need to manually add "cancel_action": "cancelurl.com" to the metadata. The package now adds this information automatically, which helps prevent spelling errors that could occur when adding it manually.

Princewil commented 10 months ago

I guess this reply is late. However I update the package on pub.

On Fri, 29 Dec 2023 at 18:22, George Ikwegbu Chinedu < @.***> wrote:

Thanks chief.

Quick question: Will you be updating the package on PubDev? The changes I've made are in my cache, and once my teammates pull from my branch, they won't have those changes in theirs.

Once again, Thanks for your help.

On Fri, Dec 29, 2023 at 5:06 PM Dr. Princewill @.***> wrote:

All good now!

— Reply to this email directly, view it on GitHub < https://github.com/Princewil/flutter_paystack_plus/issues/3#issuecomment-1872192042>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AJOQDEARWH7KM4RGBKXZXA3YL3TBRAVCNFSM6AAAAAAZK4ANKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZSGE4TEMBUGI>

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/Princewil/flutter_paystack_plus/issues/3#issuecomment-1872231546, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWWTE67C5NYXXCPFXFJO6LYL335ZAVCNFSM6AAAAAAZK4ANKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZSGIZTCNJUGY . You are receiving this because you modified the open/close state.Message ID: @.***>

gikwegbu commented 10 months ago

Good one chief