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

feat: Add support for Customer & Payments sessions, thus enabling one to use the SDK UI kit #9

Draft
wants to merge 80 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c16b2d0
Setup Intent Android Implemented
0xamogh Aug 14, 2020
65fc8df
Bug fixes
0xamogh Aug 15, 2020
6b81dbd
Setup Intents removed
0xamogh Aug 15, 2020
89378a6
Build folder generated
0xamogh Aug 16, 2020
30147ad
Testing 2.0
0xamogh Aug 16, 2020
0718938
Gitignore updated
0xamogh Aug 16, 2020
dd99012
Fixes
0xamogh Aug 17, 2020
1073bf8
Add setupPayment iOS
ChesterSim Aug 23, 2020
1c23892
Fix broken code for iOS confirmSetup
ChesterSim Aug 25, 2020
72e50b6
Enabled multidex on Android
sagarshakya Aug 25, 2020
8cc3721
Complete confirmPayment for iOS
ChesterSim Aug 26, 2020
e410d88
Merge branch 'master' of github.com:aspect-apps/react-native-stripe-p…
ChesterSim Aug 26, 2020
0396689
Add card provider
ChesterSim Aug 26, 2020
4a47a8b
Build for card provider
ChesterSim Aug 26, 2020
fe8555b
Fix card provider
ChesterSim Aug 26, 2020
542e48d
Update confirmPayment to use createWithCardParams for iOS
ChesterSim Aug 26, 2020
017cebc
Split confirmPayment into confirmPaymentWithPaymentMethodId and confi…
ChesterSim Aug 27, 2020
f0e4a46
Update README.md
ChesterSim Aug 27, 2020
8993ad7
Update README.md
ChesterSim Aug 27, 2020
a4f886b
Update README.md
Aug 27, 2020
3384ec9
Split StripePaymentsModule.java confirmPayment
ChesterSim Aug 30, 2020
c3893f3
Merge branch 'master' of github.com:aspect-apps/react-native-stripe-p…
ChesterSim Aug 30, 2020
a42f6cd
Updated Pod Minimum Target
Sep 4, 2020
fa95bd5
Updated to be more inline with the iOS implementation
Sep 4, 2020
d5df02a
Update confirmSetupIntent return object
0xamogh Sep 4, 2020
d544dce
Merge pull request #1 from amogh-jrules/master
0xamogh Sep 4, 2020
393b94a
last4 added
0xamogh Sep 4, 2020
2f0d42f
Merge pull request #2 from amogh-jrules/master
0xamogh Sep 4, 2020
d8a39f3
Build for Amogh's commit
ChesterSim Sep 4, 2020
57d1e31
Removed Redundant values from iOS
Sep 4, 2020
824493e
Updating setupIntentResult object
0xamogh Sep 4, 2020
7dd4af1
Merge remote-tracking branch 'aspect-apps-origin/master'
0xamogh Sep 4, 2020
a932d06
Built Typescript files
Sep 4, 2020
e9b7134
Returning created from Native Android
0xamogh Sep 4, 2020
0937281
Merge remote-tracking branch 'aspect-apps-origin/master'
0xamogh Sep 4, 2020
d903fdc
Built Typescript files
Sep 4, 2020
7a71db9
Updated exp month / year to match TS
Sep 4, 2020
0e462e0
Updated exp month / year
Sep 4, 2020
b08f878
Updated exp month / year
Sep 4, 2020
f792d09
Updated TS definitions
Sep 4, 2020
759b7c1
Built Typescript files
Sep 4, 2020
90fc763
Fixed Types on Return Methods
Sep 4, 2020
d706435
Android native debug
0xamogh Sep 4, 2020
a899707
Merge remote-tracking branch 'aspect-apps-origin/master'
0xamogh Sep 4, 2020
6c675b0
docs: update README.md [skip ci]
allcontributors[bot] Sep 6, 2020
be8134f
docs: create .all-contributorsrc [skip ci]
allcontributors[bot] Sep 6, 2020
f7546b4
Merge pull request #3 from aspect-apps/all-contributors/add-lukebrand…
0xamogh Sep 6, 2020
6657256
docs: update README.md [skip ci]
allcontributors[bot] Sep 6, 2020
50bcf1f
docs: update .all-contributorsrc [skip ci]
allcontributors[bot] Sep 6, 2020
0fef763
Merge pull request #7 from aspect-apps/all-contributors/add-ChesterSim
0xamogh Sep 6, 2020
cf3d99a
docs: update README.md [skip ci]
allcontributors[bot] Sep 6, 2020
c6fcb21
docs: update .all-contributorsrc [skip ci]
allcontributors[bot] Sep 6, 2020
d21e764
Merge pull request #8 from aspect-apps/all-contributors/add-amogh-jrules
0xamogh Sep 6, 2020
78fb9fa
wip
andreibarabas Sep 8, 2020
beaeb9f
index
andreibarabas Sep 8, 2020
d10ee43
finish POC
andreibarabas Sep 9, 2020
6d987b4
add support for payment method type
andreibarabas Sep 9, 2020
ede2d35
improve dev ux by using invariant
andreibarabas Sep 9, 2020
27b1a3e
fix handling of params to the ephemeralKey callback
andreibarabas Sep 9, 2020
f9445a7
properly transmit the ephemeralKey to the native side
andreibarabas Sep 9, 2020
7fb8be1
improve error handling
andreibarabas Sep 10, 2020
68b9792
small rename
andreibarabas Sep 10, 2020
cf89d99
present payment methods works again
andreibarabas Sep 13, 2020
0b23313
properly handle events
andreibarabas Sep 13, 2020
24fb3c8
wip
andreibarabas Sep 13, 2020
765ef57
accept paymentMethodId when presenting selector screen
andreibarabas Sep 13, 2020
7d449f8
remove build folders
andreibarabas Sep 14, 2020
c08c12b
add back +add card
andreibarabas Sep 14, 2020
b27f864
help with the cancelled error handling
andreibarabas Sep 14, 2020
32e2a0a
standardize the payment method fields
andreibarabas Sep 14, 2020
06d9cbc
Update package.json
andreibarabas Sep 14, 2020
f708c4c
add type to invariant
andreibarabas Sep 15, 2020
dd3a7a0
Merge branch 'master' of https://github.com/andreibarabas/react-nativ…
andreibarabas Sep 15, 2020
d3fb710
remove footer
andreibarabas Sep 15, 2020
a5b002c
add support for bundling only on one platform
andreibarabas Sep 16, 2020
90feeb4
remove npm lock
andreibarabas Sep 22, 2020
ba54549
chore: temporarily include the build files, so we don't need prepare …
andreibarabas Sep 22, 2020
2e186e6
chore: remove forgotten logs that raise a crash when data is null
andreibarabas Oct 2, 2020
0f9f79a
add missing brand field in payment method
andreibarabas Oct 22, 2020
b1cc168
Update index.d.ts
andreibarabas Oct 22, 2020
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
46 changes: 46 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"files": [
"README.md"
],
"imageSize": 100,
"commit": false,
"contributors": [
{
"login": "lukebrandonfarrell",
"name": "Luke Brandon Farrell",
"avatar_url": "https://avatars3.githubusercontent.com/u/18139277?v=4",
"profile": "http://www.lukebrandonfarrell.com",
"contributions": [
"code",
"infra",
"projectManagement"
]
},
{
"login": "ChesterSim",
"name": "Chester Sim",
"avatar_url": "https://avatars2.githubusercontent.com/u/12388321?v=4",
"profile": "https://github.com/ChesterSim",
"contributions": [
"doc",
"code"
]
},
{
"login": "amogh-jrules",
"name": "Amogh Jahagirdar",
"avatar_url": "https://avatars3.githubusercontent.com/u/31567169?v=4",
"profile": "https://jramogh.co",
"contributions": [
"doc",
"code"
]
}
],
"contributorsPerLine": 7,
"projectName": "react-native-stripe-payments",
"projectOwner": "aspect-apps",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
}
33 changes: 1 addition & 32 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,4 @@ node_modules/
npm-debug.log
yarn-error.log

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# BUCK
buck-out/
\.buckd/
*.keystore
android/build/
81 changes: 71 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
![React Native Stripe payments](https://raw.githubusercontent.com/Fitpassu/react-native-stripe-payments/master/react-native-stripe-payments.png)
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

A well typed React Native library providing support for Stripe payments on both iOS and Android.

Expand All @@ -20,49 +23,107 @@ The library ships with platform native code that needs to be compiled together w

## Usage

### Setup

First of all you have to obtain Stripe account [publishabe key](https://stripe.com/docs/keys). And then you need to set it for module.
To use the module, import it first.

```javascript
import stripe from 'react-native-stripe-payments';
```

### Setup

First of all you have to obtain a Stripe account [publishable key](https://stripe.com/docs/keys), which you need to set it for the module.

```javascript
stripe.setOptions({ publishingKey: 'STRIPE_PUBLISHING_KEY' });
```

### Validate the given card details

```javascript
import stripe from 'react-native-stripe-payments';

const isCardValid = stripe.isCardValid({
number: '4242424242424242',
expMonth: 10,
expYear: 21,
cvc: '888',
});
```
The argument for `isCardValid` is of type `CardParams`, which is used across the other APIs.

### One-time payments
### Set up a payment method for future payments (Setup Intent)

```javascript
import stripe from 'react-native-stripe-payments';
stripe.confirmSetup('client_secret_from_backend', cardParams)
.then(result => {
// result of type SetupIntentResult
// {
// paymentMethodId,
// liveMode,
// last4,
// created,
// brand
// }
})
.catch(err =>
// error performing payment
)
```
The `brand` is the provider of the card, and we use the [module](https://www.npmjs.com/package/credit-card-type) `credit-card-type` to achieve that.

### One-time payment using the `id` of a `PaymentMethod`

```javascript
stripe.confirmPaymentWithPaymentMethodId('client_secret_from_backend', paymentMethodId)
.then(result => {
// result of type PaymentResult
// {
// id,
// paymentMethodId
// }
})
.catch(err =>
// error performing payment
)
```

### One-time payment using `cardParams`

```javascript
const cardDetails = {
number: '4242424242424242',
expMonth: 10,
expYear: 21,
cvc: '888',
}
stripe.confirmPayment('client_secret_from_backend', cardDetails)
stripe.confirmPaymentWithCardParams('client_secret_from_backend', cardParams)
.then(result => {
// result of type PaymentResult
// {
// id,
// paymentMethodId
// }
})
.catch(err =>
// error performing payment
)
```

### Reusing cards
## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="http://www.lukebrandonfarrell.com"><img src="https://avatars3.githubusercontent.com/u/18139277?v=4" width="100px;" alt=""/><br /><sub><b>Luke Brandon Farrell</b></sub></a><br /><a href="https://github.com/aspect-apps/react-native-stripe-payments/commits?author=lukebrandonfarrell" title="Code">💻</a> <a href="#infra-lukebrandonfarrell" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#projectManagement-lukebrandonfarrell" title="Project Management">📆</a></td>
<td align="center"><a href="https://github.com/ChesterSim"><img src="https://avatars2.githubusercontent.com/u/12388321?v=4" width="100px;" alt=""/><br /><sub><b>Chester Sim</b></sub></a><br /><a href="https://github.com/aspect-apps/react-native-stripe-payments/commits?author=ChesterSim" title="Documentation">📖</a> <a href="https://github.com/aspect-apps/react-native-stripe-payments/commits?author=ChesterSim" title="Code">💻</a></td>
<td align="center"><a href="https://jramogh.co"><img src="https://avatars3.githubusercontent.com/u/31567169?v=4" width="100px;" alt=""/><br /><sub><b>Amogh Jahagirdar</b></sub></a><br /><a href="https://github.com/aspect-apps/react-native-stripe-payments/commits?author=amogh-jrules" title="Documentation">📖</a> <a href="https://github.com/aspect-apps/react-native-stripe-payments/commits?author=amogh-jrules" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

Not supported yet, though as we're highly invested in development of our product which depends on this library we'll do it as soon as possible!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ android {
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
versionCode 1
versionName "1.0"
multiDexEnabled true
}
lintOptions {
abortOnError false
Expand All @@ -73,7 +74,8 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.stripe:stripe-android:14.2.1'
implementation 'com.stripe:stripe-android:15.1.0'
implementation 'com.android.support:multidex:1.0.3'
}

def configureReactNativePom(def pom) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.fitpassu.stripepayments;

import com.stripe.android.EphemeralKeyProvider;
import com.stripe.android.EphemeralKeyUpdateListener;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.UiThreadUtil;


/**
*
* Ephemeral Key Provider that works with the JS thread through the bridge
*
*/
public class BridgeEphemeralKeyProvider implements EphemeralKeyProvider, EphemeralKeyUpdateListener {
private ReactApplicationContext reactContext;
private EphemeralKeyUpdateListener pendingKeyUpdateListener; //will hold the key update listener between the time when the event is raised and the JS responds back with the key

//save the context for future use
BridgeEphemeralKeyProvider(ReactApplicationContext context) {
this.reactContext = context;
}

@Override
public void createEphemeralKey(
String apiVersion,
final EphemeralKeyUpdateListener keyUpdateListener) {

//build params to send to the JS thread
WritableMap params = Arguments.createMap();
params.putString("apiVersion", apiVersion);

this.pendingKeyUpdateListener = keyUpdateListener;

//async call the JS land
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("stripeCreateEphemeralKey", params);
}

/**
*
* Called from the JS land once we have the key
*
*/
@Override
public void onKeyUpdate(final String stripeResponseJson){
if(this.pendingKeyUpdateListener != null) {
final EphemeralKeyUpdateListener keyUpdateListener = pendingKeyUpdateListener;

//
// we need to make sure the listener is updated on the UI thread
//
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
keyUpdateListener.onKeyUpdate(stripeResponseJson);
}});

this.pendingKeyUpdateListener = null; //avoid memory leaks. the listener is not used anymore
}
}


/**
*
* Called from the JS land once we have the key
*
*/
@Override
public void onKeyUpdateFailure(final int responseCode, final String message) {
if(this.pendingKeyUpdateListener != null) {
final EphemeralKeyUpdateListener keyUpdateListener = pendingKeyUpdateListener;

//
// we need to make sure the listener is updated on the UI thread
//
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
keyUpdateListener.onKeyUpdateFailure(responseCode, message);
}});

this.pendingKeyUpdateListener = null; //avoid memory leaks. the listener is not used anymore
}
}
}
Loading