GithubHelp home page GithubHelp logo

wetillix / ionic-stripe-checkout Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 0.0 417 KB

Ionic/Angular library for Stripe checkout

Home Page: https://wetillix.com/

License: MIT License

JavaScript 1.49% TypeScript 87.02% HTML 6.04% SCSS 5.46%
ionic ionic-framework ionic4 ionic5 angular stripe angular10 checkout stripe-checkout

ionic-stripe-checkout's Introduction

Ionic Stripe Checkout

Documentation Maintenance License: MIT Total downloads

A simple Ionic 5 Stripe Checkout component using Angular.

๐Ÿ“ Table of Contents

โœ… Prerequisites

The current version of the library is compatible with Ionic 4 and Ionic 5.

โฌ‡๏ธ Install

Using npm

npm install --save @vyconsulting/ionic-stripe-checkout

Using yarn

yarn add @vyconsulting/ionic-stripe-checkout

๐Ÿ›  Setup

๐Ÿš€ If you want to use it in development mode, you can use this example. It's based on Stripe secret key.

Once installed you need to import our module firstly in AppModule :

import { IonicStripeCheckoutModule } from '@vyconsulting/ionic-stripe-checkout';

@NgModule({
  ...
  imports: [IonicStripeCheckoutModule.forRoot({
    stripe_secret_key: "YOUR_STRIPE_SECRET_KEY",
  }), ...],
  ...
})
export class AppModule {
}

After do this, in your page where you want to use this component, you will do this:

import { IonicStripeCheckoutModule } from '@vyconsulting/ionic-stripe-checkout';

@NgModule({
  ...
  imports: [IonicStripeCheckoutModule, ...],
  ...
})
export class YourModule {
}

๐Ÿš€ If you want to use it in production mode, you can use this example. It's based on Stripe publishable key.

Once installed you need to import our module firstly in AppModule :

import { IonicStripeCheckoutModule } from '@vyconsulting/ionic-stripe-checkout';

@NgModule({
  ...
  imports: [IonicStripeCheckoutModule.forRoot({
    stripe_publishable_key: "YOUR_STRIPE_PUBLISHABLE_KEY",
    url_create_payment: "http://YOUR_DOMAIN/YOUR_END_POINT_FOR_CREATE_PAYMENT",
    url_token_card: "http://YOUR_DOMAIN/YOUR_END_POINT_FOR_CREATE_TOKEN",
    language: "en"
  }), ...],
  ...
})
export class AppModule {
}

After do this, in your page where you want to use this component, you will do this:

import { IonicStripeCheckoutModule } from '@vyconsulting/ionic-stripe-checkout';

@NgModule({
  ...
  imports: [IonicStripeCheckoutModule, ...],
  ...
})
export class YourModule {
}

Finally, if you use Express.js as backend, here is an example of code you can use. You can transpose the code into your backend language :

const stripe = require("stripe")("STRIPE_SECRET_KEY");
const express = require("express");
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static("."));

app.post("/create-token", async (req, res) => {
  const token = await stripe.tokens.create({
    card: {
      number: req.body.cardNumber,
      exp_month: req.body.cardMonth,
      exp_year: req.body.cardYear,
      cvc: req.body.cardCVC,
    },
  });
  res.json({ token });
});

app.post("/create-payment", async (request, response) => {
  stripe.charges
    .create({
      amount: request.body.amount,
      currency: request.body.currency,
      source: request.body.source,
    })
    .then((charge) => {
      response.json({ charge });
    })
    .catch((error) => {
      response.json({ error });
    });
});

app.listen(4242, () => console.log("Running on port 4242"));

Usage

Include the component on page template, like the example below:

  <ion-stripe-checkout
    [amount]="100"
    [currency]="'EUR'"
    (checkout)="onPay($event)"
  >
  </ion-stripe-checkout>

In your tsconfig.json file, if you use Angular Language Service extension, add this line :

{
      "compilerOptions": {
       .
       .
       .
        "paths": {
          "@vyconsulting/ionic-stripe-checkout": ["node_modules/@vyconsulting/ionic-stripe-checkout"]
        },

API

Properties

  • amount: number it is the price of your product.
  • currency: string it is the currency of your price. Check Stripe Currency Normalized

Events

  • checkout: EventEmitter<ICreatePaymentCharge | HttpErrorResponse>, the only event dedicated to payment. When the payment is successful, it returns all informations about user checkout. Otherwise it returns HttpErrorResponse from HttpClient.

Features which coming soon

  • Integrate 3D Secure payment

Author

๐Ÿ‘ค Wetillix

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


amilamen

๐Ÿ’ป

This project follows the all-contributors specification.

๐Ÿค Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿ“ License

Copyright ยฉ 2022 Wetillix.
This project is MIT licensed.

ionic-stripe-checkout's People

Contributors

amilamen avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ionic-stripe-checkout's Issues

How to get credit card number before (or) after payment?

Hi @amilamen , I just use this npm. I have a doubt that how to get the card number before or after the payment. I get the exp_Month, exp_Year, and only the last four digit of the card number not full number from stripe charges api. Is there any option to get full card number?
I will wait for your positive reply.
Thanks in advance

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.