Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f4e337d
Initial commit
cartolari Jan 8, 2016
7087eb7
Initial implementation for Android
cartolari Jan 8, 2016
8768837
Update package name
cartolari Jan 8, 2016
1b0f61f
Move Android stuff to android folder
cartolari Jan 8, 2016
84f5201
Bump version to 1.0.1
cartolari Jan 8, 2016
6cafc5d
Add usage instructions to README.md
cartolari Jan 11, 2016
8cbc642
Bump version to 1.0.2
cartolari Jan 11, 2016
099dc7a
Added react-native .gitignore
amiuhle Jan 13, 2016
54b4d41
Merge in MattFoley/react-native-paypal
amiuhle Jan 13, 2016
ad1336f
Android and iOS sections in README
amiuhle Jan 13, 2016
1e8f13d
Renamed ReactPaypal => ios
amiuhle Jan 13, 2016
e3714f6
Created MFLReactNativePayPal.xcodeproj
amiuhle Jan 13, 2016
0408873
PayPal iOS 2.13.0
amiuhle Jan 14, 2016
dbcab7c
Added PayPalMobile and CardIO
amiuhle Jan 14, 2016
e73c131
Other Linker Flags
amiuhle Jan 14, 2016
f29a992
Merge remote-tracking branch 'ios/master' into merge-ios
amiuhle Jan 14, 2016
e84d3f1
Moved license to ios folder
amiuhle Jan 14, 2016
10a81e1
Removed test project
amiuhle Jan 14, 2016
988a09a
Merge branch 'paypal-sdk' into ios
amiuhle Jan 14, 2016
f5ddd9a
Simple payment working in iOS
amiuhle Jan 14, 2016
62e9827
Updated package.json with information from deleted ios/package.json
amiuhle Jan 14, 2016
2ecfd0c
Removed ios/index.ios.js
amiuhle Jan 14, 2016
95a4831
Updated README with iOS installation instructions
amiuhle Jan 14, 2016
5ca3a94
Finished installation instructions for iOS
amiuhle Jan 14, 2016
18e20ed
Using strings for price in iOS
amiuhle Jan 15, 2016
fbfcfaf
Fix require in README.md
cartolari Jan 16, 2016
fac9e6b
[Android] PayPal SDK 2.13.0
amiuhle Jan 25, 2016
ce97908
Bumped version to 1.0.3
amiuhle Jan 25, 2016
c6e0c8d
Merge branch 'paypal-android-sdk-2.13.0' into ios
amiuhle Jan 25, 2016
e2bef42
Merge branch 'master' of github.com:MattFoley/react-native-paypal int…
Aug 14, 2016
c563f93
Unused files
Aug 14, 2016
9fb687b
Fixing example apps.
Aug 14, 2016
90900d4
Updating read, now begins with generic usage information, followed by…
Aug 14, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"rules": {
"indent": [
2,
2
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"es6": true,
"browser": false,
"node": true
},
"extends": "eslint:recommended",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
},
"plugins": [
"react",
"react-native"
]
}
24 changes: 18 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# OSX
#
.DS_Store

# Xcode
#
build/
Expand All @@ -16,11 +20,19 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
node_modules/
# CocoaPods
project.xcworkspace

# Android/IJ
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
.idea
.gradle
local.properties

# node.js
#
#Pods/
node_modules/
npm-debug.log

/android/build
/android/react-native-paypal.iml
/.tern-port
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ReactPaypal/lib/Paypal"]
path = ReactPaypal/lib/Paypal
[submodule "ios/lib/Paypal"]
path = ios/lib/Paypal
url = git@github.com:paypal/PayPal-iOS-SDK.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Vizir Software Studio

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.
213 changes: 207 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,211 @@
# react-native-paypal

Paypal wrapper for React Native, currently only supports the bare minimum of buying a product.
A Cross platform React Native interface for the PayPal Payment UI. Supports both iOS and Android currently, but can be used seperately.

###Integration
![Demo of a Payment using PayPal](/react-native-paypal.gif?raw=true "react-native-paypal")

## Usage
--

Initiating a payment is as simple as creating a single promise

```javascript
let PayPal = require('react-native-paypal');
PayPal.paymentRequest({
clientId: 'AbyfNDFV53djg6w4yYgiug_JaDfBSUiYI7o6NM9HE1CQ_qk9XxbUX0nwcPXXQHaNAWYtDfphQtWB3q4R',
environment: PayPalAndroid.SANDBOX,
price: '42.00',
currency: 'USD',
description: 'PayPal Test'
}).then((confirm, payment) => console.log('Paid'); /* At this point you should verify payment independently */)
.catch((error_code) => console.error('Failed to pay through PayPal'));
```

#### Callback parameters:

If all goes OK with the payment than the paymentRequest promise is resolved with
the following arguments as JSON strings:
- A confirm:
``` json
{
"client": {
"environment": "mock",
"paypal_sdk_version": "2.12.4",
"platform": "Android",
"product_name": "PayPal-Android-SDK"
},
"response": {
"create_time": "2014-02-12T22:29:49Z",
"id": "PAY-6RV70583SB702805EKEYSZ6Y",
"intent": "sale",
"state": "approved"
},
"response_type": "payment"
}
```

- A payment:
```json
{
"amount": "1.00",
"currency_code": "USD",
"short_description": "PayPal Test",
"intent": "sale"
}
```

Handling callbacks:
```javascript
PayPal.paymentRequest(...).then(function (payment, confirm) {
sendPaymentToConfirmInServer(payment, confirm);
})
```

If anything fails the promise will be notify an error with a code which will be
one of:
- USER\_CANCELLED
- INVALID\_CONFIG

Handling failures:

``` javascript
PayPal.paymentRequest(...).catch(function (error_code) {
if (error_code == PayPal.USER_CANCELLED) {
// User didn't complete the payment
} else if (error_code == PayPal.INVALID_CONFIG) {
// Invalid config was sent to PayPal
}
})
```

## Setup

Android
-------

1. Add react-navive-paypal to your project

``` bash
npm install --save react-native-paypal
```

2. Add the following to android/app/build.gradle

``` groovy
dependencies {
// ...
compile project(':react-native-paypal')
}
```

3. Add the following to android/settings.gradle

``` groovy
include ':react-native-paypal'
project(':react-native-paypal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-paypal/android')
```

4. Edit android/src/.../MainActivity.java

``` java
// ...
import br.com.vizir.rn.paypal.PayPalPackage; // <--
import br.com.vizir.rn.paypal.PayPal; // <--
import android.content.Intent; // <--

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
// ...
private static final int PAY_PAL_REQUEST_ID = 9; // <-- Can be any unique number
private PayPalPackage payPalPackage; // <--

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
payPalPackage = new PayPalPackage(this, PAY_PAL_REQUEST_ID); // <--

mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
// ...
.addPackage(payPalPackage) // <--
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
// ...
}

// ...

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PAY_PAL_REQUEST_ID) {
payPalPackage.handleActivityResult(requestCode, resultCode, data); // <--
} else {
otherModulesHandlers(requestCode, resultCode, data);
}
}
}
```

iOS
---

### Sample App

You'll find an iOS example in `<root>/ios/Example/`. You will need to run npm install in that directory in order to download the dependencies required by the sample application. Note this sample still uses manual NativeModule usage, and you'll likely find the above Javascript simpler than the JS used in this sample.

### Installation

Currently you have to install via `npm` from GitHub (or change the version specifier in `package.json` to `MattFoley/react-native-paypal`):

```shell
npm install --save MattFoley/react-native-paypal
```

There will be an updated npm release shortly, which will allow

#### Install the PayPal-iOS-SDK

You then have to install the PayPal-iOS-SDK into `node_modules/react-native-paypal/ios/lib/Paypal`

Here's a one-liner to download and unpack version `2.13.0`:

```shell
mkdir -p node_modules/react-native-paypal/ios/lib/Paypal && curl -L --progress https://github.com/paypal/PayPal-iOS-SDK/archive/2.13.0.tar.gz | tar -xz - -C node_modules/react-native-paypal/ios/lib/Paypal --strip-components=1
```

Include PayPal as normally, following their directions. Their integration steps and iOS SDK can be found [here](https://github.com/paypal/PayPal-iOS-SDK). After doing that, also drag MFLReactNativePayPal.h and MFLReactNativePayPal.m into your project.

#### Add `MFLReactNativePayPal.xcodeproj`

Add `node_modules/react-native-paypal/ios/MFLReactNativePayPal.xcodeproj`
to the `Libraries` group in iOS and link `libMFLReactNativePayPal.a` as described in Step 2 of the
[React Native Manual Linking docs](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking).

Follow steps 4 and 5 of [the PayPal instalation instructions](https://github.com/paypal/PayPal-iOS-SDK#if-you-dont-use-cocoapods-then), as well as the [additional steps here](https://github.com/paypal/PayPal-iOS-SDK#with-or-without-cocoapods). **This has to be done for the main app, not for the library you included.**

### Manual Usage (iOS Only)

You can access the NativeModule directly on iOS using the following instructions, if you'd like to modify the functionality.

###Initialization:

var MFLReactNativePayPal = require('NativeModules').MFLReactNativePayPal;
import {
NativeModules
} from 'react-native';
let MFLReactNativePayPal = NativeModules.MFLReactNativePayPal;
MFLReactNativePayPal.initializePaypalEnvironment(<environment>, "<Your client id>");

#####Environment Values that should be used here are declared in MFLReactNativePayPal.h
#####Environment Values that should be used here are declared in MFLReactNativePayPal.h

• Sandbox = 0
• Production = 1
• No Network = 2

###Prepare a Payment:

MFLReactNativePayPal.preparePaymentOfAmount(<Amount as a Float>, <Currency Code>, <Short description>);
Expand All @@ -35,7 +224,7 @@ Include PayPal as normally, following their directions. Their integration steps
//Handle Error
return;
} else {

console.log("payload: " + payload);
if (payload.status == 1) {
console.log(payload.confirmation);
Expand All @@ -44,3 +233,15 @@ Include PayPal as normally, following their directions. Their integration steps
}
}
});

## TODO:

* [ ] Android Sample App
* [ ] Refactor & cleanup
* [ ] Automated tests
* [ ] Future payment (subscriptions)
* [ ] Invoice and optional fields - https://github.com/MattFoley/react-native-paypal/issues/6

## Thanks

The Android portion of this library was originally built by https://github.com/Vizir for https://github.com/Vizir/react-native-paypal. The merging of the API in order to provide cross platform support was done almost entirely by https://github.com/amiuhle.
24 changes: 0 additions & 24 deletions ReactPaypal/ReactPaypalTests/Info.plist

This file was deleted.

Loading