1.5.3 • Published 7 years ago

cordova-plugin-stripe v1.5.3

Weekly downloads
879
License
MIT
Repository
github
Last release
7 years ago

Cordova Stripe Plugin

A Cordova plugin that lets you use Stripe Native SDKs for Android, iOS and Browser.

npm

NPM NPM

Installation

cordova plugin add cordova-plugin-stripe

Usage

First we need to set our publishable key. This can be your test or live key.

cordova.plugins.stripe.setPublishableKey('pk_test_MyPublishableKey');

Now we can create a credit card token to send to our backend.

var card = {
  number: '4242424242424242', // 16-digit credit card number
  expMonth: 12, // expiry month
  expYear: 2020, // expiry year
  cvc: '220', // CVC / CCV
  name: 'John Smith', // card holder name (optional)
  address_line1: '123 Some Street', // address line 1 (optional)
  address_line2: 'Suite #220', // address line 2 (optional)
  address_city: 'Toronto', // city (optional)
  address_state: 'Ontario', // state/province (optional)
  address_country: 'Canada', // country (optional)
  postal_code: 'L5L5L5', // Postal Code / Zip Code (optional)
  currency: 'CAD' // Three-letter ISO currency code (optional)
};

function onSuccess(tokenId) {
    console.log('Got card token!', tokenId);
}

function onError(errorMessage) {
    console.log('Error getting card token', errorMessage);
}

cordova.plugins.stripe.createCardToken(card, onSuccess, onError);


// bank account example
var bankAccount = {
  routing_number: '11000000',
  account_number: '000123456789',
  account_holder_name: 'John Smith', // optional
  account_holder_type: 'individual', // optional
  currency: 'CAD',
  country: 'CA'
};

cordova.plugins.stripe.createBankAccountToken(bankAccount, onSuccess, onError);

Once you have the token, you can now send it to your backend so you can charge the customer later on.

API Reference

stripe

stripe.setPublishableKey(key, success, error)

Set publishable key

Kind: static method of stripe

ParamTypeDescription
keystringPublishable key
successfunctionSuccess callback
errorfunctionError callback

stripe.createCardToken(creditCard, success, error)

Create a credit card token

Kind: static method of stripe

ParamTypeDescription
creditCardCreditCardTokenParamsCredit card information
successfunctionSuccess callback
errorfunctionError callback

stripe.createBankAccountToken(bankAccount, success, error)

Create a bank account token

Kind: static method of stripe

ParamTypeDescription
bankAccountBankAccountTokenParamsBank account information
successfunctionSuccess callback
errorfunctionError callback

stripe.validateCardNumber(cardNumber, success, error)

Validates card number

Kind: static method of stripe

ParamTypeDescription
cardNumberStringCredit card number
successfunctionSuccess callback that will be called if card number is valid
errorfunctionError callback that will be called if card number is invalid

stripe.validateExpiryDate(expMonth, expYear, success, error)

Validates the expiry date of a card

Kind: static method of stripe

ParamTypeDescription
expMonthnumberExpiry month
expYearnumberExpiry year
successfunction
errorfunction

stripe.validateCVC(cvc, success, error)

Validates a CVC of a card

Kind: static method of stripe

ParamTypeDescription
cvcstringCVC/CVV
successfunction
errorfunction

Example

function onSuccess() {
  console.log('isValid');
}

function onError() {
  console.log('invalid');
}

cordova.plugin.stripe.validateCVC('424', onSuccess, onError);

stripe.getCardType(cardNumber, success, error)

Gets a card type from a card number

Kind: static method of stripe

ParamTypeDescription
cardNumberstringCredit card number
successfunction
errorfunction

Example

cordova.plugins.stripe.getCardType('4242424242424242', function(cardType) {
  console.log(cardType); // visa
});

stripe.CreditCardTokenParams : Object

Parameters to create a credit card token

Kind: static typedef of stripe
Properties

NameTypeDescription
numberstringCard number
expMonthnumberExpiry month
expYearnumberExpiry year
cvcstringCVC/CVV
namestringCardholder name
address_line1stringAddress line 1
address_line2stringAddress line 2
address_citystringAddress line 2
address_statestringState/Province
address_countrystringCountry
postal_codestringPostal/Zip code
currencystring3-letter code for currency

stripe.BankAccountTokenParams : object

Parameters to create a bank account token

Kind: static typedef of stripe
Properties

NameTypeDescription
routing_numberstringRouting number
account_numberstringAccount number
currencystringCurrency code. Example: CAD.
countrystringCountry code. Example: CA.
account_holder_namestringAccount holder name
account_holder_typestringAccount holder type. This can be individual or company.

Tests

To test this plugin with cordova-plugin-test-framework, run the following command to install the tests:

cordova plugin add https://github.com/zyramedia/cordova-plugin-stripe#:/tests

Browser support

This plugin provides browser platform support. Method names and signatures match the API above. The plugin will automatically inject Stripe.js script into the web page when initialized.

Thanks to klirix for submitting a PR for the browser platform.

Contribution

  • Having an issue? or looking for support? Open an issue and we will get you the help you need.
  • Got a new feature or a bug fix? Fork the repo, make your changes, and submit a pull request.

Support this project

If you find this project useful, please star the repo to let people know that it's reliable. Also, share it with friends and colleagues that might find this useful as well. Thank you :smile:

1.5.3

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago