pagaris-node
Pagaris API client (i.e SDK) for Node
Installation
npm install pagaris --save# or yarn add pagaris
Usage
Promise
Using Methods that perform HTTP requests to the API (e.g. Order.prototype.create()
) return a Promise instead of using callbacks.
{ let order = amount: 5432 await order }
Configuration
Warning: Never store your credentials in plaintext. We recommend using environment variables.
Note: The private key you use in
Pagaris.private_key=
determines the current environment for all calls (i.e. sandbox or production calls).
const Pagaris Order Signature = PagarisapplicationId = processenvPAGARIS_APPLICATION_IDPagarisprivateKey = processenvPAGARIS_PRIVATE_KEY
Creating an Order
// NOTE: You can also call the static `Order.create()` method and pass the same// argumentslet order = amount: 872391 metadata: internal_id: 192 // Optional products: sku: '123' quantity: 3 // Optional redirect_url: 'https://some.url/for/redirect' // Optional, overrides app await order
Getting an Order
let order = await Order
Getting all Orders
let orders = await Orderall // Returns an array of Orders
Confirming an Order
await orderconsole // 'confirmed'
Cancelling an Order
await orderconsole // 'cancelled'
Errors
Any of the previous operations can raise one of the following errors. You can call <Error>.prototype.response
on them to inspect what caused the error.
Errors.UnauthorizedError
- Credentials were not configured correctly or the request is impossible (e.g. trying to confirm an Order which can't be confirmed)Errors.NotFoundError
- When fetching or trying to update an Order with an incorrect id (note the environment in which they were created)Errors.UnprocessableEntityError
- When the parameters are invalid (e.g. creating an Order without an amount, or with an amount less than the minimum amount or greater than the maximum amount).Errors.UnexpectedResponseError
Errors.ServerError
Example of handling errors
await Order
Verifying webhook signatures
// The value of the received `Authorization` headerlet headerValue = 'Pagaris aaa:bbb:ccc' // The path of your app in which this webhook was receivedlet path = '/pagaris_webhooks' // The raw received bodylet body = '{"some": "body"}' Signature // Returns `true` or `false`
Development
To run all tests:
yarn installyarn test
Note: HTTP interactions are recorded via PollyJS (see test/recordings). If you'd like to actually hit the API, you can change the Polly mode and set
APPLICATION_ID
andPRIVATE_KEY
environment variables in a .env file