npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rebilly-js-token

v1.5.0

Published

Rebilly payment token library

Downloads

21

Readme

Rebilly JS Token Library

Rebilly.js powers your checkout form and removes the need to send sensitive customer information directly to your servers. Use the library to generate payment tokens to reduce the scope of PCI DSS compliance.

npm devDependencies Status

Rebilly API Spec

The library uses the payment token endpoint from the Rebilly API. See the Rebilly API spec for more details.

Documentation

Visit the GitHub pages for detailed documentation.

Including Rebilly.js

Add Rebilly.js to your page using the following CDN provider, preferably at the bottom before the </body>.

Always use HTTPS when including the library.

Rebilly CDN

<script src="https://cdn.rebilly.com/[email protected]/rebilly.js"></script>

The library is then available in the global scope as Rebilly.

Usage

After including the library into your page, you must authenticate your API requests then define the data to use for the token and provide callback function.

Authentication

Once included in your checkout page, authenticate your token requests using a publishable API key generated in Rebilly.

Rebilly.setPublishableKey('pk_live_...');

Creating a token

To create a token you must provide two parameters: the form or object literal with the payment instrument data (payment card or bank account) and a callback function that will receive the resulting token from the Rebilly API.

Optionally you can also include an object literal defining extraData to combine to the main payload. This is useful when using a form to include information about the lead source.

Tip: when creating a token, prevent the default submission of the form until a value is returned by the API and injected into your page.

// payload, callback, extraData
Rebilly.createToken(Node|Object, Function[, Object])

Building the payment instrument data

The first parameter will be the payment instrument data. You can use either a form node in your page or a plain object literal.

Parse a form for the payment instrument

The library can look for field with the data-rebilly attribute and compile the data from your form directly. Specify the field name associated in Rebilly as data-rebilly="fieldName".

You can omit providing a method field, the library will detect it based on which fields you specified.

PCI Compliance Note: never define name attributes for the payment card fields in your form. This will prevent field data from showing up in your server logs.

<form>
    <input data-rebilly="pan">
    <input type="number" data-rebilly="expYear">
    <input type="number" data-rebilly="expMonth">
    <input type="number" data-rebilly="cvv">
</form>

Using the form above the library will detect a payment card.

var form = document.getElementsByTagName('form')[0];
Rebilly.createToken(form, callback);
Use an object literal
var payload = {
    method: 'payment-card',
    paymentInstrument: {
        pan: '4111111111111111',
        expYear: '2022',
        expMonth: '12',
        cvv: '123'
    }
};
Rebilly.createToken(payload, callback);
Define the callback

The callback function should be used to inject the token returned by the API into your form. Once submitted, use the value in conjunction with one of the server-side SDKs to create the customer.

// the token is returned as response.data.id
var callback = function (response) {
    // create a hidden input field
    var tokenField = document.createElement('input');
    tokenField.setAttribute('type', 'hidden');
    tokenField.setAttribute('name', 'payment-token');
    tokenField.value = response.data.id;
    // append to the form and submit to the server
    form.appendChild(tokenField);
    form.submit();
};

Rebilly.createToken(form, callback);
Callback Argument

The argument received by the callback contains additional information on the API request and can be used to detect validation errors.

| Property | Type | Description | | -------- | ---- | ----------- | | error | boolean | Defines whether there was an error with the request or not. | | message | string | The response message. Returns success if there was no errors, or the error message. | | status | number | The status code returned by the response. | | data | Object | The response data as returned by the API. The token is exposed as data.id. | | xhr | Object | The raw XHR request object. |

Development Commands

Build development dist folder without sourcemap

yarn run build:dev

Build release dist folder with sourcemap (release)

yarn run build:prod

Run all unit tests

yarn run test

Watch unit tests and re-run on change

yarn run test:watch