Socket
Book a DemoInstallSign in
Socket

use-omise

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-omise

A React hook for Omise payments

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
61
12.96%
Maintainers
1
Weekly downloads
 
Created
Source

use-omise

A React hook for collecting card details ready for Omise payments.

Installation

Install with npm

npm install use-omise

or with yarn

yarn add use-omise

And make sure you also have React installed at version 16.8 or above.

How to use

function PaymentForm() {
  const { loading, createToken } = useOmise({
    publicKey: 'YOUR-OMISE-PUBLIC-KEY',
  });

  if (loading) return <div>Loading OmiseJS...</div>;

  const handleSubmit = (cardFormValues) => {
    createToken('card', cardFormValues, (status, response) => {
      if (status === 200) {
        // The token is available as response.id.
        // Send the token to your server to create a charge e.g. { token: response.id }
      }
    });
  };

  return <CreditCardForm handleSubmit={handleSubmit} />;
}

The cardFormValues object will hold the details of the card to be charged, e.g.

{
  name: "Exmaple card holder",
  number: "4242424242424242",
  security_code: "111",
  expiration_month: "06",
  expiration_year: "2020"
}

How it works

  • Loads the Omise.js script. By default it will use the primary CDN (Singapore) but the secondary CDN (Japan) can also be used
  • Once loaded, it will initialise Omise by setting the public key that you provide
  • Returns you the createToken function which can be used to use create tokens which can then be used to make charges
    • Also returned is the createSource function for creating sources

Keywords

react

FAQs

Package last updated on 23 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts