EienPay Quickstart
Learn how to accept payments and send payouts using the EienPay API. Setup takes less than 5 minutes.
1. Install Library
2. Initialize SDK
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'
});
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.
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
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.
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.
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.
| Code | Type | Description |
|---|---|---|
| 400 - Bad Request | invalid_request_error | The request was unacceptable, often due to missing a required parameter. |
| 401 - Unauthorized | authentication_error | No valid API key provided. |
| 402 - Request Failed | card_error | The parameters were valid but the request failed. |
| 429 - Too Many Requests | rate_limit_error | Too many requests hit the API too quickly. We recommend an exponential backoff of your requests. |
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.
-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
Amount intended to be collected by this payment. A positive integer representing how much to charge in the smallest currency unit.
Three-letter ISO currency code, in lowercase. Must be a supported currency.
A payment source to be charged. This can be the ID of a card, a bank account, or an extracted token.
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.
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d email="jenny.rosen@example.com" \
-d name="Jenny Rosen" \
-d description="My First Test Customer"
Parameters
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.
Customer's full name or business name. This takes up to 256 characters.
Customer's phone number.
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.
-u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
-d charge=ch_1J2Y3Z4
Parameters
The identifier of the charge to refund.
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.
String indicating the reason for the refund. If set, possible values are duplicate, fraudulent, and requested_by_customer.