-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
React Native wrapper around our Android and iOS mobile SDKs | ||
|
||
To know more about Razorpay payment flow and steps involved, please read up here: | ||
<https://docs.razorpay.com/docs> | ||
|
||
## Installation | ||
|
||
Run the following on terminal from your project directory: | ||
|
@@ -83,25 +86,13 @@ link iOS SDK as explained in the previous section: | |
|
||
### Steps | ||
|
||
1. Import Razorpay module to your component: | ||
```js | ||
import { Razorpay } from 'react-native-razorpay'; | ||
const { RazorpayCheckout, RazorpayEventEmitter } = Razorpay; | ||
``` | ||
2. Instantiate an event emitter with `RazorpayEventEmitter`: | ||
```js | ||
const razorpayEvents = new NativeEventEmitter(RazorpayEventEmitter); | ||
``` | ||
3. Add payment event listeners to your component, preferably in `componentWillMount`: | ||
1. Import RazorpayCheckout module to your component: | ||
```js | ||
razorpayEvents.addListener('onPaymentError', (data) => { | ||
alert("Error: " + data.code + " | " + data.description) | ||
}); | ||
razorpayEvents.addListener('onPaymentSuccess', (data) => { | ||
alert("Success: " + data.payment_id) | ||
}); | ||
import RazorpayCheckout from 'react-native-razorpay'; | ||
``` | ||
4. Call RazorpayCheckout's `open` method with `options`, preferably on a user action: | ||
2. Call `RazorpayCheckout.open` method with the payment `options`. The method | ||
returns a **JS Promise** where `then` part corresponds to a successful payment | ||
and the `catch` part corresponds to payment failure. | ||
```js | ||
<TouchableHighlight onPress={() => { | ||
var options = { | ||
|
@@ -111,17 +102,22 @@ razorpayEvents.addListener('onPaymentSuccess', (data) => { | |
key: 'rzp_test_1DP5mmOlF5G5ag', | ||
amount: '5000', | ||
name: 'foo', | ||
prefill: {email: '[email protected]', contact: '8879524924', name: 'Pranav Gupta'}, | ||
prefill: { | ||
email: '[email protected]', | ||
contact: '8955806560', | ||
name: 'Akshay Bhalotia' | ||
}, | ||
theme: {color: '#F37254'} | ||
} | ||
RazorpayCheckout.open(options) | ||
RazorpayCheckout.open(options).then(data => | ||
{ alert("Success: " + data.payment_id) } | ||
).catch(data => | ||
{ alert("Error: " + data.code + " | " + data.description) } | ||
); | ||
}}> | ||
``` | ||
5. Stop listening for payment events, preferably in `componentWillMount`: | ||
```js | ||
razorpayEvents.remove(); | ||
``` | ||
|
||
A descriptive [list of valid options for checkout][options] is available (under | ||
Manual Checkout column). | ||
|
||
## Contributing | ||
|
||
|
@@ -143,3 +139,4 @@ or [contact us][contact] to help you with integrations. | |
[integrations]: https://razorpay.com/integrations "List of our integrations" | ||
[ios-docs]: https://docs.razorpay.com/v1/page/ios-integration "Documentation for the iOS Integration" | ||
[LICENSE]: /LICENSE "MIT License" | ||
[options]: https://docs.razorpay.com/docs/checkout-form#checkout-fields "Checkout Options" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/** | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* @flow | ||
*/ | ||
* Sample React Native App | ||
* https://github.com/facebook/react-native | ||
* @flow | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import { | ||
|
@@ -15,47 +15,42 @@ import { | |
NativeEventEmitter | ||
} from 'react-native'; | ||
|
||
import { Razorpay } from 'react-native-razorpay'; | ||
const { RazorpayCheckout, RazorpayEventEmitter } = Razorpay; | ||
|
||
const razorpayEvents = new NativeEventEmitter(RazorpayEventEmitter); | ||
import RazorpayCheckout from 'react-native-razorpay'; | ||
|
||
class example extends Component { | ||
componentWillMount() { | ||
razorpayEvents.addListener('onPaymentError', (data) => { | ||
alert("Error: " + data.code + " | " + data.description) | ||
}); | ||
razorpayEvents.addListener('onPaymentSuccess', (data) => { | ||
alert("Success: " + data.payment_id) | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<TouchableHighlight onPress={() => { | ||
<TouchableHighlight onPress={() => { | ||
var options = { | ||
description: 'Credits towards consultation', | ||
image: 'https://i.imgur.com/3g7nmJC.png', | ||
currency: 'INR', | ||
key: 'rzp_test_1DP5mmOlF5G5ag', | ||
amount: '5000', | ||
name: 'foo', | ||
prefill: {email: '[email protected]', contact: '8879524924', name: 'Pranav Gupta'}, | ||
prefill: { | ||
email: '[email protected]', | ||
contact: '8955806560', | ||
name: 'Akshay Bhalotia' | ||
}, | ||
theme: {color: '#F37254'} | ||
} | ||
RazorpayCheckout.open(options) | ||
}}> | ||
RazorpayCheckout.open(options).then((data) => { | ||
// handle success | ||
alert(`Success: ${data.payment_id}`); | ||
}).catch((error) => { | ||
// handle failure | ||
alert(`Error: ${error.code} | ${error.description}`); | ||
}); | ||
}}> | ||
<Text style = {styles.text}>Pay</Text> | ||
</TouchableHighlight> | ||
</View> | ||
</TouchableHighlight> | ||
</View> | ||
); | ||
} | ||
|
||
componentWillUnmount () { | ||
razorpayEvents.remove(); | ||
} | ||
|
||
} | ||
|
||
const styles = StyleSheet.create({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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