jorgenvatle:paylike

v2.2.2Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Paylike Meteor

CircleCI branch Atmosphere

A full-fledged Meteor wrapper for Paylike's API enabling synchronous consumption of their payments API.

Installation

meteor add jorgenvatle:paylike

Usage

Import package

The following examples will use the paylike constant defined below.

1import Paylike from 'meteor/jorgenvatle:paylike';
2
3// Passing your API key here is optional if you've got your API key defined in your Meteor Settings.
4const paylike = new Paylike('paylike-api-key');

Meteor settings format:

1{
2  "paylike": {
3    "private": "paylike-api-key"
4  }
5}

Apps

An app belongs to a merchant and is used to perform actions on the attached merchant. Your API key is regarded as an app.

Current app

1console.log(paylike.me);

Example output:

1{
2  "id": "5bbce49ed0dde36a097c3574",
3  "name": "Paylike Meteor Test App",
4  "created": "2018-10-09T17:26:10.187Z"
5}

Create app

This adds an app to the merchant your current API key (app) belongs to.

1const newApp = paylike.apps.create({
2    name: 'my-new-app' // Optional
3});

Merchants

The Merchant object is responsible for a funding bank account as well as all of it's associated transactions. This is essentially a shop. It is important to note that all users and apps have complete access to their merchant. This includes inviting and removing users.

Current merchant

1const merchant = paylike.merchant;
2
3console.log(merchant.name) // "My Online Shop"

Create a merchant

1const myMerchant = paylike.merchants.create({
2    name: 'Acme Commerce',
3    test: true,
4    currency: 'EUR',
5    email: 'john@example.com',
6    website: 'https://example.com',
7    descriptor: 'ACME',
8    company: {
9        country: 'RO'
10    }
11});
12
13console.log(myMerchant.name) // "Acme Commerce"

Fetch a merchant

1const myMerchant = paylike.merchants.find('some-merchant-id');

Update a merchant

1myMerchant.update({
2    name: 'Acme Commerce 2',
3    email: 'jane@example.com',
4    descriptor: 'ACME2',
5});
6
7console.log(myMerchant.name) // "Acme Commerce 2"

Fetch all merchants

1const merchants = paylike.merchants.fetch({
2    limit: 50,                          // optional - Defaults to 50.
3    before: 'merchant-id-goes-here',    // optional - Fetches all merchants before the given id.
4    after: 'merchant-id-goes-here',     // optional - Fetches all merchants after the given id.
5});

Merchant's Users

A merchant can have several users attached. These have complete access to their respective merchant and can add and remove additional apps and users.

Invite a user

1const acmeUser = myMerchant.users.invite({ email: 'steven@example.com' });
2
3console.log(acmeUser.id);       // "5bbe8430882cf804f6112d9f"
4console.log(acmeUser.isMember); // "true"/"false" - Whether or not the user was a member before creation.

Fetch a user

1const acmeUser = myMerchant.users.find('steven@example.com');

Remove a user

1// You can use:
2acmeUser.remove();
3
4// Or:
5acmeUser.revoke();
6
7// Or:
8acmeUser.delete();

Fetch all users

1myMerchant.users.fetch({
2    limit: 50,                      // optional - Defaults to 50.
3    before: 'user-id-goes-here',    // optional - Fetches all users before the given id.
4    after: 'user-id-goes-here',     // optional - Fetches all users after the given id.
5});

Transactions

A transaction, or reservation, defines an amount of funds authorized for captures, refunds and voids.

Create a transaction

1const details = {
2    currency: 'EUR',            // required - Currency
3    amount: 1337,               // required - Amount of funds to reserve.
4    descriptor: 'test-payment', // optional - Descriptor to show up on bank statement 
5};
6
7// Use the card associated with a previous transaction:
8const transaction = myMerchant.transactions.create({
9    transactionId: 'id-of-a-previous-transaction',  // required - Needs to be a valid transaction ID.
10    ...details,
11});
12
13// ... Or use a saved card:
14const cardTransaction = myMerchant.transactions.create({
15    cardId: 'card-id-goes-here',
16    ...details,
17});

Fetch a transaction

1const transaction = myMerchant.transactions.find('transaction-id-goes-here');

Capture a transaction

1transaction.capture({
2    amount: 1337, // optional - Amount to capture. (defaults to reserved amount) 
3});

Void a transaction

1transaction.void({
2    amount: 1337, // optional - Amount to void. (defaults to reserved amount) 
3});

Refund a transaction

1transaction.refund({
2    amount: 1337, // optional - Amount to refund. (defaults to captured amount)
3});

Cards

Cards saved using the Web SDK are already in your vault and doesn't need to be saved on the backend.

Save a card using a transaction

1const card = myMerchant.cards.save({
2    transactionId: 'id-of-a-previous-transaction',  // required - Needs to be a valid transaction ID.
3    notes: 'Some notes about this card',            // optional
4});

Fetch a card

1const card = myMerchant.cards.find('card-id-goes-here');

Create a transaction from card

1const transaction = card.reserve({
2    currency: 'EUR',            // required - Currency
3    amount: 1337,               // required - Amount of funds to reserve.
4    descriptor: 'test-payment', // optional - Descriptor to show up on bank statement 
5});

Fraud alerts

Fetch all fraud alerts

1const alerts = myMerchant.fraudAlerts.fetch({
2    limit: 50,                      // optional - limit the alert count. (defaults to 50)
3    before: 'alert-id-goes-here',   // optional - Fetches all users before the given id.
4    after: 'alert-id-goes-here',    // optional - Fetches all users after the given id.
5    filter: {
6        transactionId: 'some-id'    // optional - Fetch alerts only for the given transaction.
7    }
8});

Fetch an alert

1const alert = myMerchant.fraudAlerts.find('alert-id-goes-here');

Contributing

Pull requests are more than welcome! When adding new features, going through the effort to include tests for them is greatly appreciated.

Starting the development environment

  1. Add your Paylike credentials to settings.json (See settings.example.json for an example)
  2. Use npm install to install dependencies.
  3. Use npm start to start both the TypeScript build watcher and the test watcher.

Alternatively, start watchers individually

Use npm test to start just the test watcher.

Use npm run build -- --watch to start just the TypeScript build watcher.

License

This repository is licensed under the ISC license.

Copyright (c) 2018, Jørgen Vatle.