Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onPaymentResult callback not firing in both android/ios #3

Closed
cimplesid-tekkon opened this issue Apr 4, 2024 · 4 comments
Closed

Comments

@cimplesid-tekkon
Copy link

cimplesid-tekkon commented Apr 4, 2024

Describe the bug
onPaymentResult is a callback that is supposed to be triggered when any payment is made. But my payment is done and the user is redirected to the target URL but can't see any onPaymentResult callback

To Reproduce
Steps to reproduce the behavior:
just use the example from the package repo you get no callbacks

Expected behavior
When the payment is triggered, it should get a callback

Device Information (please complete the following information):

  • Device: [iPhone 15 pro max - physical device] [redmi 10 prime] (should not matter)
  • OS: [iOS 17.4.1] [Android 13 - miui 14.0.7]
  • Browser [webview - ig]
  • Version [latest]
@cimplesid-tekkon
Copy link
Author

Another code sample to reproduce:

//get pidx and store in pixres
      var pidx = pixres["pidx"];
      if (pidx != null) {
        final payConfig = KhaltiPayConfig(
          publicKey: somekey,
          pidx: pidx,
          openInKhalti: false,
          returnUrl: Uri.parse('https://hamoshare.com.np'),
          environment: kDebugMode ? Environment.test : Environment.prod,
        );
        var khalti = Khalti.init(
          enableDebugging: kDebugMode,
          payConfig: payConfig,
          onPaymentResult: (paymentResult, khalti) {
            hprint("onPaymentResult", "payment");
            hprint(paymentResult.toString());
            setState(() {
              this.paymentResult = paymentResult;
            });
            khalti.close(context);
          },
          onMessage: (
            khalti, {
            description,
            statusCode,
            event,
            needsPaymentConfirmation,
          }) async {
            hprint("onMessage:", "payment");
            hprint(
                'Description: $description, Status Code: $statusCode, Event: $event, NeedsPaymentConfirmation: $needsPaymentConfirmation',
                "payment");
            khalti.close(context);
          },
          onReturn: () =>
              hprint('Successfully redirected to return_url.', "payment"),
        );
        var cart = await khalti;
        cart.open(context);
        ```

@cimplesid-tekkon
Copy link
Author

cimplesid-tekkon commented Apr 4, 2024

Update on ^1.0.0-dev.4

  • Issue 1: encounters unnecessary networkFailure event causing no network UI even when network available
  • issue 2: no onPaymentResult callback is fired (unable to track a payment)
final payConfig = KhaltiPayConfig(
          publicKey: "",
          pidx: pidx,
          openInKhalti: false,
          returnUrl: Uri.parse('https://hamroshare.com.np'),
          environment: kDebugMode ? Environment.test : Environment.prod,
        );
        var khalti = Khalti.init(
          enableDebugging: kDebugMode,
          payConfig: payConfig,
          onPaymentResult: (paymentResult, khalti) {
            hprint("onPaymentResult", "HSpaymentModule");
            hprint(paymentResult.toString());
            setState(() {
              this.paymentResult = paymentResult;
            });
            khalti.close(context);
          },
          onMessage: (
            khalti, {
            description,
            statusCode,
            event,
            needsPaymentConfirmation,
          }) async {
            hprint("onMessage:", "HSpaymentModule");
            hprint(
                'Description: $description, Status Code: $statusCode, Event: $event, NeedsPaymentConfirmation: $needsPaymentConfirmation',
                "HSpaymentModule");
            khalti.close(context);
          },
          onReturn: () => hprint(
              'Successfully redirected to return_url.', "HSpaymentModule"),
        );`
        

-----------------------------------
        Log after complete flow
  -----------------------------------

   [HSpaymentModule] Successfully redirected to return_url.
[HSpaymentModule] onMessage:
[HSpaymentModule] Description: null, Status Code: 0, Event: KhaltiEvent.networkFailure, NeedsPaymentConfirmation: true
[HSpaymentModule] onMessage:
[HSpaymentModule] Description: Khalti payment page disposed, Status Code: null, Event: KhaltiEvent.kpgDisposed, NeedsPaymentConfirmation: true

@cimplesid-tekkon
Copy link
Author

@biplab-khalti Yeah issue was on my end and I think doc can be improved so that others do not encounter the same issue

  • Return URL current documentation (The URL to redirect after payment is successful.) but it does not say, it should be the same as in the backend param
  • use https URL and do not have "/" at the end of the URL causes a crash while redirecting and exposes the API on 404 page

possible package improments

  • injectable payconfig (not needed in initialization of Configuration
  • separate callback for error cases because when something is wrong and onPaymentResult is not fired it's hard to figure out what is wrong. Example: when publicKey is mismatched and lookup API fails. the payment is completed but will not get success callback

@biplab-khalti
Copy link
Contributor

@cimplesid-tekkon thank you for your feedback. We are still working on improving our docs and shall do so through your inputs.
About conveying messages, please check all the information being passed via onMessage callback. It also sends info about whether or not the client should re-verify the payment status on their own in certain scenarios. This was done with security concerns in mind.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants