-
Notifications
You must be signed in to change notification settings - Fork 107
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
Promise based API #3
Conversation
``` | ||
4. Call RazorpayCheckout's `open` method with `options`, preferably on a user action: | ||
2. Call RazorpayCheckout's `open` method with `options` (preferably on a user | ||
action) as a **JS Promise**. The `then` part corresponds to a successful payment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open
method withoptions
as a JS Promise
sounds a bit weird. How about the below ?
Call
RazorpayCheckout.open
method with theoptions
. The method returns a promise wherethen
part corresponds to a successful payment and thecatch
part corresponds to payment failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds great. Wasn't sure on terminology around Promises.
|
||
static open(options, successCallback, errorCallback) { | ||
return new Promise(function(resolve, reject) { | ||
let removeSubscriptions = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the function outside open
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
static open(options, successCallback, errorCallback) { | ||
return new Promise(function(resolve, reject) { | ||
let removeSubscriptions = () => { | ||
razorpayEvents.removeAllListeners('Razorpay::onPaymentSuccess'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onPaymentSuccess
, onPaymentError
looks like a handler name.
How about Razorpay::PAYMENT_SUCCESS
, Razorpay::PAYMENT_ERROR
event names ?
|
||
} | ||
|
||
export {RazorpayCheckout}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it as default export like
export default RazorpayCheckout
const { RazorpayCheckout, RazorpayEventEmitter } = Razorpay; | ||
|
||
const razorpayEvents = new NativeEventEmitter(RazorpayEventEmitter); | ||
import { RazorpayCheckout } from 'react-native-razorpay'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with default export, this will be
import RazorpayCheckout from 'react-native-razorpay'
{ alert("Success: " + data.payment_id) } | ||
).catch(data => | ||
{ alert("Error: " + data.code + " | " + data.description) } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to below style
RazorpayCheckout.open(options).then((data) => {
// handle success
alert(`Success: ${data.payment_id}`)
}).catch((error) => {
// handle error
alert(`Error: ${error.code} | ${error.description}`)
})
82d9cfa
to
996b316
Compare
996b316
to
91ea1b7
Compare
lgtm 👍 |
Changes as per discussion on #2 .
Supports promise as well as callbacks (for example, as in razorpay/razorpay-cordova )