From 03fbb190695e2750b133e892c004cc93270b64b3 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 19 Mar 2024 09:48:20 +0530 Subject: [PATCH 1/3] added expanded details methods --- documents/payment.md | 257 ++++++++++++++++++ src/main/java/com/razorpay/PaymentClient.java | 3 + .../java/com/razorpay/PaymentClientTest.java | 67 +++++ 3 files changed, 327 insertions(+) diff --git a/documents/payment.md b/documents/payment.md index 28148e5a..edeeb86f 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -826,6 +826,263 @@ Iin token = instance.iin.fetch(tokenIin); ] } ``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Payment (With Expanded EMI Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","emi"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**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 Card Details) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","card"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**Parameters:** + +| 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", + "international": false, + "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) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","offers"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**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) + +```java +JSONObject request = new JSONObject(); +request.put("expand[]","upi"); + +Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request); +``` + +**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" // appears only for Turbo UPI Payments. + } +} +``` + ------------------------------------------------------------------------------------------------------- **PN: * indicates mandatory fields**
diff --git a/src/main/java/com/razorpay/PaymentClient.java b/src/main/java/com/razorpay/PaymentClient.java index 92e0f502..1da3811f 100755 --- a/src/main/java/com/razorpay/PaymentClient.java +++ b/src/main/java/com/razorpay/PaymentClient.java @@ -119,4 +119,7 @@ public Payment validateUpi(JSONObject request) throws RazorpayException { return post(Constants.VERSION, Constants.VALIDATE_VPA, request); } + public Payment expandedDetails(String id, JSONObject request) throws RazorpayException { + return get(Constants.VERSION, String.format(Constants.PAYMENT_GET, id), request); + } } diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index a133f6ec..0a90c16a 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -934,4 +934,71 @@ public void fetchAllRefund() throws RazorpayException { assertTrue(false); } } + + @Test + public void expandedDetails() throws RazorpayException { + JSONObject request = new JSONObject(); + request.put("expand[]","payments"); + + String mockedResponseJson = "{\n" + + " \"id\": \"pay_IDRP0tbirMSsbn\",\n" + + " \"entity\": \"payment\",\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"status\": \"failed\",\n" + + " \"order_id\": \"order_H9o58N6qmLYQKC\",\n" + + " \"invoice_id\": null,\n" + + " \"terminal_id\": \"term_G5kJnYM9GhhLYT\",\n" + + " \"international\": false,\n" + + " \"method\": \"card\",\n" + + " \"amount_refunded\": 0,\n" + + " \"refund_status\": null,\n" + + " \"captured\": false,\n" + + " \"description\": null,\n" + + " \"card_id\": \"card_H9oR0ocen1cmZq\",\n" + + " \"card\": {\n" + + " \"id\": \"card_H9oR0ocen1cmZq\",\n" + + " \"entity\": \"card\",\n" + + " \"name\": \"Gaurav\",\n" + + " \"last4\": \"1213\",\n" + + " \"network\": \"RuPay\",\n" + + " \"type\": \"credit\",\n" + + " \"issuer\": \"UTIB\",\n" + + " \"international\": false,\n" + + " \"emi\": false,\n" + + " \"sub_type\": \"business\"\n" + + " },\n" + + " \"bank\": null,\n" + + " \"wallet\": null,\n" + + " \"vpa\": null,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919000090000\",\n" + + " \"notes\": {\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"phone\": \"09000090000\"\n" + + " },\n" + + " \"fee\": null,\n" + + " \"tax\": null,\n" + + " \"error_code\": \"BAD_REQUEST_ERROR\",\n" + + " \"error_description\": \"Card issuer is invalid\",\n" + + " \"error_source\": \"customer\",\n" + + " \"error_step\": \"payment_authentication\",\n" + + " \"error_reason\": \"incorrect_card_details\",\n" + + " \"acquirer_data\": {\n" + + " \"auth_code\": null,\n" + + " \"authentication_reference_number\": \"100222021120200000000742753928\"\n" + + " },\n" + + " \"created_at\": 1620807547\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.expandedDetails(PAYMENT_ID, request); + assertNotNull(fetch); + assertEquals(PAYMENT_ID,fetch.get("id")); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file From f06ae710e5c09bd956f57b24fb9f087329c162c7 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 26 Mar 2024 15:43:53 +0530 Subject: [PATCH 2/3] doc alignment --- documents/payment.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/documents/payment.md b/documents/payment.md index edeeb86f..e8373e47 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -839,10 +839,10 @@ Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request **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. | +| 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:**
@@ -899,10 +899,10 @@ Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request **Parameters:** -| Name | Type | Description | -|-------------|---------|--------------------------------------| -| paymentId* | integer | Unique identifier of the payment | -| expand[] | string | Use to expand the card details when the payment method is `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:**
@@ -972,10 +972,10 @@ Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request **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. | +| 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:**
@@ -1033,9 +1033,9 @@ Payment payment = instance.payments.expandedDetails("pay_XXXXXXXXXXXXXX",request **Parameters:** -| Name | Type | Description | -|-------------|---------|--------------------------------------| -| paymentId* | integer | Unique identifier of the payment | +| 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:**
From d5c1569b5d765e7561dabb14dc99f3808e4d02cb Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 1 Apr 2024 13:47:42 +0530 Subject: [PATCH 3/3] json string to json object --- .../java/com/razorpay/PaymentClientTest.java | 100 +++++++++--------- 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index 0a90c16a..0fdd24df 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -940,59 +940,57 @@ public void expandedDetails() throws RazorpayException { JSONObject request = new JSONObject(); request.put("expand[]","payments"); - String mockedResponseJson = "{\n" + - " \"id\": \"pay_IDRP0tbirMSsbn\",\n" + - " \"entity\": \"payment\",\n" + - " \"amount\": 100,\n" + - " \"currency\": \"INR\",\n" + - " \"status\": \"failed\",\n" + - " \"order_id\": \"order_H9o58N6qmLYQKC\",\n" + - " \"invoice_id\": null,\n" + - " \"terminal_id\": \"term_G5kJnYM9GhhLYT\",\n" + - " \"international\": false,\n" + - " \"method\": \"card\",\n" + - " \"amount_refunded\": 0,\n" + - " \"refund_status\": null,\n" + - " \"captured\": false,\n" + - " \"description\": null,\n" + - " \"card_id\": \"card_H9oR0ocen1cmZq\",\n" + - " \"card\": {\n" + - " \"id\": \"card_H9oR0ocen1cmZq\",\n" + - " \"entity\": \"card\",\n" + - " \"name\": \"Gaurav\",\n" + - " \"last4\": \"1213\",\n" + - " \"network\": \"RuPay\",\n" + - " \"type\": \"credit\",\n" + - " \"issuer\": \"UTIB\",\n" + - " \"international\": false,\n" + - " \"emi\": false,\n" + - " \"sub_type\": \"business\"\n" + - " },\n" + - " \"bank\": null,\n" + - " \"wallet\": null,\n" + - " \"vpa\": null,\n" + - " \"email\": \"gaurav.kumar@example.com\",\n" + - " \"contact\": \"+919000090000\",\n" + - " \"notes\": {\n" + - " \"email\": \"gaurav.kumar@example.com\",\n" + - " \"phone\": \"09000090000\"\n" + - " },\n" + - " \"fee\": null,\n" + - " \"tax\": null,\n" + - " \"error_code\": \"BAD_REQUEST_ERROR\",\n" + - " \"error_description\": \"Card issuer is invalid\",\n" + - " \"error_source\": \"customer\",\n" + - " \"error_step\": \"payment_authentication\",\n" + - " \"error_reason\": \"incorrect_card_details\",\n" + - " \"acquirer_data\": {\n" + - " \"auth_code\": null,\n" + - " \"authentication_reference_number\": \"100222021120200000000742753928\"\n" + - " },\n" + - " \"created_at\": 1620807547\n" + - "}"; + JSONObject mockedResponseJson = new JSONObject(); + mockedResponseJson.put("id","pay_IDRP0tbirMSsbn"); + mockedResponseJson.put("entity","payment"); + mockedResponseJson.put("amount",100); + mockedResponseJson.put("currency","INR"); + mockedResponseJson.put("status","failed"); + mockedResponseJson.put("order_id","order_H9o58N6qmLYQKC"); + mockedResponseJson.put("invoice_id", JSONObject.NULL); + mockedResponseJson.put("terminal_id","term_G5kJnYM9GhhLYT"); + mockedResponseJson.put("international",false); + mockedResponseJson.put("method","card"); + mockedResponseJson.put("amount_refunded",JSONObject.NULL); + mockedResponseJson.put("captured",false); + mockedResponseJson.put("description",JSONObject.NULL); + mockedResponseJson.put("card_id","card_H9oR0ocen1cmZq"); + JSONObject cardObj = new JSONObject(); + cardObj.put("id",""); + cardObj.put("entity","card"); + cardObj.put("name","Gaurav"); + cardObj.put("last4","1213"); + cardObj.put("network","RuPay"); + cardObj.put("type", "credit"); + cardObj.put("issuer","UTIB"); + cardObj.put("international", false); + cardObj.put("emi", false); + cardObj.put("sub_type","business"); + mockedResponseJson.put("card",cardObj); + mockedResponseJson.put("bank",JSONObject.NULL); + mockedResponseJson.put("wallet",JSONObject.NULL); + mockedResponseJson.put("vpa",JSONObject.NULL); + mockedResponseJson.put("email","gaurav.kumar@example.com"); + mockedResponseJson.put("contact","+919000090000"); + JSONObject notesObj = new JSONObject(); + notesObj.put("key1",""); + notesObj.put("key2",""); + mockedResponseJson.put("notes",notesObj); + mockedResponseJson.put("fee",JSONObject.NULL); + mockedResponseJson.put("tax",JSONObject.NULL); + mockedResponseJson.put("error_code","BAD_REQUEST_ERROR"); + mockedResponseJson.put("error_description","Card issuer is invalid"); + mockedResponseJson.put("error_source","customer"); + mockedResponseJson.put("error_step","payment_authentication"); + mockedResponseJson.put("error_reason","incorrect_card_details"); + JSONObject acquirerDataObj = new JSONObject(); + acquirerDataObj.put("auth_code",JSONObject.NULL); + acquirerDataObj.put("authentication_reference_number","100222021120200000000742753928"); + mockedResponseJson.put("acquirer_data",acquirerDataObj); + mockedResponseJson.put("created_at",1620807547); try { - mockResponseFromExternalClient(mockedResponseJson); + mockResponseFromExternalClient(mockedResponseJson.toString()); mockResponseHTTPCodeFromExternalClient(200); Payment fetch = paymentClient.expandedDetails(PAYMENT_ID, request); assertNotNull(fetch);