paystreet v0.1.0
PayStreet - Node.js library for PaySteet.io
Use this to get started on PayStreet.io fast.
Install
Get started with npm install paystreet --save
Then import the package:
const PayStreet = require('paystreet');
const ps = new PayStreet('api_key');
Use
PayStreet exposes a Promise based interface that's designed for use with async/await.
Authorize a payment
try {
let result = await ps.authorizePayment(recipient, options);
console.log(result);
} catch (err) {
console.log(err);
}
/*
For a payment of $10.00USD to the PayStret user example@paystreet
{
id: '<uuid>',
authorized: {
amount: 1000,
currency: 'usd'
},
to_deliver: {
recipient: 'example@paystreet',
amount: 941,
currency: 'usd'
},
total_fees: 59,
ttl: 3600
}
*/
The object authorized
is the amount and currency that you have authorized to pay to pay (in the base unit of that currency, eg: cents). The object to_deliver
is how much the recipient will get. to_deliver.amount
is always authorized.amount - total_fees
. ttl
is how much longer in seconds before the authorization expires for the payment.
Accept an authorized payment
If your API recieves a call with a paze-payload
attached, you can verify it using the acceptPayment
method.
try {
let result = await ps.acceptPayment(payment_id, options);
console.log(result);
} catch (err) {
console.log(err);
}
/*
For the example above
{
id: '<uuid>',
confirmed: true,
from: example2@paystreet,
amount: 941,
currency: 'usd',
data: {..}
}
*/
If confirmed
is true
then that means the payment has processed and has been credited to your connected Stirpe account.
The object data
is an optional object passed by the user that created the charge.
Cancel an authorized payment
If you have authorized a payment and want to cancel it before it gets accepted, use the cancelPayment()
method.
try {
let result = await ps.cancelPayment(payment_id);
console.log(result);
} catch (err) {
console.log(err);
}
/*
result: {
id: '<uuid>',
cancelled: true
}
*/
List payments recieved
This method lists the last 500 payments you have recieved through PayStreet. It only lists payments which actually went through, not cancelled or pending payments.
try {
let result = await ps.listRecievedPayments();
console.log(result);
} catch (err) {
console.log(err);
}
/*
[{
payment_id: '<uuid>',
from: 'example@paystreet',
amount: 941,
currency: 'usd',
created_at: timestamp
updated_at: timestamp
},
{...},]
*/
List payments sent
This method lists the last 500 payments you have sent through PayStreet. It only lists payments which actually went through, not cancelled or pending payments.
try {
let result = await ps.listSentPayments();
console.log(result);
} catch (err) {
console.log(err);
}
/*
[{
payment_id: '<uuid>',
to: 'example1@paystreet',
amount: 4054,
currency: 'usd',
created_at: timestamp
updated_at: timestamp
},
{...},]
*/
Disclaimer
PayStreet is in an early alpha and should not be used for more than penny testing. This library and associated documentation is likely to change dramatically in the future.
4 years ago