From c225f94990cb28b031a176bdb122d67532a88236 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Tue, 7 May 2024 18:44:11 +0530 Subject: [PATCH] Added expanded type (#394) --- documents/payment.md | 192 +++++++++++++++++++++++++++++++++++++++- lib/types/payments.d.ts | 113 ++++++++++++++--------- 2 files changed, 260 insertions(+), 45 deletions(-) diff --git a/documents/payment.md b/documents/payment.md index e963e29..25badb1 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -877,7 +877,197 @@ instance.iins.fetch(tokenIin); } ``` ------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded Card Details) + +```js +var paymentId = "pay_MLzFlOC98cJmHQ"; + +instance.payments.fetch(paymentId, {"expand[]": "card"}); +``` + +| Name | Type | Description | +|-------------|---------|--------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the card details when the payment method is `card`. | + +**Response:** +```json +{ + "id": "pay_H9oR0gLCaVlV6m", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "failed", + "order_id": "order_H9o58N6qmLYQKC", + "invoice_id": null, + "terminal_id": "term_G5kJnYM9GhhLYT", + "method": "card", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": "card_H9oR0ocen1cmZq", + "card": { + "id": "card_H9oR0ocen1cmZq", + "entity": "card", + "name": "Gaurav", + "last4": "1213", + "network": "RuPay", + "type": "credit", + "issuer": "UTIB", + "international": false, + "emi": false, + "sub_type": "business" + }, + "bank": null, + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919000090000", + "notes": { + "email": "gaurav.kumar@example.com", + "phone": "09000090000" + }, + "fee": null, + "tax": null, + "error_code": "BAD_REQUEST_ERROR", + "error_description": "Card issuer is invalid", + "error_source": "customer", + "error_step": "payment_authentication", + "error_reason": "incorrect_card_details", + "acquirer_data": { + "auth_code": null, + "authentication_reference_number": "100222021120200000000742753928" + }, + "created_at": 1620807547 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded Offers Details) + +```js +var paymentId = "pay_MLzFlOC98cJmHQ"; + +instance.payments.fetch(paymentId, {"expand[]": "emi"}); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|--------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the emi details when the payment method is emi. | + +**Response:**
+ +```json +{ + "id": "pay_DG4ZdRK8ZnXC3k", + "entity": "payment", + "amount": 200000, + "currency": "INR", + "status": "authorized", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "emi", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": "card_DG4ZdUO3xABb20", + "bank": "ICIC", + "wallet": null, + "vpa": null, + "email": "gaurav@example.com", + "contact": "+919972000005", + "notes": [], + "fee": null, + "tax": null, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "emi": { + "issuer": "ICIC", + "rate": 1300, + "duration": 6 + }, + "acquirer_data": { + "auth_code": "828553" + }, + "created_at": 1568026077 +} +``` + +------------------------------------------------------------------------------------------------------- +### Fetch a Payment (With Expanded UPI Details) + +```js +var paymentId = "pay_MLzFlOC98cJmHQ"; + +instance.payments.fetch(paymentId, {"expand[]": "upi"}); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|--------------------------------------| +| paymentId* | integer | Unique identifier of the payment | +| expand[] | string | Use to expand the UPI details when the payment method is upi. | + +**Response:**
+ +```json + +{ + "id": "pay_DG4ZdRK8ZnXC3k", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": "order_GjCr5oKh4AVC51", + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Payment for Adidas shoes", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gaurav.kumar@upi", + "email": "gaurav.kumar@example.com", + "contact": "9000090000", + "customer_id": "cust_K6fNE0WJZWGqtN", + "token_id": "token_KOdY$DBYQOv08n", + "notes": [], + "fee": 1, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "303107535132" + }, + "created_at": 1605871409, + "upi": { + "payer_account_type": "credit_card", + "vpa": "gaurav.kumar@upi", + "flow": "in_app" + } +} +``` + +------------------------------------------------------------------------------------------------------- + **PN: * indicates mandatory fields**

-**For reference click [here](https://razorpay.com/docs/api/payments/)** \ No newline at end of file +**For reference click [here](https://razorpay.com/docs/api/payments/)** diff --git a/lib/types/payments.d.ts b/lib/types/payments.d.ts index 608893c..f27e6a0 100644 --- a/lib/types/payments.d.ts +++ b/lib/types/payments.d.ts @@ -42,6 +42,16 @@ export declare namespace Payments { * The unique identifier of the customer you want to charge. */ customer_id: string; + /** + * The unique identifier of the subscription. + */ + subscription_id?: string; + /** + * The authentication channel for the payment. Possible value is `browser` or `app` + */ + authentication?: { + authentication_channel: string; + }; } interface RazorpayPaymentCreateRequestBody extends RazorpayPaymentBaseRequestBody { } @@ -230,6 +240,10 @@ export declare namespace Payments { * The last 4 digits of the tokenised card. */ last4?: string; + /** + * The name of the aggregator that provided the token. Possible values are `Visa`, `Mastercard`, `Amex` or `HDFC for Diners` + */ + provider_type?: string; } interface RazorpayCardCreateRequest extends RazorpayCardBaseRequestBody { } @@ -422,7 +436,7 @@ export declare namespace Payments { /** * Details of the expiry of the UPI link */ - upi: { + upi?: { /** * Specify the type of the UPI payment flow. * Possible values: `collect` (default), `intent` @@ -435,6 +449,10 @@ export declare namespace Payments { */ expiry_time?: number; } + /** + * Token of the saved VPA. + */ + token?: string; } interface RazorpayPaymentQuery extends RazorpayPaginationOptions { @@ -451,54 +469,51 @@ export declare namespace Payments { */ authentication_channel: 'browser' | 'app' } + } + + interface BrowserInfo { /** - * Information regarding the customer's browser. - * This parameter need not be passed when `authentication_channel=app`. + * Indicates whether the customer's browser supports Java. + * Obtained from the `navigator` HTML DOM object. */ - 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; - } + java_enabled: boolean; + /** + * Indicates 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 | string; + /** + * Total width of the payer's screen in pixels. + * Obtained from the `screen.width` HTML DOM property. + */ + screen_width: number | string; + /** + * Obtained from the `navigator` HTML DOM object. + */ + screen_height: number | string; + /** + * Obtained from payer's browser using + * the `screen.colorDepth` HTML DOM property. + */ + color_depth: number | string; + /** + * Obtained from payer's browser using the navigator. + * language HTML DOM property. Maximum limit of 8 characters. + */ + language: string; } interface RazorpayPaymentS2SCreateRequestBody extends RazorpayPaymentBaseRequestBody { - save:boolean | number; + save: boolean | number; /** * Pass the unique token id created when the customer made the first payment. */ - token?:string; + token?: string; /** * Pass the sub-merchant's unique identifier. */ @@ -517,6 +532,12 @@ export declare namespace Payments { * Default value will be passed by Razorpay if not provided by merchant. */ user_agent: string | null; + provider_name?: string; + /** + * Information regarding the customer's browser. + * This parameter need not be passed when `authentication_channel=app`. + */ + browser?: Partial } interface RazorpayPaymentS2SJson { @@ -555,6 +576,10 @@ export declare namespace Payments { entity: string; } + interface ExpandDetails { + 'expand[]': 'card' | 'emi' | 'offers' | 'upi' + } + } declare function payments(api: any): { @@ -581,8 +606,8 @@ declare function payments(api: any): { * @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 + fetch(paymentId: string, params?: Payments.ExpandDetails): Promise + fetch(paymentId: string, params: Payments.ExpandDetails, callback: (err: INormalizeError | null, data: Payments.RazorpayPayment) => void): void /** * Capture payment * @@ -820,4 +845,4 @@ declare function payments(api: any): { fetchPaymentDowntimeById(downtimeId: string, callback: (err: INormalizeError | null, data: Payments.RazorpayPaymentDowntime) => void): void } -export default payments \ No newline at end of file +export default payments