EienPay Quickstart

Learn how to accept payments and send payouts using the EienPay API. Setup takes less than 5 minutes.

1. Install Library

npm install @EienPay/node

2. Initialize SDK

import { EienPay } from '@EienPay/node';

const EienPay = new EienPay('sk_test_12345');

// Create a charge
const charge = await EienPay.charges.create({
  amount: 2000,
  currency: 'inr',
  source: 'tok_mastercard',
  description: 'Test Charge'
});
Security

Authentication

The EienPay API uses API keys to authenticate requests. You can view and manage your API keys in the EienPay Dashboard.

Your secret API keys should be kept confidential and only stored on your own servers. Your account's secret API key can perform any API request to EienPay without restriction.

Authentication to the API is performed via HTTP Basic Auth. Provide your API key as the basic auth username value. You do not need to provide a password.

curl https://api.EienPay.in/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
Events

Webhooks

EienPay can send webhook events that notify your application any time an event happens on your account. This is especially useful for events that are not triggered by a direct API request, like a dispute being created or a recurring payment succeeding.

Verifying Signatures

EienPay signs the webhook events it sends to your endpoints by including a signature in each event's EienPay-Signature header. This allows you to verify that the events were sent by EienPay, not by a third party.

Browser

Cross-Origin Resource Sharing (CORS)

The EienPay API supports Cross-Origin Resource Sharing (CORS) for all its REST API endpoints, allowing you to make requests directly from a React, Vue, or vanilla Javascript application in the browser.

NEVER use your secret API keys in client-side code! This exposes your account to complete compromise. ONLY use publishable API keys when making CORS requests from the browser.

Troubleshooting

Error Handling

EienPay uses conventional HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted). Codes in the 5xx range indicate an error with EienPay's servers.

CodeTypeDescription
400 - Bad Requestinvalid_request_errorThe request was unacceptable, often due to missing a required parameter.
401 - Unauthorizedauthentication_errorNo valid API key provided.
402 - Request Failedcard_errorThe parameters were valid but the request failed.
429 - Too Many Requestsrate_limit_errorToo many requests hit the API too quickly. We recommend an exponential backoff of your requests.
Core API

Charges

To charge a credit or a debit card, you create a Charge object. You can retrieve and refund individual charges as well as list all charges. Charges are identified by a unique, random ID.

Create a Charge

When you create a new charge, you must specify a source which you can get from our frontend libraries and an amount to charge.

POST/v1/charges
curl https://api.EienPay.in/v1/charges \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d amount=2000 \
  -d currency=inr \
  -d source=tok_mastercard \
  -d description="My First Test Charge (created for API docs)"

Parameters

amountREQUIRED

Amount intended to be collected by this payment. A positive integer representing how much to charge in the smallest currency unit.

currencyREQUIRED

Three-letter ISO currency code, in lowercase. Must be a supported currency.

sourceOPTIONAL

A payment source to be charged. This can be the ID of a card, a bank account, or an extracted token.

Core API

Customers

Customer objects allow you to perform recurring charges, and to track multiple charges, that are associated with the same customer.

Create a Customer

Creates a new customer object. You can optionally pass in an email, name, phone, and description.

POST/v1/customers
curl https://api.EienPay.in/v1/customers \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d email="jenny.rosen@example.com" \
  -d name="Jenny Rosen" \
  -d description="My First Test Customer"

Parameters

emailOPTIONAL

Customer's email address. It's displayed in the Dashboard and can be a useful for searching and tracking. This may be up to 512 characters.

nameOPTIONAL

Customer's full name or business name. This takes up to 256 characters.

phoneOPTIONAL

Customer's phone number.

Core API

Refunds

Refund objects allow you to refund a charge that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally charged.

Create a Refund

When you create a new refund, you must specify a charge on which to create it. Creating a new refund will refund a charge that has previously been created but not yet refunded.

POST/v1/refunds
curl https://api.EienPay.in/v1/refunds \
  -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
  -d charge=ch_1J2Y3Z4

Parameters

chargeREQUIRED

The identifier of the charge to refund.

amountOPTIONAL

A positive integer in cents representing how much of this charge to refund. Can refund only up to the remaining, unrefunded amount of the charge.

reasonOPTIONAL

String indicating the reason for the refund. If set, possible values are duplicate, fraudulent, and requested_by_customer.