Skip to content
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

Configure the repo for public release #2

Merged
merged 12 commits into from
Oct 25, 2016
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing

We love contributions from everyone.
By participating in this project,
you agree to abide by our [code_of_conduct].

We expect everyone to follow the code of conduct
anywhere in Razorpay's project codebases,
issue trackers, chatrooms, and mailing lists.

## Contributing Code

Checkout the latest master to make sure the feature hasn't been implemented or
the bug hasn't been fixed yet.

Check the issue tracker to make sure someone already hasn't requested it and/or
contributed to it.

Fork the repo.

1. Use the example project to test the module.
2. Change `"react-native-razorpay": ">=1.0.0"` in `package.json` of example to
`"react-native-razorpay": "./../"`.
3. Edit example/reload.sh to configure your path.
4. Follow instructions to link your project with the iOS SDK, as given in the [README].
5. Run example/reload.sh every time you make a change to the module.

Make your change. Follow this [style guide][style].

Push to your fork. Write a [good commit message][commit]. Submit a pull request.

Others will give constructive feedback.
This is a time for discussion and improvements,
and making the necessary changes will be required before we can
merge the contribution.

[code_of_conduct]: code_of_conduct.md "Code of Conduct"
[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html "A short guide on how to write good commit messages"
[README]: README.md#linking-ios-sdk "Linking to the iOS SDK"
[style]: https://github.com/thoughtbot/guides/tree/master/style "Styleguides by Thoughtbot"
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016 Razorpay Software Pvt. Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
149 changes: 122 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,142 @@

# react-native-razorpay

## Dev setup
React Native wrapper around our Android and iOS mobile SDKs

1. Use the examle project to test the module.
2. Run example/reload_module.sh every time you make a change to the module
To know more about Razorpay payment flow and steps involved, please read up here:
<https://docs.razorpay.com/docs>

## Installation

## Getting started
Run the following on terminal from your project directory:

`$ npm install react-native-razorpay --save`
```bash
$ npm i react-native-razorpay --save
```

### Mostly automatic installation
### Automatic installation

`$ react-native link react-native-razorpay`
```bash
$ react-native link react-native-razorpay
```

### Manual installation

If the above command doesn't work for you, try the following:

#### iOS

1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]`
2. Go to `node_modules` ➜ `react-native-razorpay` and add `RNReactNativeRazorpay.xcodeproj`
3. In XCode, in the project navigator, select your project. Add `libRNReactNativeRazorpay.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Run your project (`Cmd+R`)<
1. In XCode, in the project navigator, right click `Libraries` ➜
`Add Files to [your project's name]`
2. Go to `node_modules` ➜ `react-native-razorpay` and add `RazorpayCheckout.xcodeproj`
3. In XCode, in the project navigator, select your project. Add
`libRazorpayCheckout.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`
4. Run your project (`⌘+R`)

#### Android

1. Open up `android/app/src/main/java/[...]/MainApplication.java`
- Add `import com.razorpay.rn.RazorpayPackage;` to the imports at the top of the file
- Add `import com.razorpay.rn.RazorpayPackage;` to the imports at the top of
the file
- Add `new RazorpayPackage()` to the list returned by the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-razorpay'
project(':react-native-razorpay').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-razorpay/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-razorpay')
```


### Usage

TODO

```gradle
include ':react-native-razorpay'
project(':react-native-razorpay').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-razorpay/android')
```
3. Insert the following lines inside the dependencies block in
`android/app/build.gradle`:
```gradle
compile project(':react-native-razorpay')
```

## Linking iOS SDK

React Native creates static library for each plugin / library / framework / native module being used.

Due to some limitation on the way Xcode links static and dynamic
libraries / frameworks to projects, we require some additional
steps to be followed to link our iOS SDK to the React Native project.

You can skip steps 1, 2 and 3 if you used `npm`.

1. Download [Razorpay's iOS SDK from here][ios-docs] and unzip it.
2. Delete the `.framework` file from
`path/to/your/project/node_modules/react-native-razorpay`.
3. Copy the `.framework` file obtained in step 1 to
`path/to/your/project/node_modules/react-native-razorpay`.
4. Open `path/to/your/project/ios/<your_project>.xcworkspace` or
`path/to/your/project/ios/<your_project>.xcodeproj`
5. Also link the `.framework` file **_directly_ to your project** in Xcode. Check the
`Copy items if needed` box and select your project target from the list below.
6. Add the following line of code in your `AppDelegate.m` under the imports section:
`#import <dlfcn.h>`
7. Add the following line of code in your `AppDelegate.m` inside the
`application:didFinishLaunchingWithOptions:` method:
`dlopen("Razorpay.framework/Razorpay", RTLD_LAZY | RTLD_GLOBAL);`

## Usage

Sample code to integrate with Razorpay can be found in
[index.js][index.js] in the included example directory.
Copy link
Contributor

@selvagsz selvagsz Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to see the code snippet in usage section in addition to the example


To run the example, simply do the following in example directory and then
link iOS SDK as explained in the previous section:

`$ npm i`

### Steps

1. Import RazorpayCheckout module to your component:
```js
import RazorpayCheckout from 'react-native-razorpay';
```
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 = {
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: '8955806560',
name: 'Akshay Bhalotia'
},
theme: {color: '#F37254'}
}
RazorpayCheckout.open(options).then(data =>
{ alert("Success: " + data.payment_id) }
).catch(data =>
{ alert("Error: " + data.code + " | " + data.description) }
);
}}>
```
A descriptive [list of valid options for checkout][options] is available (under
Manual Checkout column).

## Contributing

See the [CONTRIBUTING] document. Thank you, [contributors]!

## License

react-native-razorpay is Copyright (c) 2016 Razorpay Software Pvt. Ltd.
It is distributed under [the MIT License][LICENSE].

We ♥ open source software!
See [our other supported plugins / SDKs][integrations]
or [contact us][contact] to help you with integrations.

[contact]: mailto:[email protected]?subject=Help%20with%20React%20Native "Send us a mail"
[CONTRIBUTING]: CONTRIBUTING.md "Our contributings guidelines"
[contributors]: https://github.com/razorpay/react-native-razorpay/graphs/contributors "List of contributors"
[index.js]: example/index.js "index.js"
[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"
28 changes: 25 additions & 3 deletions RazorpayCheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@

import { NativeModules, NativeEventEmitter } from 'react-native';

export const RZP = {
RazorpayCheckout: NativeModules.RazorpayCheckout,
RazorpayEventEmitter: NativeModules.RazorpayEventEmitter
const razorpayEvents = new NativeEventEmitter(NativeModules.RazorpayEventEmitter);

const removeSubscriptions = () => {
razorpayEvents.removeAllListeners('Razorpay::PAYMENT_SUCCESS');
razorpayEvents.removeAllListeners('Razorpay::PAYMENT_ERROR');
};

class RazorpayCheckout {
static open(options, successCallback, errorCallback) {
return new Promise(function(resolve, reject) {
razorpayEvents.addListener('Razorpay::PAYMENT_SUCCESS', (data) => {
let resolveFn = successCallback || resolve;
resolveFn(data);
removeSubscriptions();
});
razorpayEvents.addListener('Razorpay::PAYMENT_ERROR', (data) => {
let rejectFn = errorCallback || reject;
rejectFn(data);
removeSubscriptions();
});
NativeModules.RazorpayCheckout.open(options);
});
}
}

export default RazorpayCheckout;
10 changes: 5 additions & 5 deletions android/src/main/java/com/razorpay/rn/RazorpayModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data){
if (data != null) {
Bundle extras = data.getExtras();
if (extras != null) {
result = extras.getString("RESULT");
}
result = extras.getString("RESULT");
}
}
if (resultCode == 1) {
try {
JSONObject resultJson = new JSONObject(result);
WritableMap successParams = Arguments.createMap();
successParams.putString(MAP_KEY_PAYMENT_ID, resultJson.getString(MAP_KEY_RZP_PAYMENT_ID));
sendEvent("onPaymentSuccess", successParams);
sendEvent("Razorpay::PAYMENT_SUCCESS", successParams);
} catch(Exception e){}
}
else {
Expand All @@ -133,8 +133,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data){
WritableMap errorParams = Arguments.createMap();
errorParams.putInt(MAP_KEY_ERROR_CODE, resultCode);
errorParams.putString(MAP_KEY_ERROR_DESC, result);
sendEvent("onPaymentError", errorParams);
}
sendEvent("Razorpay::PAYMENT_ERROR", errorParams);
}
}

private void sendEvent(String eventName, @Nullable WritableMap params) {
Expand Down
74 changes: 74 additions & 0 deletions code_of_conduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [[email protected]](mailto:[email protected]?subject=Code of Conduct Issue). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
7 changes: 7 additions & 0 deletions download_ios_framework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
## Run this script after installing the module

curl -O http://downloads.razorpay.com/Razorpay.framework-0.14.1.zip
unzip ./Razorpay.framework-0.14.1.zip
rm -r ./ios/Razorpay.framework
cp -R ./Razorpay.framework ./ios/
Loading