1

I'm trying to integrate Stripe checkout in an android application. Currently I'm receiving the checkout session ID from the backend . I need to run this js code in application

<script src="https://js.stripe.com/v3/"></script>
<script>
  var stripe = Stripe('publishable_key')

  stripe.redirectToCheckout({
    sessionId:session.id

    })
</script>

In web , this code redirects to a page hosted in Stripe . How to achieve the same in android .I was advised against webview by the Stripe support as that solution appears to have some issues . How to proceed further from here .

1 Answer 1

3

If you do not wish to use a WebView then your only option is to use the Stripe android SDK. There is no other way to run js code in android directly. Especially since this code simply redirects to Stripe gateway which will require a WebView.

Stripe has proper documentation on steps to be followed at https://stripe.com/docs/payments/accept-a-payment?platform=android. You will still need to perform some operations on your backend depending on your use-case.

5
  • Thanks for your answer . In case if we use the webview , how are we going to detect if the purpose of the webview is complete and close the webview . For instance - if the payment is complete , how will we detect that so that we can close the webview Commented Jun 16, 2021 at 6:47
  • 1
    @newbie_coder I am not sure of how exactly stripe handles payments but you will need to have a webpage of your own which opens stripe and is called again after payment from stripe. You can try something like what RazorPay recommends. Do note that this will still need a lot of work and customization as webview doesn't allow multiple windows by default and payment gateways normally open the bank page on a new window (Please upvote the answer if it helped) Commented Jun 16, 2021 at 16:51
  • To clarify a bit, your own webpage (which gets loaded after payment) will be responsible for communicating with android using a JavaScriptInterface. You might be able to launch stripe's page directly on the webview but you will certainly need a webpage of your own to receive the payment status and communicate it with the app. Commented Jun 16, 2021 at 16:55
  • Thanks for replying. I don't have enough reputation to upvote . Commented Jun 17, 2021 at 16:00
  • @newbie_coder Not a problem. If my answer solved the issue, make sure you accept the answer. Commented Jun 18, 2021 at 16:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.