com.razorpay.cordova
Advanced tools
Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "com.razorpay.cordova", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Cordova/Phonegap bindings for Razorpay's Mobile SDKs", | ||
@@ -5,0 +5,0 @@ "main": "Readme.md", |
@@ -30,2 +30,6 @@ # Cordova/Phonegap bindings for Razorpay's Mobile SDKs | ||
### Orders API Flow | ||
With the advent of `auto-capture` using [Order API](https://docs.razorpay.com/v1/page/orders), the integration needs to change a little ([only if you are using this flow](https://docs.razorpay.com/v1/page/orders#auto-capturing-payment)). The only change is that the callbacks have to be added as events. Here is a code sample: | ||
```js | ||
@@ -37,2 +41,3 @@ var options = { | ||
key: 'rzp_test_1DP5mmOlF5G5ag', | ||
order_id: 'order_7HtFNLS98dSj8x' | ||
amount: '5000', | ||
@@ -50,4 +55,6 @@ name: 'foo', | ||
var successCallback = function(payment_id) { | ||
alert('payment_id: ' + payment_id) | ||
var successCallback = function(success) { | ||
alert('payment_id: ' + success.razorpay_payment_id) | ||
var orderId = success.razorpay_order_id | ||
var signature = success.razorpay_signature | ||
} | ||
@@ -59,3 +66,5 @@ | ||
RazorpayCheckout.open(options, successCallback, cancelCallback) | ||
RazorpayCheckout.on('payment.success', successCallback) | ||
RazorpayCheckout.on('payment.cancel', cancelCallback) | ||
RazorpayCheckout.open(options) | ||
``` | ||
@@ -65,7 +74,30 @@ | ||
### Orders API Flow | ||
### External Wallets | ||
We also support **displaying** wallets like Citrus and Paytm, which are currently not a part of the standard Razorpay offering. After the user chooses which one of these they want, control is handed back to you with data like wallet name, contact and email of the user. This helps you take the next steps towards facilitating the payment and Razorpay's role in that payment cycle ends there. | ||
With the advent of `auto-capture` using [Order API](https://docs.razorpay.com/v1/page/orders), the integration needs to change a little ([only if you are using this flow](https://docs.razorpay.com/v1/page/orders#auto-capturing-payment)). The only change is that the callbacks have to be added as events. Here is a code sample: | ||
To add a wallet, change the `options` JSON as follows: | ||
```js | ||
var options = { | ||
currency: 'INR', | ||
key: 'rzp_test_1DP5mmOlF5G5ag', | ||
amount: '5000', | ||
external: { | ||
wallets: ['paytm'] | ||
}, | ||
... | ||
... | ||
... | ||
} | ||
``` | ||
To get callback for this, add this before calling `open`: | ||
```js | ||
RazorpayCheckout.on('payment.external_wallet', externalWalletCallback) | ||
``` | ||
### Legacy | ||
This is legacy integration code and we will continue to support it till further notice. Your server needs to send capture request in this scenario, after the payment is completed. | ||
```js | ||
var options = { | ||
@@ -76,3 +108,2 @@ description: 'Credits towards consultation', | ||
key: 'rzp_test_1DP5mmOlF5G5ag', | ||
order_id: 'order_7HtFNLS98dSj8x' | ||
amount: '5000', | ||
@@ -90,6 +121,4 @@ name: 'foo', | ||
var successCallback = function(success) { | ||
alert('payment_id: ' + success.razorpay_payment_id) | ||
var orderId = success.razorpay_order_id | ||
var signature = success.razorpay_signature | ||
var successCallback = function(payment_id) { | ||
alert('payment_id: ' + payment_id) | ||
} | ||
@@ -101,7 +130,6 @@ | ||
RazorpayCheckout.on('payment.success', successCallback) | ||
RazorpayCheckout.on('payment.cancel', cancelCallback) | ||
RazorpayCheckout.open(options) | ||
RazorpayCheckout.open(options, successCallback, cancelCallback) | ||
``` | ||
### Android Lifecycle Guide | ||
## Android Lifecycle Guide | ||
***It is recomended that you read [this](https://cordova.apache.org/docs/en/latest/guide/platforms/android/#lifecycle-guide) first before proceeding with this section*** | ||
@@ -125,4 +153,5 @@ | ||
``` | ||
### Things to be taken care: | ||
## Things to be taken care: | ||
- Add the integration code snippet after `deviceready` event. | ||
@@ -136,1 +165,3 @@ | ||
``` | ||
- Due to the way ionic works, we can't support `ionic serve` at the moment. Try using `ionic run browser` instead of `ionic serve`. `ionic serve` doesn't support cordova browser plugins at the moment. See [driftyco/ionic-cli#354](https://github.com/driftyco/ionic-cli/issues/354). |
@@ -48,5 +48,12 @@ function injectRZPScript(callback) { | ||
options.handler = function(response) { | ||
successCallback(response.razorpay_payment_id) | ||
successCallback(response) | ||
} | ||
if (options.external.wallets.length) { | ||
options.external.handler = function(response) { | ||
response.external_wallet_name = response.wallet | ||
cancelCallback(response) | ||
} | ||
} | ||
return options | ||
@@ -53,0 +60,0 @@ } |
/*global cordova, module*/ | ||
module.exports = { | ||
var RazorpayCheckout = module.exports = { | ||
open: function (options, successCallback, errorCallback) { | ||
if (successCallback) { | ||
this.callbacks['payment.success'] = function(response) { | ||
RazorpayCheckout.callbacks['payment.success'] = function(response) { | ||
successCallback(response.razorpay_payment_id); | ||
@@ -12,8 +12,8 @@ } | ||
if (errorCallback) { | ||
this.callbacks['payment.cancel'] = errorCallback; | ||
RazorpayCheckout.callbacks['payment.cancel'] = errorCallback; | ||
} | ||
cordova.exec( | ||
this.callbacks['payment.success'], | ||
this.callbacks['payment.cancel'], | ||
RazorpayCheckout.pluginCallback, | ||
RazorpayCheckout.pluginCallback, | ||
'Checkout', | ||
@@ -27,2 +27,14 @@ 'open', | ||
pluginCallback: function(response){ | ||
if('razorpay_payment_id' in response){ | ||
RazorpayCheckout.callbacks['payment.success'](response); | ||
} | ||
else if('external_wallet_name' in response){ | ||
RazorpayCheckout.callbacks['payment.external_wallet'](response); | ||
} | ||
else if('code' in response){ | ||
RazorpayCheckout.callbacks['payment.cancel'](response); | ||
} | ||
}, | ||
callbacks: {}, | ||
@@ -32,3 +44,3 @@ | ||
if (typeof event === 'string' && typeof callback === 'function') { | ||
this.callbacks[event] = callback; | ||
RazorpayCheckout.callbacks[event] = callback; | ||
} | ||
@@ -39,10 +51,5 @@ }, | ||
if(event.pendingResult && event.pendingResult.pluginServiceName === 'Checkout'){ | ||
if(event.pendingResult.pluginStatus === "OK") { | ||
this.callbacks['payment.success'](event.pendingResult.result); | ||
} | ||
else { | ||
this.callbacks['payment.cancel'](event.pendingResult.result); | ||
} | ||
RazorpayCheckout.pluginCallback(event.pendingResult.result); | ||
} | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1818519
14
186
157