Skip to content

JorgenVatle/paylike-meteor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

import Paylike from 'meteor/jorgenvatle:paylike';

// Passing your API key here is optional if you've got your API key defined in your Meteor Settings.
const paylike = new Paylike('paylike-api-key');

Meteor settings format:

{
  "paylike": {
    "private": "paylike-api-key"
  }
}

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

console.log(paylike.me);

Example output:

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

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

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

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.

const merchant = paylike.merchant;

console.log(merchant.name) // "My Online Shop"
const myMerchant = paylike.merchants.create({
    name: 'Acme Commerce',
    test: true,
    currency: 'EUR',
    email: 'john@example.com',
    website: 'https://example.com',
    descriptor: 'ACME',
    company: {
        country: 'RO'
    }
});

console.log(myMerchant.name) // "Acme Commerce"
const myMerchant = paylike.merchants.find('some-merchant-id');
myMerchant.update({
    name: 'Acme Commerce 2',
    email: 'jane@example.com',
    descriptor: 'ACME2',
});

console.log(myMerchant.name) // "Acme Commerce 2"
const merchants = paylike.merchants.fetch({
    limit: 50,                          // optional - Defaults to 50.
    before: 'merchant-id-goes-here',    // optional - Fetches all merchants before the given id.
    after: 'merchant-id-goes-here',     // optional - Fetches all merchants after the given id.
});

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

const acmeUser = myMerchant.users.invite({ email: 'steven@example.com' });

console.log(acmeUser.id);       // "5bbe8430882cf804f6112d9f"
console.log(acmeUser.isMember); // "true"/"false" - Whether or not the user was a member before creation.
const acmeUser = myMerchant.users.find('steven@example.com');
// You can use:
acmeUser.remove();

// Or:
acmeUser.revoke();

// Or:
acmeUser.delete();
myMerchant.users.fetch({
    limit: 50,                      // optional - Defaults to 50.
    before: 'user-id-goes-here',    // optional - Fetches all users before the given id.
    after: 'user-id-goes-here',     // optional - Fetches all users after the given id.
});

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

const details = {
    currency: 'EUR',            // required - Currency
    amount: 1337,               // required - Amount of funds to reserve.
    descriptor: 'test-payment', // optional - Descriptor to show up on bank statement 
};

// Use the card associated with a previous transaction:
const transaction = myMerchant.transactions.create({
    transactionId: 'id-of-a-previous-transaction',  // required - Needs to be a valid transaction ID.
    ...details,
});

// ... Or use a saved card:
const cardTransaction = myMerchant.transactions.create({
    cardId: 'card-id-goes-here',
    ...details,
});
const transaction = myMerchant.transactions.find('transaction-id-goes-here');
transaction.capture({
    amount: 1337, // optional - Amount to capture. (defaults to reserved amount) 
});
transaction.void({
    amount: 1337, // optional - Amount to void. (defaults to reserved amount) 
});
transaction.refund({
    amount: 1337, // optional - Amount to refund. (defaults to captured amount)
});

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

const card = myMerchant.cards.save({
    transactionId: 'id-of-a-previous-transaction',  // required - Needs to be a valid transaction ID.
    notes: 'Some notes about this card',            // optional
});
const card = myMerchant.cards.find('card-id-goes-here');
const transaction = card.reserve({
    currency: 'EUR',            // required - Currency
    amount: 1337,               // required - Amount of funds to reserve.
    descriptor: 'test-payment', // optional - Descriptor to show up on bank statement 
});
const alerts = myMerchant.fraudAlerts.fetch({
    limit: 50,                      // optional - limit the alert count. (defaults to 50)
    before: 'alert-id-goes-here',   // optional - Fetches all users before the given id.
    after: 'alert-id-goes-here',    // optional - Fetches all users after the given id.
    filter: {
        transactionId: 'some-id'    // optional - Fetch alerts only for the given transaction.
    }
});
const 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.

About

💸 Meteor package enabling synchronous usage of the Paylike API

Resources

License

Stars

Watchers

Forks

Packages

No packages published