Git Product home page Git Product logo

nativescript-stripe-sdk's Introduction

NativeScript Stripe-SDK

This repo is based on @Osei Fortune's nativescript-stripe. Perfect job, Sir!

IMPORTANT: Highly recomend using @Osei Fortune's nativescript-stripe

The purpose of this plugin is to add some specific functionalities required by the app I work on. I have also wanted to use official nativescript-plugin-seed

Implemented for iOS only - this plugin uses 11.3 Stripe's SDK.

Installation

tns plugin add nativescript-stripe-sdk

Usage in Android

Set API key

Add this to the main *.module.ts file (app.module.ts)

import * as application from 'tns-core-modules/application';
import * as platform from 'tns-core-modules/platform';

const stripeSdk = require('nativescript-stripe-sdk');

application.on(application.launchEvent, () => {
  if (platform.isIOS) {
    stripeSdk.StripeSdk.setApiKey('yourAPIKey');
  }
});

Usage in UI

<StripePaymentCardTextField
  (paymentCardTextFieldDidChange)="onPaymentCardTextFieldDidChange($event)">
</StripePaymentCardTextField>

Example paymentCardTextFieldDidChange handler

import { StripeSdk } from 'nativescript-stripe-sdk';

...

onPaymentCardTextFieldDidChange(payload) {
  const isValid = StripeSdk.validateCard(payload.cardParams);

  if (isValid) {
    StripeSdk
      .createToken(payload.cardParams)
      .then(token => {
        console.log('Created token: ', token.toString());
      })
      .catch((error: Error) => {
        console.error('Create token error: ', error);
      });
  }
}

Usage in vanilla NS

IMPORTANT: SDK API key needs to be set on app startup

import { StripeSdk } from 'nativescript-stripe-sdk';

application.on(application.launchEvent, () => {
    if (platform.isIOS) {
        StripeSdk.setApiKey('pk_test_u6EwgR7lHu8YKOqO5AOynNVj');
    }
});

Usage in UI

<ui:StripePaymentCardTextField
  expDate="{{ date }}"
  number="{{ number }}"
  cvc="{{ cvc }}"/>
 <ui:StripePaymentCardTextField
  paymentCardTextFieldDidChange="{{ callbackFn }}"/>

Check if given CC is valid (card of STPCardParams type)

import { StripeSdk } from 'nativescript-stripe-sdk';

const isValid = StripeSdk.validateCard(card);

Generate stripe token

IMPORTANT: valid stripe API key needs to be set on app startup

import { StripeSdk } from 'nativescript-stripe-sdk';

StripeSdk
   .createToken(card.cardParams)
   .then(token => { console.log(token); })
   .catch(error => { console.error(error); });

API

In XML:

Property Default Description
expDate not set CC expiration date - typeof Date
number not set CC number - typeof string
cvc not set CC expiration date - typeof string

Running the demo app

git clone [email protected]:piotrilski/nativescript-stripe-sdk.git
cd src/
npm run setup
npm run demo.ios

Running angular demo

git clone [email protected]:piotrilski/nativescript-stripe-sdk.git
cd src/
npm run setup
npm run demo.angular.ios

License

Apache License Version 2.0, January 2004

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.