0.5.6 • Published 2 years ago

@agaweb/react-native-stripe v0.5.6

Weekly downloads
39
License
MIT
Repository
github
Last release
2 years ago

React Native Stripe

Stripe payments for react-native

Warning

This library is really fresh, if you encounter a bug don't be afraid to report it

Requirements

This module uses the latest iOS Stripe SDK (dropped support for iOS 10) so the minimum platform is now iOS 11

Installation

npm install @agaweb/react-native-stripe
cd ios && pod install

Additional iOS setup

It must be done or the compilation will fail (the Stripe SDK is now in full Swift)

  1. Create the famous "Dummy" swift file (xcode -> open your project -> right click on the folder named after your project, where Info.plist resides -> new File -> Swift -> say YES when asked for the bridging header)
  2. Remove the swift-5.0 search path, or you will get an error about undefined symbols (try it if you don't believe me), do this -> https://github.com/react-native-community/upgrade-support/issues/62#issuecomment-622985723

Tested with the latest Xcode, I spent a lot of hours finding the 2nd additional step, so if you have an outdated Xcode version or an outdated react-native version, please upgrade.

A note about the widget and the manual card validation

I'll be honest I couldn't manage to get the Android CardInputWidget working, the animation doesn't work (https://github.com/stripe/stripe-android/issues/655), so I implemented the CardMultilineWidget instead. It means that Android and iOS have different UI (on Android is more material design). I could have used a third party credit card form like tipsi-stripe, but on the Stripe SDK the manual card validation is now deprecated so I'm not going to implement it.

Usage

Setup

You should call this method as early as possible (ex. at the first index.js), it must be called before everything else from this module

import stripe from "@agaweb/react-native-stripe";

stripe.initModule(YOUR_PUBLISHABLE_KEY)

Component: StripeCardInputWidget

Wrapper around the Android (CardMultilineWidget) and iOS (STPPaymentCardTextField) native card collection inputs (integrated with react-native TextInputState undocumented API, so Keyboard.dismiss() will work)

Basic usage

import {StripeCardInputWidget} from '@agaweb/react-native-stripe';

export const Test = () => {
    return (
        <StripeCardInputWidget
            onCardValidCallback={({isValid, cardParams}) => {
                console.log(isValid, cardParams);
        }} />
    );
};

Props

NameDescriptionDetails
onCardValidCallbackCallback which returs {isValid, cardParams} - isValid gives you the state of the card inserted - cardParams contains the number, expMonth, expYear, cvc, brand and if enabled postalCodefunction
enabledEnable or disable the inputsboolean
postalCodeEntryEnabledEnable or disable the visibility of the postal code inputboolean
cardInputStyle iOS onlyStyle applicable only to the ios component, support for: - textColor - placeholderColor - borderColor - borderWidth - backgroundColorobject
numberPlaceholderOnly iOSstring
cvcPlaceholderOnly iOSstring
expirationPlaceholderOnly iOSstring
postalCodePlaceholderOnly iOSstring

Methods (from ref)

Use these only if really needed

NameDescription
focusMakes the native component request focus
blurMakes the native component lose focus
clearClear the native fields

Module API: confirmPaymentWithCard

Confirm using the card details you get from the widget or from anywhere else

import stripe from '@agaweb/react-native-stripe';

stripe
    .confirmPaymentWithCard(clientSecret, cardParams, savePaymentMethod?)
    .then(() => {
        console.log('Paid');
    })
    .catch((err) => {
        console.log(err);
    });
NameDescriptionRequired
clientSecretThe client secret of the source. Used for client-side retrieval using a publishable keyyes
cardParamsExample: {number: "4242424242424242", expMonth: 02, expYear: 22, cvc: "222"}yes
savePaymentMethodSave the payment method to the attached customer (if present). Used to store cards for future payments, especially helpful for confirmPaymentWithPaymentMethodIdno

Module API: confirmPaymentWithPaymentMethodId

Confirm using an already present paymentMethodId (ex. reuse cards)

import stripe from '@agaweb/react-native-stripe';

stripe
    .confirmPaymentWithPaymentMethodId(clientSecret, paymentMethodId)
    .then(() => {
        console.log('Paid');
    })
    .catch((err) => {
        console.log(err);
    });
NameDescriptionRequired
clientSecretThe client secret of the source. Used for client-side retrieval using a publishable keyyes
paymentMethodIdThe payment method attached to the customer, you can get a list of the available methods from the Stripe WSyes

Module API: confirmCardSetup

Confirm Setup Intent using the card details you get from the widget or from anywhere else Both iOS and Android call this name confirmSetupIntent, but JS deprecated it, in favor of confirmCardSetup Useful for attach cards to the customer without make a payment

import stripe from '@agaweb/react-native-stripe';

stripe
    .confirmCardSetup(clientSecret, cardParams)
    .then((data) => {
        console.log('Card Saved', data);
    })
    .catch((err) => {
        console.log(err);
    });
NameDescriptionRequired
clientSecretThe client secret of the SetupIntentyes
cardParamsOnly cardParams for now, paymentMethodId is going to be supported a bit lateryes
Result (key)Description
paymentMethodIdRegistered method id

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.5.6

2 years ago

0.5.5

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago