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 always returning pending status as pending and not redirecting to webview. #13

Open
Samriddhi98 opened this issue Aug 12, 2024 · 0 comments

Comments

@Samriddhi98
Copy link

Describe the bug
I am using the sandbox environment to test khalti payment integration. The code seems to have worked for the first couple of times but afterwards the payment status returns 'pending' and the webview is not loading.

To Reproduce
I have used bloc to initialize khalti like this:

class KhaltiBloc extends Bloc<KhaltiEvent, KhaltiState> {
  KhaltiBloc() : super(KhaltiInitial()) {
    on<InitializeKhalti>(_initializeKhalti);
  }

  PaymentResult? paymentResult;

  FutureOr<void> _initializeKhalti(
      InitializeKhalti event, Emitter<KhaltiState> emit) async {
    emit(KhaltiLoading());
    final context = event.context;
    final payConfig = KhaltiPayConfig(
      publicKey:
          event.publicKey, // This is a dummy public key for example purpose
      pidx: event.pidx,
      environment: Environment.test,
    );
    try {
      final khalti = await Khalti.init(
        enableDebugging: true,
        payConfig: payConfig,
        onPaymentResult: (paymentResult, khalti) {
          log('--pay info ------');
          log(paymentResult.toString());
          paymentResult = paymentResult;
          khalti.close(context);
        },
        onMessage: (
          khalti, {
          description,
          statusCode,
          event,
          needsPaymentConfirmation,
        }) async {
          log(
            'Description: $description, Status Code: $statusCode, Event: $event, NeedsPaymentConfirmation: $needsPaymentConfirmation',
          );
          khalti.close(context);
        },
        onReturn: () {
          log('Successfully redirected to return_url.');
        },
      );
      emit(KhaltiInitalizeSuccess(khalti: khalti));
    } catch (e) {
      emit(KhaltiInitializeError());
    }
  }
}

Note

the test credentials I used the first few times were:
Test Khalti ID 9800000005
Test MPIN 1111
Test OTP 987654

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

1 participant