Skip to content

shift4developer/shift4-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shift4 Node.js Library

Build

Installation

npm install shift4

Quick start

const api = require('shift4')('sk_test_my_secret_key');
(async () => {
  try {
    const customer = await api.customers.create({
      email: 'user@example.com',
      description: 'User description'
    })
    console.log('ID of created customer object: ', customer.id);

    const card = await api.cards.create(customer.id, {
      number: '4242424242424242',
      expMonth: '12',
      expYear: '2025',
      cvc: '123',
      cardholderName: 'John Smith'
    })
    console.log('ID of created card object: ', card.id);

    const charge = await api.charges.create({
      amount: 1000,
      currency: "EUR",
      card: card.id,
      customerId: customer.id
    });
    console.log('ID of created charge object: ', charge.id);
  } catch (e) {
    console.error(e)
    // handle errors
  }
})();

API reference

Please refer to detailed API docs (linked) for all available fields

For further information, please refer to our official documentation at https://dev.shift4.com/docs

Developing

To connect to different backend:

var api = require('shift4')({
  secretKey: 'sk_test_my_secret_key',
  apiUrl: 'https://api.myshift4env.com',
  uploadsUrl: 'https://uploads.myshift4env.com'
});

To run tests:

SECRET_KEY=sk_test_my_secret_key npm run test

To run style check:

npm run stylecheck