diff --git a/CHANGELOG.md b/CHANGELOG.md index 6105c272..8f71b645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 2.8.5 - 2023-02-22 + +feat(Typescript): add typescript definitions + +- TypeScript definitions for all modules and functions in the SDK. +- Add comments throughout the codebase to improve readability and maintainability. +- Add a type declarations file (*.d.ts) to provide better type checking and editor support for consumers of the SDK. + +Overall, this update should provide a better developer experience for anyone using the SDK, by leveraging the power of TypeScript's static type checking and providing clearer documentation and comments throughout the codebase. + ## 2.8.4 - 2022-11-21 - [#310](https://github.com/razorpay/razorpay-node/pull/310) [`3e6daf3`](https://github.com/razorpay/razorpay-node/commit/3e6daf3c555f62eb23660a54eaae756e395ea3b6) : Thanks [@ankitdas13](https://github.com/ankitdas13)! - Fixed `virtualAccount.close` function implementation diff --git a/lib/razorpay.d.ts b/lib/razorpay.d.ts index dbca385c..b1a6428f 100644 --- a/lib/razorpay.d.ts +++ b/lib/razorpay.d.ts @@ -1 +1,113 @@ -declare module "razorpay"; +import API, { RazorpayHeaders } from './types/api' +import addons from "./types/addons" +import plans from "./types/plans" +import items from "./types/items" +import fundAccount from "./types/fundAccount" +import invoices from "./types/invoices" +import transfers from "./types/transfers" +import settlements from './types/settlements' +import orders from './types/orders' +import refunds from './types/refunds' +import qrCode from './types/qrCode' +import virtualAccounts from './types/virtualAccounts' +import payments from './types/payments' +import subscriptions from './types/subscriptions' +import paymentLink from './types/paymentLink' +import cards from './types/cards' +import { validateWebhookSignature } from "./utils/razorpay-utils" +import customers from './types/customers' + +interface IRazorpayConfig { + key_id: string; + key_secret?: string; + headers?: RazorpayHeaders; +} + +declare class Razorpay { + static VERSION: string + static validateWebhookSignature: typeof validateWebhookSignature + + constructor(config: IRazorpayConfig) + api: API + /** + * Customers Entity + * @see https://razorpay.com/docs/api/customers/ + */ + customers: ReturnType + /** + * Addons Entity + * @see https://razorpay.com/docs/api/payments/subscriptions/#add-on + */ + addons: ReturnType + /** + * Plans Entity + * @see https://razorpay.com/docs/api/payments/subscriptions/#plans + */ + plans: ReturnType + /** + * Orders Entity + * @see https://razorpay.com/docs/api/orders + */ + orders: ReturnType + /** + * Orders Entity + * @see https://razorpay.com/docs/api/payments + */ + payments: ReturnType + /** + * Payments Entity + * @see https://razorpay.com/docs/api/payments/route/transfers + */ + transfers: ReturnType + /** + * Transfers Entity + * @see https://razorpay.com/docs/api/refunds + */ + refunds: ReturnType + /** + * Cards Entity + */ + cards: ReturnType + /** + * FundaAccount Entity + * @see https://razorpay.com/docs/api/x/fund-accounts/ + */ + fundAccount: ReturnType + /** + * Items Entity + * @see https://razorpay.com/docs/payments/invoices/items/api/ + */ + items: ReturnType + /** + * PaymentLinks Entity + * @see https://razorpay.com/docs/payments/payment-links/apis + */ + paymentLink: ReturnType + /** + * Invoices Entity + * @see https://razorpay.com/docs/payments/invoices/apis/ + */ + invoices: ReturnType + /** + * QrCode Entity + * @see https://razorpay.com/docs/payments/qr-codes/apis/ + */ + qrCode: ReturnType + /** + * Subscrptions Entity + * @see https://razorpay.com/docs/api/payments/subscriptions/#subscriptions + */ + subscriptions: ReturnType + /** + * Settlements Entity + * @see https://razorpay.com/docs/api/settlements + */ + settlements: ReturnType + /** + * VirtualAccounts Entity + * @see https://razorpay.com/docs/api/payments/smart-collect/ + */ + virtualAccounts: ReturnType +} + +export = Razorpay diff --git a/lib/types/addons.d.ts b/lib/types/addons.d.ts new file mode 100644 index 00000000..8df072f0 --- /dev/null +++ b/lib/types/addons.d.ts @@ -0,0 +1,72 @@ +import API, { INormalizeError, RazorpayPaginationOptions } from './api' +import { Items } from './items'; + +export declare namespace Addons { + interface RazorpayAddon { + /** + * The unique identifier of the created add-on. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * Details of the created add-on. + */ + item: Items.RazorpayItem; + /** + * This specifies the number of units of the add-on to be charged to the customer. For example, `2`. The total amount is calculated as `amount` * `quantity`. + */ + quantity: number; + /** + * The Unix timestamp, indicates when the add-on was created. For example, `1581597318`. + */ + created_at: number; + /** + * The unique identifier of the Subscription to which the add-on is being added. + */ + subscription_id: string; + /** + * The add-on is added to the next invoice that is generated after it is created. This field is populated only after the invoice is generated. Until then, it is `null`. Once the add-on is linked to an invoice, it cannot be deleted. + */ + invoice_id: string; + } +} + + +declare function addons(api: API): { + /** + * Fetches an addon given Addon ID + * + * @param addonId - addon id to be fetched + * + */ + fetch(addonId: string): Promise + fetch(addonId: string, callback: (err: INormalizeError | null, data: Addons.RazorpayAddon) => void): void; + /** + * Delete a addon given Addon ID + * + * @param addonId - addon id to be fetched + * + */ + delete(addonId: string): Promise<[]> + delete(addonId: string, callback: (err: INormalizeError | null, data: []) => void): void; + /** + * Get all addons + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#fetch-all-add-ons) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string, + count: number, + items: Array + }>; + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void +}; +export default addons; diff --git a/lib/types/api.d.ts b/lib/types/api.d.ts new file mode 100644 index 00000000..fa5c8078 --- /dev/null +++ b/lib/types/api.d.ts @@ -0,0 +1,84 @@ +import nodeify from '../utils/nodeify' + +interface IOption { + hostUrl: string; + key_id: string; + key_secret?: string; + ua: string; + headers?: string; +} + +interface IPayload { + url: string; + data: T; +} + +export type INotify = 'email' | 'sms' + +export interface RazorpayHeaders { + 'X-Razorpay-Account'?: string; + 'Content-Type'?: string; +} + +/** + * Key-value pairs + */ +export interface IMap { + [key: string]: T | null; +} + +export type PartialOptional = Omit & Partial> + +export interface RazorpayPaginationOptions { + /** + * The Unix timestamp from when data are to be fetched + */ + from?: number; + /** + * The Unix timestamp till when data are to be fetched. + */ + to?: number; + /** + * The number of data to be fetched. Default value is `10`. Maximum value is `100`. + * This can be used for pagination, in combination with skip. + */ + count?: number; + /** + * The number of data to be skipped. Default value is `0`. + * This can be used for pagination, in combination with count. + */ + skip?: number; +} + +export interface INormalizeError { + statusCode: string | number; + error: { + code: string; + description: string; + field?: any; + source?: string; + step?: string; + reason?: string; + metadata?: { [key: string]: string }; + } +} + +declare class API { + constructor(options: IOption) + get(params: IPayload): Promise + get(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + + post(params: IPayload): Promise + post(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + + put(params: IPayload): Promise + put(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + + patch(params: IPayload): Promise + patch(params: IPayload, callback: (err: INormalizeError, data: V) => void): void + + delete(params: IPayload): Promise + delete(params: IPayload, callback: (err: INormalizeError, data: V) => void): void +} + +export default API \ No newline at end of file diff --git a/lib/types/cards.d.ts b/lib/types/cards.d.ts new file mode 100644 index 00000000..e28e3a0a --- /dev/null +++ b/lib/types/cards.d.ts @@ -0,0 +1,16 @@ +import { Payments } from "./payments"; +import { INormalizeError } from "./api"; + +declare function cards(api: any): { + /** + * Fetch a card given a Card ID + * + * @param cardId - The unique identifier of the card + * + */ + fetch(cardId: string): Promise + fetch(cardId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayCard) => void): void + +} + +export default cards \ No newline at end of file diff --git a/lib/types/customers.d.ts b/lib/types/customers.d.ts new file mode 100644 index 00000000..1a239bb8 --- /dev/null +++ b/lib/types/customers.d.ts @@ -0,0 +1,140 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions } from "./api"; +import { Invoices } from "./invoices"; +import { Tokens } from "./tokens"; + +export declare namespace Customers { + interface RazorpayCustomerBaseRequestBody { + /** + * Customer's name. Alphanumeric value with period (.), apostrophe (') + * and parentheses are allowed. The name must be between 3-50 characters + * in length. For example, `Gaurav Kumar`. + */ + name: string; + /** + * The customer's email address. A maximum length of 64 characters. + * For example, `gaurav.kumar@example.com`. + */ + email?: string; + /** + * The customer's phone number. A maximum length of 15 characters including country code + */ + contact?: string | number; + /** + * `0`: If a customer with the same details already exists, fetches details of the existing customer. + * + * `1` (default): If a customer with the same details already exists, throws an error. + */ + fail_existing?: boolean | 0 | 1; + /** + * Customer's GST number, if available + */ + gstin?: string | null; + /** + * This is a key-value pair that can be used to store additional information about the entity + */ + notes?: IMap; + } + + interface RazorpayCustomerCreateRequestBody extends RazorpayCustomerBaseRequestBody { } + + interface RazorpayCustomerUpdateRequestBody extends Partial> { } + + interface RazorpayCustomer extends RazorpayCustomerBaseRequestBody { + /** + * The unique identifier of the customer. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * Unix timestamp, when the customer was created. + */ + created_at: number; + /** + * Details of the customer's shipping address. + */ + shipping_address?: Invoices.RazorpayInvoiceAddress[]; + } +} + +declare function customers(api: any): { + /** + * Creates a customer + * + * @param params - Check [doc](https://razorpay.com/docs/api/customers/#create-a-customer) for required params + * + */ + create(params: Customers.RazorpayCustomerCreateRequestBody): Promise + create(params: Customers.RazorpayCustomerCreateRequestBody, callback: (err: INormalizeError | null, data: Customers.RazorpayCustomer) => void): void; + /** + * Get all customers + * + * @param params - Check [doc](https://razorpay.com/docs/api/customers/#fetch-all-customers) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string, + count: number, + items: Array + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void; + /** + * Fetches a customer given Customer ID + * + * @param customerId - The unique identifier of the customer. + * + */ + fetch(customerId: string): Promise + fetch(customerId: string, callback: (err: INormalizeError | null, data: Customers.RazorpayCustomer) => void): void; + /** + * Edit a customer given Customer ID + * + * @param customerId - The unique identifier of the customer. + * @param params - Check [doc](https://razorpay.com/docs/api/customers/#edit-customer-details) for required params + * + */ + edit(customerId: string, params: Customers.RazorpayCustomerUpdateRequestBody): Promise + edit(customerId: string, params: Customers.RazorpayCustomerUpdateRequestBody, callback: (err: INormalizeError | null, data: Customers.RazorpayCustomer) => void): void; + /** + * Fetch tokens by customerId + * + * @param customerId - The unique identifier of the customer. + * + */ + fetchTokens(customerId: string): Promise<{ + entity: string, + count: number; + items: Array + }> + fetchTokens(customerId: string, callback: (err: INormalizeError | null, data: { + entity: string, + count: number; + items: Array + }) => void): void; + /** + * Fetch particular token + * + * @param customerId - The unique identifier of the customer. + * @param tokenId - The unique identifier of the token. + * + */ + fetchToken(customerId: string, tokenId: string): Promise + fetchToken(customerId: string, tokenId: string, callback: (err: INormalizeError | null, data: Tokens.RazorpayToken) => void): void; + /** + * Delete a token + * + * @param customerId - The unique identifier of the customer. + * @param tokenId - The unique identifier of the token. + * + */ + deleteToken(customerId: string, tokenId: string): Promise<{ deleted: boolean }> + deleteToken(customerId: string, tokenId: string, callback: (err: INormalizeError | null, data: { deleted: boolean }) => void): void; +} + +export default customers \ No newline at end of file diff --git a/lib/types/fundAccount.d.ts b/lib/types/fundAccount.d.ts new file mode 100644 index 00000000..3b6db312 --- /dev/null +++ b/lib/types/fundAccount.d.ts @@ -0,0 +1,108 @@ +import { IMap, INormalizeError } from "./api"; + +export declare namespace FundAccounts { + interface RazorpayFundAccountBaseRequestBody { + /** + * This is the unique ID linked to a customer. + * For example, `cust_Aa000000000001`. + */ + customer_id: string; + /** + * Data type `string`. The type of account to be linked to the customer ID. + * In this case it will be `bank_account`. + */ + account_type: string; + /** + * Customer bank account details. + */ + bank_account: RazorpayBankAccountBaseRequestBody; + } + + interface RazorpayFundAccountCreateRequestBody extends RazorpayFundAccountBaseRequestBody { } + + interface RazorpayBankAccountBaseRequestBody { + /** + * Data type string. Name of account holder as per bank records. + * For example, `Gaurav Kumar`. + */ + name: string; + /** + * Data type string. Beneficiary account number. + * For example, `11214311215411`. + */ + account_number: string | number; + /** + * Data type string. Customer's bank IFSC. + * For example, `HDFC0000053`. + */ + ifsc: string; + } + + interface RazorpayBankAccount extends RazorpayBankAccountBaseRequestBody { + /** + * Customer's bank name + */ + bank_name: string; + /** + * Key-value pair that can be used to store additional information about the entity. + * Maximum 15 key-value pairs, 256 characters (maximum) each. + */ + notes: IMap | []; + } + + interface RazorpayFundAccount extends Omit { + /** + * The unique ID linked to the fund account. + */ + id: string, + /** + * Indicates the type of entity. + */ + entity: string, + batch_id: string | null, + /** + * Customer bank account details. + */ + bank_account: RazorpayBankAccount; + /** + * Data type string. Status of the fund account + */ + active: boolean, + /** + * The time at which the account was created at Razorpay. + * The output for this parameter is date and time in the Unix format + */ + created_at: number + } +} + + +declare function fundAccount(api: any): { + /** + * Create a Fund Account + * + * @param params - Check [doc](https://razorpay.com/docs/payments/customers/customer-fund-account-api/#create-a-fund-account) for required params + * + */ + create(params: FundAccounts.RazorpayFundAccountCreateRequestBody): Promise + create(params: FundAccounts.RazorpayFundAccountCreateRequestBody, callback: (err: INormalizeError | null, data: FundAccounts.RazorpayFundAccount) => void): void; + /** + * Fetch all Fund Accounts + * + * @param customerId - The unique identifier of the customer + * + */ + fetch(customerId: string): Promise<{ + entity: string; + count: number; + items: Array; + }> + fetch(customerId: string, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array; + }) => void): void + +} + +export default fundAccount \ No newline at end of file diff --git a/lib/types/invoices.d.ts b/lib/types/invoices.d.ts new file mode 100644 index 00000000..ed94d94b --- /dev/null +++ b/lib/types/invoices.d.ts @@ -0,0 +1,404 @@ +import { IMap, INormalizeError, INotify, RazorpayPaginationOptions } from './api' +import { Items } from './items'; +import { Tokens } from './tokens'; + +export declare namespace Invoices { + + interface RazorpayInvoiceBaseRequestBody { + /** + * Indicates the type of entity. Here, it is `invoice`. + */ + type: 'invoice' | 'link'; + /** + * A brief description of the invoice. + */ + description?: string | null; + /** + * Invoice is created in `draft` state when value is set to `1`. + */ + draft?: string; + date?: number | null; + /** + * You can pass the customer_id in this field, if you are using the + * [Customers API](https://razorpay.com/docs/api/customers/). + * If not, you can pass the customer object described in the below fields. + */ + customer_id?: string; + /** + * The currency associated with the invoice. + */ + currency?: string; + /** + * Customer details. + */ + customer?: RazorpayCustomerDetailsBaseRequestBody; + /** + * The unique identifier of the order associated with the invoice. + */ + order_id?: string; + /** + * Details of the line item that is billed in the invoice. + * Maximum of 50 line items. + */ + line_items: RazorpayLineItemsBaseRequestBody[]; + /** + * Timestamp, in Unix format, at which the invoice will expire. + */ + expire_by?: number | null; + /** + * Defines who handles the SMS notification. `1` (default) + */ + sms_notify?: boolean | 0 | 1; + /** + * Defines who handles the email notification. `1` (default) + */ + email_notify?: boolean | 0 | 1; + /** + * Indicates whether the customer can make a partial payment on the invoice. `false` (default) + */ + partial_payment?: boolean | 0 | 1; + /** + * Any custom notes added to the invoice. Maximum of 2048 characters. + */ + notes?: IMap; + /** + * The unique receipt number that you entered for internal purposes. + */ + receipt?: string | null; + /** + * Amount to be paid using the invoice + */ + amount?: number | string; + } + + interface RazorpayInvoiceAddressBaseRequestBody { + /** + * The first line of the customer's address. + */ + line1: string; + /** + * The second line of the customer's address. + */ + line2?: string; + /** + * The zipcode + */ + zipcode: string | number; + /** + * The city + */ + city: string; + /** + * The state + */ + state?: string; + /** + * The country + */ + country: string; + } + + interface RazorpayInvoiceAddress extends RazorpayInvoiceAddressBaseRequestBody { + id: string; + type: string; + primary: boolean; + contact: string | null; + name: string | null; + tag: string | null; + landmark: string | null; + } + + interface RazorpayCustomerDetailsBaseRequestBody { + /** + * Customer's name. Alphanumeric, with period (.),apostrophe (') and + * parentheses allowed. The name must be between 3-50 characters in + * length. For example, Gaurav Kumar. + */ + name?: string | null; + /** + * The customer's email address. A maximum length of 64 characters. + * For example, `gaurav.kumar@example.com`. + */ + email?: string | null; + /** + * The customer's phone number. A maximum length of + * 15 characters including country code. + */ + contact?: string | number | null; + /** + * Details of the customer's billing address. + */ + billing_address?: RazorpayInvoiceAddressBaseRequestBody; + /** + * Details of the customer's shipping address. + */ + shipping_address?: RazorpayInvoiceAddressBaseRequestBody; + } + + interface RazorpayCustomerDetails extends Omit { + /** + * Unique identifier of the customer + */ + id?: string; + /** + * GST number linked to the customer. + */ + gstin?: string | null; + /** + * The customer's name. + */ + customer_name?: string | null; + /** + * The customer's email address. + */ + customer_email?: string | null; + /** + * The customer's contact number. + */ + customer_contact?: string | null; + /** + * Details of the customer's billing address. + */ + billing_address?: RazorpayInvoiceAddress; + /** + * Details of the customer's shipping address. + */ + shipping_address?: RazorpayInvoiceAddress; + } + + interface RazorpayInvoiceCreateRequestBody extends RazorpayInvoiceBaseRequestBody { } + + interface RazorpayInvoiceUpdateRequestBody extends Partial { } + + interface RazorpayLineItemsBaseRequestBody extends Partial { + /** + * Unique identifier that is generated if a new item has been created while creating the invoice. + */ + id?: string; + /** + * Unique identifier of the item generated using Items API that has been billed in the invoice. + */ + item_id?: string; + /** + * The quantity of the item billed in the invoice. Defaults to `1`. + */ + quantity?: number; + } + + interface RazorpayLineItems extends Items.RazorpayItem { + item_id?: string; + ref_id: string | null; + ref_type: string | null; + gross_amount: number | null; + tax_amount: number | null; + taxable_amount: number | null; + net_amount: number | null; + taxes: any[]; + quantity: number; + } + + interface RazorpayInvoice extends RazorpayInvoiceBaseRequestBody { + /** + * The unique identifier of the invoice. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * Unique number you added for internal reference. + * The minimum character length is 1 and maximum is 40. + */ + invoice_number: string; + /** + * Details of the customer. + */ + customer_details: RazorpayCustomerDetails; + /** + * Details of the line item that is billed in the invoice. + * Maximum of 50 line items. + */ + line_items: RazorpayLineItems[]; + /** + * Unique identifier of a payment made against this invoice. + */ + payment_id?: string | null; + /** + * Timestamp, in Unix format, at which the invoice was issued to the customer. + */ + issued_at?: number | null; + /** + * Timestamp, in Unix format, at which the payment was made. + */ + paid_at?: number | null; + /** + * Timestamp, in Unix format, at which the invoice was cancelled. + */ + cancelled_at?: number | null; + /** + * Timestamp, in Unix format, at which the invoice expired. + */ + expired_at?: number | null; + /** + * The delivery status of the SMS notification for the invoice + * sent to the customer. + */ + sms_status?: 'pending' | 'sent' | null; + /** + * The delivery status of the email notification for the invoice + * sent to the customer. + */ + email_status?: 'pending' | 'sent' | null; + gross_amount?: number; + tax_amount?: number; + taxable_amount?: number; + /** + * The status of the invoice. Know more about + * [Invoice States](https://razorpay.com/docs/payments/invoices/states) +. + */ + status?: + | 'draft' + | 'issued' + | 'partially_paid' + | 'paid' + | 'cancelled' + | 'cancelled' + | 'expired' + | 'deleted'; + /** + * Amount paid by the customer against the invoice. + */ + amount_paid?: number; + /** + * The remaining amount to be paid by the customer for the issued invoice. + */ + amount_due?: number; + /** + * The short URL that is generated. Share this link with customers to accept payments. + */ + short_url?: string | null; + currency_symbol?: string | null; + billing_start?: number | null; + billing_end?: number | null; + group_taxes_discounts?: boolean; + terms?: number | null; + comment?: number | null; + /** + * Timestamp, in Unix format, at which the invoice was cancelled. + */ + created_at: number; + view_less?: boolean; + idempotency_key?: any + ref_num?: any; + /** + * Details related to the authorization transaction such as max amount and bank + * account information. Pass a value in the `first_payment_amount` parameter + * if you want to auto-charge the customer the first payment immediately + * after authorization. + */ + token?: Tokens.RazorpayAuthorizationToken; + } + + interface RazorpayInvoiceQuery extends RazorpayPaginationOptions { + type?: string; + /** + * The unique identifier of the payment made by the customer against the invoice. + */ + payment_id?: string; + /** + * The unique receipt number that you entered for internal purposes. + */ + receipt?: string; + /** + * The unique identifier of the customer. When used, + * fetches all invoices generated for a customer. + */ + customer_id?: string; + /** + * The unique identifier linked to the Subscription. + */ + subscription_id?: string; + } +} + +declare function invoices(api: any): { + /** + * Creates a invoice + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/invoices/#create-an-invoice) for required params + * + */ + create(params: Invoices.RazorpayInvoiceCreateRequestBody): Promise + create(params: Invoices.RazorpayInvoiceCreateRequestBody, callback: (err: INormalizeError | null, data: Invoices.RazorpayInvoice) => void): void; + /** + * Get all invoices + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/invoices/#fetch-multiple-invoices) for required params + * + */ + all(params?: Invoices.RazorpayInvoiceQuery): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: Invoices.RazorpayInvoiceQuery, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetches a invoice given Invoice ID + * + * @param invoiceId - The unique identifier of the invoice + * + */ + fetch(invoiceId: string): Promise + fetch(invoiceId: string, callback: (err: INormalizeError | null, data: Invoices.RazorpayInvoice) => void): void; + /** + * Edit a invoice given Invoice ID + * + * @param invoiceId - The unique identifier of the invoice + * @param params - Check [doc](https://razorpay.com/docs/api/payments/invoices/#update-an-invoice) for required params + * + */ + edit(invoiceId: string, params: Invoices.RazorpayInvoiceUpdateRequestBody): Promise + edit(invoiceId: string, params: Invoices.RazorpayInvoiceUpdateRequestBody, callback: (err: INormalizeError | null, data: Invoices.RazorpayInvoice) => void): void; + + /** + * Issue an invoice + * + * @param invoiceId - The unique identifier of the invoice + * + */ + issue(invoiceId: string): Promise + issue(invoiceId: string, callback: (err: INormalizeError | null, data: Invoices.RazorpayInvoice) => void): void; + /** + * Delete an invoice + * + * @param invoiceId - The unique identifier of the invoice + * + */ + delete(invoiceId: string): Promise<[]> + delete(invoiceId: string, callback: (err: INormalizeError | null, data: []) => void): void; + /** + * Cancel an invoice + * + * @param invoiceId - The unique identifier of the invoice + * + */ + cancel(invoiceId: string): Promise + cancel(invoiceId: string, callback: (err: INormalizeError | null, data: Invoices.RazorpayInvoice) => void): void; + /** + * Send notification + * + * @param invoiceId - The unique identifier of the invoice + * @param medium - Possible values: `sms`, `email` + * + */ + notifyBy(invoiceId: string, medium: INotify): Promise<{ success: boolean }> + notifyBy(invoiceId: string, medium: INotify, callback: (err: INormalizeError | null, data: { success: boolean }) => void): void; +} + +export default invoices \ No newline at end of file diff --git a/lib/types/items.d.ts b/lib/types/items.d.ts new file mode 100644 index 00000000..9597fbde --- /dev/null +++ b/lib/types/items.d.ts @@ -0,0 +1,155 @@ +import { RazorpayPaginationOptions, INormalizeError } from "./api"; + +export declare namespace Items { + interface RazorpayItemBaseRequestBody { + /** + * A name for the item. For example, `Extra appala (papadum)`. + */ + name: string; + /** + * The amount you want to charge the customer for the item, in the currency subunit. For example, `30000`. + */ + amount: number | string; + /** + * The currency in which the customer should be charged for the item. For example, `INR`. + */ + currency: string; + /** + * Description for the item. For example, `1 extra oil fried appala with meals` + */ + description?: string; + } + + interface RazorpayItemCreateRequestBody extends RazorpayItemBaseRequestBody { } + + interface RazorpayItemUpdateRequestBody extends Partial { + /** + * Indicates the status of the item. Possible values : + * `true` - Item is in `active` state + * `false` - Item is in `inactive` state. By + * default, the item is in `active` state. + */ + active?: boolean; + } + + interface RazorpayItem extends RazorpayItemBaseRequestBody { + /** + * The unique identifier of the item. + */ + id: string; + /** + * The per unit billing amount for each individual unit. + */ + unit_amount: number; + /** + * Here, it must be `invoice` + */ + type: string; + /** + * The number of units of the item billed in the invoice. + */ + unit: number | null; + /** + * Indicates whether the base amount includes tax. + * + * `true`: The base amount includes tax. + * + * `false`: The base amount does not include tax. By default, the value is set to `false`. + */ + tax_inclusive: boolean; + /** + * The 8-digit code used to classify the product as per the Harmonised System of Nomenclature. + */ + hsn_code: number | null; + /** + * The 6-digit code used to classify the service as per the Services Accounting Code. + */ + sac_code: number | null; + /** + * The percentage at which an individual or a corporation is taxed. + */ + tax_rate: number | null; + /** + * The identification number that gets displayed on invoices issued to the customer. + */ + tax_id: string | null; + /** + * The identification number for the tax group. A tax group is a collection of taxes + * that can be applied as a single set of rules. + */ + tax_group_id: string | null; + /** + * Unix timestamp, at which the item was created. For example, `1649843796`. + */ + created_at: number; + /** + * Unix timestamp, at which the item was updated. + */ + updated_at: number; + /** + * Indicates the status of the item. Possible values : + * `true` - Item is in `active` state + * `false` - Item is in `inactive` state. By + * default, the item is in `active` state. + */ + active: boolean; + } + + interface RazorpayItemQuery extends RazorpayPaginationOptions { + active?: number; + } +} + +declare function items(api: any): { + /** + * Create an Item + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/items#create-an-item) for required params + * + */ + create(params: Items.RazorpayItemCreateRequestBody): Promise + create(params: Items.RazorpayItemCreateRequestBody, callback: (err: INormalizeError | null, data: Items.RazorpayItem) => void): void; + /** + * Get all Items + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/items#fetch-multiple-items) for required params + * + */ + all(params?: Items.RazorpayItemQuery): Promise<{ + entity: string, + count: number, + items: Array + }>; + all(params: Items.RazorpayItemQuery, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetch a item given Item ID + * + * @param itemId - The unique identifier of the item. + * + */ + fetch(itemId: string): Promise + fetch(itemId: string, callback: (err: INormalizeError | null, data: Items.RazorpayItem) => void): void; + /** + * Edit a items given Item ID + * + * @param itemId - The unique identifier of the item. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/items#update-an-item) for required params + * + */ + edit(itemId: string, params: Items.RazorpayItemUpdateRequestBody): Promise + edit(itemId: string, params: Items.RazorpayItemUpdateRequestBody, callback: (err: INormalizeError | null, data: Items.RazorpayItem) => void): void; + /** + * Delete a item given Item ID + * + * @param itemId - The unique identifier of the item. + * + */ + delete(itemId: string): Promise<[]> + delete(itemId: string, callback: (err: INormalizeError | null, data: []) => void): void; +} + +export default items \ No newline at end of file diff --git a/lib/types/orders.d.ts b/lib/types/orders.d.ts new file mode 100644 index 00000000..ed46f164 --- /dev/null +++ b/lib/types/orders.d.ts @@ -0,0 +1,295 @@ +import { IMap, RazorpayPaginationOptions, INormalizeError } from './api' +import { FundAccounts } from './fundAccount' +import { Payments } from './payments' +import { Tokens } from './tokens' +import { Transfers } from './transfers' + +export declare namespace Orders { + + interface RazorpayOrderBankDetailsBaseRequestBody { + /** + * The bank account number from which the customer should make the payment. + * For example, `765432123456789` + */ + account_number: string | number; + /** + * The bank IFSC. For example, `HDFC0000053` + */ + ifsc: string; + } + + interface RazorpayOrderBankDetailsCreateRequestBody extends RazorpayOrderBankDetailsBaseRequestBody { + /** + * The name linked to the bank account. For example, Gaurav Kumar. + */ + name: string; + } + + + interface RazorpayOrderBaseRequestBody { + /** + * The amount for which the order was created, in currency subunits. + * For example, for an amount of ₹295, enter 29500 + */ + amount: number | string; + /** + * ISO code for the currency in which you want to accept the payment. + */ + currency: string; + /** + * Receipt number that corresponds to this order, set for your internal reference. + * Can have a maximum length of 40 characters and has to be unique. + */ + receipt?: string; + /** + * The unique identifier of the offer that is linked to the Subscription. + * You can obtain this from the Dashboard. + * For example, `offer_JHD834hjbxzhd38d` + */ + offer_id?: string | null; + /** + * The payment method used to make the payment. If this parameter is not passed, + * customers will be able to make payments using both netbanking and UPI payment methods + */ + method?: 'netbanking' | 'upi' | 'card' | 'emandate' | 'nach'; + /** + * Details of the bank account that the customer has provided at the time of registration. + */ + bank_account?: RazorpayOrderBankDetailsCreateRequestBody; + /** + * Key-value pair that can be used to store additional information about the entity. + * Maximum 15 key-value pairs, 256 characters (maximum) each. + */ + notes?: IMap; + /** + * Indicates whether the customer can make a partial payment. Possible values: + * `true` The customer can make partial payments. + * `false` (default) : The customer cannot make partial payments. + */ + partial_payment?: boolean; + /** + * Minimum amount that must be paid by the customer as the first partial payment. + * For example, if an amount of ₹7,000 is to be received from the customer in + * two installments of #1 - ₹5,000, #2 - ₹2,000, then you can set this value as 500000. + * This parameter should be passed only if partial_payment is true. + */ + first_payment_min_amount?: number; + /** + * Payment capture settings for the payment. The options sent here override the account + * level [auto-capture settings]( https://razorpay.com/docs/payments/payments/capture-settings) configured using the Dashboard. + */ + payment?: RazorpayCapturePayment; + } + + interface RazorpayOrderCreateRequestBody extends RazorpayOrderBaseRequestBody { } + + interface RazorpayTransferCreateRequestBody extends Pick { + /** + * Details regarding the transfer. + */ + transfers: Transfers.RazorpayOrderCreateRequestBody[]; + } + + interface RazorpayAuthorizationCreateRequestBody extends Omit { + /** + * Determines whether tha payment status should be changed to captured automatically or not. + * `true`: Payments are captured automatically. + * `false`: Payments are not captured automatically. + */ + payment_capture?: boolean; + /** + * The unique identifier of the customer. + */ + customer_id: string; + /** + * Details related to the authorization such as max amount, + * frequency and expiry information. + */ + token: Tokens.RazorpayTokenCard | Tokens.RazorpayTokenEmandate | Tokens.RazorpayTokenNach; + } + + interface RazorpayOrderUpdateRequestBody extends Pick { } + + interface RazorpayOrder extends Omit { + /** + * The unique identifier of the order + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The amount paid against the order. + */ + amount_paid: number; + /** + * The amount pending against the order. + */ + amount_due: number, + /** + * The status of the order. + */ + status: 'created' | 'attempted' | 'paid'; + /** + * The number of payment attempts, successful and failed, + * that have been made against this order. + */ + attempts: number; + /** + * Indicates the Unix timestamp when this order was created. + */ + created_at: number; + /** + * A description that appears on the hosted page. + * For example, `12:30 p.m. Thali meals (Gaurav Kumar)`. + */ + description: string; + /** + * Details related to the authorization such as max amount, + * frequency and expiry information. + */ + token: Tokens.RazorpayAuthorizationToken; + payments?: { [key:string] : string }; + offers?: { [key:string] : string }; + transfers?: {entity: string; count: string; items: Transfers.RazorpayTransfer[] } | Transfers.RazorpayTransfer[]; + } + + interface RazorpayOrderQuery extends RazorpayPaginationOptions { + /** + * Possible values: + * `1` : Retrieves Orders for which payments have been authorized. Payment and order states differ. + * `0` : Retrieves orders for which payments have not been authorized. + */ + authorized?: boolean | 1 | 0; + /** + * Retrieves the orders that contain the provided value for receipt. + */ + receipt?: string; + /** + * Used to retrieve additional information about the payment. + * Using this parameter will cause a sub-entity to be added to the response. + */ + 'expand[]'?: 'payments' | 'payments.card' | 'transfers' | 'virtual_account'; + } + + interface RazorpayBankAccountBaseRequestBody { + /** + * Name of the beneficiary. + */ + beneficiary_name: string; + beneficiary_mobile?: string; + /** + * Customer's bank account number. + */ + account_number: string | number; + /** + * Customer's bank account type. `savings`(default) + */ + account_type: 'savings' | 'current'; + /** + * Customer's bank IFSC. For example `UTIB0000001`. + */ + ifsc_code: string; + } + + interface RazorpayBankAccount extends Omit { + beneficiary_email: string; + } + + interface RazorpayCapturePayment { + /** + * Option to automatically capture payment + */ + capture: 'automatic' | 'manual'; + capture_options?: { + /** + * Time in minutes till when payments in the `authorized` + * state should be auto-captured. Minimum value `12` minutes. + * This parameter is mandatory only if the value of `capture` + * parameter is `automatic`. + */ + automatic_expiry_period: number; + /** + * Time in minutes till when you can manually + * capture payments in the `authorized` state. + */ + manual_expiry_period: number; + /** + * Refund speed for payments that were not + * captured (automatically or manually). + */ + refund_speed: 'optimum' | 'normal'; + } + } +} + +declare function orders(api: any): { + /** + * Creates a order + * + * @param params - Check [doc](https://razorpay.com/docs/api/orders/#create-an-order) for required params + * @see https://razorpay.com/docs/api/payments/recurring-payments/ + */ + create(params: Orders.RazorpayOrderCreateRequestBody | Orders.RazorpayTransferCreateRequestBody | Orders.RazorpayAuthorizationCreateRequestBody): Promise + create(params: Orders.RazorpayOrderCreateRequestBody | Orders.RazorpayTransferCreateRequestBody | Orders.RazorpayAuthorizationCreateRequestBody, callback: (err: INormalizeError | null, data: Orders.RazorpayOrder) => void): void; + /** + * Get all orders + * + * @param params + * + */ + all(params?: Orders.RazorpayOrderQuery): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: Orders.RazorpayOrderQuery, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetches a order given Order ID + * + * @param orderId - The unique identifier of the order + * + */ + fetch(orderId: string): Promise + fetch(orderId: string, callback: (err: INormalizeError | null, data: Orders.RazorpayOrder) => void): void + /** + * Edit a order given Order ID + * + * @param orderId - The unique identifier of the order + * @param params - Check [doc](https://razorpay.com/docs/api/orders/#update-order) for required params + * + */ + edit(orderId: string, params: Orders.RazorpayOrderUpdateRequestBody): Promise + edit(orderId: string, params: Orders.RazorpayOrderUpdateRequestBody, callback: (err: INormalizeError | null, data: Orders.RazorpayOrder) => void): void + /** + * Fetch payments for an order + * + * @param orderId - The unique identifier of the order + * + */ + fetchPayments(orderId: string, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + fetchPayments(orderId: string): Promise<{ + entity: string, + count: number, + items: Array + }> + /** + * Fetch transfers for an order + * + * @param orderId - The unique identifier of the order + * + */ + fetchTransferOrder(orderId: string): Promise + fetchTransferOrder(orderId: string, callback: (err: INormalizeError | null, data: Orders.RazorpayOrder) => void): void +} + +export default orders \ No newline at end of file diff --git a/lib/types/paymentLink.d.ts b/lib/types/paymentLink.d.ts new file mode 100644 index 00000000..093b52d0 --- /dev/null +++ b/lib/types/paymentLink.d.ts @@ -0,0 +1,410 @@ +import { IMap, INormalizeError, INotify, RazorpayPaginationOptions, PartialOptional } from "./api"; +import { Customers } from "./customers"; +import { Transfers } from "./transfers"; + +export declare namespace PaymentLinks { + + interface RazorpayPaymentLinkBaseRequestBody { + /** + * Must be set to `true` for creating UPI Payment Link. + */ + upi_link?: boolean; + /** + * Amount to be paid using the Payment Link. Must be in the smallest unit of the currency. + * For example, if you want to receive a payment of ₹299.95, you must enter the value 29995. + */ + amount: number | string; + /** + * A three-letter ISO code for the currency in which you want to accept the payment. + * For example, `INR`. + */ + currency?: string; + /** + * Indicates whether customers can make partial payments using the Payment Link. + * + * `true`: Customer can make partial payments. + * + * `false` (default): Customer cannot make partial payments. + */ + accept_partial?: boolean; + expire_by?: number; + reference_id?: string; + /** + * Minimum amount, in currency subunits, that must be paid by the customer as the first partial payment. + * Default value is `100`. Default currency is `INR`. For example, if an amount of ₹7,000 is to be received + * from the customer in two installments of #1 - ₹5,000, #2 - ₹2,000, then you can set this value as `500000`. + * Must be passed along with accept_partial parameter. + */ + first_min_partial_amount?: number; + /** + * A brief description of the Payment Link. The maximum character limit supported is 2048. + */ + description?: string; + /** + * Customer details + */ + customer: Pick; + /** + * Defines who handles Payment Link notification. + */ + notify?: { + /** + * Defines who handles the email notification. + */ + email?: boolean; + /** + * Defines who handles the SMS notification. + */ + sms?: boolean; + whatsapp?: boolean; + }, + /** + * Used to send remindersfor the Payment Link. + */ + reminder_enable?: boolean; + /** + * Key-value pair that can be used to store additional information about the entity. + */ + notes?: IMap; + /** + * If specified, adds a redirect URL to the Payment Link. Once customers completes the payment, + * they are redirected to the specified URL. + */ + callback_url?: string; + /** + * If callback_url parameter is passed, callback_method must be passed with the value `get`. + */ + callback_method?: string; + } + + interface RazorpayPaymentLinkCreateRequestBody extends RazorpayPaymentLinkBaseRequestBody { } + + interface RazorpayPaymentLinkUpdateRequestBody extends Pick { } + + interface RazorpayPaymentLink extends RazorpayPaymentLinkBaseRequestBody { + /** + * Amount paid by the customer. + */ + amount_paid: number; + /** + * Timestamp, in Unix, at which the Payment Link was cancelled by you. + */ + cancelled_at: number; + /** + * Timestamp, in Unix, at which the Payment Link expired. + */ + expired_at: number; + /** + * The unique identifier of the Payment Link + */ + id: string; + /** + * Payment details such as amount, payment ID, Payment Link ID and more. + * This array gets populated only after the customer makes a payment. + * Until then, the value is `null`. + */ + payments: RazorpayPaymentBaseRequestBody | null; + reminders: { + status: string; + }; + /** + * The unique short URL generated for the Payment Link. + */ + short_url: string; + + source?: string; + source_id?: string; + /** + * Displays the current state of the Payment Link + */ + status: 'created' | 'partially_paid' | 'expired' | 'cancelled' | 'paid'; + /** + * Timestamp, in Unix, indicating when the Payment Link was updated. + */ + updated_at: number; + /** + * A unique identifier for the user role through which the Payment Link was created. + * For example, `HD1JAKCCPGDfRx`. + */ + user_id: string; + created_at: string; + } + + interface RazorpayPaymentBaseRequestBody { + /** + * The amount paid by the customer using the Payment Link. + */ + amount: string; + /** + * Timestamp, in Unix, indicating when the payment was made. + */ + created_at: string; + /** + * The payment method used to make the payment. + */ + method: 'card' | 'netbanking' | 'wallet' | 'emi' | 'upi' | 'bank_transfer'; + /** + * Unique identifier of the payment made against the Payment Link. + */ + payment_id: string; + /** + * Unique identifier of the Payment Link. For example, `plink_ERgihyaAAC0VNW` + */ + plink_id: string; + /** + * The payment state. + */ + status: 'captured' | 'failed'; + /** + * Timestamp, in Unix, indicating when the payment was updated. + */ + updated_at: number; + } + + interface RazorpayPaymentLinkAdvanceOption extends RazorpayPaymentLinkBaseRequestBody { + options: + | RazorpayTransferPayment + | RazorpayOffer + | RazorpayCustomizeCheckout + } + + interface RazorpayTransferPayment { + /** + * Options to configure the transfer in the Payment Link. + * Parent parameter under which the order child parameter must be passed. + */ + order: { + /** + * Pass transfer details such as amount, account, linked account information and more + */ + transfers: PartialOptional[] + } + } + + interface RazorpayOffer { + /** + * Options to associate the offer_id with the Payment Link. + * Parent parameter under which the `order` child parameter must be passed. + */ + order: { + /** + * Unique identifier of the offer + */ + offers: string[]; + } + } + + interface RazorpayCustomizeCheckout { + checkout: + | RazorpayCheckoutRenameLabels + | RazorpayCheckoutChangeBusinessName + | RazorpayCheckoutPrefillCard + | RazorpayCheckoutPrefillNetBanking + | RazorpayCheckoutPrefillWallet + | RazorpayCheckoutPrefillVpa + | RazorpayCheckoutPaymentMethod + | RazorpayCheckoutReadonly + | RazorpayCheckoutThematicChange + } + + interface RazorpayCheckoutRenameLabels { + /** + * Options to rename the labels for partial payment fields in the checkout form. + * Parent parameter under which the `checkout` and `partial_payment` child parameters + * must be passed. + */ + partial_payment: { + /** + * Changes the label for the `Minimum first amount` field. + */ + min_amount_label: string; + /** + * Changes the label for the `Make payment in parts` field. + */ + partial_amount_label: string; + /** + * Changes the label for the `Pay some now and the remaining later` field. + */ + partial_amount_description: string; + /** + * Changes the label for the `Pay in full` field. + */ + full_amount_label: string; + } + } + + interface RazorpayCheckoutChangeBusinessName { + /** + * Used to change the business name that appears on the Checkout section + * of the Payment Link's payment request page. + */ + name?: string; + description?: string; + } + + interface RazorpayCheckoutPrefillCard { + /** + * Prefills the payment method and related details on Checkout. + */ + prefill: { + /** + * Pre-selection of the payment method for the customer. + * Will only work if contact and email are also pre-filled + */ + method?: 'card' | 'netbanking' | 'wallet' | 'upi'; + /** + * The name of the owner, who owns the card. + * This is usually found printed in front of the card. + */ + 'card[name]': string; + /** + * Unformatted card number. This should be 16 digits in total. + */ + 'card[number]': string; + /** + * Expiry month and year for card. This should be in MM/YY format. + */ + 'card[expiry]': string; + 'card[cvv]': string; + } + } + + interface RazorpayCheckoutPrefillNetBanking { + /** + * Prefills the payment method and related details on Checkout. + */ + prefill: { + /** + * Pre-selection of the payment method for the customer. + * Will only work if contact and email are also pre-filled + */ + method?: 'card' | 'netbanking' | 'wallet' | 'upi'; + /** + * Prefills the customer's bank code. The value must be entered in upper case. + * For example, for HDFC bank, it should be "HDFC". + */ + bank: string; + } + } + + interface RazorpayCheckoutPrefillWallet { + /** + * Prefills the payment method and related details on Checkout. + */ + prefill: { + /** + * Pre-selection of the payment method for the customer. + * Will only work if contact and email are also pre-filled + */ + method?: 'card' | 'netbanking' | 'wallet' | 'upi'; + /** + * Wallet code used to authorize the payment requested. + */ + wallet: string; + } + } + + interface RazorpayCheckoutPrefillVpa { + /** + * Prefills the payment method and related details on Checkout. + */ + prefill: { + /** + * Pre-selection of the payment method for the customer. + * Will only work if contact and email are also pre-filled + */ + method?: 'card' | 'netbanking' | 'wallet' | 'upi'; + /** + * UPI ID for making the payment on the UPI app. + */ + vpa: string; + } + } + + interface RazorpayCheckoutPaymentMethod { + /** + * Options to display or hide payment methods on the Checkout section. + * Parent parameter under which the checkout and method child parameters must be passed. + */ + method: { + netbanking: boolean | 1 | 0 | string; + card: boolean | 1 | 0 | string; + upi: boolean | 1 | 0 | string; + wallet: boolean | 1 | 0 | string; + } + } + + interface RazorpayCheckoutReadonly { + readonly: { + email?: boolean | 1 | 0; + contact?: boolean | 1 | 0; + } + } + + interface RazorpayCheckoutThematicChange { + theme: { + hide_topbar: boolean; + } + } +} + +declare function paymentLink(api: any): { + /** + * Create payment link + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/payment-links#create-payment-link) for required params. + * + * @link https://razorpay.com/docs/api/payments/payment-links + * @link https://razorpay.com/docs/api/payments/payment-links/customise + * @link https://razorpay.com/docs/api/payments/payment-links/advanced-options + */ + create(params: PaymentLinks.RazorpayPaymentLinkCreateRequestBody | PaymentLinks.RazorpayPaymentLinkAdvanceOption): Promise + create(params: PaymentLinks.RazorpayPaymentLinkCreateRequestBody | PaymentLinks.RazorpayPaymentLinkAdvanceOption, callback: (err: INormalizeError | null, data: PaymentLinks.RazorpayPaymentLink) => void): void + /** + * Get all paymentLinks + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/payment-links#fetch-all-payment-links) for required params. + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + payment_links: Array; + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + payment_links: Array; + }) => void): void + /** + * Fetch a paymentLink given paymentLink ID + * + * @param paymentLinkId - The unique identifier of the paymentlink. + * + */ + fetch(paymentLinkId: string): Promise + fetch(paymentLinkId: string, callback: (err: INormalizeError | null, data: PaymentLinks.RazorpayPaymentLink) => void): void + /** + * Edit a paymentLink given paymentLink ID + * + * @param paymentLinkId - The unique identifier of the paymentlink. + * @param param - Check [doc](https://razorpay.com/docs/api/payments/payment-links#update-payment-link) for required params. + */ + edit(paymentLinkId: string, params: PaymentLinks.RazorpayPaymentLinkUpdateRequestBody): Promise + edit(paymentLinkId: string, params: PaymentLinks.RazorpayPaymentLinkUpdateRequestBody, callback: (err: INormalizeError | null, data: PaymentLinks.RazorpayPaymentLink) => void): void + /** + * Cancel a payment link + * + * @param paymentLinkId - The unique identifier of the paymentlink. + * + */ + cancel(paymentLinkId: string): Promise + cancel(paymentLinkId: string, callback: (err: INormalizeError | null, data: PaymentLinks.RazorpayPaymentLink) => void): void + /** + * Send notification + * + * @param paymentLinkId - The unique identifier of the paymentlink. + * @param medium - Possible values: `sms`, `email` + * + */ + notifyBy(paymentLinkId: string, medium: INotify): Promise<{ success: boolean }> + notifyBy(paymentLinkId: string, medium: INotify, callback: (err: INormalizeError | null, data: { success: boolean }) => void): void +} + +export default paymentLink \ No newline at end of file diff --git a/lib/types/payments.d.ts b/lib/types/payments.d.ts new file mode 100644 index 00000000..754a18dd --- /dev/null +++ b/lib/types/payments.d.ts @@ -0,0 +1,798 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions, PartialOptional } from "./api"; +import { Orders } from "./orders"; +import { Refunds } from "./refunds" +import { Tokens } from "./tokens"; +import { Transfers } from "./transfers" +import { VirtualAccounts } from "./virtualAccounts" + +export declare namespace Payments { + interface RazorpayPaymentBaseRequestBody { + /** + * The payment amount represented in smallest unit of the currency passed. + * For example, amount = 100 translates to 100 paise, that is ₹1 (default currency is INR). + */ + amount: number | string; + /** + * The currency in which the customer should be charged for the item. For example, `INR`. + */ + currency: string; + /** + * The unique identifier of the order + */ + order_id: string; + /** + * Customer email address used for the payment. + */ + email: string; + /** + * Customer contact number used for the payment. + */ + contact: string | number; + /** + * Key-value pair you can use to store additional information about the entity. + * Maximum of 15 key-value pairs, 256 characters each. + */ + notes: { [key: string]: string } + /** + * A user-entered description for the payment. + * For example, `Creating recurring payment for Gaurav Kumar`. + */ + description?: string; + /** + * The unique identifier of the customer you want to charge. + */ + customer_id: string; + } + + interface RazorpayPaymentCreateRequestBody extends RazorpayPaymentBaseRequestBody { } + + interface RazorpayPaymentUpdateRequestBody extends Pick { } + + interface RazorpayRefundPaymentLinkAccountCreateRequestBody extends Pick { + /** + * Reverses transfer made to a linked account.Possible values. + * `1` - Reverses transfer made to a linked account. + * `0` - Does not reverse transfer made to a linked account. + */ + reverse_all?: boolean | 0 | 1; + } + + interface RazorpayPayment extends RazorpayPaymentCreateRequestBody { + /** + * Unique identifier of the payment. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: 'payment'; + /** + * The status of the payment + */ + status: 'created' | 'authorized' | 'captured' | 'refunded' | 'failed'; + /** + * Unique identifier of the invoice. + */ + invoice_id: string | null; + /** + * Indicates whether the payment is done via an international card or a domestic one. + */ + international: boolean; + /** + * The refund status of the payment. + */ + refund_status: 'null' | 'partial' | 'full'; + /** + * The amount refunded in smallest unit of the currency passed. + * For example, if `amount_refunded` = 100, here 100 stands for 100 paise, + * which is equal to ₹1. INR is the default currency. + */ + amount_refunded?: number; + /** + * Indicates if the payment is captured. + */ + captured: boolean; + /** + * The 4-character bank code which the customer's account is associated with. + * For example, UTIB for Axis Bank. + */ + bank: string; + /** + * The unique identifier of the card used by the customer to make the payment. + */ + card_id: string | null; + /** + * The name of the wallet used by the customer to make the payment. + * For example, `payzapp`. + */ + wallet: string | null; + /** + * The customer's VPA (Virtual Payment Address) or UPI id used to make the payment. + * For example, `gauravkumar@exampleupi`. + */ + vpa: string | null; + /** + * GST charged for the payment. + */ + tax: number; + /** + * Unique identifier of the token. + */ + token_id: string | null; + /** + * Fee (including GST) charged by Razorpay. + */ + fee: number; + /** + * Error that occurred during payment. For example, `BAD_REQUEST_ERROR`. + */ + error_code: string | null; + /** + * The point of failure. For example, `customer` + */ + error_source: string | null; + /** + * Description of the error that occurred during payment. For example, + * Payment processing failed because of incorrect OTP. + */ + error_description: string | null; + /** + * The stage where the transaction failure occurred. + * The stages can vary depending on the payment method used to complete the transaction. + * For example, `payment_authentication`. + */ + error_step: string | null; + /** + * The exact error reason. For example, `incorrect_otp`. + */ + error_reason: string | null; + /** + * A dynamic array consisting of a unique reference numbers. + */ + acquirer_data: { + /** + * A unique bank reference number provided by the banking partner when a refund is processed. + * This reference number can be used by the customer to track the status of the refund with + * the bank. + */ + rrn?: string; + /** + * A unique reference number generated for RuPay card payments. + */ + authentication_reference_number?: string; + /** + * A unique reference number provided by the banking partner in case of netbanking payments. + */ + bank_transaction_id?: string; + auth_code?: string; + upi_transaction_id?: string; + } + emi?: { + issuer: string; + type: string; + rate: string; + duration: string; + }; + /** + * Timestamp, in UNIX format, on which the payment was created. + */ + created_at: number; + /** + * The payment method used to make the payment. + * If this parameter is not passed, customers will be able to make + * payments using both netbanking and UPI payment methods + */ + method: string; + token?: Tokens.RazorpayToken; + offers: { + entity: string; + count: number; + items: { id: string }[] + + } + card?: RazorpayCard; + } + + interface RazorpayCardBaseRequestBody { + /** + * Unformatted card number. + */ + number: string; + /** + * Name of the cardholder. + */ + name: string; + /** + * Expiry month for card in MM format. + */ + expiry_month: number; + /** + * Expiry year for card in YY format. + */ + expiry_year: number; + /** + * CVV printed on the back of card. + */ + cvv: number; + } + + interface RazorpayCardCreateRequest extends RazorpayCardBaseRequestBody { } + + interface RazorpayCard extends RazorpayCardCreateRequest { + /** + * The unique identifier of the card used by the customer to make the payment. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The last 4 digits of the card number. + */ + last4: string; + /** + * The card network. + */ + network: + | "American Express" + | "Diners Club" + | "Maestro" + | "MasterCard" + | "RuPay" + | "Unknown" + | "Visa"; + /** + * The card type. + */ + type: "credit" | "debit" | "prepaid" | "unknown"; + /** + * The card issuer. The 4-character code denotes the issuing bank. + */ + issuer: string; + /** + * This attribute is set to `true` if the card can be used for EMI payment method. + */ + emi: boolean; + /** + * The sub-type of the customer's card. + */ + sub_type: 'customer' | 'business'; + token_iin: string | null; + /** + * The transaction flow details. + */ + flows: { + otp?: boolean; + recurring: boolean; + } + international: boolean; + cobranding_partner?: string | null + } + + interface RazorpayPaymentDowntime { + /** + * Unique identifier of the downtime's occurrence. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The payment method that is experiencing the downtime. Possible values include: + * `card`, `netbanking`, `wallet`, `upi` + */ + method: string; + /** + * Timestamp (in Unix) that indicates the start of the downtime. + * Applicable for both scheduled and unscheduled downtimes. + */ + begin: number | null; + /** + * Timestamp (in Unix) that indicates the end of the downtime. + * Available only for scheduled downtimes, where the end-time is known. + * Set to null when the end-time in unknown, possibly during unscheduled downtimes. + */ + end: number | null; + /** + * Status of the downtime. + */ + status: 'scheduled' | 'started' | 'resolved' | 'cancelled'; + /** + * `true` - This is a scheduled downtime by the issuer, + * network, or the bank, which was informed to Razorpay. + * `false` - This is an unscheduled downtime. + */ + scheduled: boolean; + /** + * Severity of the downtime. + */ + severity: 'high' | 'medium' | 'low'; + /** + * Payment method that is under performing. + */ + instrument: RazorpayPaymentDowntimeInstrument + /** + * Timestamp (in Unix) that indicates the time at which the + * downtime was recorded in Razorpay servers. + */ + created_at: number; + /** + * Timestamp (in Unix) that indicates the time at which the + * downtime record was updated in Razorpay servers. + */ + updated_at: number; + } + + interface RazorpayPaymentDowntimeInstrument { + /** + * Bank code of the affected bank. + */ + bank?: string; + /** + * Code of the affected Payment Service Provider (PSP). + * This is populated only when VPA handles associated with the PSP are down. + * If a PSP is associated with multiple VPA handles, + * it is marked down only when all the handles associated with it are down. + * For example, `google_pay` is marked down only when all Google Pay handles + * `oksbi`, `okhdfcbank`, `okicici` and `okaxis` are down. + */ + psp?: 'google_pay' | 'phonepe' | 'paytm' | 'bhim'; + /** + * Affected VPA handle. For example, `@oksbi`. To learn about the possible values, + * refer to the [list of handles supported by NPCI](https://www.npci.org.in/what-we-do/upi/3rd-party-apps). + * If the entire UPI system is experiencing a downtime, the value `ALL` is displayed. + */ + vpa_handle?: string; + /** + * Affected wallet code. + */ + wallet?: string; + } + + interface RazorpayRecurringPaymentCreateRequestBody extends Payments.RazorpayPaymentBaseRequestBody { + /** + * he `token_id` generated when the customer successfully completes the authorization payment. + * Different payment instruments for the same customer have different `token_id`. + */ + token: string; + /** + * Determines whether recurring payment is enabled or not. + */ + recurring: boolean | 1 | 0 | string; + } + + interface RazorpayPaymentThirdPartyCreateRequestBody extends Omit { + /** + * The customer's bank code. For example, `HDFC`. + */ + bank?: string; + /** + * The payment method that is experiencing the downtime. Possible values include: + * `card`, `netbanking`, `wallet`, `upi` + */ + method: string; + } + + interface RazorpayPaymentUpiCreateRequestBody extends PartialOptional { + method: string; + /** + * Specifies if the VPA should be stored as tokens. + * `1` Saves the VPA details. + * `0`(default) - Does not save the VPA details. + */ + save?: boolean | 1 | 0; + /** + * The customer's IP address. + */ + ip: string; + /** + * URL where Razorpay will submit the final payment status. + */ + callback_url?: string; + /** + * Value of referer header passed by the client's browser. + * For example,`https://example.com/` + */ + referer: string; + /** + * Value of `user_agent` header passed by the client's browser. + * For example, + * Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) + * Chrome/79.0.3945.130 Safari/537.36 + */ + user_agent: string; + /** + * Details of the expiry of the UPI link + */ + upi: { + /** + * Specify the type of the UPI payment flow. + * Possible values: `collect` (default), `intent` + */ + flow: string; + vpa?: string; + /** + * Period of time (in minutes) after which the link will expire. + * The default value is 5. + */ + expiry_time?: number; + } + } + + interface RazorpayPaymentQuery extends RazorpayPaginationOptions { + 'expand[]'?: string; + } + + interface RazorpayCardS2SMethod extends RazorpayCardBaseRequestBody { + /** + * Details of the authentication channel. + */ + authentication?: { + /** + * The authentication channel for the payment. + */ + authentication_channel: 'browser' | 'app' + } + /** + * Information regarding the customer's browser. + * This parameter need not be passed when `authentication_channel=app`. + */ + browser?: { + /** + * Indicates whether the customer's browser supports Java. + * Obtained from the `navigator` HTML DOM object. + */ + java_enabled: boolean; + /** + * ndicates whether the customer's browser is able to execute JavaScript. + * Obtained from the `navigator` HTML DOM object. + */ + javascript_enabled: boolean; + /** + * Time difference between UTC time and the cardholder browser local time. + * Obtained from the `getTimezoneOffset()` method applied to Date object. + */ + timezone_offset: number; + /** + * Total width of the payer's screen in pixels. + * Obtained from the `screen.width` HTML DOM property. + */ + screen_width: number; + /** + * Obtained from the `navigator` HTML DOM object. + */ + screen_height: number; + /** + * Obtained from payer's browser using + * the `screen.colorDepth` HTML DOM property. + */ + color_depth: string; + /** + * Obtained from payer's browser using the navigator. + * language HTML DOM property. Maximum limit of 8 characters. + */ + language: string; + } + } + + interface RazorpayPaymentS2SCreateRequestBody extends RazorpayPaymentBaseRequestBody { + card: RazorpayCardS2SMethod; + /** + * The customer's IP address. + */ + ip: string; + /** + * Referrer header passed by the client's browser. + */ + referer: string; + /** + * The User-Agent header of the user's browser. + * Default value will be passed by Razorpay if not provided by merchant. + */ + user_agent: string | null; + } + + interface RazorpayPaymentS2SJson { + /** + * Unique identifier of the payment. Present for all responses. + */ + razorpay_payment_id: string; + /** + * A list of action objects available to you to continue the payment process. + * Present when the payment requires further processing. + */ + next: [ + { + [key: string]: string + } + ]; + metadata?: { + [key: string]: string + } + } + + interface RazorpayPaymentDetails { + id: string; + entity: string; + payment_id: string; + mode: string; + bank_reference: string; + amount: number | string; + payer_bank_account: RazorpayBankAccount; + virtual_account_id: string; + virtual_account: VirtualAccounts.RazorpayVirtualAccount; + } + + interface RazorpayBankAccount extends Orders.RazorpayBankAccount { + id: string; + entity: string; + } + +} + +declare function payments(api: any): { + /** + * Get all payments + * + * @param params + * + */ + all(params?: Payments.RazorpayPaymentQuery): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: Payments.RazorpayPaymentQuery, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetch a payment + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/#fetch-a-payment) for required params + * + */ + fetch(paymentId: string, params?: { 'expand[]': 'card' | 'emi' | 'offers' }): Promise + fetch(paymentId: string, params: { 'expand[]': 'card' | 'emi' | 'offers' }, callback: (err: INormalizeError | null, data: Payments.RazorpayPayment) => void): void + /** + * Capture payment + * + * @param paymentId - The unique identifier of the payment. + * @param amount - The amount to be captured (should be equal to the authorised amount, + * in the smallest unit of the chosen currency). + * @param currency - ISO code of the currency in which the payment was made. + * + */ + capture(paymentId: string, amount: number | string, currency: string): Promise + capture(paymentId: string, amount: number | string, currency: string, callback: (err: INormalizeError | null, data: Payments.RazorpayPayment) => void): void + /** + * Edit a payment given Payment ID + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/#update-the-payment) for required params + * + */ + edit(paymentId: string, params: { notes: IMap }): Promise + edit(paymentId: string, params: { notes: IMap }, callback: (err: INormalizeError | null, data: Payments.RazorpayPayment) => void): void + /** + * Create payment json + * + * @param params - Check [doc](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/json/v2/build-integration/cards/#12-create-a-payment) for required params + * + */ + createPaymentJson(params: Payments.RazorpayPaymentS2SCreateRequestBody | Payments.RazorpayPaymentThirdPartyCreateRequestBody): Promise + createPaymentJson(params: Payments.RazorpayPaymentS2SCreateRequestBody | Payments.RazorpayPaymentThirdPartyCreateRequestBody, callback: (err: INormalizeError | null, data: Payments.RazorpayPaymentS2SJson) => void): void + /** + * Create a recurring payment + * + * @param params + * @link https://razorpay.com/docs/api/payments/recurring-payments/emandate/create-subsequent-payments#32-create-a-recurring-payment + * @link https://razorpay.com/docs/api/payments/recurring-payments/cards/create-subsequent-payments#32-create-a-recurring-payment + * @link https://razorpay.com/docs/api/payments/recurring-payments/paper-nach/create-subsequent-payments#32-create-a-recurring-payment + * @link https://razorpay.com/docs/api/payments/recurring-payments/upi/create-subsequent-payments#32-create-a-recurring-payment + * + */ + createRecurringPayment(params: Payments.RazorpayRecurringPaymentCreateRequestBody): Promise<{ + razorpay_payment_id?: string; + razorpay_order_id?: string; + razorpay_signature?: string; + }> + createRecurringPayment(params: Payments.RazorpayRecurringPaymentCreateRequestBody, callback: (err: INormalizeError | null, data: { + razorpay_payment_id?: string; + razorpay_order_id?: string; + razorpay_signature?: string; + }) => void): void + /** + * Generate otp + * + * @param paymentId - The unique identifier of the payment. + * + */ + otpGenerate(paymentId: string): Promise + otpGenerate(paymentId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayPaymentS2SJson) => void): void + /** + * Otp submit + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/payments/payment-gateway/s2s-integration/json/v2/build-integration/cards/#response-on-submitting-otp) for required params + * + */ + otpSubmit(paymentId: string, params: { otp: string }): Promise<{ + razorpay_payment_id: string; + razorpay_order_id: string; + razorpay_signature: string; + }> + otpGenerate(paymentId: string, params: { otp: string }, callback: (err: INormalizeError | null, data: { + razorpay_payment_id: string; + razorpay_order_id: string; + razorpay_signature: string; + }) => void): void + /** + * OTP Resend + * + * @param paymentId - The unique identifier of the payment. + * + */ + otpResend(paymentId: string): Promise<{ + "next": string[]; + "razorpay_payment_id": string; + }> + otpResend(paymentId: string, callback: (err: INormalizeError | null, data: { + "next": string[]; + "razorpay_payment_id": string; + }) => void): void + /** + * Create Payment UPI s2s / VPA token (Third party validation) + * + * @param params + * @link https://razorpay.com/docs/payments/third-party-validation/s2s-integration/upi/collect#step-14-initiate-a-payment + * @link https://razorpay.com/docs/payments/third-party-validation/s2s-integration/upi/intent/#step-2-initiate-a-payment + * + */ + createUpi(params: Payments.RazorpayPaymentUpiCreateRequestBody): Promise<{ razorpay_payment_id: string; link?: string; }> + createUpi(params: Payments.RazorpayPaymentUpiCreateRequestBody, callback: (err: INormalizeError | null, data: { + razorpay_payment_id: string; + link?: string + }) => void): void + /** + * Validate vpa + * + * @param params - Check [doc](https://razorpay.com/docs/payments/third-party-validation/s2s-integration/upi/collect#step-13-validate-the-vpa) for required params + * + */ + validateVpa(params: { vpa: string }): Promise<{ + vpa: string; + success: boolean; + customer_name: string; + }> + validateVpa(params: { vpa: string }, callback: (err: INormalizeError | null, data: { + vpa: string; + success: boolean; + customer_name: string; + }) => void): void + /** + * Fetch payment methods + * + * @link https://razorpay.com/docs/payments/third-party-validation/s2s-integration/methods-api/#fetch-payment-methods + * + */ + fetchPaymentMethods(): Promise<{ [key: string]: string }> + fetchPaymentMethods(callback: (err: INormalizeError | null, data: { + [key: string]: string; + }) => void): void + /** + * Create a normal/instant instant refund. + * + * Refund payments and reverse transfer from a linked account + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/refunds/#create-a-normal-refund) for required params + * @param params - Check [doc](https://razorpay.com/docs/api/payments/route/transfers#refund-payments-and-reverse-transfer-from-a-linked) for required params + */ + refund(paymentId: string, params: Payments.RazorpayRefundPaymentLinkAccountCreateRequestBody | Refunds.RazorpayRefundCreateRequestBody): Promise + refund(paymentId: string, params: Payments.RazorpayRefundPaymentLinkAccountCreateRequestBody | Refunds.RazorpayRefundCreateRequestBody, callback: (err: INormalizeError | null, data: Refunds.RazorpayRefund) => void): void + /** + * Fetch multiple refunds for a payment + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/refunds/#fetch-multiple-refunds-for-a-payment) for required params + * + */ + fetchMultipleRefund(paymentId: string, params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: number; + items: Array; + }> + fetchMultipleRefund(paymentId: string, params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + + /** + * Fetch a specific refund for a payment + * + * @param paymentId - The unique identifier of the payment. + * @param refundId - The unique identifier of the refund. + * + */ + fetchRefund(paymentId: string, refundId: string): Promise + fetchRefund(paymentId: string, refundId: string, callback: (err: INormalizeError | null, data: Refunds.RazorpayRefund) => void): void + /** + * Fetch transfers for a payment + * + * @param paymentId - The unique identifier of the payment. + * + */ + fetchTransfer(paymentId: string): Promise<{ + entity: string; + count: number; + items: Array; + }> + fetchTransfer(paymentId: string, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + + /** + * Create transfers from payment + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/route/transfers/#create-transfers-from-payments) for required params + * + */ + transfer(paymentId: string, params: { transfers: Transfers.RazorpayPaymentCreateRequestBody[] }): Promise<{ + entity: string; + count: number; + items: Array; + }> + transfer(paymentId: string, params: { transfers: Transfers.RazorpayPaymentCreateRequestBody[] }, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + /** + * Fetch payment details using id and transfer method + * + * @param paymentId - The unique identifier of the payment. + * + */ + bankTransfer(paymentId: string): Promise + bankTransfer(paymentId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayPaymentDetails) => void): void + /** + * Fetch card details with paymentId + * + * @param paymentId - The unique identifier of the payment. + * + */ + fetchCardDetails(paymentId: string): Promise + fetchCardDetails(paymentId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayCard) => void): void + /** + * Fetch Payment Downtime Details + */ + fetchPaymentDowntime(): Promise<{ + entity: string; + count: number; + items: Array + }> + fetchPaymentDowntime(callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array + }) => void): void + /** + * Fetch Payment Downtime + * + * @param downtimeId - The unique identifier of the payment. + * + */ + fetchPaymentDowntimeById(downtimeId: string): Promise + fetchPaymentDowntimeById(downtimeId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayPaymentDowntime) => void): void +} + +export default payments \ No newline at end of file diff --git a/lib/types/plans.d.ts b/lib/types/plans.d.ts new file mode 100644 index 00000000..dbc13dc6 --- /dev/null +++ b/lib/types/plans.d.ts @@ -0,0 +1,87 @@ +import { IMap, RazorpayPaginationOptions, INormalizeError } from "./api"; +import { Items } from "./items"; + +export declare namespace Plans { + interface RazorpayPlanBaseRequestBody { + /** + * Details of the plan. + */ + item: Items.RazorpayItemBaseRequestBody; + /** + * This, combined with interval, defines the frequency. Possible values: + * `daily`, `weekly`, `monthly`, `yearly` + * + * If the billing cycle is 2 months, the value should be monthly. + */ + period: "daily" | "weekly" | "monthly" | "yearly"; + /** + * This, combined with `period`, defines the frequency. + * If the billing cycle is 2 months, the value should be `2`. + */ + interval: number; + /** + * Notes you can enter for the contact for future reference. + * This is a key-value pair. You can enter a maximum of 15 key-value pairs. + * For example, `note_key`: `Beam me up Scotty` + */ + notes?: IMap; + } + + interface RazorpayPlanCreateRequestBody extends RazorpayPlanBaseRequestBody { } + + interface RazorPayPlans extends RazorpayPlanBaseRequestBody { + /** + * The unique identifier linked to a plan + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The Unix timestamp at which the plan was created. + */ + created_at: number; + /** + * Details of the plan. + */ + item: Items.RazorpayItem; + } +} + +declare function plans(api: any): { + /** + * Creates a plan + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#create-a-plan) for required params + * + */ + create(params: Plans.RazorpayPlanCreateRequestBody): Promise + create(params: Plans.RazorpayPlanCreateRequestBody, callback: (err: INormalizeError | null, data: Plans.RazorPayPlans) => void): void; + /** + * Get all plans + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#fetch-all-plans) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: string; + items: Array + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetch a plans given Plan ID + * + * @param planId - The unique identifier of the plan + * + */ + fetch(planId: string): Promise + fetch(planId: string, callback: (err: INormalizeError | null, data: Plans.RazorPayPlans) => void): void; +} + +export default plans \ No newline at end of file diff --git a/lib/types/qrCode.d.ts b/lib/types/qrCode.d.ts new file mode 100644 index 00000000..abd6a9fb --- /dev/null +++ b/lib/types/qrCode.d.ts @@ -0,0 +1,227 @@ +import { IMap, RazorpayPaginationOptions, INormalizeError } from "./api" +import { Payments } from "./payments" + +export declare namespace QrCode { + + interface RazorpayTaxInvoice { + /** + * This is the invoice number against which the payment is collected. + * If not provided, the transaction will default to non-GST compliant UPI flow. + */ + number?: string; + /** + * Unix Timestamp that indicates the issue date of the invoice. + * If not provided, it will default to the current date. + */ + date?: number; + /** + * Customer name on the invoice. If not provided, the transaction + * will default to non-GST compliant UPI flow. + */ + customer_name?: string; + /** + * The GSTIN mentioned on the invoice. + */ + business_gstin?: string; + /** + * GST amount on the invoice in paise. If not provided, the transaction + * will default to the non-GST compliant UPI flow. + */ + gst_amount?: number; + /** + * CESS Amount on the invoice in paise. If not provided, the transaction + * will default to the non-GST compliant UPI flow. + */ + cess_amount?: number; + /** + * Indicates whether the transaction is interstate or intrastate. Possible values: + * + * `interstate` or `intrastate` If not provided, the transaction will default to the non-GST compliant UPI flow. + */ + supply_type?: 'interstate' | 'intrastate'; + } + + interface RazorpayQrCodeBaseRequestBody { + /** + * The type of the QR Code. Possible values: + * + * `upi_qr`: Create a QR Code that accepts only UPI payments. + * + * `bharat_qr`: Create a QR Code that accepts UPI and card payments. + */ + type: 'upi_qr' | 'bharat_qr'; + /** + * Label entered to identify the QR Code. For example, `Store Front Display`. + */ + name?: string; + /** + * Indicates if the QR Code should be allowed to accept single payment or + * multiple payments. Possible values: + * + * `single_use`: QR Code will accept only one payment and then close automatically. + * + * `multiple_use` (default): QR Code will accept multiple payments. + */ + usage: string; + /** + * Indicates if the QR Code should accept payments of specific amounts or any amount. + * + * `true`: QR Code accepts only a specific amount. + * + * `false` (default): QR code accepts any amount. + */ + fixed_amount?: boolean; + /** + * The amount allowed for a transaction. If this is specified, + * then any transaction of an amount less than or more than this + * value is not allowed. For example, if this amount is set as `500000`, + * the customer cannot pay an amount less than or more than ₹5000. + * `(if fixed_amount=true)` + */ + payment_amount?: number; + /** + * A brief description about the QR Code. + */ + description?: string; + /** + * The unique identifier of the customer the QR Code is linked with. + */ + customer_id?: string; + /** + * Unix timestamp at which the QR Code is scheduled to be automatically closed. + * The time must be at least 15 minutes after the current time. + */ + close_by?: number; + /** + * Key-value pair that can be used to store additional information about the QR Code. + */ + notes?: IMap; + + } + + interface RazorpayQrCodeCreateRequestBody extends RazorpayQrCodeBaseRequestBody { } + + interface RazorpayQrCodeGstCreateRequestBody extends RazorpayQrCodeBaseRequestBody { + /** + * This block contains information about the invoices. + */ + tax_invoice?: RazorpayTaxInvoice; + } + + interface RazorpayQrCode extends RazorpayQrCodeBaseRequestBody, RazorpayQrCodeGstCreateRequestBody { + /** + * The unique identifier of the QR Code. + */ + id: string, + /** + * Indicates the type of entity. + */ + entity: string, + /** + * The unix timestamp at which the QR Code was created. + */ + created_at: number, + /** + * The URL of the QR Code. A sample short URL looks like + * this `http://rzp.io/l6MS`. Click the link to download the code. + */ + image_url: string, + /** + * Indicates the status of the QR Code. + */ + status: 'active' | 'closed', + /** + * The total amount received on the QR Code. All captured payments are considered. + */ + payments_amount_received: number, + /** + * The total number of payments received on the QR Code. All captured + * payments are considered. + */ + payments_count_received: number, + /** + * The unix timestamp at which the QR Code is automatically closed. + */ + closed_at: number, + /** + * The reason for the closure of the QR Code. Possible values: + * + * `on_demand`: When you close the QR Code using the APIs or the Razorpay Dashboard. + * + * `paid`: If the QR Code is created with the usage=single_payment parameter, + * the QR Code closes automatically once the customer makes the payment, + * with the reason marked as paid. + * + * `null`: The QR Code has not been closed yet. + */ + close_reason?: 'on_demand' | 'paid' | null + } + + interface RazorpayQrCodeQuery extends RazorpayPaginationOptions { + customer_id?: string; + payment_id?: string; + } +} + + +declare function qrCode(api: any): { + /** + * Creates a qrcode + * + * @param params - Check [doc](https://razorpay.com/docs/api/qr-codes/gst/#create-a-qr-code) for required params + * + */ + create(params: QrCode.RazorpayQrCodeCreateRequestBody | QrCode.RazorpayQrCodeGstCreateRequestBody): Promise + create(params: QrCode.RazorpayQrCodeCreateRequestBody | QrCode.RazorpayQrCodeGstCreateRequestBody, callback: (err: INormalizeError | null, data: QrCode.RazorpayQrCode) => void): void; + /** + * Get all qrcodes + * + * @param params - Check [doc](https://razorpay.com/docs/api/qr-codes/gst/#fetch-multiple-qr-codes) for required params + * + */ + all(params?: QrCode.RazorpayQrCodeQuery): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: QrCode.RazorpayQrCodeQuery, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetches a qrode given QrCode ID + * + * @param qrCodeId - The unique identifier of the QR Code. + * + */ + fetch(qrCodeId: string): Promise + fetch(qrCodeId: string, callback: (err: INormalizeError | null, data: QrCode.RazorpayQrCode) => void): void; + /** + * Fetch Payments for a QR Code + * + * @param qrCodeId - The unique identifier of the QR Code. + * @param params - Check [doc](https://razorpay.com/docs/api/qr-codes/gst/#fetch-payments-for-a-qr-code) for required params + * + */ + fetchAllPayments(qrCodeId: string, params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: number; + items: Array; + }> + fetchAllPayments(qrCodeId: string, params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Close a QR Code + * + * @param qrCodeId - The unique identifier of the QR Code. + * + */ + close(qrCodeId: string): Promise + close(qrCodeId: string, callback: (err: INormalizeError | null, data: QrCode.RazorpayQrCode) => void): void; +} + +export default qrCode \ No newline at end of file diff --git a/lib/types/refunds.d.ts b/lib/types/refunds.d.ts new file mode 100644 index 00000000..6246d739 --- /dev/null +++ b/lib/types/refunds.d.ts @@ -0,0 +1,119 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions } from "./api"; + +export declare namespace Refunds { + interface RazorpayRefundBaseRequestBody { + /** + * The amount to be refunded (in the smallest unit of currency). + */ + amount?: number; + /** + * Speed at which the refund is to be processed. + */ + speed?: 'normal' | 'optimum'; + /** + * Key-value store for storing your reference data. + */ + notes?: IMap; + /** + * A unique identifier provided by you for your internal reference. + */ + receipt?: string | null; + } + + interface RazorpayRefundCreateRequestBody extends RazorpayRefundBaseRequestBody {} + + interface RazorpayRefundUpdateRequestBody extends RazorpayRefundBaseRequestBody { + notes: IMap + } + + interface RazorpayRefund extends Omit { + /** + * The unique identifier of the refund. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The currency of payment amount for which the refund is initiated. + */ + currency: string; + /** + * The unique identifier of the payment for which a refund is initiated. + * For example, `pay_FgR9UMzgmKDJRi`. + */ + payment_id: string, + /** + * A dynamic array consisting of a unique reference number (either RRN, ARN or UTR) + * that is provided by the banking partner when a refund is processed. + * This reference number can be used by the customer to track the status of the + * refund with the bank. + */ + acquirer_data?: IMap; + /** + * Unix timestamp at which the refund was created. + */ + created_at: number, + /** + * This parameter is populated if the refund was created as part of a batch upload. + * For example, `batch_00000000000001` + */ + batch_id?: string | null, + /** + * Indicates the state of the refund. + */ + status: 'pending' | 'processed' | 'failed', + /** + * This is a parameter in the response which describes the mode used to process a refund. + * This attribute is seen in the refund response only if the speed parameter is set in + * the refund request. + */ + speed_processed: 'instant' | 'normal'; + /** + * The processing mode of the refund seen in the refund response. + * This attribute is seen in the refund response only if the `speed` + * parameter is set in the refund request. + */ + speed_requested: 'normal' | 'optimum'; + } +} + +declare function refunds(api: any): { + /** + * Get all refunds + * + * @param params - Check [doc](https://razorpay.com/docs/api/refunds/#fetch-all-refunds) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string, + count: number, + items: Array + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetch a refund given Refund ID + * + * @param refundId - The unique identifier of the refund. + * @param params - The unique identifier of the payment. + * + */ + fetch(refundId: string, params?: { payment_id: string }): Promise + fetch(refundId: string, params: { payment_id?: string }, callback: (err: INormalizeError | null, data: Refunds.RazorpayRefund) => void): void + /** + * Edit a payment given Refund ID + * + * @param paymentId - The unique identifier of the payment. + * @param params - Check [doc](https://razorpay.com/docs/api/refunds/#update-refund) for required params + * + */ + edit(refundId: string, params: Refunds.RazorpayRefundUpdateRequestBody): Promise + edit(refundId: string, params: Refunds.RazorpayRefundUpdateRequestBody, callback: (err: INormalizeError | null, data: Refunds.RazorpayRefund) => void): void +} + +export default refunds \ No newline at end of file diff --git a/lib/types/settlements.d.ts b/lib/types/settlements.d.ts new file mode 100644 index 00000000..5dc79b76 --- /dev/null +++ b/lib/types/settlements.d.ts @@ -0,0 +1,347 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions } from "./api"; + +export declare namespace Settlements { + + interface RazorpayInstantSettlementBaseRequestBody { + /** + * The amount, in paise, you want settled to your account. + */ + amount: number | string; + /** + * `true`: Razorpay will settle the maximum amount possible. + * Values passed in the amount parameter are ignored. + * + * `false` (default value): Razorpay will settle the amount + * requested in the amount parameter. + */ + settle_full_balance?: boolean | 0 | 1; + /** + * This is a custom note you can pass for the instant + * settlement for your reference. + */ + description?: string; + /** + * Key-value pair that can be used to store additional + * information about the entity. + */ + notes?: IMap; + } + + interface RazorpayInstantSettlementCreateRequestBody extends RazorpayInstantSettlementBaseRequestBody {} + + interface RazorpaySettlement extends RazorpayInstantSettlementBaseRequestBody{ + /** + * The unique identifier of the settlement. + */ + id: string; + /** + * Indicates the type of entity + */ + entity: string; + initiated_at?: number | null; + processed_at?: number | null; + reversed_at?: number | null; + /** + * Total amount (minus fees and tax), in paise, settled to the bank account. + */ + amount_settled?: number | null; + /** + * Indicates the state of the instant settlement. + */ + status: + | 'created' + | 'processed' + | 'failed' + | 'initiated' + | 'reversed' + | 'partially_processed'; + /** + * Total amount (fees+tax), in paise, deducted for the instant settlement. + */ + fees: number | null; + /** + * Total tax, in paise, charged for the fee component. + */ + tax: number | null; + /** + * The Unique Transaction Reference (UTR) number available across banks, + * which can be used to track a particular settlement in your bank account. + */ + utr: string | null; + /** + * Unix timestamp at which the instant settlement was created. + */ + created_at: number; + } + + interface RazorpaySettlementReconBaseRequestBody { + /** + * The year the settlement was received in the `YYYY` format. + * For example, `2022`. + */ + year: number; + /** + * The month the settlement was received in the `MM` format. + * For example, `06`. + */ + month?: number; + /** + * The date on which the settlement was received in the `DD` format. + * For example, `11`. + */ + day?: number; + /** + * Specifies the number of available settlements to be fetched. + * Maximum count can be `1000`. + */ + count?: number; + /** + * Specifies the number of available settlements to be skipped when fetching a `count`. + */ + skip?: number; + } + + interface RazorpaySettlementRecon { + /** + * The unique identifier of the transaction that has been settled. + */ + entity_id: string; + /** + * Indicates the type of transaction. + */ + type: string; + /** + * The amount, in paise, that has been debited from your account. + */ + debit: number; + /** + * The amount, in paise, that has been credited to your account. + */ + credit: number; + /** + * The total amount, in paise, debited or credited from your account. + */ + amount: number | string; + /** + * The 3-letter ISO currency code for the transaction. + */ + currency: string; + /** + * The fees, in paise, charged to processing the transaction. + */ + fee: number; + /** + * The tax on the fee, in paise, charged to processing the transaction. + */ + tax: number; + /** + * Indicates whether the account settlement for transfer is on hold. + */ + on_hold: boolean; + /** + * Indicates whether the transaction has been settled or not. + */ + settled: boolean; + /** + * Unix timestamp at which the transaction was created. + */ + created_at: number; + /** + * Unix timestamp when the transaction was settled. + */ + settled_at: number; + /** + * The unique identifier of the settlement transaction. + */ + settlement_id: string; + /** + * + */ + posted_at?: number | null; + credit_type: string; + /** + * Brief description about the transaction. + */ + description: string | null; + /** + * Notes for the transaction. + */ + notes: IMap; + /** + * The unique identifier of the payment linked to `refund` or `transfer` + * that has been settled. + */ + payment_id?: string; + /** + * The unique reference number linked to the settlement. + */ + settlement_utr: string; + /** + * Order ID linked to the payment made by the customer that has been settled. + */ + order_id: string; + /** + * Receipt number entered while [creating the Order](https://razorpay.com/docs/api/orders). + */ + order_receipt?: string | null; + /** + * The payment method used to complete the payment. + */ + method: 'card' | 'netbanking' | 'wallet' | 'emi' | 'upi'; + /** + * The card network used to process the payment. + */ + card_network: + | 'American Express' + | 'Diners Club' + | 'Maestro' + | 'MasterCard' + | 'RuPay' + | 'Visa' + | 'unknown'; + card_issuer: string; + /** + * This is a 4-character code denoting the issuing bank. + */ + card_type: 'credit' | 'debit'; + /** + * The unique identifier of any dispute, if any, for this transaction. + */ + dispute_id?: string | null; + } + + + interface RazorpayInstantSettlement extends RazorpayInstantSettlementBaseRequestBody{ + /** + * The unique identifier of the instant settlement transaction. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The settlement amount, in paise, requested by you. + */ + amount_requested: number; + /** + * Total amount (minus fees and tax), in paise, + * settled to the bank account. + */ + amount_settled: number; + /** + * Portion of the requested amount, in paise, yet + * to be settled to you. + */ + amount_pending: number; + /** + * Portion of the requested amount, in paise, that was not settled to you. + * This amount is reversed to your PG current balance. + */ + amount_reversed: number; + /** + * Total amount (fees+tax), in paise, deducted for the instant settlement. + */ + fees: number; + /** + * Total tax, in paise, charged for the fee component. + */ + tax: number; + /** + * The 3-letter ISO currency code for the settlement. + */ + currency: string; + /** + * Indicates the state of the instant settlement + */ + status: 'created' | 'processed' | 'failed' | 'initiated' | 'reversed' | 'partially_processed'; + /** + * Unix timestamp at which the instant settlement was created. + */ + created_at: number; + /** + * List of payouts created for the instant settlement. + */ + ondemand_payouts?: { + entity: string; + count: number; + items: Settlements.RazorpaySettlement[]; + } + scheduled: boolean; + } + + interface RazorpayOndemandSettlementQuery extends RazorpayPaginationOptions { + 'expand[]'?: string; + } +} + +declare function settlements(api: any): { + /** + * Create on-demand settlement + * + * @param params - Check [doc](https://razorpay.com/docs/api/settlements/instant#create-an-instant-settlement) for required params + * + */ + createOndemandSettlement(params: Settlements.RazorpayInstantSettlementCreateRequestBody): Promise + createOndemandSettlement(params: Settlements.RazorpayInstantSettlementCreateRequestBody, callback: (err: INormalizeError | null, data: Settlements.RazorpayInstantSettlement) => void): void + /** + * Get all settlements + * + * @param params - Check [doc](https://razorpay.com/docs/api/settlements/instant#fetch-all-instant-settlements) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + /** + * Fetches a settlement given Settlement ID + * + * @param settlementId - The unique identifier of the settlement. + * + */ + fetch(settlementId: string): Promise + fetch(settlementId: string, callback: (err: INormalizeError | null, data: Settlements.RazorpaySettlement) => void): void + /** + * Fetch all demand settlements + * + * @param settlementId - The unique identifier of the settlement. + * @param params - Check [doc](https://razorpay.com/docs/api/settlements/instant#fetch-all-instant-settlements) for required params + * + */ + fetchAllOndemandSettlement(params: Settlements.RazorpayOndemandSettlementQuery): Promise<{ + entity: string; + count: number; + items: Settlements.RazorpayInstantSettlement[]; + }> + fetchAllOndemandSettlement(params: Settlements.RazorpayOndemandSettlementQuery, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Settlements.RazorpayInstantSettlement[]; + }) => void): void + /** + * Fetch on-demand settlement by ID + * + * @param settlementId - The unique identifier of the settlement. + * @param params - Check [doc](https://razorpay.com/docs/api/settlements/instant#fetch-instant-settlement-by-id) for required params + * + */ + fetchOndemandSettlementById(settlementId: string, params?: { 'expand[]': 'ondemand_payouts' }): Promise; + fetchOndemandSettlementById(settlementId: string, params: { 'expand[]'?: 'ondemand_payouts' }, callback: (err: INormalizeError | null, data: Settlements.RazorpayInstantSettlement) => void): void + /** + * Settlement report for a month + * + * @param params - Check [doc](https://razorpay.com/docs/api/settlements#settlement-recon) for required params + * + */ + reports(params: Settlements.RazorpaySettlementReconBaseRequestBody): Promise + reports(params: Settlements.RazorpaySettlementReconBaseRequestBody, callback: (err: INormalizeError | null, data: Settlements.RazorpaySettlementRecon) => void): void +} + +export default settlements \ No newline at end of file diff --git a/lib/types/subscriptions.d.ts b/lib/types/subscriptions.d.ts new file mode 100644 index 00000000..1f171f58 --- /dev/null +++ b/lib/types/subscriptions.d.ts @@ -0,0 +1,397 @@ +import { Addons } from "./addons"; +import { IMap, RazorpayPaginationOptions, PartialOptional, INormalizeError } from "./api"; +import { Invoices } from "./invoices"; +import { Orders } from "./orders"; +import { Items } from "./items"; +import { Tokens } from "./tokens"; +import { FundAccounts } from "./fundAccount"; + +export declare namespace Subscriptions { + + interface RazorpaySubscriptionBaseRequestBody { + /** + * The unique identifier of a plan that should be linked to the Subscription. + * For example, `plan_00000000000001`. + */ + plan_id: string; + /** + * The number of billing cycles for which the customer should be charged. + */ + total_count: number; + /** + * Indicates whether the communication to the customer would be handled by you or us. + * Possible values: + * + * `0`: communication handled by you. + * + * `1` (default): communication handled by Razorpay. + */ + customer_notify?: boolean | 0 | 1; + /** + * The number of times the customer should be charged the plan + * amount per invoice. + */ + quantity?: number; + /** + * The unique identifier of the offer that is linked to the Subscription. + * You can obtain this from the Dashboard. + */ + offer_id?: string; + /** + * Unix timestamp that indicates from when the Subscription should start. + * If not passed, the Subscription starts immediately after the authorisation + * payment. + */ + start_at?: number; + /** + * Unix timestamp that indicates till when the customer can make the + * authorisation payment. + */ + expire_by?: number; + /** + * This can be used to charge the customer a one-time fee before the + * start of the Subscription. This can include something like a one-time + * delivery charge or a security deposit. Know more about + * [Add-ons](https://razorpay.com/docs/payments/subscriptions/create-add-ons). + */ + addons?: Pick[]; + /** + * Notes you can enter for the contact for future reference. This is a + * key-value pair. + */ + notes?: IMap; + /** + * Represents when the Subscription should be updated. Possible values: + * + * `now` (default value): Updates the Subscription immediately. + * + * `cycle_end`: Updates the Subscription at the end of the current billing cycle. + */ + schedule_change_at?: 'now' | 'cycle_end'; + } + + interface RazorpaySubscriptionAddonsBaseRequestBody { + /** + * List of invoices generated for the Subscription. + */ + item: Items.RazorpayItemBaseRequestBody; + /** + * The number of units of the item billed in the invoice. + * For example, `1`. + */ + quantity?: number; + } + + interface RazorpaySubscriptionCreateRequestBody extends RazorpaySubscriptionBaseRequestBody { } + + interface RazorpaySubscriptionUpdateRequestBody extends PartialOptional { + /** + * Indicates the number of billing cycles remaining on the Subscription. + */ + remaining_count?: number; + } + + interface RazorpaySubscriptionLinkCreateRequestBody extends RazorpaySubscriptionBaseRequestBody { + /** + * The customer's email and phone number to which notifications + * are to be sent. + */ + notify_info?: RazorpaySubscriptionNotifyInfo; + } + + interface RazorpaySubscriptionNotifyInfo { + notify_phone?: string | number; + notify_email?: string; + } + + interface RazorpaySubscription extends RazorpaySubscriptionBaseRequestBody { + /** + * The unique identifier linked to a Subscription. + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * Status of the Subscription. + */ + status: + | 'created' + | 'authenticated' + | 'active' + | 'pending' + | 'halted' + | 'cancelled' + | 'completed' + | 'expired'; + /** + * Indicates the start time of the current billing cycle of a Subscription. + */ + current_start?: number | null; + /** + * Indicates the end time of the current billing cycle of a Subscription. + */ + current_end?: number | null; + /** + * The Unix timestamp of when the Subscription has completed its period or + * has been cancelled midway. + */ + ended_at?: number | null; + /** + * The Unix timestamp of when the next charge on the Subscription + * should be made. + */ + charge_at: number; + /** + * The Unix timestamp, indicates from when the Subscription should start. + * If not passed, the Subscription starts immediately after the authorisation + * payment. + */ + start_at: number; + end_at: number; + /** + * The number of times the charge for the current billing cycle has been + * attempted on the card. + */ + auth_attempts: number; + /** + * Indicates the number of billing cycles the customer has already been charged. + */ + paid_count: number; + /** + * The Unix timestamp at which the plan was created. + */ + created_at: number; + /** + * URL that can be used to make the authorisation payment. + * For example, `https://rzp.io/i/PWtAiEo`. + */ + short_url: string; + /** + * Indicates if the Subscription has any scheduled changes. + */ + has_scheduled_changes: boolean; + change_scheduled_at?: number | null; + source: string; + /** + * Indicates the number of billing cycles remaining on + * the Subscription. For example, `2`. + */ + remaining_count: string; + /** + * he unique identifer of the customer who is subscribing to a plan. + * This is populated automatically after the customer completes the + * authorisation transaction. + */ + customer_id: string | null; + payment_method: string | null; + } + + interface RazorpaySubscriptionRegistrationBaseRequestBody { + /** + * The authorization method + */ + method?: 'card' | 'emandate' | 'nach' | 'upi'; + /** + * Use to set the maximum amount (in paise) per debit request. + * The value can range from `500` - `9999900`. The default value is ₹99,000. + */ + max_amount?: number; + /** + * The Unix timestamp till when you can use the token (authorization on the payment method) + * to charge the customer subsequent payments. + */ + expire_at?: number; + } + + interface RazorpaySubscriptionRegistrationUpi extends RazorpaySubscriptionRegistrationBaseRequestBody {} + + interface RazorpaySubscriptionRegistrationUpiTpv extends RazorpaySubscriptionRegistrationBaseRequestBody { + /** + * The frequency at which you can charge your customer. + */ + frequency: string; + bank_account?: Pick; + } + + interface RazorpaySubscriptionRegistrationNach extends RazorpaySubscriptionRegistrationBaseRequestBody { + bank_account?: Orders.RazorpayBankAccountBaseRequestBody; + /** + * Additional information to be printed on the NACH form your customer will sign. + */ + nach?: { + /** + * A user entered reference that appears on the NACH form. + */ + form_reference1?: string; + /** + * A user entered reference that appears on the NACH form. + */ + form_reference2?: string; + /** + * A user entered description that appears on the hosted page. + */ + description?: string; + } + } + + interface RazorpaySubscriptionRegistrationEmandate extends RazorpaySubscriptionRegistrationBaseRequestBody { + first_payment_amount: number; + /** + * The payment method used to make the authorization transaction. + */ + auth_type?: 'netbanking' | 'debitcard' | 'aadhaar' | 'physical'; + /** + * The customer's bank account details. + */ + bank_account?: Orders.RazorpayBankAccountBaseRequestBody; + } + + interface RazorpayRegistrationLinkBaseRequestBody extends Omit { + /** + * Details of the authorization payment. + */ + subscription_registration: + | RazorpaySubscriptionRegistrationUpi + | RazorpaySubscriptionRegistrationNach + | RazorpaySubscriptionRegistrationEmandate + | RazorpaySubscriptionRegistrationUpiTpv + } + + interface RazorpayRegistrationLink extends Invoices.RazorpayInvoice { + auth_link_status: string | null; + token?: Tokens.RazorpayAuthorizationToken; + nach_form_url?: string | null; + } + + interface RazorpaySubscriptionQuery extends RazorpayPaginationOptions { + plan_id?: string + } +} + +declare function subscriptions(api: any): { + /** + * Creates a Subscription + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#create-a-subscription) for required params + * + */ + create(params: Subscriptions.RazorpaySubscriptionCreateRequestBody | Subscriptions.RazorpaySubscriptionLinkCreateRequestBody): Promise + create(params: Subscriptions.RazorpaySubscriptionCreateRequestBody | Subscriptions.RazorpaySubscriptionLinkCreateRequestBody, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Get all Subscriptions + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#fetch-all-subscriptions) for required params + * + */ + all(params?: Subscriptions.RazorpaySubscriptionQuery ): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: Subscriptions.RazorpaySubscriptionQuery , callback: (err: INormalizeError | null, data: { + entity: string, + count: number, + items: Array + }) => void): void + /** + * Fetch a Subscription given Subcription ID + * + * @param subscriptionId - The unique identifier of the Subscription. + * + */ + fetch(subscriptionId: string): Promise + fetch(subscriptionId: string, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Edit a subscription given Subcription ID + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#update-a-subscription) for required params + * + */ + update(subscriptionId: string, params: Subscriptions.RazorpaySubscriptionUpdateRequestBody): Promise + update(subscriptionId: string, params: Subscriptions.RazorpaySubscriptionUpdateRequestBody, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Fetch details of pending update + * + * @param subscriptionId - The unique identifier of the Subscription. + * + */ + pendingUpdate(subscriptionId: string): Promise + pendingUpdate(subscriptionId: string, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Cancel a update + * + * @param subscriptionId - The unique identifier of the Subscription. + * + */ + cancelScheduledChanges(subscriptionId: string): Promise + cancelScheduledChanges(subscriptionId: string, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Pause a subscription + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#pause-a-subscription) for required params + * + */ + pause(subscriptionId: string, params?: { 'pause_at': 'now' }): Promise + pause(subscriptionId: string, params: { 'pause_at': 'now' }, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Resume a subscription + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#resume-a-subscription) for required params + * + */ + resume(subscriptionId: string, params?: { 'resume_at': 'now' }): Promise + resume(subscriptionId: string, params: { 'resume_at': 'now' }, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Cancel a subscription given id and optional cancelAtCycleEnd + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param cancelAtCycleEnd - `false` (default): Cancel the subscription immediately. + * + */ + cancel(subscriptionId: string, cancelAtCycleEnd?: boolean): Promise + cancel(subscriptionId: string, cancelAtCycleEnd: boolean, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Delete offer linked to a subscription + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param offerId - The unique identifier of the offer you want remove from the Subscription. + * + */ + deleteOffer(subscriptionId: string, offerId: string): Promise + deleteOffer(subscriptionId: string, offerId: string, callback: (err: INormalizeError | null, data: Subscriptions.RazorpaySubscription) => void): void; + /** + * Creates addon for a given subscription + * + * @param subscriptionId - The unique identifier of the Subscription. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/subscriptions/#create-an-add-on) for required params + * + */ + createAddon(subscriptionId: string, params: Subscriptions.RazorpaySubscriptionAddonsBaseRequestBody): Promise + createAddon(subscriptionId: string, params: Subscriptions.RazorpaySubscriptionAddonsBaseRequestBody, callback: (err: INormalizeError | null, data: Addons.RazorpayAddon) => void): void; + /** + * Creates a Registration Link + * + * @param params + * @link https://razorpay.com/docs/api/payments/recurring-payments/emandate/create-authorization-transaction#121-create-a-registration-link + * @link https://razorpay.com/docs/api/payments/recurring-payments/cards/create-authorization-transaction#121-create-a-registration-link + * @link https://razorpay.com/docs/api/payments/recurring-payments/paper-nach/create-authorization-transaction#121-create-a-registration-link + * @link https://razorpay.com/docs/api/payments/recurring-payments/upi/create-authorization-transaction#121-create-a-registration-link + * @link https://razorpay.com/docs/api/payments/recurring-payments/upi-tpv/create-authorization-transaction#121-create-a-registration-link + * + */ + createRegistrationLink(params: Subscriptions.RazorpayRegistrationLinkBaseRequestBody): Promise + createRegistrationLink(params: Subscriptions.RazorpayRegistrationLinkBaseRequestBody, callback: (err: INormalizeError | null, data: Subscriptions.RazorpayRegistrationLink) => void): void; +} + +export default subscriptions \ No newline at end of file diff --git a/lib/types/tokens.d.ts b/lib/types/tokens.d.ts new file mode 100644 index 00000000..6a84ed9f --- /dev/null +++ b/lib/types/tokens.d.ts @@ -0,0 +1,212 @@ +import { IMap } from "./api"; +import { Invoices } from "./invoices"; +import { Orders } from "./orders"; +import { Payments } from "./payments"; + + +export declare namespace Tokens { + + interface RazorpayTokenCard { + /** + * The maximum amount that can be auto-debited in a single charge. + * The minimum value is 100 (₹1 ), and the maximum value is 1500000 (₹15,000). + */ + max_amount: number; + /** + * The Unix timestamp that indicates when the authorization transaction must expire. + * The default value is 10 years. + */ + expire_at: number; + /** + * The frequency at which you can charge your customer. + * Currently supported frequencies are `as_presented` and `monthly`. + */ + frequency: string + } + + interface RazorpayTokenEmandate { + /** + * Emandate type used to make the authorization payment + */ + auth_type?: 'netbanking' | 'debitcard' | 'aadhaar' | 'physical'; + /** + * The maximum amount in paise a customer can be charged in a transaction. + * The value can range from `500` to `100000000`. The default value is `9999900` (₹99,999). + */ + max_amount?: number; + /** + * The Unix timestamp to indicate till when you can use the token (authorization on the payment method) + * to charge the customer subsequent payments. The default value is 10 years for emandate. + */ + expire_at?: number; + /** + * Key-value pair that can be used to store additional information about the entity. + * Maximum 15 key-value pairs, 256 characters (maximum) each. For example + */ + notes?: IMap; + /** + * Customer's bank account details that should be pre-filled on the checkout. + */ + bank_account?: Orders.RazorpayBankAccountBaseRequestBody; + /** + * The amount, in paise, that should be auto-charged in addition to the + * authorization amount. For example, `100000`. + */ + first_payment_amount?: number; + } + + interface RazorpayTokenNach extends RazorpayTokenEmandate{ + /** + * Additional information to be printed on the NACH form that your customer will sign. + */ + nach: { + /** + * A user-entered reference that appears on the NACH form. + */ + form_reference1: string; + /** + * A user-entered reference that appears on the NACH form. + */ + form_reference2: string; + /** + * A user-entered description that appears on the hosted page. + * For example, `Form for Gaurav Kumar`. + */ + description: string; + } + } + + interface RazorpayAuthorizationToken extends RazorpayTokenEmandate { + method: string; + currency: string; + bank_account: RazorpayBankAccount; + recurring_status: any; + failure_reason: any; + nach?: { + create_form: boolean; + /** + * A user-entered reference that appears on the NACH form. + */ + form_reference1: string; + /** + * A user-entered reference that appears on the NACH form. + */ + form_reference2: string; + /** + * The link from where you can download the pre-filled NACH form. + */ + prefilled_form: string; + prefilled_form_transient: string; + /** + * The link where the NACH form should be uploaded once it is signed by the customer. + */ + upload_form_url: string; + /** + * A user-entered description that appears on the hosted page. + * For example, `Form for Gaurav Kumar`. + */ + description: string; + } + } + + interface RazorpayBankAccount extends Orders.RazorpayBankAccount, Orders.RazorpayBankAccountBaseRequestBody {} + + interface RazorpayToken { + /** + * The unique identifier linked to an item + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: string; + /** + * The token is being fetched. + */ + token: string; + /** + * Card issuing bank details. + */ + bank: string | null; + /** + * Provides wallet information. + */ + wallet: string | null; + /** + * The payment method used to make the transaction. + */ + method: string; + /** + * Details related to card used to make the transaction. + */ + card?: Payments.RazorpayCard; + /** + * The VPA details + */ + vpa?: { + /** + * The username of the VPA holder. For example, `gaurav.kumar`. + */ + username: string | null; + /** + * The VPA handle. Here it is `upi`. + */ + handle: string | null; + /** + * The name of the VPA holder. + */ + name: string | null; + }, + bank_details?: Tokens.RazorpayBankAccount; + /** + * This represents whether recurring is enabled for this token or not. + */ + recurring: boolean; + recurring_details: { + status: string; + failure_reason: string | null; + }, + /** + * The authorization type details. + */ + auth_type: string | null; + /** + * The unique identifier issued by the payment gateway during customer registration. + * This can be Gateway Reference Number or Gateway Token. + */ + mrn: string | null; + /** + * The VPA usage timestamp + */ + used_at: number; + start_time: number; + /** + * The token creation timestamp. + */ + created_at: number; + /** + * The token expiry date timestamp. + */ + expired_at: number; + /** + * Indicates whether the option to change currency is enabled or not. + */ + dcc_enabled: boolean; + /** + * The maximum amount that can be auto-debited in a single charge. + * The minimum value is 100 (₹1 ), and the maximum value is 1500000 (₹15,000). + */ + max_amount?: number; + status?:string; + error_description?: string | null; + internal_error_code?: string | null; + source: string | null; + notes?: IMap; + compliant_with_tokenisation_guidelines?: boolean; + /** + * Details of the customer's billing address. + */ + billing_address: Invoices.RazorpayInvoiceAddress; + } + +} \ No newline at end of file diff --git a/lib/types/transfers.d.ts b/lib/types/transfers.d.ts new file mode 100644 index 00000000..3da4b77b --- /dev/null +++ b/lib/types/transfers.d.ts @@ -0,0 +1,222 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions } from "./api"; + +export declare namespace Transfers { + interface RazorpayTransferBaseRequestBody { + /** + * Unique identifier of the linked account to which the transfer must be made. + */ + account: string; + /** + * The amount (in paise) to be transferred to the linked account. + * For example, for an amount of ₹200.35, the value of this field should be 20035. + */ + amount: number | string; + /** + * The currency used in the transaction. We support only INR for Route transactions. + */ + currency: string; + /** + * Set of key-value pairs that can be associated with an entity. + * These pairs can be useful for storing additional information about the entity. + * A maximum of 15 key-value pairs, each of 256 characters (maximum), are supported. + */ + notes?: IMap; + + } + + interface RazorpayTransferCreateRequestBody extends RazorpayTransferBaseRequestBody { } + + interface RazorpayTransferUpdateRequestBody { + /** + * Indicates whether the account settlement for transfer is on hold. + * Possible values: + * `1` - Put the transfer settlement on hold + * `0` - Releases the settlement. + */ + on_hold: boolean | 0 | 1; + /** + * Timestamp, in Unix, that indicates until when the settlement of the transfer must be put on hold. + * If no value is passed, the settlement is put on hold indefinitely. + */ + on_hold_until?: number; + } + + interface RazorpayOrderCreateRequestBody extends RazorpayTransferBaseRequestBody, RazorpayTransferUpdateRequestBody { + linked_account_notes?: string[]; + } + + interface RazorpayPaymentCreateRequestBody extends RazorpayOrderCreateRequestBody { } + + interface RazorpayTransfer extends Omit, Omit { + /** + * Unique identifier of the transfer. + */ + id: string; + /** + * The name of the entity. + */ + entity: string; + /** + * The status of the transfer. + */ + status: 'created' | 'pending' | 'processed' | 'failed' | 'reversed' | 'partially_reversed'; + /** + * The status of the settlement. + */ + settlement_status?: 'pending' | 'on_hold' | 'settled' | null; + /** + * Unique identifier of the transfer source. The source can be a `payment` or an order. + */ + source: string; + /** + * Unique identifier of the transfer destination, that is, the linked account. + */ + recipient: string; + /** + * Amount reversed from this transfer for refunds. + */ + amount_reversed: number; + /** + * Fee (including GST) charged by Razorpay + */ + fees: number; + /** + * GST charged for the payment. + */ + tax: number | null; + /** + * Unique identifier of the settlement. + */ + recipient_settlement_id: string | null; + recipient_settlement: string | null; + /** + * Timestamp, in Unix, at which the record was created. + */ + created_at: number; + processed_at: number; + error: { + code: string | null; + description: string | null; + reason: string | null; + field: string | null; + step: string | null; + id: string | null; + source: string | null; + metadata: string | null; + } + } + + interface RazorpayReversal { + /** + * The unique identifier of the reversal. + */ + id: string, + /** + * The name of the entity. + */ + entity: string, + /** + * Unique identifier of the transfer that was reversed. + */ + transfer_id: string, + /** + * The amount that was reversed, in paise. + */ + amount: number, + /** + * Fee (including GST) charged by Razorpay + */ + fee: number | null, + /** + * GST charged for the payment. + */ + tax: number | null, + /** + * ISO currency code. We support route reversals only in INR. + */ + currency: string, + /** + * Timestamp in Unix. This indicates when the reversal was created. + */ + notes: IMap, + initiator_id: string | null, + customer_refund_id: string | null, + /** + * Description of the error that occurred during payment. + */ + created_at: number + } + + interface RazorpayTransferQuery extends RazorpayPaginationOptions { + recipient_settlement_id?: string + } +} + +declare function transfers(api: any): { + /** + * Creates a transfer + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/route/transfers/#direct-transfers) for required params + * + */ + create(params: Transfers.RazorpayTransferCreateRequestBody): Promise + create(params: Transfers.RazorpayTransferCreateRequestBody, callback: (err: INormalizeError | null, data: Transfers.RazorpayTransfer) => void): void + /** + * Fetch Transfers for a Settlement + * + * @param params - Unique identifier of a settlement obtained from the `settlement.processed` webhook payload. + * + */ + all(params?: Transfers.RazorpayTransferQuery): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: Transfers.RazorpayTransferQuery, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + /** + * Fetch a transfer + * + * @param transferId - The unique identifier of the transfer. + * + */ + fetch(transferId: string): Promise + fetch(transferId: string, callback: (err: INormalizeError | null, data: Transfers.RazorpayTransfer) => void): void + /** + * Edit a payment given Transfer ID + * + * @param transferId - The unique identifier of the transfer. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/route/transfers/#modify-settlement-hold-for-transfers) for required params + * + */ + edit(transferId: string, params: Transfers.RazorpayTransferUpdateRequestBody): Promise + edit(transferId: string, params: Transfers.RazorpayTransferUpdateRequestBody, callback: (err: INormalizeError | null, data: Transfers.RazorpayTransfer) => void): void + /** + * Reverse transfers from all linked accounts + * + * @param transferId - The unique identifier of the transfer. + * @param params - Check [doc](https://razorpay.com/docs/api/payments/route/transfers/#reverse-a-transfer) for required params + * + */ + reverse(transferId: string, params?: { amount: number }): Promise + reverse(transferId: string, params: { amount?: number }, callback: (err: INormalizeError | null, data: Transfers.RazorpayReversal) => void): void + /** + * Fetch settlement details + * + */ + fetchSettlements(): Promise<{ + entity: string; + count: string; + items: Array + }> + fetchSettlements(callback: (err: INormalizeError | null, data: { + entity: string; + count: string; + items: Array + }) => void): void +} + +export default transfers \ No newline at end of file diff --git a/lib/types/virtualAccounts.d.ts b/lib/types/virtualAccounts.d.ts new file mode 100644 index 00000000..e197617b --- /dev/null +++ b/lib/types/virtualAccounts.d.ts @@ -0,0 +1,274 @@ +import { IMap, INormalizeError, RazorpayPaginationOptions } from "./api"; +import { Orders } from "./orders"; +import { Payments } from "./payments"; + +export declare namespace VirtualAccounts { + interface RazorpayVirtualAccountBaseRequestBody { + /** + * The `merchant billing label ` as it + * appears on the Razorpay Dashboard. + */ + name?: string; + /** + * A brief description about the Customer Identifier. + */ + description?: string; + amount_expected?: string | number | null; + /** + * he amount paid by the customer into the Customer Identifier. + */ + amount_paid?: string | number; + /** + * Unique identifier of the customer the Customer Identifier + * is linked with. + */ + customer_id?: string; + /** + * Configuration of desired receivers for the Customer Identifier. + */ + receivers: RazorVirtualAccountReceiverBaseRequestBody; + /** + * UNIX timestamp at which the Customer Identifier is scheduled to + * be automatically closed + */ + close_by?: number; + /** + * Any custom notes you might want to add to the Customer Identifier + * can be entered here. + */ + notes?: IMap; + } + + interface RazorpayVirtualAccountCreateRequestBody extends RazorpayVirtualAccountBaseRequestBody { } + + interface RazorpayVirtualAccountTPVCreateRequestBody extends RazorpayVirtualAccountBaseRequestBody { + /** + * Details of customer bank accounts which will be allowed to make + * payments to your Customer Identifier. + */ + allowed_payers: RazorpayAllowedPayerBaseRequestBody[]; + } + + interface RazorpayVirtualAccount extends Omit { + /** + * The unique identifier linked to an virtual account + */ + id: string; + /** + * Indicates the type of entity. + */ + entity: 'virtual_account'; + /** + * Indicates whether the Customer Identifier is in active or closed state. + */ + status: 'active' | 'closed'; + /** + * UNIX timestamp at which the Customer Identifier is scheduled to be + * automatically closed. + */ + closed_at?: number; + /** + * UNIX timestamp at which the Customer Identifier was created. + */ + created_at?: number; + /** + * Configuration of desired receivers for the Customer Identifier. + */ + receivers: RazorpayVirtualAccountReceiver[]; + /** + * Details of customer bank accounts which will be allowed to make + * payments to your Customer Identifier. + */ + allowed_payers: RazorpayAllowedPayer[]; + } + + interface RazorpayAllowedPayerBaseRequestBody { + /** + * The type of account. Possible value is `bank_account`. + */ + type: 'bank_account'; + /** + * Indicates the bank account details such as + * `ifsc` and `account_number`. + */ + bank_account: Orders.RazorpayOrderBankDetailsBaseRequestBody; + } + + interface RazorpayAllowedPayer extends RazorpayAllowedPayerBaseRequestBody { + /** + * The unique identifier of the virtual bank account or virtual UPI ID. + * Sample IDs for: + * + * virtual bank account: `ba_Di5gbQsGn0QSz3` + * + * virtual UPI ID: `vpa_CkTmLXqVYPkbxx` + */ + id: string, + /** + * Name of the entity. Possible values are: `bank_account`, `vpa` + */ + entity: string, + } + + interface RazorVirtualAccountReceiverBaseRequestBody { + /** + * The receiver type to be added to the Customer Identifier. + */ + types?: ['bank_account' | 'vpa' | 'qr_code']; + /** + * Descriptor details for the virtual UPI ID. This is to be passed + * only when `vpa` is passed as the receiver `types`. + */ + vpa?: { + descriptor: string + }; + } + + interface RazorpayVirtualAccountReceiver { + id: string; + entity: string; + /** + * The IFSC for the virtual bank account created. + */ + ifsc: string; + /** + * The bank associated with the virtual bank account. + */ + bank_name: string; + /** + * The unique account number provided by the bank + */ + account_number: string; + /** + * The `merchant billing label ` as it + * appears on the Razorpay Dashboard. + */ + name: string; + /** + * Any custom notes you might want to add to the virtual bank account + * or virtual UPI ID can be entered here. + */ + notes: IMap; + /** + * The UPI ID consists of the username and the bank handle. + */ + username?: string; + /** + * The bank name that forms the second half of the virtual + * UPI ID. For example, icici + */ + handle?: string; + /** + * The UPI ID that combines the `username` and the `handle` with the `@` symbol. + */ + address?: string; + /** + * The URL of the QR code. + */ + short_url?: string; + /** + * A 14-digit reference number or a receipt for the payment. + * It will be the same as the value of id without the prefix `qr_`. + * A sample `reference` value will look like this: `4lsdkfldlteskf`. + */ + reference?: string | null; + updated_at:number; + /** + * The status of the payment. It can have two values, + * `active` and `closed`. + */ + status?: string; + } +} + +declare function virtualAccounts(api: any): { + /** + * Create a virtual account + * + * @param params + * @link https://razorpay.com/docs/api/payments/smart-collect/#create-a-customer-identifier + * @link https://razorpay.com/docs/api/payments/smart-collect-tpv#create-a-customer-identifier + * @link https://razorpay.com/docs/payments/payment-methods/bharatqr/api/#create + * + */ + create(params: VirtualAccounts.RazorpayVirtualAccountCreateRequestBody | VirtualAccounts.RazorpayVirtualAccountTPVCreateRequestBody): Promise + create(params: VirtualAccounts.RazorpayVirtualAccountCreateRequestBody | VirtualAccounts.RazorpayVirtualAccountTPVCreateRequestBody, callback: (err: INormalizeError | null, data: VirtualAccounts.RazorpayVirtualAccount) => void): void + /** + * Fetch all virtual account + * + * @param params - Check [doc](https://razorpay.com/docs/api/payments/smart-collect#fetch-all-customer-identifiers) for required params + * + */ + all(params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: number; + items: Array; + }> + all(params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + /** + * Fetch virtual account by id + * + * @param virtualId - The unique identifier of the virtual account + * + */ + fetch(virtualId: string): Promise + fetch(virtualId: string, callback: (err: INormalizeError | null, data: VirtualAccounts.RazorpayVirtualAccount) => void): void + /** + * Close virtual account + * + * @param virtualId - The unique identifier of the virtual account + * + */ + close(virtualId: string): Promise + close(virtualId: string, callback: (err: INormalizeError | null, data: any) => void): void + /** + * Fetch payments for a virtual account + * + * @param virtualId - The unique identifier of the virtual account + * @param params - Check [doc](https://razorpay.com/docs/api/payments/smart-collect-tpv#fetch-payments-for-a-customer-identifier) for required params + * + */ + fetchPayments(virtualId: string, params?: RazorpayPaginationOptions): Promise<{ + entity: string; + count: number; + items: Array; + }> + fetchPayments(virtualId: string, params: RazorpayPaginationOptions, callback: (err: INormalizeError | null, data: { + entity: string; + count: number; + items: Array; + }) => void): void + /** + * Add receiver to an existing virtual account + * + * @param virtualId - The unique identifier of the virtual account + * @param params - Check [doc](https://razorpay.com/docs/api/payments/smart-collect-tpv#add-receiver-to-an-existing-customer-identifier) for required params + * + */ + addReceiver(virtualId: string, params: VirtualAccounts.RazorVirtualAccountReceiverBaseRequestBody): Promise + addReceiver(virtualId: string, params: VirtualAccounts.RazorVirtualAccountReceiverBaseRequestBody, callback: (err: INormalizeError | null, data: VirtualAccounts.RazorpayVirtualAccount) => void): void + /** + * Add an Allowed Payer Account + * + * @param virtualId - The unique identifier of the virtual account + * @param params - Check [doc](https://razorpay.com/docs/api/payments/smart-collect-tpv#add-an-allowed-payer-account) for required params + * + */ + allowedPayer(virtualId: string, params: VirtualAccounts.RazorpayAllowedPayerBaseRequestBody): Promise + allowedPayer(virtualId: string, params: VirtualAccounts.RazorpayAllowedPayerBaseRequestBody, callback: (err: INormalizeError | null, data: VirtualAccounts.RazorpayVirtualAccount) => void): void + /** + * Delete an Allowed Payer Account + * + * @param virtualId - The unique identifier of the virtual account + * @param allowedPayerId + * + */ + deleteAllowedPayer(virtualId: string, allowedPayerId: string): Promise + deleteAllowedPayer(virtualId: string, allowedPayerId: string, callback: (err: INormalizeError | null, data: null) => void): void +} + +export default virtualAccounts \ No newline at end of file diff --git a/lib/utils/nodeify.d.ts b/lib/utils/nodeify.d.ts new file mode 100644 index 00000000..3b4ca343 --- /dev/null +++ b/lib/utils/nodeify.d.ts @@ -0,0 +1 @@ +export default function (promise: Promise, callback?: (err: any, data: any) => void): Promise; \ No newline at end of file diff --git a/lib/utils/razorpay-utils.d.ts b/lib/utils/razorpay-utils.d.ts new file mode 100644 index 00000000..5acfcafd --- /dev/null +++ b/lib/utils/razorpay-utils.d.ts @@ -0,0 +1,88 @@ +export interface RazorpayWebhook { + /** + * Payment ID of the successful payment. + */ + payment_id: string; +} + +export interface RazorpayVerifyPayment extends RazorpayWebhook { + /** + * The id of the order to be fetched + */ + order_id: string; +} + +export interface RazorpayVerifySubscription extends RazorpayWebhook { + /** + * The id of the subscription to be fetched + */ + subscription_id: string; +} + +export interface RazorpayVerifyPaymentLink extends RazorpayWebhook { + /** + * Payment Link ID generated at the time of link creation. + */ + payment_link_id: string; + /** + * Internal order ID set by you for business reference using the `reference_id` + * parameter at the time of link creation. No value is returned if `reference_id` + * parameter was not used. + */ + payment_link_reference_id: string; + /** + * Current status of the link. + */ + payment_link_status: string; +} + +export function getDateInSecs(date: string): number + +export function normalizeDate(date: number | string): number + +export function isNumber(num: any): boolean + +export function isNonNullObject(input: Object | undefined): boolean + +export function normalizeBoolean(bool: boolean | undefined): 1 | 0 + +export function isDefined(value: any): boolean + +export function normalizeNotes(notes: Object): Object + +export function getTestError(summary: string, expectedVal: string, gotVal: string): Error + +/** +* Verify webhook verification +* +* @param body +* raw webhook request body +* @param signature +* The hash signature is calculated using HMAC with SHA256 algorithm; with your webhook +* secret set as the key and the webhook request body as the message. +* @param secret +* your webhook secret +* +*/ +export function validateWebhookSignature(body: string, signature: string, secret: string): boolean + +/** +* Payment verfication +* +* @param payload +* Check [doc](https://github.com/razorpay/razorpay-node/blob/master/documents/paymentVerfication.md) for required params +* @param signature +* The hash signature is calculated using HMAC with SHA256 algorithm; with your webhook +* secret set as the key and the webhook request body as the message. +* @param secret +* your webhook secret +* +*/ +export function validatePaymentVerification(payload: RazorpayVerifyPayment | RazorpayVerifySubscription | RazorpayVerifyPaymentLink, signature: string, secret: string): boolean + +/** +* given an object , returns prettified string +* +* @param val +*/ +export function prettify(val: Object): string \ No newline at end of file diff --git a/package.json b/package.json index 77419514..ad7d6625 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "razorpay", - "version": "2.8.4", + "version": "2.8.5", "description": "Official Node SDK for Razorpay API", "main": "dist/razorpay", "typings": "dist/razorpay", "scripts": { "prepublish": "npm test", "clean": "rm -rf dist && mkdir dist", - "cp-ts": "cp lib/razorpay.d.ts dist/", + "cp-types":"mkdir dist/types && cp lib/types/* dist/types && cp lib/utils/*d.ts dist/utils", + "cp-ts": "cp lib/razorpay.d.ts dist/ && npm run cp-types", "build:commonjs": "babel lib -d dist", "build": "npm run clean && npm run build:commonjs && npm run cp-ts", "debug": "npm run build && node-debug examples/index.js", @@ -43,8 +44,10 @@ "nock": "^13.1.1" }, "dependencies": { + "@types/request-promise": "^4.1.48", "promise": "^8.1.0", "request": "^2.88.0", - "request-promise": "^4.2.6" + "request-promise": "^4.2.6", + "typescript": "^4.9.4" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..566b3210 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,95 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "es2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + //"types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + //"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + "declarationMap": true, /* Create sourcemaps for d.ts files. */ + //"emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + //"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + //"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + //"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + //"skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} \ No newline at end of file