paylike-meteor
v2.2.2
Published
[![CircleCI branch](https://img.shields.io/circleci/project/github/JorgenVatle/paylike-meteor/master.svg)](https://circleci.com/gh/JorgenVatle/paylike-meteor) [![Atmosphere](https://img.shields.io/badge/atmosphere-jorgenvatle%3Apaylike-blue.svg)](https://
Downloads
20
Readme
Paylike Meteor
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"
}
}
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
console.log(paylike.me);
Example output:
{
"id": "5bbce49ed0dde36a097c3574",
"name": "Paylike Meteor Test App",
"created": "2018-10-09T17:26:10.187Z"
}
Create app
This adds an app to the merchant your current API key (app) belongs to.
const newApp = paylike.apps.create({
name: 'my-new-app' // Optional
});
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
const merchant = paylike.merchant;
console.log(merchant.name) // "My Online Shop"
Create a merchant
const myMerchant = paylike.merchants.create({
name: 'Acme Commerce',
test: true,
currency: 'EUR',
email: '[email protected]',
website: 'https://example.com',
descriptor: 'ACME',
company: {
country: 'RO'
}
});
console.log(myMerchant.name) // "Acme Commerce"
Fetch a merchant
const myMerchant = paylike.merchants.find('some-merchant-id');
Update a merchant
myMerchant.update({
name: 'Acme Commerce 2',
email: '[email protected]',
descriptor: 'ACME2',
});
console.log(myMerchant.name) // "Acme Commerce 2"
Fetch all merchants
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.
});
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
const acmeUser = myMerchant.users.invite({ email: '[email protected]' });
console.log(acmeUser.id); // "5bbe8430882cf804f6112d9f"
console.log(acmeUser.isMember); // "true"/"false" - Whether or not the user was a member before creation.
Fetch a user
const acmeUser = myMerchant.users.find('[email protected]');
Remove a user
// You can use:
acmeUser.remove();
// Or:
acmeUser.revoke();
// Or:
acmeUser.delete();
Fetch all users
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.
});
Transactions
A transaction, or reservation, defines an amount of funds authorized for captures, refunds and voids.
Create a transaction
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,
});
Fetch a transaction
const transaction = myMerchant.transactions.find('transaction-id-goes-here');
Capture a transaction
transaction.capture({
amount: 1337, // optional - Amount to capture. (defaults to reserved amount)
});
Void a transaction
transaction.void({
amount: 1337, // optional - Amount to void. (defaults to reserved amount)
});
Refund a transaction
transaction.refund({
amount: 1337, // optional - Amount to refund. (defaults to captured amount)
});
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
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
});
Fetch a card
const card = myMerchant.cards.find('card-id-goes-here');
Create a transaction from card
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
});
Fraud alerts
Fetch all fraud alerts
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.
}
});
Fetch an alert
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
- Add your Paylike credentials to
settings.json
(Seesettings.example.json
for an example) - Use
npm install
to install dependencies. - 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.