Create a WebView on Mobile App
Code Sample
JavaScript
callback_url points to should to handle incoming POST requests.
For a successful payment, the callback URL will have razorpay_payment_id. In addition, razorpay_order_id and razorpay_signature will be returned in the request body, provided your server-side has been integrated with Orders API. Know more about Orders API.
Handy Tips
callback_url to map it with entities at your end. For example, following is a valid callback URL: https://your-site.com/callback?cart_id=12345
Failed Payment
Parameter | Present? | Example
error | Array Always present |
error [code] | Always present | BAD_REQUEST_ERROR
error [description] | Always present | Payment failed due to incorrect card number
error [field]| Present if payment fails due to basic validation error | card [number]
Hand Over Payment Result to Native App
If you are loading the checkout form to WebView on your native mobile app without using the Razorpay SDK, provide acallback_url in the Razorpay Checkout parameters. After a successful payment, a redirect is made to the specified URL. You can enable the handover control from the page loaded at callback_url to your native app code.
Payment Callbacks to Android Native Code
The webpage will be loaded into a WebView class. To communicate anything from the webpage loaded into WebView to native code, you would need to add a JavaScriptInterface to the WebView.Add JavascriptInterface to WebView
Enable Cookies
You should enable cookies on your app to access features such as saved cards. Know more about saved cards.Code to Enable Cookies
Add the following code to your WebView to enable cookies.Enable Cookies
Handy Tips
setAcceptThirdPartyCookies for API level 21 and above.
Payment Callbacks to iOS Native Code
WKWebView framework is used to implement a bridge between JavaScript and the native code as UIWebView does not provide this functionality. The bridge is added by passing an instance of WKScriptMessageHandler and a string (which is the name of the bridge).swift
swift
JavaScript
userContentController can be called from the JavaScript by evaluating the above-mentioned script. The messageBody passed by the script must contain the appropriate data to control the flow of the native code.