From c0fd920e258316e862f5f1031a26296008145f2e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 25 Jan 2022 13:35:43 +0530 Subject: [PATCH 01/78] updated addon module --- src/main/java/com/razorpay/AddonClient.java | 15 ++++++++++++++- src/main/java/com/razorpay/Constants.java | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/AddonClient.java b/src/main/java/com/razorpay/AddonClient.java index 774548ec..9dff37bf 100644 --- a/src/main/java/com/razorpay/AddonClient.java +++ b/src/main/java/com/razorpay/AddonClient.java @@ -1,5 +1,9 @@ package com.razorpay; +import java.util.List; + +import org.json.JSONObject; + public class AddonClient extends ApiClient { AddonClient(String auth) { @@ -10,8 +14,17 @@ public class AddonClient extends ApiClient { public Addon fetch(String id) throws RazorpayException { return get(String.format(Constants.ADDON_GET, id), null); } + + + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.ADDON_LIST, request); + } public void delete(String id) throws RazorpayException { delete(String.format(Constants.ADDON_DELETE, id), null); } -} +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..c19d7f5d 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -68,6 +68,7 @@ public class Constants { static final String ADDON_GET = "addons/%s"; static final String ADDON_DELETE = "addons/%s"; + static final String ADDON_LIST = "addons"; static final String VIRTUAL_ACCOUNT_CREATE = "virtual_accounts"; static final String VIRTUAL_ACCOUNT_GET = "virtual_accounts/%s"; From 994812eea47270eb8159c21ccb3e6108d6047fb6 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 27 Jan 2022 14:24:39 +0530 Subject: [PATCH 02/78] add static class --- src/main/java/com/razorpay/ApiClient.java | 26 ++++++++++++++++++++- src/main/java/com/razorpay/StaticClass.java | 8 +++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/razorpay/StaticClass.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 07014f78..afa61d66 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; @@ -95,6 +96,22 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } + + private String StaticEntity(Response response) { + List url = response.request().url().pathSegments(); + + switch(url.get(1)) { + case "invoices": + return StaticClass.Invoice; + + case "payments": + return StaticClass.Payment; + + default : + return "empty"; + } + } + T processResponse(Response response) throws RazorpayException { if (response == null) { @@ -104,7 +121,6 @@ T processResponse(Response response) throws RazorpayException int statusCode = response.code(); String responseBody = null; JSONObject responseJson = null; - try { responseBody = response.body().string(); responseJson = new JSONObject(responseBody); @@ -113,6 +129,14 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { + + if(!responseJson.has(ENTITY)) { + String cls = StaticEntity(response); + if(cls != "empty") { + responseJson.put("entity",cls); + } + } + return parseResponse(responseJson); } diff --git a/src/main/java/com/razorpay/StaticClass.java b/src/main/java/com/razorpay/StaticClass.java new file mode 100644 index 00000000..9bebf439 --- /dev/null +++ b/src/main/java/com/razorpay/StaticClass.java @@ -0,0 +1,8 @@ +package com.razorpay; + +public class StaticClass { + + static final String Invoice = "Invoice"; + + static final String Payment = "Payment"; +} From a9e14aa861200cd6164770f6409d3cdcbdc8d784 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 28 Jan 2022 17:06:16 +0530 Subject: [PATCH 03/78] add populate entity function --- src/main/java/com/razorpay/ApiClient.java | 36 +++++++++---------- src/main/java/com/razorpay/EntityMapping.java | 28 +++++++++++++++ src/main/java/com/razorpay/StaticClass.java | 8 ----- 3 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/razorpay/EntityMapping.java delete mode 100644 src/main/java/com/razorpay/StaticClass.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index afa61d66..2316b527 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; @@ -97,19 +96,18 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } - private String StaticEntity(Response response) { - List url = response.request().url().pathSegments(); - - switch(url.get(1)) { - case "invoices": - return StaticClass.Invoice; - - case "payments": - return StaticClass.Payment; - - default : - return "empty"; - } + private EntityMapping populateEntityNameFromURL(String args) { + + switch(args) { + case "invoices": + return EntityMapping.Invoice; + + case "payments": + return EntityMapping.Payment; + + default : + return EntityMapping.Default; + } } @@ -129,11 +127,11 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { - String cls = StaticEntity(response); - if(cls != "empty") { - responseJson.put("entity",cls); + EntityMapping cls = populateEntityNameFromURL(response.request().url().pathSegments().get(1).toString()); + if(cls != EntityMapping.Default) { + responseJson.put("entity",cls.toString()); } } @@ -215,4 +213,4 @@ private Class getClass(String entity) { return null; } } -} +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/EntityMapping.java b/src/main/java/com/razorpay/EntityMapping.java new file mode 100644 index 00000000..74729770 --- /dev/null +++ b/src/main/java/com/razorpay/EntityMapping.java @@ -0,0 +1,28 @@ +package com.razorpay; + +import java.util.Arrays; + + +public enum EntityMapping { + + Invoice("invoices"), + Payment("payments"), + Default("empty"); + + private String entity; + + EntityMapping(String entity) { + this.entity= entity; + } + + private String getEntity() + { + return entity; + } + + public static String getEntityClassName(String urlStirng) + { + EntityMapping item = Arrays.asList(values()).stream().filter( val -> val.name().equalsIgnoreCase(urlStirng)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unable to resolve")); + return item.getEntity(); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/StaticClass.java b/src/main/java/com/razorpay/StaticClass.java deleted file mode 100644 index 9bebf439..00000000 --- a/src/main/java/com/razorpay/StaticClass.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.razorpay; - -public class StaticClass { - - static final String Invoice = "Invoice"; - - static final String Payment = "Payment"; -} From 2a397bf3eae7d6f2cadefb16fabc5c025703c140 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 28 Jan 2022 17:51:18 +0530 Subject: [PATCH 04/78] pchange argument in populateEntityUrl --- src/main/java/com/razorpay/ApiClient.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 2316b527..ce8a495f 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,11 +2,13 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; import org.json.JSONObject; +import okhttp3.HttpUrl; import okhttp3.Response; class ApiClient { @@ -96,9 +98,11 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } - private EntityMapping populateEntityNameFromURL(String args) { - - switch(args) { + private EntityMapping populateEntityNameFromURL(HttpUrl url) { + + String param = url.pathSegments().get(1).toString(); + + switch(param) { case "invoices": return EntityMapping.Invoice; @@ -129,10 +133,8 @@ T processResponse(Response response) throws RazorpayException if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { if(!responseJson.has(ENTITY)) { - EntityMapping cls = populateEntityNameFromURL(response.request().url().pathSegments().get(1).toString()); - if(cls != EntityMapping.Default) { + EntityMapping cls = populateEntityNameFromURL(response.request().url()); responseJson.put("entity",cls.toString()); - } } return parseResponse(responseJson); From 87a09c5470e609c6a6cda4f90cbf667b39d421b5 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 28 Jan 2022 18:39:29 +0530 Subject: [PATCH 05/78] fixed issues --- src/main/java/com/razorpay/ApiClient.java | 20 ++++--------- src/main/java/com/razorpay/EntityMapping.java | 28 ------------------- .../com/razorpay/EntityNameURLMapping.java | 27 ++++++++++++++++++ 3 files changed, 32 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/com/razorpay/EntityMapping.java create mode 100644 src/main/java/com/razorpay/EntityNameURLMapping.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index ce8a495f..bd684bfb 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -98,20 +98,10 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } - private EntityMapping populateEntityNameFromURL(HttpUrl url) { + private String populateEntityNameFromURL(HttpUrl url) { - String param = url.pathSegments().get(1).toString(); - - switch(param) { - case "invoices": - return EntityMapping.Invoice; - - case "payments": - return EntityMapping.Payment; - - default : - return EntityMapping.Default; - } + String param = url.pathSegments().get(1); + return EntityNameURLMapping.getEntityClassName(param); } @@ -133,8 +123,8 @@ T processResponse(Response response) throws RazorpayException if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { if(!responseJson.has(ENTITY)) { - EntityMapping cls = populateEntityNameFromURL(response.request().url()); - responseJson.put("entity",cls.toString()); + String entityName = populateEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); } return parseResponse(responseJson); diff --git a/src/main/java/com/razorpay/EntityMapping.java b/src/main/java/com/razorpay/EntityMapping.java deleted file mode 100644 index 74729770..00000000 --- a/src/main/java/com/razorpay/EntityMapping.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.razorpay; - -import java.util.Arrays; - - -public enum EntityMapping { - - Invoice("invoices"), - Payment("payments"), - Default("empty"); - - private String entity; - - EntityMapping(String entity) { - this.entity= entity; - } - - private String getEntity() - { - return entity; - } - - public static String getEntityClassName(String urlStirng) - { - EntityMapping item = Arrays.asList(values()).stream().filter( val -> val.name().equalsIgnoreCase(urlStirng)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unable to resolve")); - return item.getEntity(); - } -} \ No newline at end of file diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java new file mode 100644 index 00000000..888437f0 --- /dev/null +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -0,0 +1,27 @@ +package com.razorpay; + +import java.util.Arrays; + + +public enum EntityNameURLMapping { + + INVOICES("invoice"), + PAYMENTS("payment"); + + private String entity; + + EntityNameURLMapping(String entity) { + this.entity= entity; + } + + private String getEntity() + { + return entity; + } + + public static String getEntityClassName(String urlStirng) + { + EntityNameURLMapping item = Arrays.asList(values()).stream().filter( val -> val.name().equalsIgnoreCase(urlStirng)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unable to resolve")); + return item.getEntity(); + } +} \ No newline at end of file From baa7daf2c3493a1f9dc9c3bb46434a3057aef897 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Feb 2022 12:13:17 +0530 Subject: [PATCH 06/78] change function name --- src/main/java/com/razorpay/ApiClient.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index bd684bfb..89acd406 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -98,10 +98,9 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } - private String populateEntityNameFromURL(HttpUrl url) { - + private String getEntityNameFromURL(HttpUrl url) { String param = url.pathSegments().get(1); - return EntityNameURLMapping.getEntityClassName(param); + return EntityNameURLMapping.getEntityClassName(param); } @@ -123,7 +122,7 @@ T processResponse(Response response) throws RazorpayException if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { if(!responseJson.has(ENTITY)) { - String entityName = populateEntityNameFromURL(response.request().url()); + String entityName = getEntityNameFromURL(response.request().url()); responseJson.put("entity",entityName); } From 4690fdbbb285fadd1d677c9a7e558ef5946d7782 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Feb 2022 13:29:07 +0530 Subject: [PATCH 07/78] add java docs --- src/main/java/com/razorpay/ApiClient.java | 8 ++++++-- src/main/java/com/razorpay/EntityNameURLMapping.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 89acd406..7c38c572 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -97,10 +97,14 @@ private ArrayList parseCollectionResponse(JSONObject jsonO throw new RazorpayException("Unable to parse response"); } - + + /* + * this method will take http url as : https://api.razorpay.com/v1/invocies + * and will return entity name with the help of @EntityNameURLMapping class + */ private String getEntityNameFromURL(HttpUrl url) { String param = url.pathSegments().get(1); - return EntityNameURLMapping.getEntityClassName(param); + return EntityNameURLMapping.getEntityName(param); } diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java index 888437f0..996f8b4f 100644 --- a/src/main/java/com/razorpay/EntityNameURLMapping.java +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -2,10 +2,15 @@ import java.util.Arrays; + /** + * Enum name is acting as & entity is denoting Entity class + * ex: https://api.razorpay.com/v1/invocies + * getEntityName method will take "invoices" from above mentioned url + * & will return "invoice" as entity name as mentioned as below in mapping INVOICES("invoice") + */ public enum EntityNameURLMapping { - - INVOICES("invoice"), + INVOICES("invoice"), PAYMENTS("payment"); private String entity; @@ -19,7 +24,7 @@ private String getEntity() return entity; } - public static String getEntityClassName(String urlStirng) + public static String getEntityName(String urlStirng) { EntityNameURLMapping item = Arrays.asList(values()).stream().filter( val -> val.name().equalsIgnoreCase(urlStirng)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unable to resolve")); return item.getEntity(); From 2124df8faa66c8c3c276caa56ae22320c0aba05e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Feb 2022 13:31:18 +0530 Subject: [PATCH 08/78] fix java doc --- src/main/java/com/razorpay/EntityNameURLMapping.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java index 996f8b4f..0cad70b2 100644 --- a/src/main/java/com/razorpay/EntityNameURLMapping.java +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -3,10 +3,10 @@ import java.util.Arrays; /** - * Enum name is acting as & entity is denoting Entity class + * Enum name is acting as url & entity is denoting Entity class * ex: https://api.razorpay.com/v1/invocies * getEntityName method will take "invoices" from above mentioned url - * & will return "invoice" as entity name as mentioned as below in mapping INVOICES("invoice") + * & will return "invoice" as entity name as mentioned below in mapping INVOICES("invoice") */ public enum EntityNameURLMapping { From 10785a71951034cdb66dd28a61f4b5be5ae65fda Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Feb 2022 14:34:49 +0530 Subject: [PATCH 09/78] mockito base --- .gitignore | 3 - pom.xml | 62 ++++++++++++++---- .../java/com/razorpay/AddonClientTest.java | 4 ++ src/test/java/com/razorpay/BaseTest.java | 63 +++++++++++++++++++ 4 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 src/test/java/com/razorpay/AddonClientTest.java create mode 100644 src/test/java/com/razorpay/BaseTest.java diff --git a/.gitignore b/.gitignore index 680f7214..bfee5201 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,3 @@ # Maven log/ target/ - -#Test -src/test/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index b09aef95..f4629bb1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.razorpay @@ -33,15 +33,55 @@ repo - + UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 - + + + + junit + junit + 4.13.2 + test + + + + + org.springframework + spring-core + 2.5.6 + test + + + + org.mockito + mockito-inline + 2.13.0 + test + + + + org.json + json + test + + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + test + + + + + + com.squareup.okhttp3 okhttp @@ -71,7 +111,7 @@ commons-text 1.3 - + @@ -86,14 +126,14 @@ - + src/main/resources true - + org.sonatype.plugins @@ -147,7 +187,7 @@ - + - - + + \ No newline at end of file diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java new file mode 100644 index 00000000..28460c31 --- /dev/null +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -0,0 +1,4 @@ +import static org.junit.Assert.*; +public class AddonClientTest { + +} \ No newline at end of file diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java new file mode 100644 index 00000000..a255e141 --- /dev/null +++ b/src/test/java/com/razorpay/BaseTest.java @@ -0,0 +1,63 @@ +package com.razorpay; + +import okhttp3.*; +import org.json.JSONObject; +import org.junit.Before; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.mockito.stubbing.OngoingStubbing; +import org.springframework.util.ReflectionUtils; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.List; + +import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class BaseTest { + @InjectMocks + protected AddonClient client = new AddonClient("test"); + private OkHttpClient okHttpClient; + Response mockedResponse; + + @Before + public void setUp() throws Exception { + + MockitoAnnotations.initMocks(this); + mockGetCall(); + + } + + private void mockGetCall() throws IOException { + + okHttpClient = mock(OkHttpClient.class); + mockedResponse = mock(Response.class); + Field clientField = ReflectionUtils.findField(ApiUtils.class, "client", OkHttpClient.class); + clientField.setAccessible(true); + ReflectionUtils.setField(clientField,new ApiUtils(),okHttpClient); + Call call = mock(Call.class); + when(call.execute()).thenReturn(mockedResponse); + when(okHttpClient.newCall(anyObject())).thenReturn(call); + } + + protected void mockResponseHTTPCodeFromExternalClient(int code) + { + when(mockedResponse.code()).thenReturn(200); + } + protected void mockURL(List urlString) + { + HttpUrl url = mock(HttpUrl.class); + when(url.pathSegments()).thenReturn(urlString); + Request request = mock(Request.class); + when(request.url()).thenReturn(url); + when(mockedResponse.request()).thenReturn(request); + } + protected void mockResponseFromExternalClient(String jsonObject) throws IOException { + JSONObject parse = new JSONObject(jsonObject); + ResponseBody rb = mock(ResponseBody.class); + when(rb.string()).thenReturn(parse.toString()); + when(mockedResponse.body()).thenReturn(rb); + } +} \ No newline at end of file From bbbb5902e461c13d2198e76bd56a98b525b15aec Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Feb 2022 14:38:40 +0530 Subject: [PATCH 10/78] remove addon test --- src/test/java/com/razorpay/AddonClientTest.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/test/java/com/razorpay/AddonClientTest.java diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java deleted file mode 100644 index 28460c31..00000000 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ /dev/null @@ -1,4 +0,0 @@ -import static org.junit.Assert.*; -public class AddonClientTest { - -} \ No newline at end of file From 1c420f94e9ea1dbd6178e1accbb7b42db0a24ea6 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 12:15:39 +0530 Subject: [PATCH 11/78] added card testcase --- .../java/com/razorpay/CardClientTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/java/com/razorpay/CardClientTest.java diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java new file mode 100644 index 00000000..d2093a18 --- /dev/null +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -0,0 +1,32 @@ +package com.razorpay; + +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class CardClientTest extends BaseTest{ + + @InjectMocks + private CardClient cardClientClient = new CardClient("test"); + + public static final String CARD_ID = "card_DZon6fd8J3IcA2"; + + @Test + public void fetch() throws RazorpayException { + + String json = "{\n \"id\": \"card_DZon6fd8J3IcA2\",\n \"entity\": \"card\",\n \"international\": false,\n \"last4\": 1111,\n \"name\": \"sample name\",\n \"network\": \"Visa\",\n \"type\": \"debit\"\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Card fetch = cardClientClient.fetch(CARD_ID); + assertNotNull(fetch); + assertEquals(CARD_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From 9a9978f1f8e541766a9426241ac49991f995b0f9 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 13:22:54 +0530 Subject: [PATCH 12/78] updated invoice api including testcases --- src/main/java/com/razorpay/Constants.java | 3 + src/main/java/com/razorpay/InvoiceClient.java | 20 +++ .../java/com/razorpay/InvoiceClientTest.java | 140 ++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 src/test/java/com/razorpay/InvoiceClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..d10b5dbd 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -39,6 +39,8 @@ public class Constants { static final String INVOICE_GET = "invoices/%s"; static final String INVOICE_LIST = "invoices"; static final String INVOICE_CANCEL = "invoices/%s/cancel"; + static final String INVOICE_ISSUE = "invoices/%s/issue"; + static final String INVOICE_NOTIFY = "invoices/%s/notify_by/%s"; static final String CARD_GET = "cards/%s"; @@ -65,6 +67,7 @@ public class Constants { static final String SUBSCRIPTION_LIST = "subscriptions"; static final String SUBSCRIPTION_CANCEL = "subscriptions/%s/cancel"; static final String SUBSCRIPTION_ADDON_CREATE = "subscriptions/%s/addons"; + static final String SUBSCRIPTION_REGISTRATION_LINK = "subscription_registration/auth_links"; static final String ADDON_GET = "addons/%s"; static final String ADDON_DELETE = "addons/%s"; diff --git a/src/main/java/com/razorpay/InvoiceClient.java b/src/main/java/com/razorpay/InvoiceClient.java index a08d0385..0fa93660 100644 --- a/src/main/java/com/razorpay/InvoiceClient.java +++ b/src/main/java/com/razorpay/InvoiceClient.java @@ -29,4 +29,24 @@ public Invoice fetch(String id) throws RazorpayException { public Invoice cancel(String id) throws RazorpayException { return post(String.format(Constants.INVOICE_CANCEL, id), null); } + + public Invoice notifyBy(String id, String medium) throws RazorpayException { + return post(String.format(Constants.INVOICE_NOTIFY, id, medium), null); + } + + public Invoice createRegistrationLink(JSONObject request) throws RazorpayException { + return post(Constants.SUBSCRIPTION_REGISTRATION_LINK, request); + } + + public Invoice issue(String id) throws RazorpayException { + return post(String.format(Constants.INVOICE_ISSUE, id), null); + } + + public Invoice edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.INVOICE_GET, id), request); + } + + public void delete(String id) throws RazorpayException { + delete(String.format(Constants.INVOICE_GET, id), null); + } } diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java new file mode 100644 index 00000000..8512576a --- /dev/null +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -0,0 +1,140 @@ +package com.razorpay; + +import org.json.JSONObject; + +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class InvoiceClientTest extends BaseTest{ + + @InjectMocks + private InvoiceClient invoiceClient = new InvoiceClient("test"); + + public static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; + + @Test + public void create() throws RazorpayException { + JSONObject request = new JSONObject("{\n \"type\":\"link\",\n \"decsription\":\"test\",\n \"line_items\":[\n {\n \"name\":\"name\",\n \"amount\":100\n }\n ]\n}\n"); + String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"random_id\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice invoice = invoiceClient.create(request); + assertNotNull(invoice); + assertEquals("invoice",invoice.get("entity")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchAll() throws RazorpayException { + + String json = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n }\n ]\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = invoiceClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("type")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetch() throws RazorpayException { + + String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"inv_DAweOiQ7amIUVd\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice fetch = invoiceClient.fetch(INVOICE_ID); + assertNotNull(fetch); + assertEquals(INVOICE_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void cancel() throws RazorpayException { + + String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"inv_DAweOiQ7amIUVd\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"cancelled\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice fetch = invoiceClient.cancel(INVOICE_ID); + assertNotNull(fetch); + assertEquals(INVOICE_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void notifyBy() throws RazorpayException { + + String json = "{\n \"entity\" : \"invoice\",\n \"success\": true\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice fetch = invoiceClient.notifyBy(INVOICE_ID,"sms"); + assertNotNull(fetch); + assertEquals(true,fetch.get("success")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void createRegistrationLink() throws RazorpayException { + + JSONObject request = new JSONObject("{\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9123456789\",\n \"amount\": 1000,\n \"currency\": \"INR\",\n \"order_id\": \"order_1Aa00000000002\",\n \"customer_id\": \"cust_1Aa00000000001\",\n \"token\": \"token_1Aa00000000001\",\n \"recurring\": \"1\",\n \"description\": \"Creating recurring payment for Gaurav Kumar\",\n \"notes\": {\n \"note_key 1\": \"Beam me up Scotty\",\n \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n }\n}"); + String json = "{\n \"entity\" : \"invoice\",\n \"razorpay_payment_id\" : \"pay_1Aa00000000001\",\n \"razorpay_order_id\" : \"order_1Aa00000000001\",\n \"razorpay_signature\" : \"9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d\"\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice fetch = invoiceClient.createRegistrationLink(request); + assertNotNull(fetch); + assertEquals(true,fetch.has("razorpay_payment_id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void issue() throws RazorpayException { + + String json = "{\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": \"order_DBG3P8ZgDd1dsG\",\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"issued\",\n \"expire_by\": 1567103399,\n \"issued_at\": 1566974805,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": 0,\n \"amount_due\": 600,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": \"\",\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice fetch = invoiceClient.issue(INVOICE_ID); + assertNotNull(fetch); + assertEquals(INVOICE_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void edit() throws RazorpayException { + JSONObject request = new JSONObject("{ \n \"notes\": {\n \"updated-key\": \"An updated note.\"\n }\n}"); + String json = "{\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Invoice invoice = invoiceClient.edit(INVOICE_ID,request); + assertNotNull(invoice); + assertEquals(INVOICE_ID,invoice.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From f35650ea467567126942d744d20f3f6e533cd75e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 16:44:18 +0530 Subject: [PATCH 13/78] remove spring framework --- pom.xml | 7 ------- src/test/java/com/razorpay/BaseTest.java | 18 +++++++++--------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index f4629bb1..2c6c4f8c 100644 --- a/pom.xml +++ b/pom.xml @@ -51,13 +51,6 @@ - - org.springframework - spring-core - 2.5.6 - test - - org.mockito mockito-inline diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index a255e141..bcfc0e87 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -1,12 +1,11 @@ package com.razorpay; import okhttp3.*; +import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.Before; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; -import org.mockito.stubbing.OngoingStubbing; -import org.springframework.util.ReflectionUtils; import java.io.IOException; import java.lang.reflect.Field; @@ -30,21 +29,22 @@ public void setUp() throws Exception { } - private void mockGetCall() throws IOException { + private void mockGetCall() throws IOException, IllegalAccessException { okHttpClient = mock(OkHttpClient.class); mockedResponse = mock(Response.class); - Field clientField = ReflectionUtils.findField(ApiUtils.class, "client", OkHttpClient.class); - clientField.setAccessible(true); - ReflectionUtils.setField(clientField,new ApiUtils(),okHttpClient); + Field clientField =FieldUtils.getDeclaredField(ApiUtils.class,"client",true); + FieldUtils.writeField(clientField,new ApiUtils(),okHttpClient); + Call call = mock(Call.class); when(call.execute()).thenReturn(mockedResponse); when(okHttpClient.newCall(anyObject())).thenReturn(call); + } protected void mockResponseHTTPCodeFromExternalClient(int code) { - when(mockedResponse.code()).thenReturn(200); + when(mockedResponse.code()).thenReturn(code); } protected void mockURL(List urlString) { @@ -54,8 +54,8 @@ protected void mockURL(List urlString) when(request.url()).thenReturn(url); when(mockedResponse.request()).thenReturn(request); } - protected void mockResponseFromExternalClient(String jsonObject) throws IOException { - JSONObject parse = new JSONObject(jsonObject); + protected void mockResponseFromExternalClient(String response) throws IOException { + JSONObject parse = new JSONObject(response); ResponseBody rb = mock(ResponseBody.class); when(rb.string()).thenReturn(parse.toString()); when(mockedResponse.body()).thenReturn(rb); From 81d5b88f82a52f83b3c0daf867a2e1e29021c0b2 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 18:39:38 +0530 Subject: [PATCH 14/78] updated customer api with testcases --- src/main/java/com/razorpay/Constants.java | 1 + .../java/com/razorpay/CustomerClient.java | 8 ++ .../java/com/razorpay/CustomerClientTest.java | 108 ++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/test/java/com/razorpay/CustomerClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..471981e1 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -45,6 +45,7 @@ public class Constants { static final String CUSTOMER_CREATE = "customers"; static final String CUSTOMER_GET = "customers/%s"; static final String CUSTOMER_EDIT = "customers/%s"; + static final String CUSTOMER_LIST = "customers"; static final String TOKEN_LIST = "customers/%s/tokens"; static final String TOKEN_GET = "customers/%s/tokens/%s"; diff --git a/src/main/java/com/razorpay/CustomerClient.java b/src/main/java/com/razorpay/CustomerClient.java index 2aa82d96..598a45e2 100644 --- a/src/main/java/com/razorpay/CustomerClient.java +++ b/src/main/java/com/razorpay/CustomerClient.java @@ -22,6 +22,14 @@ public Customer edit(String id, JSONObject request) throws RazorpayException { return put(String.format(Constants.CUSTOMER_EDIT, id), request); } + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.CUSTOMER_LIST, request); + } + public List fetchTokens(String id) throws RazorpayException { return getCollection(String.format(Constants.TOKEN_LIST, id), null); } diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java new file mode 100644 index 00000000..434a3603 --- /dev/null +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -0,0 +1,108 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; +import static org.junit.Assert.*; + +public class CustomerClientTest extends BaseTest{ + + @InjectMocks + private CustomerClient customerClient = new CustomerClient("test"); + + public static final String CUSTOMER_ID = "cust_1Aa00000000004"; + + public static final String TOKEN_ID = "token_Hxe0skTXLeg9pF"; + + @Test + public void create() throws RazorpayException{ + + JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"contact\": 9123456780,\n \"email\": \"gaurav.kumar@example.com\",\n \"fail_existing\": 0,\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n }\n}"); + String json = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Gaurav Kumar\",\n \"email\" : \"gaurav.kumar@example.com\",\n \"contact\" : \"9123456780\",\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\":{\n \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n \"notes_key_2\":\"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at \": 1234567890\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Customer customer = customerClient.create(request); + assertNotNull(customer); + assertEquals(CUSTOMER_ID,customer.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetch() throws RazorpayException { + + String json = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Saurav Kumar\",\n \"email\" : \"Saurav.kumar@example.com\",\n \"contact\" : \"+919000000000\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\" : [],\n \"created_at \": 1234567890\n}\n"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Customer fetch = customerClient.fetch(CUSTOMER_ID); + assertNotNull(fetch); + assertEquals(CUSTOMER_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchAll() throws RazorpayException { + String json = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"cust_1Aa00000000001\",\n \"entity\":\"customer\",\n \"name\":\"Gaurav Kumar\",\n \"email\":\"gaurav.kumar@example.com\",\n \"contact\":\"9876543210\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\":{\n \"note_key_1\":\"September\",\n \"note_key_2\":\"Make it so.\"\n },\n \"created_at \":1234567890\n }\n ]\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = customerClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void edit() throws RazorpayException { + + JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": 9000000000\n}"); + String json = "{\n \"id\": \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": \"9000000000\",\n \"gstin\": null,\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at\": 1582033731\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Customer fetch = customerClient.edit(CUSTOMER_ID,request); + assertNotNull(fetch); + assertEquals(CUSTOMER_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchTokens() throws RazorpayException{ + String json = "{\n \"id\": \"token_Hxe0skTXLeg9pF\",\n \"entity\": \"token\",\n \"token\": \"F85BgXnGVwcuqV\",\n \"bank\": null,\n \"wallet\": null,\n \"method\": \"card\",\n \"card\": {\n \"entity\": \"card\",\n \"name\": \"ankit\",\n \"last4\": \"5449\",\n \"network\": \"MasterCard\",\n \"type\": \"credit\",\n \"issuer\": \"UTIB\",\n \"international\": false,\n \"emi\": false,\n \"sub_type\": \"consumer\",\n \"expiry_month\": 12,\n \"expiry_year\": 2024,\n \"flows\": {\n \"recurring\": true\n }\n },\n \"recurring\": true,\n \"auth_type\": null,\n \"mrn\": null,\n \"used_at\": 1632976165,\n \"created_at\": 1631687852,\n \"expired_at\": 1634215992,\n \"dcc_enabled\": false\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Token fetch = customerClient.fetchToken(CUSTOMER_ID,TOKEN_ID); + assertNotNull(fetch); + assertEquals(TOKEN_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchToken() throws RazorpayException{ + String json = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"token_Hxe0skTXLeg9pF\",\n \"entity\":\"token\",\n \"token\":\"2JPRk664pZHUWG\",\n \"bank\":null,\n \"wallet\":null,\n \"method\":\"card\",\n \"card\":{\n \"entity\":\"card\",\n \"name\":\"Gaurav Kumar\",\n \"last4\":\"8950\",\n \"network\":\"Visa\",\n \"type\":\"credit\",\n \"issuer\":\"STCB\",\n \"international\":false,\n \"emi\":false,\n \"sub_type\":\"consumer\",\n \"expiry_month\":12,\n \"expiry_year\":2021,\n \"flows\":{\n \"otp\":true,\n \"recurring\":true\n }\n },\n \"recurring\":true,\n \"recurring_details\":{\n \"status\":\"confirmed\",\n \"failure_reason\":null\n },\n \"auth_type\":null,\n \"mrn\":null,\n \"used_at\":1629779657,\n \"created_at\":1629779657,\n \"expired_at\":1640975399,\n \"dcc_enabled\":false,\n \"billing_address\":null\n }\n ]\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = customerClient.fetchTokens(CUSTOMER_ID); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From 38e317df0c859ab1927239f38f63187f86395926 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 19:07:29 +0530 Subject: [PATCH 15/78] implement fundaccount api with testcases --- src/main/java/com/razorpay/Constants.java | 3 ++ src/main/java/com/razorpay/FundAccount.java | 10 ++++ .../java/com/razorpay/FundAccountClient.java | 18 +++++++ .../java/com/razorpay/RazorpayClient.java | 2 + .../com/razorpay/FundAccountClientTest.java | 47 +++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 src/main/java/com/razorpay/FundAccount.java create mode 100644 src/main/java/com/razorpay/FundAccountClient.java create mode 100644 src/test/java/com/razorpay/FundAccountClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..e5a0a9d9 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -30,6 +30,9 @@ public class Constants { static final String REFUND_LIST = "refunds"; static final String REFUND_CREATE = "refunds"; + static final String FUND_ACCOUNT_CREATE = "fund_accounts"; + static final String FUND_ACCOUNT_FETCH = "fund_accounts/%s"; + static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; static final String ORDER_LIST = "orders"; diff --git a/src/main/java/com/razorpay/FundAccount.java b/src/main/java/com/razorpay/FundAccount.java new file mode 100644 index 00000000..6dc35c6a --- /dev/null +++ b/src/main/java/com/razorpay/FundAccount.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class FundAccount extends Entity { + + public FundAccount(JSONObject jsonObject) { + super(jsonObject); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/FundAccountClient.java b/src/main/java/com/razorpay/FundAccountClient.java new file mode 100644 index 00000000..e7133314 --- /dev/null +++ b/src/main/java/com/razorpay/FundAccountClient.java @@ -0,0 +1,18 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class FundAccountClient extends ApiClient{ + + FundAccountClient(String auth) { + super(auth); + } + + public FundAccount create(JSONObject request) throws RazorpayException { + return post(Constants.FUND_ACCOUNT_CREATE, request); + } + + public FundAccount fetch(String id) throws RazorpayException { + return get(String.format(Constants.FUND_ACCOUNT_FETCH, id), null); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index abea7d3b..f5be666a 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -16,6 +16,7 @@ public class RazorpayClient { public SubscriptionClient Subscriptions; public AddonClient Addons; public PlanClient Plans; + public FundAccountClient FundAccount; public VirtualAccountClient VirtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -35,6 +36,7 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R Subscriptions = new SubscriptionClient(auth); Addons = new AddonClient(auth); Plans = new PlanClient(auth); + FundAccount = new FundAccountClient(auth); VirtualAccounts = new VirtualAccountClient(auth); } diff --git a/src/test/java/com/razorpay/FundAccountClientTest.java b/src/test/java/com/razorpay/FundAccountClientTest.java new file mode 100644 index 00000000..dd178baa --- /dev/null +++ b/src/test/java/com/razorpay/FundAccountClientTest.java @@ -0,0 +1,47 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; + +import static org.junit.Assert.*; + +public class FundAccountClientTest extends BaseTest{ + + @InjectMocks + private FundAccountClient fundAccountClient = new FundAccountClient("test"); + + public static final String FUNDACCOUNT_ID = "fa_Aa00000000001"; + + @Test + public void create() throws RazorpayException { + JSONObject request = new JSONObject("{\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\"\n }\n}"); + String json = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + FundAccount fundaccount = fundAccountClient.create(request); + assertNotNull(fundaccount); + assertEquals(FUNDACCOUNT_ID,fundaccount.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetch() throws RazorpayException { + + String json = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + FundAccount fetch = fundAccountClient.fetch(FUNDACCOUNT_ID); + assertNotNull(fetch); + assertEquals(FUNDACCOUNT_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From fed30cadc1501507b3a36bf1121c3a45522232c0 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Feb 2022 23:18:06 +0530 Subject: [PATCH 16/78] implement item api with testcases --- src/main/java/com/razorpay/ApiClient.java | 17 +++- src/main/java/com/razorpay/Constants.java | 6 ++ .../com/razorpay/EntityNameURLMapping.java | 3 +- src/main/java/com/razorpay/Item.java | 10 +++ src/main/java/com/razorpay/ItemClient.java | 36 +++++++++ .../java/com/razorpay/RazorpayClient.java | 2 + .../java/com/razorpay/ItemClientTest.java | 79 +++++++++++++++++++ 7 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/razorpay/Item.java create mode 100644 src/main/java/com/razorpay/ItemClient.java create mode 100644 src/test/java/com/razorpay/ItemClientTest.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..94a57da4 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -154,6 +154,17 @@ ArrayList processCollectionResponse(Response response) throw new RazorpayException(e.getMessage()); } + if(responseJson.has("items")){ + JSONArray jsonArray = responseJson.getJSONArray("items"); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + if(!jsonObj.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + jsonObj.put("entity",entityName); + } + } + } + if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { return parseCollectionResponse(responseJson); } @@ -173,7 +184,11 @@ private void processDeleteResponse(Response response) throws RazorpayException { try { responseBody = response.body().string(); - responseJson = new JSONObject(responseBody); + if(responseBody.startsWith("[")) { + responseJson = new JSONObject("{}"); + }else { + responseJson = new JSONObject(responseBody); + } } catch (IOException e) { throw new RazorpayException(e.getMessage()); } diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..4e1201d1 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -40,6 +40,12 @@ public class Constants { static final String INVOICE_LIST = "invoices"; static final String INVOICE_CANCEL = "invoices/%s/cancel"; + static final String ITEM_CREATE = "items"; + static final String ITEM_GET = "items/%s"; + static final String ITEM_LIST = "items"; + static final String ITEM_EDIT = "items/%s"; + static final String ITEM_DELETE = "items/%s"; + static final String CARD_GET = "cards/%s"; static final String CUSTOMER_CREATE = "customers"; diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java index 0cad70b2..42eb4bd4 100644 --- a/src/main/java/com/razorpay/EntityNameURLMapping.java +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -11,7 +11,8 @@ public enum EntityNameURLMapping { INVOICES("invoice"), - PAYMENTS("payment"); + PAYMENTS("payment"), + ITEMS("item"); private String entity; diff --git a/src/main/java/com/razorpay/Item.java b/src/main/java/com/razorpay/Item.java new file mode 100644 index 00000000..e0e5bfa0 --- /dev/null +++ b/src/main/java/com/razorpay/Item.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class Item extends Entity { + + public Item(JSONObject jsonObject) { + super(jsonObject); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/ItemClient.java b/src/main/java/com/razorpay/ItemClient.java new file mode 100644 index 00000000..2637e327 --- /dev/null +++ b/src/main/java/com/razorpay/ItemClient.java @@ -0,0 +1,36 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +public class ItemClient extends ApiClient{ + + ItemClient(String auth) { + super(auth); + } + + public Item create(JSONObject request) throws RazorpayException { + return post(Constants.ITEM_CREATE, request); + } + + public Item fetch(String id) throws RazorpayException { + return get(String.format(Constants.ITEM_GET, id), null); + } + + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + public Item edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.ITEM_EDIT, id), request); + } + + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.ITEM_LIST, request); + } + + public void delete(String id) throws RazorpayException { + delete(String.format(Constants.ITEM_DELETE, id), null); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index abea7d3b..46226eb0 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -16,6 +16,7 @@ public class RazorpayClient { public SubscriptionClient Subscriptions; public AddonClient Addons; public PlanClient Plans; + public ItemClient Items; public VirtualAccountClient VirtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -35,6 +36,7 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R Subscriptions = new SubscriptionClient(auth); Addons = new AddonClient(auth); Plans = new PlanClient(auth); + Items = new ItemClient(auth); VirtualAccounts = new VirtualAccountClient(auth); } diff --git a/src/test/java/com/razorpay/ItemClientTest.java b/src/test/java/com/razorpay/ItemClientTest.java new file mode 100644 index 00000000..57079e42 --- /dev/null +++ b/src/test/java/com/razorpay/ItemClientTest.java @@ -0,0 +1,79 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class ItemClientTest extends BaseTest{ + + @InjectMocks + private ItemClient itemClient = new ItemClient("test"); + + public static final String ITEM_ID = "item_IJol6jPh1ummTK"; + + @Test + public void create() throws RazorpayException { + JSONObject request = new JSONObject("{\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"); + String json = "{\n \"entity\" : \"item\",\n \"id\": \"item_IJol6jPh1ummTK\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Item item = itemClient.create(request); + assertNotNull(item); + assertEquals(ITEM_ID,item.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetch() throws RazorpayException { + + String json = "{\n \"entity\": \"item\",\n \"id\": \"item_7Oxp4hmm6T4SCn\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Item fetch = itemClient.fetch(ITEM_ID); + assertNotNull(fetch); + assertEquals("item",fetch.get("entity")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchAll() throws RazorpayException{ + + String json = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"item_7OxoGnoxCuUKbo\",\n \"entity\" : \"item\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": null,\n \"amount\": 20000,\n \"currency\": \"INR\"\n }\n ]\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = itemClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("entity")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void edit() throws RazorpayException{ + + JSONObject request = new JSONObject("{\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :).\",\n \"amount\": 20000,\n \"currency\": \"INR\",\n \"active\": true\n}"); + String json = "{\n \"entity\" : \"item\",\n \"id\": \"item_IJol6jPh1ummTK\",\n \"active\": true,\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :)\",\n \"amount\": 15000,\n \"currency\": \"INR\"\n}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Item item = itemClient.edit(ITEM_ID,request); + assertNotNull(item); + assertEquals(ITEM_ID,item.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From bc8f89d5f02411ee91df00f249bb565c0bc7f543 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 11:40:33 +0530 Subject: [PATCH 17/78] string to variable --- src/main/java/com/razorpay/ApiClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..3523b16e 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -127,7 +127,7 @@ T processResponse(Response response) throws RazorpayException if(!responseJson.has(ENTITY)) { String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); + responseJson.put(ENTITY,entityName); } return parseResponse(responseJson); From bba0cd240154ef557a6a67637aa1decd766d138d Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 13:56:10 +0530 Subject: [PATCH 18/78] add addon instance --- src/test/java/com/razorpay/AddonClientTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java index ab23f383..352f4b91 100644 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -1,6 +1,7 @@ package com.razorpay; import org.junit.Test; +import org.mockito.InjectMocks; import java.io.IOException; import java.util.List; @@ -10,7 +11,10 @@ public class AddonClientTest extends BaseTest{ - public static final String ADDON_ID = "ao_00000000000001"; + @InjectMocks + protected AddonClient client = new AddonClient("test"); + + private static final String ADDON_ID = "ao_00000000000001"; @Test public void fetch() throws RazorpayException { From 0cc488f1cb12b61d20fcfa8f9f073701466cc58c Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 14:02:36 +0530 Subject: [PATCH 19/78] change instance access modifier --- src/test/java/com/razorpay/CardClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index d2093a18..f6da0abe 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -11,9 +11,9 @@ public class CardClientTest extends BaseTest{ @InjectMocks - private CardClient cardClientClient = new CardClient("test"); + protected CardClient cardClientClient = new CardClient("test"); - public static final String CARD_ID = "card_DZon6fd8J3IcA2"; + private static final String CARD_ID = "card_DZon6fd8J3IcA2"; @Test public void fetch() throws RazorpayException { From fa6125cb78b74c8bdd798f3e4052dc06b61f7b84 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 14:15:21 +0530 Subject: [PATCH 20/78] change instance access modifier --- src/test/java/com/razorpay/InvoiceClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index 8512576a..852f9997 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -13,9 +13,9 @@ public class InvoiceClientTest extends BaseTest{ @InjectMocks - private InvoiceClient invoiceClient = new InvoiceClient("test"); + protected InvoiceClient invoiceClient = new InvoiceClient("test"); - public static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; + private static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; @Test public void create() throws RazorpayException { From 27987a3d3c55947ac425a57b9dc0291348c29a30 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 15:32:03 +0530 Subject: [PATCH 21/78] remove addon client instance --- src/test/java/com/razorpay/BaseTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index bcfc0e87..1bc27b1e 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -16,8 +16,7 @@ import static org.mockito.Mockito.when; public class BaseTest { - @InjectMocks - protected AddonClient client = new AddonClient("test"); + private OkHttpClient okHttpClient; Response mockedResponse; From bd52db574ecea7e1cd98de960472c854c3a02147 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 16:40:51 +0530 Subject: [PATCH 22/78] add static secret --- src/test/java/com/razorpay/BaseTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 1bc27b1e..52eaad71 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -20,6 +20,8 @@ public class BaseTest { private OkHttpClient okHttpClient; Response mockedResponse; + static final String TEST_SECRET_KEY = "test"; + @Before public void setUp() throws Exception { From 9599a01adaed6375343f8de36d3d14763075f8a3 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 18:37:24 +0530 Subject: [PATCH 23/78] update order api with test cases --- src/main/java/com/razorpay/Constants.java | 1 + src/main/java/com/razorpay/OrderClient.java | 4 + .../java/com/razorpay/OrderClientTest.java | 90 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/test/java/com/razorpay/OrderClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..1b01a1c0 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -32,6 +32,7 @@ public class Constants { static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; + static final String ORDER_EDIT = "orders/%s"; static final String ORDER_LIST = "orders"; static final String ORDER_PAYMENT_LIST = "orders/%s/payments"; diff --git a/src/main/java/com/razorpay/OrderClient.java b/src/main/java/com/razorpay/OrderClient.java index f2063442..f9c8361d 100644 --- a/src/main/java/com/razorpay/OrderClient.java +++ b/src/main/java/com/razorpay/OrderClient.java @@ -29,4 +29,8 @@ public Order fetch(String id) throws RazorpayException { public List fetchPayments(String id) throws RazorpayException { return getCollection(String.format(Constants.ORDER_PAYMENT_LIST, id), null); } + + public Order edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.ORDER_EDIT, id), request); + } } diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java new file mode 100644 index 00000000..b0f97c29 --- /dev/null +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -0,0 +1,90 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class OrderClientTest extends BaseTest{ + + @InjectMocks + protected OrderClient orderClient = new OrderClient(TEST_SECRET_KEY); + + private static final String ORDER_ID = "order_EKwxwAgItmmXdp"; + + @Test + public void create() throws RazorpayException { + JSONObject request = new JSONObject("{amount:50000,currency:\"INR\",receipt:\"receipt#1\",notes:{key1:\"value3\",key2:\"value2\"}}"); + String json = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":50000,\"amount_paid\":0,\"amount_due\":50000,\"currency\":\"INR\",\"receipt\":\"receipt#1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582628071}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Order fetch = orderClient.create(request); + assertNotNull(fetch); + assertEquals(ORDER_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchAll() throws RazorpayException{ + String json = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"order_EKzX2WiEWbMxmx\",\"entity\":\"order\",\"amount\":1234,\"amount_paid\":0,\"amount_due\":1234,\"currency\":\"INR\",\"receipt\":\"ReceiptNo.1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582637108}]}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = orderClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("amount")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetch() throws RazorpayException{ + String json = "{\"id\":\"order_DaaS6LOUAASb7Y\",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"status\":\"attempted\",\"attempts\":1,\"notes\":[],\"created_at\":1572505143}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Order fetch = orderClient.fetch(ORDER_ID); + assertNotNull(fetch); + assertEquals(true,fetch.has("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void fetchPayments() throws RazorpayException{ + String json = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"pay_DaaSOvhgcOfzgR\",\"entity\":\"payment\",\"amount\":2200,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_DaaS6LOUAASb7Y\",\"invoice_id\":null,\"international\":false,\"method\":\"card\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"Beansineveryimaginableflavour\",\"card_id\":\"card_DZon6fd8J3IcA2\",\"bank\":null,\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999988\",\"notes\":[],\"fee\":44,\"tax\":0,\"error_code\":null,\"error_description\":null,\"created_at\":1572505160}]}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = orderClient.fetchPayments(ORDER_ID); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void edit() throws RazorpayException { + JSONObject request = new JSONObject("{\"notes\":{\"key1\":\"value3\",\"key2\":\"value2\"}}"); + String json = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"offer_id\":null,\"status\":\"attempted\",\"attempts\":1,\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"},\"created_at\":1572505143}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Order fetch = orderClient.edit(ORDER_ID,request); + assertNotNull(fetch); + assertEquals(ORDER_ID,fetch.get("id")); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file From c4c848189a4790f9e95663d9c09c50311599b201 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 19:08:37 +0530 Subject: [PATCH 24/78] add static variable --- src/test/java/com/razorpay/CardClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index f6da0abe..9f33ce52 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -11,7 +11,7 @@ public class CardClientTest extends BaseTest{ @InjectMocks - protected CardClient cardClientClient = new CardClient("test"); + protected CardClient cardClientClient = new CardClient(TEST_SECRET_KEY); private static final String CARD_ID = "card_DZon6fd8J3IcA2"; From b7c96cf61c812905b36fedae0d0f071a41c6c932 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 19:31:15 +0530 Subject: [PATCH 25/78] add static variable --- src/test/java/com/razorpay/InvoiceClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index 852f9997..745f2f6b 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -13,7 +13,7 @@ public class InvoiceClientTest extends BaseTest{ @InjectMocks - protected InvoiceClient invoiceClient = new InvoiceClient("test"); + protected InvoiceClient invoiceClient = new InvoiceClient(TEST_SECRET_KEY); private static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; From 392b7eb3a392fadbca7b5f8af80b3924a11f63f9 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Feb 2022 19:36:08 +0530 Subject: [PATCH 26/78] add static variable --- src/test/java/com/razorpay/AddonClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java index 352f4b91..c4555110 100644 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -12,7 +12,7 @@ public class AddonClientTest extends BaseTest{ @InjectMocks - protected AddonClient client = new AddonClient("test"); + protected AddonClient client = new AddonClient(TEST_SECRET_KEY); private static final String ADDON_ID = "ao_00000000000001"; From d28341af44ac4f6c6a30c794ed9970f0f95a6ae4 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 10:12:39 +0530 Subject: [PATCH 27/78] add static variable --- src/test/java/com/razorpay/CustomerClientTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index 434a3603..448ef78f 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -11,11 +11,11 @@ public class CustomerClientTest extends BaseTest{ @InjectMocks - private CustomerClient customerClient = new CustomerClient("test"); + protected CustomerClient customerClient = new CustomerClient(TEST_SECRET_KEY); - public static final String CUSTOMER_ID = "cust_1Aa00000000004"; + private static final String CUSTOMER_ID = "cust_1Aa00000000004"; - public static final String TOKEN_ID = "token_Hxe0skTXLeg9pF"; + private static final String TOKEN_ID = "token_Hxe0skTXLeg9pF"; @Test public void create() throws RazorpayException{ From da26aa251732c2e7f4d868e0b20ecd1d1154b0ea Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 10:25:56 +0530 Subject: [PATCH 28/78] add static variable --- src/test/java/com/razorpay/FundAccountClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/razorpay/FundAccountClientTest.java b/src/test/java/com/razorpay/FundAccountClientTest.java index dd178baa..fb439d06 100644 --- a/src/test/java/com/razorpay/FundAccountClientTest.java +++ b/src/test/java/com/razorpay/FundAccountClientTest.java @@ -11,9 +11,9 @@ public class FundAccountClientTest extends BaseTest{ @InjectMocks - private FundAccountClient fundAccountClient = new FundAccountClient("test"); + protected FundAccountClient fundAccountClient = new FundAccountClient(TEST_SECRET_KEY); - public static final String FUNDACCOUNT_ID = "fa_Aa00000000001"; + private static final String FUNDACCOUNT_ID = "fa_Aa00000000001"; @Test public void create() throws RazorpayException { From fa70f3cc70e7fcd05c78f498034f2f1b8c3e7a60 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 16:49:04 +0530 Subject: [PATCH 29/78] change json name to mockedResponseJson --- src/test/java/com/razorpay/CardClientTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index 9f33ce52..4a3b51c5 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -18,9 +18,9 @@ public class CardClientTest extends BaseTest{ @Test public void fetch() throws RazorpayException { - String json = "{\n \"id\": \"card_DZon6fd8J3IcA2\",\n \"entity\": \"card\",\n \"international\": false,\n \"last4\": 1111,\n \"name\": \"sample name\",\n \"network\": \"Visa\",\n \"type\": \"debit\"\n}"; + String mockedResponseJson = "{\n \"id\": "+CARD_ID+",\n \"entity\": \"card\",\n \"international\": false,\n \"last4\": 1111,\n \"name\": \"sample name\",\n \"network\": \"Visa\",\n \"type\": \"debit\"\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Card fetch = cardClientClient.fetch(CARD_ID); assertNotNull(fetch); From 7e665f376d7c1ac21f75a12d8437ed555f11d0dc Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 18:35:47 +0530 Subject: [PATCH 30/78] mutiple testing cases --- .../java/com/razorpay/InvoiceClientTest.java | 68 +++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index 745f2f6b..f0a9986e 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -17,124 +17,154 @@ public class InvoiceClientTest extends BaseTest{ private static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; + /** Create invoice mock */ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject("{\n \"type\":\"link\",\n \"decsription\":\"test\",\n \"line_items\":[\n {\n \"name\":\"name\",\n \"amount\":100\n }\n ]\n}\n"); - String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"random_id\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + String mockedResponseJson = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"random_id\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice invoice = invoiceClient.create(request); assertNotNull(invoice); assertEquals("invoice",invoice.get("entity")); + assertTrue(invoice.has("customer_details")); + assertTrue(invoice.has("short_url")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Fetch all invoices mock */ @Test public void fetchAll() throws RazorpayException { - String json = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n }\n ]\n}"; + String mockedResponseJson = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n }\n ]\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = invoiceClient.fetchAll(); assertNotNull(fetch); - assertEquals(true,fetch.get(0).has("type")); + assertTrue(fetch.get(0).has("type")); + assertTrue(fetch.get(0).has("receipt")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Fetch invoices mock */ @Test public void fetch() throws RazorpayException { - String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"inv_DAweOiQ7amIUVd\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + String mockedResponseJson = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": "+INVOICE_ID+", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.fetch(INVOICE_ID); assertNotNull(fetch); assertEquals(INVOICE_ID,fetch.get("id")); + assertTrue(fetch.has("customer_details")); + assertTrue(fetch.has("issued_at")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Cancel invoice mock */ @Test public void cancel() throws RazorpayException { - String json = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"inv_DAweOiQ7amIUVd\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"cancelled\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; + String mockedResponseJson = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": "+INVOICE_ID+", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"cancelled\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.cancel(INVOICE_ID); assertNotNull(fetch); assertEquals(INVOICE_ID,fetch.get("id")); + assertTrue(fetch.has("customer_details")); + assertTrue(fetch.has("issued_at")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Send notification to the customer mock */ @Test public void notifyBy() throws RazorpayException { - String json = "{\n \"entity\" : \"invoice\",\n \"success\": true\n}"; + String mockedResponseJson = "{\n \"entity\" : \"invoice\",\n \"success\": true\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.notifyBy(INVOICE_ID,"sms"); assertNotNull(fetch); - assertEquals(true,fetch.get("success")); + assertTrue(fetch.has("success")); + assertTrue(fetch.has("entity")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Create a registration link mock */ @Test public void createRegistrationLink() throws RazorpayException { JSONObject request = new JSONObject("{\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9123456789\",\n \"amount\": 1000,\n \"currency\": \"INR\",\n \"order_id\": \"order_1Aa00000000002\",\n \"customer_id\": \"cust_1Aa00000000001\",\n \"token\": \"token_1Aa00000000001\",\n \"recurring\": \"1\",\n \"description\": \"Creating recurring payment for Gaurav Kumar\",\n \"notes\": {\n \"note_key 1\": \"Beam me up Scotty\",\n \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n }\n}"); - String json = "{\n \"entity\" : \"invoice\",\n \"razorpay_payment_id\" : \"pay_1Aa00000000001\",\n \"razorpay_order_id\" : \"order_1Aa00000000001\",\n \"razorpay_signature\" : \"9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d\"\n}"; + String mockedResponseJson = "{\n \"entity\" : \"invoice\",\n \"razorpay_payment_id\" : \"pay_1Aa00000000001\",\n \"razorpay_order_id\" : \"order_1Aa00000000001\",\n \"razorpay_signature\" : \"9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d\"\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.createRegistrationLink(request); assertNotNull(fetch); - assertEquals(true,fetch.has("razorpay_payment_id")); + assertTrue(fetch.has("razorpay_payment_id")); + assertTrue(fetch.has("razorpay_order_id")); + assertTrue(fetch.has("razorpay_signature")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** Issue an invoice */ @Test public void issue() throws RazorpayException { - String json = "{\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": \"order_DBG3P8ZgDd1dsG\",\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"issued\",\n \"expire_by\": 1567103399,\n \"issued_at\": 1566974805,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": 0,\n \"amount_due\": 600,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": \"\",\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; + String mockedResponseJson = "{\n \"id\": "+INVOICE_ID+",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": \"order_DBG3P8ZgDd1dsG\",\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"issued\",\n \"expire_by\": 1567103399,\n \"issued_at\": 1566974805,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": 0,\n \"amount_due\": 600,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": \"\",\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.issue(INVOICE_ID); assertNotNull(fetch); assertEquals(INVOICE_ID,fetch.get("id")); + assertEquals("invoice",fetch.get("entity")); + assertTrue(fetch.has("invoice_number")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } + /** update an invoice mock */ @Test public void edit() throws RazorpayException { JSONObject request = new JSONObject("{ \n \"notes\": {\n \"updated-key\": \"An updated note.\"\n }\n}"); - String json = "{\n \"id\": \"inv_DAweOiQ7amIUVd\",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; + String mockedResponseJson = "{\n \"id\": "+INVOICE_ID+",\n \"entity\": \"invoice\",\n \"receipt\": \"#0961\",\n \"invoice_number\": \"#0961\",\n \"customer_id\": \"cust_DAtUWmvpktokrT\",\n \"customer_details\": {\n \"id\": \"cust_DAtUWmvpktokrT\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"gaurav.kumar@example.com\",\n \"contact\": \"9977886633\",\n \"gstin\": null,\n \"billing_address\": {\n \"id\": \"addr_DAtUWoxgu91obl\",\n \"type\": \"billing_address\",\n \"primary\": true,\n \"line1\": \"318 C-Wing, Suyog Co. Housing Society Ltd.\",\n \"line2\": \"T.P.S Road, Vazira, Borivali\",\n \"zipcode\": \"400092\",\n \"city\": \"Mumbai\",\n \"state\": \"Maharashtra\",\n \"country\": \"in\"\n },\n \"shipping_address\": null,\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9977886633\"\n },\n \"order_id\": null,\n \"line_items\": [\n {\n \"id\": \"li_DAweOizsysoJU6\",\n \"item_id\": null,\n \"name\": \"Book English August - Updated name and quantity\",\n \"description\": \"150 points in Quidditch\",\n \"amount\": 400,\n \"unit_amount\": 400,\n \"gross_amount\": 400,\n \"tax_amount\": 0,\n \"taxable_amount\": 400,\n \"net_amount\": 400,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n },\n {\n \"id\": \"li_DAwjWQUo07lnjF\",\n \"item_id\": null,\n \"name\": \"Book A Wild Sheep Chase\",\n \"description\": null,\n \"amount\": 200,\n \"unit_amount\": 200,\n \"gross_amount\": 200,\n \"tax_amount\": 0,\n \"taxable_amount\": 200,\n \"net_amount\": 200,\n \"currency\": \"INR\",\n \"type\": \"invoice\",\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"unit\": null,\n \"quantity\": 1,\n \"taxes\": []\n }\n ],\n \"payment_id\": null,\n \"status\": \"draft\",\n \"expire_by\": 1567103399,\n \"issued_at\": null,\n \"paid_at\": null,\n \"cancelled_at\": null,\n \"expired_at\": null,\n \"sms_status\": null,\n \"email_status\": null,\n \"date\": 1566891149,\n \"terms\": null,\n \"partial_payment\": false,\n \"gross_amount\": 600,\n \"tax_amount\": 0,\n \"taxable_amount\": 600,\n \"amount\": 600,\n \"amount_paid\": null,\n \"amount_due\": null,\n \"currency\": \"INR\",\n \"currency_symbol\": \"\u20b9\",\n \"description\": \"This is a test invoice.\",\n \"notes\": {\n \"updated-key\": \"An updated note.\"\n },\n \"comment\": null,\n \"short_url\": null,\n \"view_less\": true,\n \"billing_start\": null,\n \"billing_end\": null,\n \"type\": \"invoice\",\n \"group_taxes_discounts\": false,\n \"created_at\": 1566906474,\n \"idempotency_key\": null\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Invoice invoice = invoiceClient.edit(INVOICE_ID,request); assertNotNull(invoice); assertEquals(INVOICE_ID,invoice.get("id")); + assertEquals("invoice",invoice.get("entity")); + assertTrue(invoice.has("receipt")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From e2318561554db88d551eb7fda9d306fff776b164 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 19:03:51 +0530 Subject: [PATCH 31/78] add java doc --- src/test/java/com/razorpay/CardClientTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index 4a3b51c5..796da422 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -15,6 +15,9 @@ public class CardClientTest extends BaseTest{ private static final String CARD_ID = "card_DZon6fd8J3IcA2"; + /** fetch card details + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { @@ -25,8 +28,10 @@ public void fetch() throws RazorpayException { Card fetch = cardClientClient.fetch(CARD_ID); assertNotNull(fetch); assertEquals(CARD_ID,fetch.get("id")); + assertTrue(fetch.has("international")); } catch (IOException e) { e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From 780e61be1958499b0907d51bae5f8d92eb5c403f Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 8 Feb 2022 19:23:13 +0530 Subject: [PATCH 32/78] java doc correction --- .../java/com/razorpay/InvoiceClientTest.java | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index f0a9986e..a5eb45c7 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -17,7 +17,11 @@ public class InvoiceClientTest extends BaseTest{ private static final String INVOICE_ID = "inv_DAweOiQ7amIUVd"; - /** Create invoice mock */ + + /** + * Create invoice mock + * @throws RazorpayException + */ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject("{\n \"type\":\"link\",\n \"decsription\":\"test\",\n \"line_items\":[\n {\n \"name\":\"name\",\n \"amount\":100\n }\n ]\n}\n"); @@ -36,7 +40,11 @@ public void create() throws RazorpayException { } } - /** Fetch all invoices mock */ + + /** + * Fetch all invoices mock + * @throws RazorpayException + */ @Test public void fetchAll() throws RazorpayException { @@ -54,7 +62,11 @@ public void fetchAll() throws RazorpayException { } } - /** Fetch invoices mock */ + + /** + * Fetch invoices mock + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { @@ -73,7 +85,11 @@ public void fetch() throws RazorpayException { } } - /** Cancel invoice mock */ + + /** + * Cancel invoice mock + * @throws RazorpayException + */ @Test public void cancel() throws RazorpayException { @@ -92,7 +108,11 @@ public void cancel() throws RazorpayException { } } - /** Send notification to the customer mock */ + + /** + * Send notification to the customer mock + * @throws RazorpayException + */ @Test public void notifyBy() throws RazorpayException { @@ -110,7 +130,11 @@ public void notifyBy() throws RazorpayException { } } - /** Create a registration link mock */ + + /** + * Create a registration link mock + * @throws RazorpayException + */ @Test public void createRegistrationLink() throws RazorpayException { @@ -130,7 +154,10 @@ public void createRegistrationLink() throws RazorpayException { } } - /** Issue an invoice */ + /** + * Issue an invoice + * @throws RazorpayException + */ @Test public void issue() throws RazorpayException { @@ -149,7 +176,10 @@ public void issue() throws RazorpayException { } } - /** update an invoice mock */ + /** + * Update an invoice mock + * @throws RazorpayException + */ @Test public void edit() throws RazorpayException { JSONObject request = new JSONObject("{ \n \"notes\": {\n \"updated-key\": \"An updated note.\"\n }\n}"); From d7c9365560ede426dc256c92816d42515dd4b4b4 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 9 Feb 2022 14:18:10 +0530 Subject: [PATCH 33/78] add fetch card detail of payment --- src/main/java/com/razorpay/CardClient.java | 4 +++ src/main/java/com/razorpay/Constants.java | 1 + .../java/com/razorpay/CardClientTest.java | 25 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/CardClient.java b/src/main/java/com/razorpay/CardClient.java index a563eb19..0e66480f 100755 --- a/src/main/java/com/razorpay/CardClient.java +++ b/src/main/java/com/razorpay/CardClient.java @@ -9,4 +9,8 @@ public class CardClient extends ApiClient { public Card fetch(String id) throws RazorpayException { return get(String.format(Constants.CARD_GET, id), null); } + + public Card fetchCardDetails(String id) throws RazorpayException{ + return get(String.format(Constants.FETCH_CARD_DETAILS, id), null); + } } diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..5d681c27 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -41,6 +41,7 @@ public class Constants { static final String INVOICE_CANCEL = "invoices/%s/cancel"; static final String CARD_GET = "cards/%s"; + static final String FETCH_CARD_DETAILS = "payments/%s/card"; static final String CUSTOMER_CREATE = "customers"; static final String CUSTOMER_GET = "customers/%s"; diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index 796da422..77bfa4eb 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -15,7 +15,9 @@ public class CardClientTest extends BaseTest{ private static final String CARD_ID = "card_DZon6fd8J3IcA2"; - /** fetch card details + private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; + + /** Fetch card details * @throws RazorpayException */ @Test @@ -34,4 +36,25 @@ public void fetch() throws RazorpayException { assertTrue(false); } } + + /** Fetch Card Details of a Payment + * @throws RazorpayException + */ + @Test + public void fetchCardDetails() throws RazorpayException { + + String mockedResponseJson = "{\"id\":"+CARD_ID+",\"entity\":\"card\",\"name\":\"GauravKumar\",\"last4\":\"8430\",\"network\":\"Visa\",\"type\":\"credit\",\"issuer\":\"HDFC\",\"international\":false,\"emi\":true,\"sub_type\":\"consumer\",\"token_iin\":null}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Card fetch = cardClientClient.fetchCardDetails(PAYMENT_ID); + assertNotNull(fetch); + assertEquals(CARD_ID,fetch.get("id")); + assertTrue(fetch.has("name")); + assertTrue(fetch.has("network")); + } catch (IOException e) { + e.printStackTrace(); + assertTrue(false); + } + } } \ No newline at end of file From 2629c3be1a7e92d8c98817ceecf330f6ec7eeaf4 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 9 Feb 2022 18:24:59 +0530 Subject: [PATCH 34/78] remove printstacktrack --- src/test/java/com/razorpay/CardClientTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index 77bfa4eb..5cf3daa7 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -17,7 +17,7 @@ public class CardClientTest extends BaseTest{ private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; - /** Fetch card details + /** Retrieving a specific card details using card id * @throws RazorpayException */ @Test @@ -32,13 +32,13 @@ public void fetch() throws RazorpayException { assertEquals(CARD_ID,fetch.get("id")); assertTrue(fetch.has("international")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } - /** Fetch Card Details of a Payment + /** Fetch the details of the card used to make a payment * @throws RazorpayException + * @return void */ @Test public void fetchCardDetails() throws RazorpayException { @@ -53,7 +53,6 @@ public void fetchCardDetails() throws RazorpayException { assertTrue(fetch.has("name")); assertTrue(fetch.has("network")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } From f55a90fa94028a5d67f8e320ebf2f926d57a6e6c Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 9 Feb 2022 19:15:24 +0530 Subject: [PATCH 35/78] add more description in java doc --- .../java/com/razorpay/InvoiceClientTest.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index a5eb45c7..7224a3a9 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -19,12 +19,13 @@ public class InvoiceClientTest extends BaseTest{ /** - * Create invoice mock + * Invoice is created using the customer and item details. + * Here, the customer and item are created while creating the invoice. * @throws RazorpayException */ @Test public void create() throws RazorpayException { - JSONObject request = new JSONObject("{\n \"type\":\"link\",\n \"decsription\":\"test\",\n \"line_items\":[\n {\n \"name\":\"name\",\n \"amount\":100\n }\n ]\n}\n"); + JSONObject request = new JSONObject("{\n type: \"invoice\",\n description: \"Invoice for the month of January 2020\",\n partial_payment: true,\n customer: {\n name: \"Gaurav Kumar\",\n contact: 9999999999,\n email: \"gaurav.kumar@example.com\",\n billing_address: {\n line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n line2: \"Hosur Road\",\n zipcode: 560068,\n city: \"Bengaluru\",\n state: \"Karnataka\",\n country: \"in\"\n },\n shipping_address: {\n line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n line2: \"Hosur Road\",\n zipcode: 560068,\n city: \"Bengaluru\",\n state: \"Karnataka\",\n country: \"in\"\n }\n },\n line_items: [\n {\n name: \"Master Cloud Computing in 30 Days\",\n description: \"Book by Ravena Ravenclaw\",\n amount: 399,\n currency: \"USD\",\n quantity: 1\n }\n ],\n sms_notify: 1,\n email_notify: 1,\n currency: \"USD\",\n expire_by: 1589765167\n}"); String mockedResponseJson = "{\n \"issued_at\": 1481541533,\n \"customer_details\":\n {\n \"customer_name\": \"Gaurav Kumar\",\n \"customer_email\": \"gaurav.kumar@example.com\",\n \"customer_contact\": \"9999999999\"\n },\n \"short_url\": \"http://bit.ly/link\", \n \"receipt\": null, \n \"entity\": \"invoice\", \n \"currency\": \"INR\", \n \"paid_at\": null, \n \"view_less\": true, \n \"id\": \"random_id\", \n \"customer_id\": \"cust_E7q0trFqXgExmT\", \n \"type\": null, \n \"status\": \"issued\", \n \"description\": \"random decsription\", \n \"order_id\": \"order_random_id\", \n \"sms_status\": \"pending\", \n \"date\": 1481541533, \n \"payment_id\": null, \n \"amount\": 100,\n \"email_status\": \"pending\",\n \"created_at\": 1481541534\n}"; try { mockResponseFromExternalClient(mockedResponseJson); @@ -35,14 +36,13 @@ public void create() throws RazorpayException { assertTrue(invoice.has("customer_details")); assertTrue(invoice.has("short_url")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Fetch all invoices mock + * Details of all the invoices can be retrieved. * @throws RazorpayException */ @Test @@ -57,14 +57,13 @@ public void fetchAll() throws RazorpayException { assertTrue(fetch.get(0).has("type")); assertTrue(fetch.get(0).has("receipt")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Fetch invoices mock + * Retrieve all the invoice details of respective customer using invoice id. * @throws RazorpayException */ @Test @@ -80,14 +79,13 @@ public void fetch() throws RazorpayException { assertTrue(fetch.has("customer_details")); assertTrue(fetch.has("issued_at")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Cancel invoice mock + * Cancel an unpaid invoice of respective customer using invoice id. * @throws RazorpayException */ @Test @@ -100,6 +98,7 @@ public void cancel() throws RazorpayException { Invoice fetch = invoiceClient.cancel(INVOICE_ID); assertNotNull(fetch); assertEquals(INVOICE_ID,fetch.get("id")); + assertEquals("pending",fetch.get("email_status")); assertTrue(fetch.has("customer_details")); assertTrue(fetch.has("issued_at")); } catch (IOException e) { @@ -110,7 +109,8 @@ public void cancel() throws RazorpayException { /** - * Send notification to the customer mock + * Send notifications with the short URL to the customer via email or SMS + * using invoice id * @throws RazorpayException */ @Test @@ -125,14 +125,13 @@ public void notifyBy() throws RazorpayException { assertTrue(fetch.has("success")); assertTrue(fetch.has("entity")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Create a registration link mock + * Create a registration for a recurring payment * @throws RazorpayException */ @Test @@ -145,17 +144,17 @@ public void createRegistrationLink() throws RazorpayException { mockResponseHTTPCodeFromExternalClient(200); Invoice fetch = invoiceClient.createRegistrationLink(request); assertNotNull(fetch); + assertEquals("invoice",fetch.get("entity")); assertTrue(fetch.has("razorpay_payment_id")); assertTrue(fetch.has("razorpay_order_id")); assertTrue(fetch.has("razorpay_signature")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Issue an invoice + * Invoice in the draft status can only be issued using customer's invoice id * @throws RazorpayException */ @Test @@ -170,14 +169,14 @@ public void issue() throws RazorpayException { assertEquals(INVOICE_ID,fetch.get("id")); assertEquals("invoice",fetch.get("entity")); assertTrue(fetch.has("invoice_number")); + assertTrue(fetch.has("receipt")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } /** - * Update an invoice mock + * Update an invoice of respective customer using invoice id with object of that properties * @throws RazorpayException */ @Test @@ -191,9 +190,9 @@ public void edit() throws RazorpayException { assertNotNull(invoice); assertEquals(INVOICE_ID,invoice.get("id")); assertEquals("invoice",invoice.get("entity")); + assertTrue(invoice.has("invoice_number")); assertTrue(invoice.has("receipt")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } From bbac4dd49f7b5375c7297e2000c89a59eb990896 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 10 Feb 2022 22:33:24 +0530 Subject: [PATCH 36/78] updated payment api with unit test --- src/main/java/com/razorpay/CardClient.java | 4 + src/main/java/com/razorpay/Constants.java | 5 + src/main/java/com/razorpay/PaymentClient.java | 17 ++ src/test/java/com/razorpay/BaseTest.java | 2 + .../java/com/razorpay/PaymentClientTest.java | 210 ++++++++++++++++++ 5 files changed, 238 insertions(+) create mode 100644 src/test/java/com/razorpay/PaymentClientTest.java diff --git a/src/main/java/com/razorpay/CardClient.java b/src/main/java/com/razorpay/CardClient.java index a563eb19..5198b9b2 100755 --- a/src/main/java/com/razorpay/CardClient.java +++ b/src/main/java/com/razorpay/CardClient.java @@ -9,4 +9,8 @@ public class CardClient extends ApiClient { public Card fetch(String id) throws RazorpayException { return get(String.format(Constants.CARD_GET, id), null); } + + public Card fetchCardDetails(String id) throws RazorpayException{ + return get(String.format(Constants.FETCH_CARD_DETAILS, id), null); + } } diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..0b262389 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -22,6 +22,11 @@ public class Constants { static final String PAYMENT_TRANSFER_CREATE = "payments/%s/transfers"; static final String PAYMENT_TRANSFER_GET = "payments/%s/transfers"; static final String PAYMENT_BANK_TRANSFER_GET = "payments/%s/bank_transfer"; + static final String PAYMENT_EDIT = "payments/%s"; + static final String FETCH_CARD_DETAILS = "payments/%s/card"; + static final String FETCH_DOWNTIME_LIST = "payments/downtimes"; + static final String FETCH_DOWNTIME_GET = "payments/downtimes"; + static final String PAYMENT_JSON_CREATE = "payments/create/json"; static final String PAYMENT_REFUND_LIST = "payments/%s/refunds"; static final String PAYMENT_REFUND_GET = "payments/%s/refunds/%s"; diff --git a/src/main/java/com/razorpay/PaymentClient.java b/src/main/java/com/razorpay/PaymentClient.java index 6b99e362..caefc959 100755 --- a/src/main/java/com/razorpay/PaymentClient.java +++ b/src/main/java/com/razorpay/PaymentClient.java @@ -80,4 +80,21 @@ public List fetchAllTransfers(String id, JSONObject request) throws Ra public BankTransfer fetchBankTransfers(String id) throws RazorpayException { return get(String.format(Constants.PAYMENT_BANK_TRANSFER_GET, id), null); } + + public Payment edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.PAYMENT_EDIT, id), request); + } + + public List fetchPaymentDowntime() throws RazorpayException { + return getCollection(Constants.FETCH_DOWNTIME_LIST, null); + } + + public Payment fetchPaymentDowntimeById(String id) throws RazorpayException { + return get(String.format(Constants.FETCH_DOWNTIME_GET, id), null); + } + + public Payment createJsonPayment(JSONObject request) throws RazorpayException { + return post(Constants.PAYMENT_JSON_CREATE, request); + } + } diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 1bc27b1e..52eaad71 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -20,6 +20,8 @@ public class BaseTest { private OkHttpClient okHttpClient; Response mockedResponse; + static final String TEST_SECRET_KEY = "test"; + @Before public void setUp() throws Exception { diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java new file mode 100644 index 00000000..d790be95 --- /dev/null +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -0,0 +1,210 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class PaymentClientTest extends BaseTest{ + + @InjectMocks + protected PaymentClient paymentClient = new PaymentClient(TEST_SECRET_KEY); + + private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; + + private static final String REFUND_ID = "rfnd_FP8QHiV938haTz"; + /** + * Fetch a payment + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + + String mockedResponseJson = "{\"id\":"+PAYMENT_ID+",\"entity\":\"payment\",\"amount\":1000,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VPOayFxWEU28\",\"invoice_id\":null,\"international\":false,\"method\":\"upi\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":null,\"wallet\":null,\"vpa\":\"gaurav.kumar@exampleupi\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":24,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"rrn\":\"033814379298\"},\"created_at\":1606985209}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.fetch(PAYMENT_ID); + assertNotNull(fetch); + assertEquals(PAYMENT_ID,fetch.get("id")); + assertTrue(fetch.has("status")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Fetch Multiple Payments + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + + String mockedResponseJson = "{\"entity\":\"collection\",\"count\":2,\"items\":[{\"id\":\"pay_G8VaL2Z68LRtDs\",\"entity\":\"payment\",\"amount\":900,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VXfKDWDEOHHd\",\"invoice_id\":null,\"international\":false,\"method\":\"netbanking\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":\"KKBK\",\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":22,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"bank_transaction_id\":\"0125836177\"},\"created_at\":1606985740}]}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = paymentClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("amount")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Capture payment + * @throws RazorpayException + */ + @Test + public void capture() throws RazorpayException{ + + JSONObject request = new JSONObject("{\"amount\":1000,\"currency\":\"INR\"}"); + String mockedResponseJson = "{\"id\":"+PAYMENT_ID+",\"entity\":\"payment\",\"amount\":1000,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VPOayFxWEU28\",\"invoice_id\":null,\"international\":false,\"method\":\"upi\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":null,\"wallet\":null,\"vpa\":\"gaurav.kumar@exampleupi\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":24,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"rrn\":\"033814379298\"},\"created_at\":1606985209}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.capture(PAYMENT_ID,request); + assertNotNull(fetch); + assertEquals(PAYMENT_ID,fetch.get("id")); + assertTrue(fetch.has("entity")); + assertTrue(fetch.has("amount")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void refund() throws RazorpayException{ + + JSONObject request = new JSONObject("{\"amount\":\"100\",\"speed\":\"normal\",\"notes\":{\"notes_key_1\":\"BeammeupScotty.\",\"notes_key_2\":\"Engage\"},\"receipt\":\"ReceiptNo.31\"}"); + String mockedResponseJson = "{\"id\":\"rfnd_FP8QHiV938haTz\",\"entity\":\"refund\",\"amount\":500100,\"receipt\":\"ReceiptNo.31\",\"currency\":\"INR\",\"payment_id\":\"pay_FCXKPFtYfPXJPy\",\"notes\":[],\"acquirer_data\":{\"arn\":null},\"created_at\":1597078866,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Refund fetch = paymentClient.refund(PAYMENT_ID,request); + assertNotNull(fetch); + assertEquals("rfnd_FP8QHiV938haTz",fetch.get("id")); + assertTrue(fetch.has("entity")); + assertTrue(fetch.has("amount")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void testRefund() throws Exception{ + JSONObject request = new JSONObject("{\"amount\":\"100\",\"speed\":\"normal\",\"notes\":{\"notes_key_1\":\"BeammeupScotty.\",\"notes_key_2\":\"Engage\"},\"receipt\":\"ReceiptNo.31\"}"); + String mockedResponseJson = "{\"id\":"+REFUND_ID+",\"entity\":\"refund\",\"amount\":500100,\"receipt\":\"ReceiptNo.31\",\"currency\":\"INR\",\"payment_id\":\"pay_FCXKPFtYfPXJPy\",\"notes\":[],\"acquirer_data\":{\"arn\":null},\"created_at\":1597078866,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Refund fetch = paymentClient.refund(PAYMENT_ID,request); + assertNotNull(fetch); + assertEquals(REFUND_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("payment_id")); + } catch (IOException e) { + assertTrue(false); + } + } + + + @Test + public void FetchAllRefunds() throws RazorpayException{ + JSONObject request = new JSONObject("{}"); + String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"rfnd_IDQbLKwiy0aHrA\",\"entity\":\"refund\",\"amount\":100,\"currency\":\"INR\",\"payment_id\":\"pay_I3eaMwGV0462JA\",\"notes\":[],\"receipt\":null,\"acquirer_data\":{\"arn\":\"10000000000000\"},\"created_at\":1635134062,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\",\"speed_requested\":\"normal\"}]}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = paymentClient.fetchAllRefunds(PAYMENT_ID,request); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("payment_id")); + assertTrue(fetch.get(0).has("notes")); + } catch (IOException e) { + assertTrue(false); + } + } + + + @Test + public void transfers() throws RazorpayException{ + JSONObject request = new JSONObject("{\"transfers\":[{\"account\":\"acc_CPRsN1LkFccllA\",\"amount\":100,\"currency\":\"INR\",\"notes\":{\"name\":\"GauravKumar\",\"roll_no\":\"IEC2011025\"},\"linked_account_notes\":[\"roll_no\"],\"on_hold\":true,\"on_hold_until\":1671222870}]}"); + String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"trf_ItzBst0oybrcNx\",\"entity\":\"transfer\",\"status\":\"pending\",\"source\":\"pay_IOyKpYsPTMSWph\",\"recipient\":\"acc_I0QRP7PpvaHhpB\",\"amount\":100,\"currency\":\"INR\",\"amount_reversed\":0,\"notes\":{\"name\":\"GauravKumar\",\"roll_no\":\"IEC2011025\"},\"linked_account_notes\":[\"roll_no\"],\"on_hold\":true,\"on_hold_until\":1671222870,\"recipient_settlement_id\":null,\"created_at\":1644426157,\"processed_at\":null,\"error\":{\"code\":null,\"description\":null,\"reason\":null,\"field\":null,\"step\":null,\"id\":\"trf_ItzBst0oybrcNx\",\"source\":null,\"metadata\":null}}]}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = paymentClient.transfer(PAYMENT_ID,request); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("status")); + assertTrue(fetch.get(0).has("source")); + assertTrue(fetch.get(0).has("recipient")); + assertTrue(fetch.get(0).has("currency")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void fetchAllTransfers() throws RazorpayException{ + + String mockedResponseJson = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"trf_EAznuJ9cDLnF7Y\",\n \"entity\": \"transfer\",\n \"source\": \"pay_E9up5WhIfMYnKW\",\n \"recipient\": \"acc_CMaomTz4o0FOFz\",\n \"amount\": 1000,\n \"currency\": \"INR\",\n \"amount_reversed\": 100,\n \"notes\": [],\n \"fees\": 3,\n \"tax\": 0,\n \"on_hold\": false,\n \"on_hold_until\": null,\n \"recipient_settlement_id\": null,\n \"created_at\": 1580454666,\n \"linked_account_notes\": [],\n \"processed_at\": 1580454666\n }\n ]\n}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = paymentClient.fetchAllTransfers(PAYMENT_ID); + assertNotNull(fetch); + //assertEquals("bt_Di5iqCElVyRlCb",fetch.get("id")); + assertTrue(fetch.get(0).has("source")); + assertTrue(fetch.get(0).has("recipient")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void fetchBankTransfers() throws RazorpayException{ + + String mockedResponseJson = "{\n \"id\": \"bt_Di5iqCElVyRlCb\",\n \"entity\": \"bank_transfer\",\n \"payment_id\": "+PAYMENT_ID+",\n \"mode\": \"NEFT\",\n \"bank_reference\": \"157414364471\",\n \"amount\": 239000,\n \"payer_bank_account\": {\n \"id\": \"ba_Di5iqSxtYrTzPU\",\n \"entity\": \"bank_account\",\n \"ifsc\": \"UTIB0003198\",\n \"bank_name\": \"Axis Bank\",\n \"name\": \"Acme Corp\",\n \"notes\": [],\n \"account_number\": \"765432123456789\"\n },\n \"virtual_account_id\": \"va_Di5gbNptcWV8fQ\",\n \"virtual_account\": {\n \"id\": \"va_Di5gbNptcWV8fQ\",\n \"name\": \"Acme Corp\",\n \"entity\": \"virtual_account\",\n \"status\": \"closed\",\n \"description\": \"Virtual Account created for MS ABC Exports\",\n \"amount_expected\": 2300,\n \"notes\": {\n \"material\": \"teakwood\"\n },\n \"amount_paid\": 239000,\n \"customer_id\": \"cust_DOMUFFiGdCaCUJ\",\n \"receivers\": [\n {\n \"id\": \"ba_Di5gbQsGn0QSz3\",\n \"entity\": \"bank_account\",\n \"ifsc\": \"RATN0VAAPIS\",\n \"bank_name\": \"RBL Bank\",\n \"name\": \"Acme Corp\",\n \"notes\": [],\n \"account_number\": \"1112220061746877\"\n }\n ],\n \"close_by\": 1574427237,\n \"closed_at\": 1574164078,\n \"created_at\": 1574143517\n }\n}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + BankTransfer fetch = paymentClient.fetchBankTransfers(PAYMENT_ID); + assertNotNull(fetch); + assertEquals("bt_Di5iqCElVyRlCb",fetch.get("id")); + assertEquals("bank_transfer",fetch.get("entity")); + assertEquals(PAYMENT_ID,fetch.get("payment_id")); + assertTrue(fetch.has("entity")); + assertTrue(fetch.has("amount")); + } catch (IOException e) { + assertTrue(false); + } + } + + @Test + public void createJsonPayment() throws RazorpayException { + + JSONObject request = new JSONObject("{\"amount\":\"100\",\"currency\":\"INR\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"9123456789\",\"order_id\":\"order_ItZMEZjpBD6dhT\",\"method\":\"upi\"}"); + String mockedResponseJson = "{\"entity\":\"payment\",\"type\":\"respawn\",\"request\":{\"url\":\"https://api.razorpay.com/v1/payments?key_id=rzp_test_pNL6H0AmbBEyjD\",\"method\":\"POST\",\"content\":{\"amount\":\"100\",\"currency\":\"INR\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"9123456789\",\"order_id\":\"order_ItYKzxCxnKAKlD\",\"method\":\"upi\",\"card\":{\"number\":\"4854980604708430\",\"cvv\":\"123\",\"expiry_month\":\"12\",\"expiry_year\":\"21\",\"name\":\"GauravKumar\"},\"_\":{\"library\":\"s2s\"},\"upi\":{\"flow\":\"collect\",\"type\":\"default\"}}},\"image\":null,\"theme\":\"#3594E2\",\"method\":\"upi\",\"version\":\"1\",\"missing\":[\"vpa\"],\"base\":\"api.razorpay.com\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.createJsonPayment(request); + assertNotNull(fetch); + assertEquals("upi",fetch.get("method")); + assertEquals("payment",fetch.get("entity")); + assertTrue(fetch.has("request")); + assertTrue(fetch.has("base")); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 2229bfa192b5bce448a55133e7fab8400d1c8b99 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 12:16:24 +0530 Subject: [PATCH 37/78] add javadocs --- .../java/com/razorpay/CustomerClientTest.java | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index 448ef78f..1553b69f 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -17,92 +17,116 @@ public class CustomerClientTest extends BaseTest{ private static final String TOKEN_ID = "token_Hxe0skTXLeg9pF"; + /** + * Create customers with basic details such as name and contact details + * @throws RazorpayException + */ @Test public void create() throws RazorpayException{ JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"contact\": 9123456780,\n \"email\": \"gaurav.kumar@example.com\",\n \"fail_existing\": 0,\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n }\n}"); - String json = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Gaurav Kumar\",\n \"email\" : \"gaurav.kumar@example.com\",\n \"contact\" : \"9123456780\",\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\":{\n \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n \"notes_key_2\":\"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at \": 1234567890\n}"; + String mockedResponseJson = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Gaurav Kumar\",\n \"email\" : \"gaurav.kumar@example.com\",\n \"contact\" : \"9123456780\",\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\":{\n \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n \"notes_key_2\":\"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at \": 1234567890\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Customer customer = customerClient.create(request); assertNotNull(customer); assertEquals(CUSTOMER_ID,customer.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve the customers details using customer id. + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { - String json = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Saurav Kumar\",\n \"email\" : \"Saurav.kumar@example.com\",\n \"contact\" : \"+919000000000\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\" : [],\n \"created_at \": 1234567890\n}\n"; + String mockedResponseJson = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Saurav Kumar\",\n \"email\" : \"Saurav.kumar@example.com\",\n \"contact\" : \"+919000000000\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\" : [],\n \"created_at \": 1234567890\n}\n"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Customer fetch = customerClient.fetch(CUSTOMER_ID); assertNotNull(fetch); assertEquals(CUSTOMER_ID,fetch.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Details of all the customers can be retrieved. + * @throws RazorpayException + */ @Test public void fetchAll() throws RazorpayException { - String json = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"cust_1Aa00000000001\",\n \"entity\":\"customer\",\n \"name\":\"Gaurav Kumar\",\n \"email\":\"gaurav.kumar@example.com\",\n \"contact\":\"9876543210\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\":{\n \"note_key_1\":\"September\",\n \"note_key_2\":\"Make it so.\"\n },\n \"created_at \":1234567890\n }\n ]\n}"; + String mockedResponseJson = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"cust_1Aa00000000001\",\n \"entity\":\"customer\",\n \"name\":\"Gaurav Kumar\",\n \"email\":\"gaurav.kumar@example.com\",\n \"contact\":\"9876543210\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\":{\n \"note_key_1\":\"September\",\n \"note_key_2\":\"Make it so.\"\n },\n \"created_at \":1234567890\n }\n ]\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = customerClient.fetchAll(); assertNotNull(fetch); assertEquals(true,fetch.get(0).has("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Update customer details using customer id with object of that properties + * @throws RazorpayException + */ @Test public void edit() throws RazorpayException { JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": 9000000000\n}"); - String json = "{\n \"id\": \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": \"9000000000\",\n \"gstin\": null,\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at\": 1582033731\n}"; + String mockedResponseJson = "{\n \"id\": \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": \"9000000000\",\n \"gstin\": null,\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at\": 1582033731\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Customer fetch = customerClient.edit(CUSTOMER_ID,request); assertNotNull(fetch); assertEquals(CUSTOMER_ID,fetch.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve all tokens details. + * @throws RazorpayException + */ @Test public void fetchTokens() throws RazorpayException{ - String json = "{\n \"id\": \"token_Hxe0skTXLeg9pF\",\n \"entity\": \"token\",\n \"token\": \"F85BgXnGVwcuqV\",\n \"bank\": null,\n \"wallet\": null,\n \"method\": \"card\",\n \"card\": {\n \"entity\": \"card\",\n \"name\": \"ankit\",\n \"last4\": \"5449\",\n \"network\": \"MasterCard\",\n \"type\": \"credit\",\n \"issuer\": \"UTIB\",\n \"international\": false,\n \"emi\": false,\n \"sub_type\": \"consumer\",\n \"expiry_month\": 12,\n \"expiry_year\": 2024,\n \"flows\": {\n \"recurring\": true\n }\n },\n \"recurring\": true,\n \"auth_type\": null,\n \"mrn\": null,\n \"used_at\": 1632976165,\n \"created_at\": 1631687852,\n \"expired_at\": 1634215992,\n \"dcc_enabled\": false\n}"; + String mockedResponseJson = "{\n \"id\": \"token_Hxe0skTXLeg9pF\",\n \"entity\": \"token\",\n \"token\": \"F85BgXnGVwcuqV\",\n \"bank\": null,\n \"wallet\": null,\n \"method\": \"card\",\n \"card\": {\n \"entity\": \"card\",\n \"name\": \"ankit\",\n \"last4\": \"5449\",\n \"network\": \"MasterCard\",\n \"type\": \"credit\",\n \"issuer\": \"UTIB\",\n \"international\": false,\n \"emi\": false,\n \"sub_type\": \"consumer\",\n \"expiry_month\": 12,\n \"expiry_year\": 2024,\n \"flows\": {\n \"recurring\": true\n }\n },\n \"recurring\": true,\n \"auth_type\": null,\n \"mrn\": null,\n \"used_at\": 1632976165,\n \"created_at\": 1631687852,\n \"expired_at\": 1634215992,\n \"dcc_enabled\": false\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Token fetch = customerClient.fetchToken(CUSTOMER_ID,TOKEN_ID); assertNotNull(fetch); assertEquals(TOKEN_ID,fetch.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve tokens details using token id. + * @throws RazorpayException + */ @Test public void fetchToken() throws RazorpayException{ - String json = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"token_Hxe0skTXLeg9pF\",\n \"entity\":\"token\",\n \"token\":\"2JPRk664pZHUWG\",\n \"bank\":null,\n \"wallet\":null,\n \"method\":\"card\",\n \"card\":{\n \"entity\":\"card\",\n \"name\":\"Gaurav Kumar\",\n \"last4\":\"8950\",\n \"network\":\"Visa\",\n \"type\":\"credit\",\n \"issuer\":\"STCB\",\n \"international\":false,\n \"emi\":false,\n \"sub_type\":\"consumer\",\n \"expiry_month\":12,\n \"expiry_year\":2021,\n \"flows\":{\n \"otp\":true,\n \"recurring\":true\n }\n },\n \"recurring\":true,\n \"recurring_details\":{\n \"status\":\"confirmed\",\n \"failure_reason\":null\n },\n \"auth_type\":null,\n \"mrn\":null,\n \"used_at\":1629779657,\n \"created_at\":1629779657,\n \"expired_at\":1640975399,\n \"dcc_enabled\":false,\n \"billing_address\":null\n }\n ]\n}"; + String mockedResponseJson = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"token_Hxe0skTXLeg9pF\",\n \"entity\":\"token\",\n \"token\":\"2JPRk664pZHUWG\",\n \"bank\":null,\n \"wallet\":null,\n \"method\":\"card\",\n \"card\":{\n \"entity\":\"card\",\n \"name\":\"Gaurav Kumar\",\n \"last4\":\"8950\",\n \"network\":\"Visa\",\n \"type\":\"credit\",\n \"issuer\":\"STCB\",\n \"international\":false,\n \"emi\":false,\n \"sub_type\":\"consumer\",\n \"expiry_month\":12,\n \"expiry_year\":2021,\n \"flows\":{\n \"otp\":true,\n \"recurring\":true\n }\n },\n \"recurring\":true,\n \"recurring_details\":{\n \"status\":\"confirmed\",\n \"failure_reason\":null\n },\n \"auth_type\":null,\n \"mrn\":null,\n \"used_at\":1629779657,\n \"created_at\":1629779657,\n \"expired_at\":1640975399,\n \"dcc_enabled\":false,\n \"billing_address\":null\n }\n ]\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = customerClient.fetchTokens(CUSTOMER_ID); assertNotNull(fetch); assertEquals(true,fetch.get(0).has("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From b8d07db07586c7a37f66b11ff7ad71325161b984 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 12:58:05 +0530 Subject: [PATCH 38/78] add javadoc --- .../com/razorpay/FundAccountClientTest.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/razorpay/FundAccountClientTest.java b/src/test/java/com/razorpay/FundAccountClientTest.java index fb439d06..f635e283 100644 --- a/src/test/java/com/razorpay/FundAccountClientTest.java +++ b/src/test/java/com/razorpay/FundAccountClientTest.java @@ -14,34 +14,42 @@ public class FundAccountClientTest extends BaseTest{ protected FundAccountClient fundAccountClient = new FundAccountClient(TEST_SECRET_KEY); private static final String FUNDACCOUNT_ID = "fa_Aa00000000001"; - + + /** + * Fund account is created using the customer and item details. + * @throws RazorpayException + */ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject("{\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\"\n }\n}"); - String json = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + String mockedResponseJson = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); FundAccount fundaccount = fundAccountClient.create(request); assertNotNull(fundaccount); assertEquals(FUNDACCOUNT_ID,fundaccount.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } - + + /** + * Retrieve all fund account of respective customer using customer id. + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { - String json = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + String mockedResponseJson = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); FundAccount fetch = fundAccountClient.fetch(FUNDACCOUNT_ID); assertNotNull(fetch); assertEquals(FUNDACCOUNT_ID,fetch.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From 5074a446e92de85739af7bb19d3fa801d8e55a94 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 13:29:41 +0530 Subject: [PATCH 39/78] add javadoc & exception --- .../java/com/razorpay/ItemClientTest.java | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/razorpay/ItemClientTest.java b/src/test/java/com/razorpay/ItemClientTest.java index 57079e42..6db4bf59 100644 --- a/src/test/java/com/razorpay/ItemClientTest.java +++ b/src/test/java/com/razorpay/ItemClientTest.java @@ -12,68 +12,96 @@ public class ItemClientTest extends BaseTest{ @InjectMocks - private ItemClient itemClient = new ItemClient("test"); + protected ItemClient itemClient = new ItemClient("test"); public static final String ITEM_ID = "item_IJol6jPh1ummTK"; - + + /** + * Create item with basic details such as name and amount details + * @throws RazorpayException + */ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject("{\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"); - String json = "{\n \"entity\" : \"item\",\n \"id\": \"item_IJol6jPh1ummTK\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + String mockedResponseJson = "{\n \"entity\" : \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Item item = itemClient.create(request); assertNotNull(item); assertEquals(ITEM_ID,item.get("id")); + assertEquals("item",item.get("entity")); + assertTrue(item.has("active")); + assertTrue(item.has("name")); + assertTrue(item.has("name")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve the item details using item id. + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { - String json = "{\n \"entity\": \"item\",\n \"id\": \"item_7Oxp4hmm6T4SCn\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + String mockedResponseJson = "{\n \"entity\": \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Item fetch = itemClient.fetch(ITEM_ID); assertNotNull(fetch); + assertEquals(ITEM_ID,fetch.get("id")); assertEquals("item",fetch.get("entity")); + assertTrue(fetch.has("amount")); + assertTrue(fetch.has("currency")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } - + + /** + * Details of all the items can be retrieved. + * @throws RazorpayException + */ @Test public void fetchAll() throws RazorpayException{ - String json = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"item_7OxoGnoxCuUKbo\",\n \"entity\" : \"item\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": null,\n \"amount\": 20000,\n \"currency\": \"INR\"\n }\n ]\n}"; + String mockedResponseJson = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"item_7OxoGnoxCuUKbo\",\n \"entity\" : \"item\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": null,\n \"amount\": 20000,\n \"currency\": \"INR\"\n }\n ]\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = itemClient.fetchAll(); assertNotNull(fetch); - assertEquals(true,fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("active")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } - + + /** + * Update an item details using item id with object of that properties + * @throws RazorpayException + */ @Test public void edit() throws RazorpayException{ JSONObject request = new JSONObject("{\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :).\",\n \"amount\": 20000,\n \"currency\": \"INR\",\n \"active\": true\n}"); - String json = "{\n \"entity\" : \"item\",\n \"id\": \"item_IJol6jPh1ummTK\",\n \"active\": true,\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :)\",\n \"amount\": 15000,\n \"currency\": \"INR\"\n}"; + String mockedResponseJson = "{\n \"entity\" : \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :)\",\n \"amount\": 15000,\n \"currency\": \"INR\"\n}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Item item = itemClient.edit(ITEM_ID,request); assertNotNull(item); assertEquals(ITEM_ID,item.get("id")); + assertEquals("item",item.get("entity")); + assertTrue(item.has("amount")); + assertTrue(item.has("description")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From e380f145c681990a0b00ac94b363ef949da5d881 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 13:52:59 +0530 Subject: [PATCH 40/78] add javadoc and exception --- .../java/com/razorpay/OrderClientTest.java | 65 ++++++++++++++----- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java index b0f97c29..2fec1a76 100644 --- a/src/test/java/com/razorpay/OrderClientTest.java +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -16,75 +16,106 @@ public class OrderClientTest extends BaseTest{ private static final String ORDER_ID = "order_EKwxwAgItmmXdp"; + /** + * Create order with basic details such as currency and amount details + * @throws RazorpayException + */ @Test public void create() throws RazorpayException { JSONObject request = new JSONObject("{amount:50000,currency:\"INR\",receipt:\"receipt#1\",notes:{key1:\"value3\",key2:\"value2\"}}"); - String json = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":50000,\"amount_paid\":0,\"amount_due\":50000,\"currency\":\"INR\",\"receipt\":\"receipt#1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582628071}"; + String mockedResponseJson = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":50000,\"amount_paid\":0,\"amount_due\":50000,\"currency\":\"INR\",\"receipt\":\"receipt#1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582628071}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Order fetch = orderClient.create(request); assertNotNull(fetch); assertEquals(ORDER_ID,fetch.get("id")); + assertEquals("order",fetch.get("entity")); + assertTrue(fetch.has("amount")); + assertTrue(fetch.has("amount_paid")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Details of all the order can be retrieved. + * @throws RazorpayException + */ @Test public void fetchAll() throws RazorpayException{ - String json = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"order_EKzX2WiEWbMxmx\",\"entity\":\"order\",\"amount\":1234,\"amount_paid\":0,\"amount_due\":1234,\"currency\":\"INR\",\"receipt\":\"ReceiptNo.1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582637108}]}"; + String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"order_EKzX2WiEWbMxmx\",\"entity\":\"order\",\"amount\":1234,\"amount_paid\":0,\"amount_due\":1234,\"currency\":\"INR\",\"receipt\":\"ReceiptNo.1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582637108}]}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = orderClient.fetchAll(); assertNotNull(fetch); - assertEquals(true,fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("amount_paid")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve the order details using order id. + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException{ - String json = "{\"id\":\"order_DaaS6LOUAASb7Y\",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"status\":\"attempted\",\"attempts\":1,\"notes\":[],\"created_at\":1572505143}"; + String mockedResponseJson = "{\"id\":"+ORDER_ID+",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"status\":\"attempted\",\"attempts\":1,\"notes\":[],\"created_at\":1572505143}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Order fetch = orderClient.fetch(ORDER_ID); assertNotNull(fetch); assertEquals(true,fetch.has("id")); + assertTrue(fetch.has("entity")); + assertTrue(fetch.has("amount")); + assertTrue(fetch.has("amount_paid")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Retrieve the payment details of respective customer using payment id. + * @throws RazorpayException + */ @Test public void fetchPayments() throws RazorpayException{ - String json = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"pay_DaaSOvhgcOfzgR\",\"entity\":\"payment\",\"amount\":2200,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_DaaS6LOUAASb7Y\",\"invoice_id\":null,\"international\":false,\"method\":\"card\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"Beansineveryimaginableflavour\",\"card_id\":\"card_DZon6fd8J3IcA2\",\"bank\":null,\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999988\",\"notes\":[],\"fee\":44,\"tax\":0,\"error_code\":null,\"error_description\":null,\"created_at\":1572505160}]}"; + String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"pay_DaaSOvhgcOfzgR\",\"entity\":\"payment\",\"amount\":2200,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_DaaS6LOUAASb7Y\",\"invoice_id\":null,\"international\":false,\"method\":\"card\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"Beansineveryimaginableflavour\",\"card_id\":\"card_DZon6fd8J3IcA2\",\"bank\":null,\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999988\",\"notes\":[],\"fee\":44,\"tax\":0,\"error_code\":null,\"error_description\":null,\"created_at\":1572505160}]}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); List fetch = orderClient.fetchPayments(ORDER_ID); assertNotNull(fetch); - assertEquals(true,fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("currency")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } + /** + * Update an order of respective customer using order id with object of that properties + * @throws RazorpayException + */ @Test public void edit() throws RazorpayException { JSONObject request = new JSONObject("{\"notes\":{\"key1\":\"value3\",\"key2\":\"value2\"}}"); - String json = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"offer_id\":null,\"status\":\"attempted\",\"attempts\":1,\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"},\"created_at\":1572505143}"; + String mockedResponseJson = "{\"id\":"+ORDER_ID+",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"offer_id\":null,\"status\":\"attempted\",\"attempts\":1,\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"},\"created_at\":1572505143}"; try { - mockResponseFromExternalClient(json); + mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); Order fetch = orderClient.edit(ORDER_ID,request); assertNotNull(fetch); assertEquals(ORDER_ID,fetch.get("id")); + assertEquals(ORDER_ID,fetch.get("id")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } } \ No newline at end of file From 15829808e9c11c96f7c7a4c331baa0ecae71ffc8 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 16:39:19 +0530 Subject: [PATCH 41/78] add java docs --- .../java/com/razorpay/PaymentClientTest.java | 61 +++++++++++-------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index d790be95..16ec208c 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -17,8 +17,9 @@ public class PaymentClientTest extends BaseTest{ private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; private static final String REFUND_ID = "rfnd_FP8QHiV938haTz"; + /** - * Fetch a payment + * Retrieve payment details of respective customer using payment id. * @throws RazorpayException */ @Test @@ -32,13 +33,14 @@ public void fetch() throws RazorpayException{ assertNotNull(fetch); assertEquals(PAYMENT_ID,fetch.get("id")); assertTrue(fetch.has("status")); + assertTrue(fetch.has("currency")); } catch (IOException e) { assertTrue(false); } } /** - * Fetch Multiple Payments + * Details of all the payments can be retrieved. * @throws RazorpayException */ @Test @@ -59,7 +61,8 @@ public void fetchAll() throws RazorpayException{ } /** - * Capture payment + * Capture a payment that verifies the amount deducted from the customer + * is same as the amount paid by the customer on website * @throws RazorpayException */ @Test @@ -80,26 +83,12 @@ public void capture() throws RazorpayException{ } } + /** + * Create a refunds to respective customers + * @throws RazorpayException + */ @Test - public void refund() throws RazorpayException{ - - JSONObject request = new JSONObject("{\"amount\":\"100\",\"speed\":\"normal\",\"notes\":{\"notes_key_1\":\"BeammeupScotty.\",\"notes_key_2\":\"Engage\"},\"receipt\":\"ReceiptNo.31\"}"); - String mockedResponseJson = "{\"id\":\"rfnd_FP8QHiV938haTz\",\"entity\":\"refund\",\"amount\":500100,\"receipt\":\"ReceiptNo.31\",\"currency\":\"INR\",\"payment_id\":\"pay_FCXKPFtYfPXJPy\",\"notes\":[],\"acquirer_data\":{\"arn\":null},\"created_at\":1597078866,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\"}"; - try { - mockResponseFromExternalClient(mockedResponseJson); - mockResponseHTTPCodeFromExternalClient(200); - Refund fetch = paymentClient.refund(PAYMENT_ID,request); - assertNotNull(fetch); - assertEquals("rfnd_FP8QHiV938haTz",fetch.get("id")); - assertTrue(fetch.has("entity")); - assertTrue(fetch.has("amount")); - } catch (IOException e) { - assertTrue(false); - } - } - - @Test - public void testRefund() throws Exception{ + public void refund() throws Exception{ JSONObject request = new JSONObject("{\"amount\":\"100\",\"speed\":\"normal\",\"notes\":{\"notes_key_1\":\"BeammeupScotty.\",\"notes_key_2\":\"Engage\"},\"receipt\":\"ReceiptNo.31\"}"); String mockedResponseJson = "{\"id\":"+REFUND_ID+",\"entity\":\"refund\",\"amount\":500100,\"receipt\":\"ReceiptNo.31\",\"currency\":\"INR\",\"payment_id\":\"pay_FCXKPFtYfPXJPy\",\"notes\":[],\"acquirer_data\":{\"arn\":null},\"created_at\":1597078866,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\"}"; try { @@ -115,7 +104,10 @@ public void testRefund() throws Exception{ } } - + /** + * Retrieve all the refunds for a payment by default only last 10 refunds returned. + * @throws RazorpayException + */ @Test public void FetchAllRefunds() throws RazorpayException{ JSONObject request = new JSONObject("{}"); @@ -134,7 +126,11 @@ public void FetchAllRefunds() throws RazorpayException{ } } - + /** + * Create transfer from payments using payment id and with + * object of that properties + * @throws RazorpayException + */ @Test public void transfers() throws RazorpayException{ JSONObject request = new JSONObject("{\"transfers\":[{\"account\":\"acc_CPRsN1LkFccllA\",\"amount\":100,\"currency\":\"INR\",\"notes\":{\"name\":\"GauravKumar\",\"roll_no\":\"IEC2011025\"},\"linked_account_notes\":[\"roll_no\"],\"on_hold\":true,\"on_hold_until\":1671222870}]}"); @@ -153,6 +149,10 @@ public void transfers() throws RazorpayException{ } } + /** + * Details of all the transfers payment can be retrieved. + * @throws RazorpayException + */ @Test public void fetchAllTransfers() throws RazorpayException{ @@ -162,14 +162,19 @@ public void fetchAllTransfers() throws RazorpayException{ mockResponseHTTPCodeFromExternalClient(200); List fetch = paymentClient.fetchAllTransfers(PAYMENT_ID); assertNotNull(fetch); - //assertEquals("bt_Di5iqCElVyRlCb",fetch.get("id")); assertTrue(fetch.get(0).has("source")); assertTrue(fetch.get(0).has("recipient")); + assertTrue(fetch.get(0).has("amount")); } catch (IOException e) { assertTrue(false); } } + + /** + * Retrieve transfers for a payment using payment id + * @throws RazorpayException + */ @Test public void fetchBankTransfers() throws RazorpayException{ @@ -188,7 +193,11 @@ public void fetchBankTransfers() throws RazorpayException{ assertTrue(false); } } - + + /** + * Create a payment of customer after order is created (Server to server integration) + * @throws RazorpayException + */ @Test public void createJsonPayment() throws RazorpayException { From a0a49812cb56d9341658dd4d27ee2bececa6c7fe Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 17:40:45 +0530 Subject: [PATCH 42/78] implement paymentlink api with test cases --- src/main/java/com/razorpay/Constants.java | 6 + .../com/razorpay/EntityNameURLMapping.java | 3 +- src/main/java/com/razorpay/PaymentLink.java | 10 ++ .../java/com/razorpay/PaymentLinkClient.java | 34 +++++ .../java/com/razorpay/RazorpayClient.java | 2 + .../java/com/razorpay/PaymentLinkTest.java | 131 ++++++++++++++++++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/razorpay/PaymentLink.java create mode 100644 src/main/java/com/razorpay/PaymentLinkClient.java create mode 100644 src/test/java/com/razorpay/PaymentLinkTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..c0c4eb01 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -23,6 +23,12 @@ public class Constants { static final String PAYMENT_TRANSFER_GET = "payments/%s/transfers"; static final String PAYMENT_BANK_TRANSFER_GET = "payments/%s/bank_transfer"; + static final String PAYMENTLINK_CREATE = "payment_links"; + static final String PAYMENTLINK_GET = "payment_links/%s"; + static final String PAYMENTLINK_EDIT = "payment_links/%s"; + static final String PAYMENTLINK_CANCEL = "payment_links/%s/cancel"; + static final String PAYMENTLINK_NOTIFYBY = "payment_links/%s/notify_by/%s"; + static final String PAYMENT_REFUND_LIST = "payments/%s/refunds"; static final String PAYMENT_REFUND_GET = "payments/%s/refunds/%s"; diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java index 0cad70b2..9d6e8850 100644 --- a/src/main/java/com/razorpay/EntityNameURLMapping.java +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -11,7 +11,8 @@ public enum EntityNameURLMapping { INVOICES("invoice"), - PAYMENTS("payment"); + PAYMENTS("payment"), + PAYMENT_LINKS("payment_link"); private String entity; diff --git a/src/main/java/com/razorpay/PaymentLink.java b/src/main/java/com/razorpay/PaymentLink.java new file mode 100644 index 00000000..4584791d --- /dev/null +++ b/src/main/java/com/razorpay/PaymentLink.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class PaymentLink extends Entity { + + public PaymentLink(JSONObject jsonObject) { + super(jsonObject); + } +} diff --git a/src/main/java/com/razorpay/PaymentLinkClient.java b/src/main/java/com/razorpay/PaymentLinkClient.java new file mode 100644 index 00000000..dba73505 --- /dev/null +++ b/src/main/java/com/razorpay/PaymentLinkClient.java @@ -0,0 +1,34 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +import okhttp3.Response; + +public class PaymentLinkClient extends ApiClient { + + PaymentLinkClient(String auth) { + super(auth); + } + + public PaymentLink create(JSONObject request) throws RazorpayException { + return post(Constants.PAYMENTLINK_CREATE, request); + } + + public PaymentLink fetch(String id) throws RazorpayException { + return get(String.format(Constants.PAYMENTLINK_GET, id), null); + } + + public PaymentLink cancel(String id) throws RazorpayException { + return post(String.format(Constants.PAYMENTLINK_CANCEL, id), null); + } + + public PaymentLink edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.PAYMENTLINK_EDIT, id), request); + } + + public PaymentLink notifyBy(String id, String medium) throws RazorpayException { + return post(String.format(Constants.PAYMENTLINK_NOTIFYBY, id, medium), null); + } +} diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index abea7d3b..0eadbc2b 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -16,6 +16,7 @@ public class RazorpayClient { public SubscriptionClient Subscriptions; public AddonClient Addons; public PlanClient Plans; + public PaymentLinkClient PaymentLink; public VirtualAccountClient VirtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -35,6 +36,7 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R Subscriptions = new SubscriptionClient(auth); Addons = new AddonClient(auth); Plans = new PlanClient(auth); + PaymentLink = new PaymentLinkClient(auth); VirtualAccounts = new VirtualAccountClient(auth); } diff --git a/src/test/java/com/razorpay/PaymentLinkTest.java b/src/test/java/com/razorpay/PaymentLinkTest.java new file mode 100644 index 00000000..907900f0 --- /dev/null +++ b/src/test/java/com/razorpay/PaymentLinkTest.java @@ -0,0 +1,131 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; + +import static org.junit.Assert.*; + +public class PaymentLinkTest extends BaseTest{ + + @InjectMocks + protected PaymentLinkClient paymentLinkClient = new PaymentLinkClient(TEST_SECRET_KEY); + + private static final String PAYMENTLINK_ID = "plink_ETbyWrRHW2oXVt"; + + /** + * Create basic or customized Payment Links + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + + JSONObject request = new JSONObject("{\"amount\":500,\"currency\":\"INR\",\"accept_partial\":true,\"first_min_partial_amount\":100,\"description\":\"ForXYZpurpose\",\"customer\":{\"name\":\"GauravKumar\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\"},\"notify\":{\"sms\":true,\"email\":true},\"reminder_enable\":true,\"notes\":{\"policy_name\":\"JeevanBima\"},\"callback_url\":\"https://example-callback-url.com/\",\"callback_method\":\"get\"}"); + String mockedResponseJson = "{\"entity\":\"payment_link\",\"accept_partial\":false,\"amount\":1000,\"amount_paid\":0,\"cancelled_at\":0,\"created_at\":1584524459,\"currency\":\"INR\",\"customer\":{\"contact\":\"9912650835\",\"email\":\"gaurav.kumar@razorpay.com\",\"name\":\"GauravKumar\"},\"description\":\"Paymentforpolicyno#23456\",\"expire_by\":0,\"expired_at\":0,\"first_min_partial_amount\":0,\"id\":"+PAYMENTLINK_ID+",\"upi_link\":\"true\",\"notes\":{\"policy_name\":\"JeevanBima\"},\"payments\":null,\"reference_id\":\"#456\",\"reminder_enable\":true,\"reminders\":[],\"short_url\":\"https://rzp.io/i/AiGGmnh\",\"status\":\"created\",\"updated_at\":null,\"user_id\":\"API\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + PaymentLink fetch = paymentLinkClient.create(request); + assertNotNull(fetch); + assertEquals("payment_link",fetch.get("entity")); + assertEquals(PAYMENTLINK_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("amount_paid")); + assertTrue(fetch.has("upi_link")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve the payment-link details using payment-link id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + + String mockedResponseJson = "{\"entity\":\"payment_link\",\"accept_partial\":false,\"amount\":1000,\"amount_paid\":0,\"cancelled_at\":0,\"created_at\":1584524459,\"currency\":\"INR\",\"customer\":{\"contact\":\"9912650835\",\"email\":\"gaurav.kumar@razorpay.com\",\"name\":\"GauravKumar\"},\"description\":\"Paymentforpolicyno#23456\",\"expire_by\":0,\"expired_at\":0,\"first_min_partial_amount\":0,\"id\":"+PAYMENTLINK_ID+",\"upi_link\":\"true\",\"notes\":{\"policy_name\":\"JeevanBima\"},\"payments\":null,\"reference_id\":\"#456\",\"reminder_enable\":true,\"reminders\":[],\"short_url\":\"https://rzp.io/i/AiGGmnh\",\"status\":\"created\",\"updated_at\":null,\"user_id\":\"API\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + PaymentLink fetch = paymentLinkClient.fetch(PAYMENTLINK_ID); + assertNotNull(fetch); + assertEquals("payment_link",fetch.get("entity")); + assertEquals(PAYMENTLINK_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("amount_paid")); + assertTrue(fetch.has("upi_link")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Cancel the payment-link using payment-link id. + * @throws RazorpayException + */ + @Test + public void cancel() throws RazorpayException{ + + String mockedResponseJson = "{\"entity\":\"payment_link\",\"accept_partial\":true,\"amount\":1000,\"amount_paid\":0,\"callback_method\":\"get\",\"callback_url\":\"https://example-callback-url.com/\",\"cancelled_at\":1591097270,\"created_at\":1591097057,\"currency\":\"INR\",\"customer\":{\"contact\":\"+919999999999\",\"email\":\"gaurav.kumar@example.com\",\"name\":\"GauravKumar\"},\"description\":\"Paymentforpolicyno#23456\",\"expire_by\":1691097057,\"expired_at\":0,\"first_min_partial_amount\":100,\"id\":"+PAYMENTLINK_ID+",\"notes\":{\"policy_name\":\"JeevanBima\"},\"notify\":{\"email\":true,\"sms\":true},\"payments\":[],\"reference_id\":\"TS1989\",\"reminder_enable\":true,\"reminders\":{\"status\":\"failed\"},\"short_url\":\"https://rzp.io/i/nxrHnLJ\",\"source\":\"\",\"source_id\":\"\",\"status\":\"cancelled\",\"updated_at\":1591097270,\"user_id\":\"\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + PaymentLink fetch = paymentLinkClient.cancel(PAYMENTLINK_ID); + assertNotNull(fetch); + assertEquals("payment_link",fetch.get("entity")); + assertEquals(PAYMENTLINK_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("callback_method")); + assertTrue(fetch.has("cancelled_at")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Send or resend notifications to customer via email and SMS + * using payment-link id + * @throws RazorpayException + */ + @Test + public void notifyBy() throws RazorpayException{ + + String mockedResponseJson = "{\"entity\":\"payment_link\",\"success\":true}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + PaymentLink fetch = paymentLinkClient.notifyBy(PAYMENTLINK_ID,"sms"); + assertNotNull(fetch); + assertEquals("payment_link",fetch.get("entity")); + assertTrue(fetch.get("success")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Update an payment-link of using invoice payment-link id with object of that properties + * @throws RazorpayException + */ + @Test + public void edit() throws RazorpayException{ + JSONObject request = new JSONObject("{\"reference_id\":\"TS35\",\"expire_by\":1653347540,\"reminder_enable\":false,\"notes\":{\"policy_name\":\"JeevanSaral\"}}"); + String mockedResponseJson = "{\"entity\":\"payment_link\",\"accept_partial\":false,\"amount\":100,\"amount_paid\":100,\"cancelled_at\":0,\"created_at\":1602522293,\"currency\":\"INR\",\"customer\":{\"contact\":\"9999999999\",\"email\":\"gaurav.kumar@razorpay.com\"},\"description\":\"PaymentforAcmeInc\",\"expire_by\":1653347540,\"expired_at\":0,\"first_min_partial_amount\":0,\"id\":\"plink_Fo48rl281ENAg9\",\"notes\":{\"policy_name\":\"JeevanSaral\"},\"notify\":{\"email\":true,\"sms\":true},\"order_id\":\"order_Fo491cL6NGAjkI\",\"payments\":[{\"amount\":100,\"created_at\":1602522351,\"method\":\"upi\",\"payment_id\":\"pay_Fo49sHbQ78PCMI\",\"status\":\"captured\"}],\"reference_id\":\"TS35\",\"reminder_enable\":false,\"reminders\":[],\"short_url\":\"https://rzp.io/i/XQiMe4w\",\"status\":\"paid\",\"updated_at\":1602523645,\"upi_link\":true,\"user_id\":\"FmjfFPCOUOAcSH\"}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + PaymentLink fetch = paymentLinkClient.edit(PAYMENTLINK_ID,request); + assertNotNull(fetch); + assertEquals("plink_Fo48rl281ENAg9",fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("accept_partial")); + assertTrue(fetch.has("order_id")); + assertTrue(fetch.has("payments")); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 260c01f966cb609a2c2608e9b58c5cfead743cb7 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 14 Feb 2022 21:02:17 +0530 Subject: [PATCH 43/78] implement paymentlink api with test cases --- src/main/java/com/razorpay/ApiClient.java | 29 +++++++++++++++++-- src/main/java/com/razorpay/Constants.java | 1 + .../java/com/razorpay/PaymentLinkClient.java | 8 +++++ .../java/com/razorpay/PaymentLinkTest.java | 22 ++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..25a2f5b6 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -82,7 +82,17 @@ private ArrayList parseCollectionResponse(JSONObject jsonO ArrayList modelList = new ArrayList(); if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { - JSONArray jsonArray = jsonObject.getJSONArray("items"); + + JSONArray jsonArray = new JSONArray(); + + if(jsonObject.has("items")) { + jsonArray = jsonObject.getJSONArray("items"); + } + + if(jsonObject.has("payment_links")) { + jsonArray = jsonObject.getJSONArray("payment_links"); + } + try { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); @@ -124,7 +134,7 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { String entityName = getEntityNameFromURL(response.request().url()); responseJson.put("entity",entityName); @@ -153,7 +163,20 @@ ArrayList processCollectionResponse(Response response) } catch (IOException e) { throw new RazorpayException(e.getMessage()); } - + + if(responseJson.has("payment_links")){ + responseJson.put("entity","collection"); + JSONArray jsonArray = responseJson.getJSONArray("payment_links"); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + if(!jsonObj.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + jsonObj.put("entity",entityName); + } + + } + } + if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { return parseCollectionResponse(responseJson); } diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index c0c4eb01..9a49e926 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -24,6 +24,7 @@ public class Constants { static final String PAYMENT_BANK_TRANSFER_GET = "payments/%s/bank_transfer"; static final String PAYMENTLINK_CREATE = "payment_links"; + static final String PAYMENTLINK_LIST = "payment_links"; static final String PAYMENTLINK_GET = "payment_links/%s"; static final String PAYMENTLINK_EDIT = "payment_links/%s"; static final String PAYMENTLINK_CANCEL = "payment_links/%s/cancel"; diff --git a/src/main/java/com/razorpay/PaymentLinkClient.java b/src/main/java/com/razorpay/PaymentLinkClient.java index dba73505..f09a7c01 100644 --- a/src/main/java/com/razorpay/PaymentLinkClient.java +++ b/src/main/java/com/razorpay/PaymentLinkClient.java @@ -19,6 +19,14 @@ public PaymentLink create(JSONObject request) throws RazorpayException { public PaymentLink fetch(String id) throws RazorpayException { return get(String.format(Constants.PAYMENTLINK_GET, id), null); } + + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.PAYMENTLINK_LIST, request); + } public PaymentLink cancel(String id) throws RazorpayException { return post(String.format(Constants.PAYMENTLINK_CANCEL, id), null); diff --git a/src/test/java/com/razorpay/PaymentLinkTest.java b/src/test/java/com/razorpay/PaymentLinkTest.java index 907900f0..78345f7b 100644 --- a/src/test/java/com/razorpay/PaymentLinkTest.java +++ b/src/test/java/com/razorpay/PaymentLinkTest.java @@ -5,6 +5,7 @@ import org.mockito.InjectMocks; import java.io.IOException; +import java.util.List; import static org.junit.Assert.*; @@ -128,4 +129,25 @@ public void edit() throws RazorpayException{ assertTrue(false); } } + + /** + * Details of all the payment-links can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + String mockedResponseJson = "{\"payment_links\":[{\"cancelled_at\":1644517434,\"reminders\":{\"status\":\"in_progress\"},\"amount_paid\":0,\"notes\":{\"policy_name\":\"JeevanBima\"},\"reference_id\":\"\",\"payments\":[],\"created_at\":1644517182,\"description\":\"ForXYZpurpose\",\"expired_at\":0,\"notify\":{\"sms\":true,\"email\":true},\"short_url\":\"https://rzp.io/i/Yyzzizh\",\"callback_url\":\"https://example-callback-url.com/\",\"updated_at\":1644517434,\"upi_link\":false,\"accept_partial\":true,\"currency\":\"INR\",\"id\":\"plink_IuP2QzddqlPG2A\",\"callback_method\":\"get\",\"expire_by\":0,\"first_min_partial_amount\":100,\"amount\":500,\"reminder_enable\":true,\"user_id\":\"\",\"entity\":\"payment_link\",\"customer\":{\"contact\":\"+919999999999\",\"name\":\"GauravKumar\",\"email\":\"gaurav.kumar@example.com\"},\"status\":\"cancelled\"},{\"cancelled_at\":0,\"reminders\":{\"status\":\"in_progress\"},\"amount_paid\":0,\"notes\":{\"policy_name\":\"JeevanBima\"},\"reference_id\":\"\",\"payments\":[],\"created_at\":1643024367,\"description\":\"ForXYZpurpose\",\"expired_at\":0,\"notify\":{\"sms\":true,\"email\":true},\"short_url\":\"https://rzp.io/i/zdFAncL\",\"callback_url\":\"https://example-callback-url.com/\",\"updated_at\":1643024367,\"upi_link\":false,\"accept_partial\":true,\"currency\":\"INR\",\"id\":\"plink_InZ8aqDn9IfpAj\",\"callback_method\":\"get\",\"expire_by\":0,\"first_min_partial_amount\":100,\"amount\":500,\"reminder_enable\":true,\"user_id\":\"\",\"entity\":\"payment_link\",\"customer\":{\"name\":\"GauravKumar\",\"email\":\"gaurav.kumar@example.com\"},\"status\":\"created\"},]}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = paymentLinkClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("cancelled_at")); + assertTrue(fetch.get(0).has("reminders")); + assertTrue(fetch.get(0).has("created_at")); + assertTrue(fetch.get(0).has("currency")); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file From e8a81f49948f9870ab7109cf73151bf4fa988369 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 15 Feb 2022 09:53:24 +0530 Subject: [PATCH 44/78] updated utils with test cases --- src/main/java/com/razorpay/Utils.java | 20 +++++++ src/test/java/com/razorpay/UtilsTest.java | 67 +++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/test/java/com/razorpay/UtilsTest.java diff --git a/src/main/java/com/razorpay/Utils.java b/src/main/java/com/razorpay/Utils.java index 72345bc7..b6d28c68 100644 --- a/src/main/java/com/razorpay/Utils.java +++ b/src/main/java/com/razorpay/Utils.java @@ -17,6 +17,26 @@ public static boolean verifyPaymentSignature(JSONObject attributes, String apiSe return verifySignature(payload, expectedSignature, apiSecret); } + public static boolean verifySubscription(JSONObject attributes, String apiSecret) + throws RazorpayException { + String expectedSignature = attributes.getString("razorpay_signature"); + String subscriptionId = attributes.getString("razorpay_subscription_id"); + String paymentId = attributes.getString("razorpay_payment_id"); + String payload = paymentId + '|' + subscriptionId; + return verifySignature(payload, expectedSignature, apiSecret); + } + + public static boolean verifyPaymentLink(JSONObject attributes, String apiSecret) + throws RazorpayException { + String expectedSignature = attributes.getString("razorpay_signature"); + String paymentLinkStatus = attributes.getString("payment_link_status"); + String paymentLinkId = attributes.getString("payment_link_id"); + String paymentLinkRefId = attributes.getString("payment_link_reference_id"); + String paymentId = attributes.getString("razorpay_payment_id"); + String payload = paymentLinkId + '|' + paymentLinkRefId + '|' + paymentLinkStatus + '|' + paymentId; + return verifySignature(payload, expectedSignature, apiSecret); + } + public static boolean verifyWebhookSignature(String payload, String expectedSignature, String webhookSecret) throws RazorpayException { return verifySignature(payload, expectedSignature, webhookSecret); diff --git a/src/test/java/com/razorpay/UtilsTest.java b/src/test/java/com/razorpay/UtilsTest.java new file mode 100644 index 00000000..a1d83536 --- /dev/null +++ b/src/test/java/com/razorpay/UtilsTest.java @@ -0,0 +1,67 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class UtilsTest { + + + /** + * Verify razorpay payment signature + * @throws RazorpayException + */ + @Test + public void verifyPaymentSignature() throws RazorpayException{ + JSONObject options = new JSONObject(); + options.put("razorpay_order_id", "order_IEIaMR65cu6nz3"); + options.put("razorpay_payment_id", "pay_IH4NVgf4Dreq1l"); + options.put("razorpay_signature", "0d4e745a1838664ad6c9c9902212a32d627d68e917290b0ad5f08ff4561bc50f"); + + assertTrue(Utils.verifyPaymentSignature(options, "EnLs21M47BllR3X8PSFtjtbd")); + } + + /** + * Verify razorpay subscription + * @throws RazorpayException + */ + @Test + public void verifySubscription() throws RazorpayException{ + JSONObject options = new JSONObject(); + options.put("razorpay_subscription_id", "sub_ID6MOhgkcoHj9I"); + options.put("razorpay_payment_id", "pay_IDZNwZZFtnjyym"); + options.put("razorpay_signature", "601f383334975c714c91a7d97dd723eb56520318355863dcf3821c0d07a17693"); + + assertTrue(Utils.verifySubscription(options, "EnLs21M47BllR3X8PSFtjtbd")); + } + + /** + * Verify razorpay payment link signature + * @throws RazorpayException + */ + @Test + public void verifyPaymentLink() throws RazorpayException{ + JSONObject options = new JSONObject(); + options.put("payment_link_reference_id", "TSsd1989"); + options.put("razorpay_payment_id", "pay_IH3d0ara9bSsjQ"); + options.put("payment_link_status", "paid"); + options.put("payment_link_id", "plink_IH3cNucfVEgV68"); + options.put("razorpay_signature", "07ae18789e35093e51d0a491eb9922646f3f82773547e5b0f67ee3f2d3bf7d5b"); + + assertTrue(Utils.verifyPaymentLink(options, "EnLs21M47BllR3X8PSFtjtbd")); + } + + /** + * Verify razorpay webhook signature + * @throws RazorpayException + */ + @Test + public void verifyWebhookSignature() throws RazorpayException{ + String signature = "2fe04e22977002e6c7cb553adab8b460cb9e2a4970d5953cb27a8472752e3bbc"; + String payload = "{\"a\":1,\"b\":2,\"c\":{\"d\":3}}"; + String secret = "123456"; + assertTrue(Utils.verifyWebhookSignature(payload,signature, secret)); + } + +} \ No newline at end of file From 232a8b35692b908c514d817ffbe0c0229b753c7e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 11:36:02 +0530 Subject: [PATCH 45/78] remove e.printStackTrace --- src/test/java/com/razorpay/InvoiceClientTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index 7224a3a9..897e9708 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -102,7 +102,6 @@ public void cancel() throws RazorpayException { assertTrue(fetch.has("customer_details")); assertTrue(fetch.has("issued_at")); } catch (IOException e) { - e.printStackTrace(); assertTrue(false); } } From dd328fc31e8c35a5545631a2e76fe4edb808c44c Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 17:42:15 +0530 Subject: [PATCH 46/78] update qr --- src/main/java/com/razorpay/ApiClient.java | 3 +- src/main/java/com/razorpay/Constants.java | 6 +++ src/main/java/com/razorpay/QrCode.java | 10 +++++ src/main/java/com/razorpay/QrCodeClient.java | 39 +++++++++++++++++++ .../java/com/razorpay/RazorpayClient.java | 2 + 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/razorpay/QrCode.java create mode 100644 src/main/java/com/razorpay/QrCodeClient.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..c3ee5fde 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -79,8 +79,7 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa private ArrayList parseCollectionResponse(JSONObject jsonObject) throws RazorpayException { - - ArrayList modelList = new ArrayList(); + ArrayList modelList = new ArrayList(); if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { JSONArray jsonArray = jsonObject.getJSONArray("items"); try { diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..c9047c79 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -26,6 +26,12 @@ public class Constants { static final String PAYMENT_REFUND_LIST = "payments/%s/refunds"; static final String PAYMENT_REFUND_GET = "payments/%s/refunds/%s"; + static final String QRCODE_CREATE = "payments/qr_codes"; + static final String QRCODE_FETCH = "payments/qr_codes/%s"; + static final String QRCODE_CLOSE = "payments/qr_codes/%s/close"; + static final String QRCODE_LIST = "payments/qr_codes"; + static final String QRCODE_FETCH_PAYMENT = "payments"; + static final String REFUND_GET = "refunds/%s"; static final String REFUND_LIST = "refunds"; static final String REFUND_CREATE = "refunds"; diff --git a/src/main/java/com/razorpay/QrCode.java b/src/main/java/com/razorpay/QrCode.java new file mode 100644 index 00000000..fc37312e --- /dev/null +++ b/src/main/java/com/razorpay/QrCode.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class QrCode extends Entity { + + public QrCode(JSONObject jsonObject) { + super(jsonObject); + } +} diff --git a/src/main/java/com/razorpay/QrCodeClient.java b/src/main/java/com/razorpay/QrCodeClient.java new file mode 100644 index 00000000..0ccf9b02 --- /dev/null +++ b/src/main/java/com/razorpay/QrCodeClient.java @@ -0,0 +1,39 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +import okhttp3.Response; + +public class QrCodeClient extends ApiClient { + + QrCodeClient(String auth) { + super(auth); + } + + public QrCode create(JSONObject request) throws RazorpayException { + return post(Constants.QRCODE_CREATE, request); + } + + public QrCode fetch(String id) throws RazorpayException { + return get(String.format(Constants.QRCODE_FETCH, id), null); + } + + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.QRCODE_LIST, request); + } + + public List fetchAllPayments(String id,JSONObject request) throws RazorpayException { + return getCollection(Constants.QRCODE_LIST+"/"+id+"/"+Constants.QRCODE_FETCH_PAYMENT, request); + } + + public QrCode close(String id) throws RazorpayException { + return post(String.format(Constants.QRCODE_CLOSE, id), null); + } + +} diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index abea7d3b..5658b112 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -16,6 +16,7 @@ public class RazorpayClient { public SubscriptionClient Subscriptions; public AddonClient Addons; public PlanClient Plans; + public QrCodeClient QrCode; public VirtualAccountClient VirtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -35,6 +36,7 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R Subscriptions = new SubscriptionClient(auth); Addons = new AddonClient(auth); Plans = new PlanClient(auth); + QrCode = new QrCodeClient(auth); VirtualAccounts = new VirtualAccountClient(auth); } From 265f22f3898c9014178c65966e64f35a3167e4ea Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 17:59:34 +0530 Subject: [PATCH 47/78] add javadoc and json format --- .../java/com/razorpay/CustomerClient.java | 9 ++ .../java/com/razorpay/CustomerClientTest.java | 152 +++++++++++++++++- 2 files changed, 153 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/razorpay/CustomerClient.java b/src/main/java/com/razorpay/CustomerClient.java index 598a45e2..b7491a92 100644 --- a/src/main/java/com/razorpay/CustomerClient.java +++ b/src/main/java/com/razorpay/CustomerClient.java @@ -22,10 +22,19 @@ public Customer edit(String id, JSONObject request) throws RazorpayException { return put(String.format(Constants.CUSTOMER_EDIT, id), request); } + /** + * It is wrapper of fetchAll with parameter here sending null defines fetchAll + * with a default values without filteration + * @throws RazorpayException + */ public List fetchAll() throws RazorpayException { return fetchAll(null); } + /** + * This method get list of customers filtered by parameters @request + * @throws RazorpayException + */ public List fetchAll(JSONObject request) throws RazorpayException { return getCollection(Constants.CUSTOMER_LIST, request); } diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index 1553b69f..c6d98f00 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -24,8 +24,32 @@ public class CustomerClientTest extends BaseTest{ @Test public void create() throws RazorpayException{ - JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"contact\": 9123456780,\n \"email\": \"gaurav.kumar@example.com\",\n \"fail_existing\": 0,\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n }\n}"); - String mockedResponseJson = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Gaurav Kumar\",\n \"email\" : \"gaurav.kumar@example.com\",\n \"contact\" : \"9123456780\",\n \"gstin\": \"29XAbbA4369J1PA\",\n \"notes\":{\n \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n \"notes_key_2\":\"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at \": 1234567890\n}"; + JSONObject request = new JSONObject("{\n " + + "\"name\": \"Gaurav Kumar\",\n " + + "\"contact\": 9123456780,\n " + + "\"email\": \"gaurav.kumar@example.com\",\n " + + "\"fail_existing\": 0,\n " + + "\"gstin\": \"29XAbbA4369J1PA\",\n " + + "\"notes\": {\n " + + "\"notes_key_1\": " + + "\"Tea, Earl Grey, Hot\",\n " + + "\"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n" + + " }\n" + + "}"); + + String mockedResponseJson = "{\n " + + "\"id\" : \"cust_1Aa00000000004\",\n" + + "\"entity\": \"customer\",\n" + + "\"name\" : \"Gaurav Kumar\",\n" + + "\"email\" : \"gaurav.kumar@example.com\",\n" + + "\"contact\" : \"9123456780\",\n" + + "\"gstin\": \"29XAbbA4369J1PA\",\n" + + "\"notes\":{\n" + + "\"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + "\"notes_key_2\":\"Tea, Earl Grey\u2026 decaf.\"\n" + + " },\n" + + "\"created_at \": 1234567890\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -44,7 +68,16 @@ public void create() throws RazorpayException{ @Test public void fetch() throws RazorpayException { - String mockedResponseJson = "{\n \"id\" : \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\" : \"Saurav Kumar\",\n \"email\" : \"Saurav.kumar@example.com\",\n \"contact\" : \"+919000000000\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\" : [],\n \"created_at \": 1234567890\n}\n"; + String mockedResponseJson = "{\n " + + "\"id\" : \"cust_1Aa00000000004\",\n" + + "\"entity\": \"customer\",\n " + + "\"name\" : \"Saurav Kumar\",\n" + + "\"email\" : \"Saurav.kumar@example.com\",\n" + + "\"contact\" : \"+919000000000\",\n" + + "\"gstin\":\"29XAbbA4369J1PA\",\n" + + "\"notes\" : [],\n" + + "\"created_at \": 1234567890\n" + + "}\n"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -62,7 +95,24 @@ public void fetch() throws RazorpayException { */ @Test public void fetchAll() throws RazorpayException { - String mockedResponseJson = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"cust_1Aa00000000001\",\n \"entity\":\"customer\",\n \"name\":\"Gaurav Kumar\",\n \"email\":\"gaurav.kumar@example.com\",\n \"contact\":\"9876543210\",\n \"gstin\":\"29XAbbA4369J1PA\",\n \"notes\":{\n \"note_key_1\":\"September\",\n \"note_key_2\":\"Make it so.\"\n },\n \"created_at \":1234567890\n }\n ]\n}"; + String mockedResponseJson = "{\n " + + "\"entity\":\"collection\",\n " + + "\"count\":1,\n " + + "\"items\":[\n " + + "{\n " + + "\"id\":\"cust_1Aa00000000001\",\n " + + "\"entity\":\"customer\",\n" + + "\"name\":\"Gaurav Kumar\",\n" + + "\"email\":\"gaurav.kumar@example.com\",\n" + + "\"contact\":\"9876543210\",\n" + + "\"gstin\":\"29XAbbA4369J1PA\",\n" + + "\"notes\":{\n " + + "\"note_key_1\":\"September\",\n" + + "\"note_key_2\":\"Make it so.\"\n" + + "},\n" + + "\"created_at \":1234567890\n" + + "}\n ]" + + "\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -81,8 +131,28 @@ public void fetchAll() throws RazorpayException { @Test public void edit() throws RazorpayException { - JSONObject request = new JSONObject("{\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": 9000000000\n}"); - String mockedResponseJson = "{\n \"id\": \"cust_1Aa00000000004\",\n \"entity\": \"customer\",\n \"name\": \"Gaurav Kumar\",\n \"email\": \"Gaurav.Kumar@example.com\",\n \"contact\": \"9000000000\",\n \"gstin\": null,\n \"notes\": {\n \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n \"notes_key_2\": \"Tea, Earl Grey\u2026 decaf.\"\n },\n \"created_at\": 1582033731\n}"; + JSONObject request = new JSONObject("{\n " + + "\"name\": \"Gaurav Kumar\",\n " + + "\"email\": \"Gaurav.Kumar@example.com\",\n " + + "\"contact\": 9000000000\n" + + "}"); + + String mockedResponseJson = "{\n " + + "\"id\": \"cust_1Aa00000000004\",\n " + + "\"entity\": \"customer\",\n " + + "\"name\": \"Gaurav Kumar\",\n " + + "\"email\": \"Gaurav.Kumar@example.com\",\n " + + "\"contact\": \"9000000000\",\n " + + "\"gstin\": null,\n " + + "\"notes\": {\n " + + "\"notes_key_1\": " + + "\"Tea, Earl Grey, Hot\",\n " + + "\"notes_key_2\": " + + "\"Tea, Earl Grey\u2026 decaf.\"\n " + + "},\n " + + "\"created_at\": " + + "1582033731\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -100,7 +170,36 @@ public void edit() throws RazorpayException { */ @Test public void fetchTokens() throws RazorpayException{ - String mockedResponseJson = "{\n \"id\": \"token_Hxe0skTXLeg9pF\",\n \"entity\": \"token\",\n \"token\": \"F85BgXnGVwcuqV\",\n \"bank\": null,\n \"wallet\": null,\n \"method\": \"card\",\n \"card\": {\n \"entity\": \"card\",\n \"name\": \"ankit\",\n \"last4\": \"5449\",\n \"network\": \"MasterCard\",\n \"type\": \"credit\",\n \"issuer\": \"UTIB\",\n \"international\": false,\n \"emi\": false,\n \"sub_type\": \"consumer\",\n \"expiry_month\": 12,\n \"expiry_year\": 2024,\n \"flows\": {\n \"recurring\": true\n }\n },\n \"recurring\": true,\n \"auth_type\": null,\n \"mrn\": null,\n \"used_at\": 1632976165,\n \"created_at\": 1631687852,\n \"expired_at\": 1634215992,\n \"dcc_enabled\": false\n}"; + String mockedResponseJson = "{\n " + + "\"id\": \"token_Hxe0skTXLeg9pF\",\n" + + "\"entity\": \"token\",\n" + + "\"token\": \"F85BgXnGVwcuqV\",\n" + + "\"bank\": null,\n" + + "\"wallet\": null,\n" + + "\"method\": \"card\",\n" + + "\"card\": {\n" + + "\"entity\": \"card\",\n" + + "\"name\": \"ankit\",\n" + + "\"last4\": \"5449\",\n " + + "\"network\": \"MasterCard\",\n" + + "\"type\": \"credit\",\n" + + "\"issuer\": \"UTIB\",\n" + + "\"international\": false,\n" + + "\"emi\": false,\n" + + "\"sub_type\": \"consumer\",\n" + + "\"expiry_month\": 12,\n" + + "\"expiry_year\": 2024,\n" + + "\"flows\": {\n" + + "\"recurring\": true\n" + + "}\n },\n" + + "\"recurring\": true,\n" + + "\"auth_type\": null,\n" + + "\"mrn\": null,\n" + + "\"used_at\": 1632976165,\n" + + "\"created_at\": 1631687852,\n" + + "\"expired_at\": 1634215992,\n" + + "\"dcc_enabled\": false\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -118,7 +217,44 @@ public void fetchTokens() throws RazorpayException{ */ @Test public void fetchToken() throws RazorpayException{ - String mockedResponseJson = "{\n \"entity\":\"collection\",\n \"count\":1,\n \"items\":[\n {\n \"id\":\"token_Hxe0skTXLeg9pF\",\n \"entity\":\"token\",\n \"token\":\"2JPRk664pZHUWG\",\n \"bank\":null,\n \"wallet\":null,\n \"method\":\"card\",\n \"card\":{\n \"entity\":\"card\",\n \"name\":\"Gaurav Kumar\",\n \"last4\":\"8950\",\n \"network\":\"Visa\",\n \"type\":\"credit\",\n \"issuer\":\"STCB\",\n \"international\":false,\n \"emi\":false,\n \"sub_type\":\"consumer\",\n \"expiry_month\":12,\n \"expiry_year\":2021,\n \"flows\":{\n \"otp\":true,\n \"recurring\":true\n }\n },\n \"recurring\":true,\n \"recurring_details\":{\n \"status\":\"confirmed\",\n \"failure_reason\":null\n },\n \"auth_type\":null,\n \"mrn\":null,\n \"used_at\":1629779657,\n \"created_at\":1629779657,\n \"expired_at\":1640975399,\n \"dcc_enabled\":false,\n \"billing_address\":null\n }\n ]\n}"; + String mockedResponseJson = "{\n" + + "\"entity\":\"collection\",\n" + + "\"count\":1,\n \"items\":[\n" + + "{\n" + + "\"id\":\"token_Hxe0skTXLeg9pF\",\n" + + "\"entity\":\"token\",\n " + + "\"token\":\"2JPRk664pZHUWG\",\n" + + "\"bank\":null,\n" + + "\"wallet\":null,\n" + + "\"method\":\"card\",\n" + + "\"card\":{\n" + + "\"entity\":\"card\",\n" + + "\"name\":\"Gaurav Kumar\",\n" + + "\"last4\":\"8950\",\n " + + "\"network\":\"Visa\",\n " + + "\"type\":\"credit\",\n " + + "\"issuer\":\"STCB\",\n " + + "\"international\":false,\n" + + "\"emi\":false,\n" + + "\"sub_type\":\"consumer\",\n " + + "\"expiry_month\":12,\n" + + "\"expiry_year\":2021,\n" + + "\"flows\":{\n " + + "\"otp\":true,\n" + + "\"recurring\":true\n" + + "}\n },\n" + + "\"recurring\":true,\n" + + "\"recurring_details\":{\n" + + "\"status\":\"confirmed\",\n" + + "\"failure_reason\":null\n" + + "},\n" + + "\"auth_type\":null,\n" + + "\"mrn\":null,\n" + + "\"used_at\":1629779657,\n" + + "\"created_at\":1629779657,\n" + + "\"expired_at\":1640975399,\n " + + "\"dcc_enabled\":false,\n" + + "\"billing_address\":null\n}\n ]\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); From c955491b960b0f7f8c4c8c791bb91dbb08218d40 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 19:07:28 +0530 Subject: [PATCH 48/78] json format --- .../java/com/razorpay/ItemClientTest.java | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/razorpay/ItemClientTest.java b/src/test/java/com/razorpay/ItemClientTest.java index 6db4bf59..21402349 100644 --- a/src/test/java/com/razorpay/ItemClientTest.java +++ b/src/test/java/com/razorpay/ItemClientTest.java @@ -22,8 +22,22 @@ public class ItemClientTest extends BaseTest{ */ @Test public void create() throws RazorpayException { - JSONObject request = new JSONObject("{\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"); - String mockedResponseJson = "{\n \"entity\" : \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + JSONObject request = new JSONObject("{\n" + + "\"name\": \"Book English August\",\n" + + "\"description\": \"An indian story, Booker prize winner.\",\n" + + "\"amount\": 20000,\n" + + "\"currency\": \"INR\"\n" + + "}"); + + String mockedResponseJson = "{\n" + + "\"entity\" : \"item\",\n" + + "\"id\": "+ITEM_ID+",\n" + + "\"active\": true,\n" + + "\"name\": \"Book English August\",\n" + + "\"description\": \"An indian story, Booker prize winner.\",\n" + + "\"amount\": 20000,\n" + + "\"currency\": \"INR\"\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -46,7 +60,15 @@ public void create() throws RazorpayException { @Test public void fetch() throws RazorpayException { - String mockedResponseJson = "{\n \"entity\": \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": \"An indian story, Booker prize winner.\",\n \"amount\": 20000,\n \"currency\": \"INR\"\n}"; + String mockedResponseJson = "{\n " + + "\"entity\": \"item\",\n" + + "\"id\": "+ITEM_ID+",\n" + + "\"active\": true,\n" + + "\"name\": \"Book English August\",\n" + + "\"description\": \"An indian story, Booker prize winner.\",\n" + + "\"amount\": 20000,\n" + + "\"currency\": \"INR\"\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -68,7 +90,19 @@ public void fetch() throws RazorpayException { @Test public void fetchAll() throws RazorpayException{ - String mockedResponseJson = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"item_7OxoGnoxCuUKbo\",\n \"entity\" : \"item\",\n \"active\": true,\n \"name\": \"Book English August\",\n \"description\": null,\n \"amount\": 20000,\n \"currency\": \"INR\"\n }\n ]\n}"; + String mockedResponseJson = "{\n " + + "\"entity\": \"collection\",\n" + + "\"count\": 1,\n" + + "\"items\": [\n" + + "{\n" + + "\"id\": \"item_7OxoGnoxCuUKbo\",\n" + + "\"entity\" : \"item\",\n" + + "\"active\": true,\n" + + "\"name\": \"Book English August\",\n" + + "\"description\": null,\n" + + "\"amount\": 20000,\n" + + "\"currency\": \"INR\"\n" + + "}\n]\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -89,8 +123,21 @@ public void fetchAll() throws RazorpayException{ @Test public void edit() throws RazorpayException{ - JSONObject request = new JSONObject("{\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :).\",\n \"amount\": 20000,\n \"currency\": \"INR\",\n \"active\": true\n}"); - String mockedResponseJson = "{\n \"entity\" : \"item\",\n \"id\": "+ITEM_ID+",\n \"active\": true,\n \"name\": \"Book Ignited Minds - Updated name!\",\n \"description\": \"New descirption too. :)\",\n \"amount\": 15000,\n \"currency\": \"INR\"\n}"; + JSONObject request = new JSONObject("{\n" + + "\"name\": \"Book Ignited Minds - Updated name!\",\n" + + "\"description\": \"New descirption too. :).\",\n" + + "\"amount\": 20000,\n \"currency\": \"INR\",\n" + + "\"active\": true\n}"); + + String mockedResponseJson = "{\n " + + "\"entity\" : \"item\",\n" + + "\"id\": "+ITEM_ID+",\n" + + "\"active\": true,\n" + + "\"name\": \"Book Ignited Minds - Updated name!\",\n" + + "\"description\": \"New descirption too. :)\",\n" + + "\"amount\": 15000,\n" + + "\"currency\": \"INR\"\n" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); From b769cc16184bbba7b87dc29610f833f9289c14a7 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 19:16:47 +0530 Subject: [PATCH 49/78] json format --- .../com/razorpay/FundAccountClientTest.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/razorpay/FundAccountClientTest.java b/src/test/java/com/razorpay/FundAccountClientTest.java index f635e283..dfb22728 100644 --- a/src/test/java/com/razorpay/FundAccountClientTest.java +++ b/src/test/java/com/razorpay/FundAccountClientTest.java @@ -21,8 +21,27 @@ public class FundAccountClientTest extends BaseTest{ */ @Test public void create() throws RazorpayException { - JSONObject request = new JSONObject("{\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\"\n }\n}"); - String mockedResponseJson = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + JSONObject request = new JSONObject("{\n " + + "\"customer_id\":\"cust_Aa000000000001\",\n" + + "\"account_type\":\"bank_account\",\n" + + "\"bank_account\":{\n" + + "\"name\":\"Gaurav Kumar\",\n" + + "\"account_number\":\"11214311215411\",\n" + + "\"ifsc\":\"HDFC0000053\"\n}\n}"); + + String mockedResponseJson = "{\n " + + "\"id\":\"fa_Aa00000000001\",\n" + + "\"entity\":\"fund_account\",\n" + + "\"customer_id\":\"cust_Aa000000000001\",\n" + + "\"account_type\":\"bank_account\",\n" + + "\"bank_account\":{\n" + + "\"name\":\"Gaurav Kumar\",\n" + + "\"account_number\":\"11214311215411\",\n" + + "\"ifsc\":\"HDFC0000053\",\n" + + "\"bank_name\":\"HDFC Bank\"\n" + + "},\n" + + "\"active\":true,\n" + + "\"created_at\":1543650891\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -41,7 +60,19 @@ public void create() throws RazorpayException { @Test public void fetch() throws RazorpayException { - String mockedResponseJson = "{\n \"id\":\"fa_Aa00000000001\",\n \"entity\":\"fund_account\",\n \"customer_id\":\"cust_Aa000000000001\",\n \"account_type\":\"bank_account\",\n \"bank_account\":{\n \"name\":\"Gaurav Kumar\",\n \"account_number\":\"11214311215411\",\n \"ifsc\":\"HDFC0000053\",\n \"bank_name\":\"HDFC Bank\"\n },\n \"active\":true,\n \"created_at\":1543650891\n}"; + String mockedResponseJson = "{\n" + + "\"id\":\"fa_Aa00000000001\",\n" + + "\"entity\":\"fund_account\",\n" + + "\"customer_id\":\"cust_Aa000000000001\",\n" + + "\"account_type\":\"bank_account\",\n" + + "\"bank_account\":{\n" + + "\"name\":\"Gaurav Kumar\",\n" + + "\"account_number\":\"11214311215411\",\n" + + "\"ifsc\":\"HDFC0000053\",\n" + + "\"bank_name\":\"HDFC Bank\"\n" + + "},\n" + + "\"active\":true,\n" + + "\"created_at\":1543650891\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); From 812c594ca883f26ab59884435e934567c0482c03 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 16 Feb 2022 19:53:50 +0530 Subject: [PATCH 50/78] json format --- .../java/com/razorpay/PaymentClientTest.java | 278 +++++++++++++++++- 1 file changed, 265 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index 16ec208c..6ecf17d3 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -25,7 +25,37 @@ public class PaymentClientTest extends BaseTest{ @Test public void fetch() throws RazorpayException{ - String mockedResponseJson = "{\"id\":"+PAYMENT_ID+",\"entity\":\"payment\",\"amount\":1000,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VPOayFxWEU28\",\"invoice_id\":null,\"international\":false,\"method\":\"upi\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":null,\"wallet\":null,\"vpa\":\"gaurav.kumar@exampleupi\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":24,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"rrn\":\"033814379298\"},\"created_at\":1606985209}"; + String mockedResponseJson = "{" + + "\"id\":"+PAYMENT_ID+"," + + "\"entity\":\"payment\"," + + "\"amount\":1000," + + "\"currency\":\"INR\"," + + "\"status\":\"captured\"," + + "\"order_id\":\"order_G8VPOayFxWEU28\"," + + "\"invoice_id\":null," + + "\"international\":false," + + "\"method\":\"upi\"," + + "\"amount_refunded\":0," + + "\"refund_status\":null," + + "\"captured\":true," + + "\"description\":\"PurchaseShoes\"," + + "\"card_id\":null," + + "\"bank\":null," + + "\"wallet\":null," + + "\"vpa\":\"gaurav.kumar@exampleupi\"," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"+919999999999\"," + + "\"customer_id\":\"cust_DitrYCFtCIokBO\"," + + "\"notes\":[]," + + "\"fee\":24," + + "\"tax\":4," + + "\"error_code\":null," + + "\"error_description\":null," + + "\"error_source\":null," + + "\"error_step\":null," + + "\"error_reason\":null," + + "\"acquirer_data\":{\"rrn\":\"033814379298\"}," + + "\"created_at\":1606985209}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -46,7 +76,39 @@ public void fetch() throws RazorpayException{ @Test public void fetchAll() throws RazorpayException{ - String mockedResponseJson = "{\"entity\":\"collection\",\"count\":2,\"items\":[{\"id\":\"pay_G8VaL2Z68LRtDs\",\"entity\":\"payment\",\"amount\":900,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VXfKDWDEOHHd\",\"invoice_id\":null,\"international\":false,\"method\":\"netbanking\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":\"KKBK\",\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":22,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"bank_transaction_id\":\"0125836177\"},\"created_at\":1606985740}]}"; + String mockedResponseJson = "{" + + "\"entity\":\"collection\"," + + "\"count\":2," + + "\"items\":[{\"id\":\"pay_G8VaL2Z68LRtDs\"," + + "\"entity\":\"payment\"," + + "\"amount\":900," + + "\"currency\":\"INR\"," + + "\"status\":\"captured\"," + + "\"order_id\":\"order_G8VXfKDWDEOHHd\"," + + "\"invoice_id\":null," + + "\"international\":false," + + "\"method\":\"netbanking\"," + + "\"amount_refunded\":0," + + "\"refund_status\":null," + + "\"captured\":true," + + "\"description\":\"PurchaseShoes\"," + + "\"card_id\":null," + + "\"bank\":\"KKBK\"," + + "\"wallet\":null," + + "\"vpa\":null," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"+919999999999\"," + + "\"customer_id\":\"cust_DitrYCFtCIokBO\"," + + "\"notes\":[]," + + "\"fee\":22," + + "\"tax\":4," + + "\"error_code\":null," + + "\"error_description\":null," + + "\"error_source\":null," + + "\"error_step\":null," + + "\"error_reason\":null," + + "\"acquirer_data\":{\"bank_transaction_id\":\"0125836177\"}," + + "\"created_at\":1606985740}]}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -68,8 +130,41 @@ public void fetchAll() throws RazorpayException{ @Test public void capture() throws RazorpayException{ - JSONObject request = new JSONObject("{\"amount\":1000,\"currency\":\"INR\"}"); - String mockedResponseJson = "{\"id\":"+PAYMENT_ID+",\"entity\":\"payment\",\"amount\":1000,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_G8VPOayFxWEU28\",\"invoice_id\":null,\"international\":false,\"method\":\"upi\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"PurchaseShoes\",\"card_id\":null,\"bank\":null,\"wallet\":null,\"vpa\":\"gaurav.kumar@exampleupi\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999999\",\"customer_id\":\"cust_DitrYCFtCIokBO\",\"notes\":[],\"fee\":24,\"tax\":4,\"error_code\":null,\"error_description\":null,\"error_source\":null,\"error_step\":null,\"error_reason\":null,\"acquirer_data\":{\"rrn\":\"033814379298\"},\"created_at\":1606985209}"; + JSONObject request = new JSONObject("{" + + "\"amount\":1000," + + "\"currency\":\"INR\"}"); + + String mockedResponseJson = "{" + + "\"id\":"+PAYMENT_ID+"," + + "\"entity\":\"payment\"," + + "\"amount\":1000," + + "\"currency\":\"INR\"," + + "\"status\":\"captured\"," + + "\"order_id\":\"order_G8VPOayFxWEU28\"," + + "\"invoice_id\":null," + + "\"international\":false," + + "\"method\":\"upi\"," + + "\"amount_refunded\":0," + + "\"refund_status\":null," + + "\"captured\":true," + + "\"description\":\"PurchaseShoes\"," + + "\"card_id\":null," + + "\"bank\":null," + + "\"wallet\":null," + + "\"vpa\":\"gaurav.kumar@exampleupi\"," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"+919999999999\"," + + "\"customer_id\":\"cust_DitrYCFtCIokBO\"," + + "\"notes\":[]," + + "\"fee\":24," + + "\"tax\":4," + + "\"error_code\":null," + + "\"error_description\":null," + + "\"error_source\":null," + + "\"error_step\":null," + + "\"error_reason\":null," + + "\"acquirer_data\":{\"rrn\":\"033814379298\"}," + + "\"created_at\":1606985209}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -89,8 +184,24 @@ public void capture() throws RazorpayException{ */ @Test public void refund() throws Exception{ - JSONObject request = new JSONObject("{\"amount\":\"100\",\"speed\":\"normal\",\"notes\":{\"notes_key_1\":\"BeammeupScotty.\",\"notes_key_2\":\"Engage\"},\"receipt\":\"ReceiptNo.31\"}"); - String mockedResponseJson = "{\"id\":"+REFUND_ID+",\"entity\":\"refund\",\"amount\":500100,\"receipt\":\"ReceiptNo.31\",\"currency\":\"INR\",\"payment_id\":\"pay_FCXKPFtYfPXJPy\",\"notes\":[],\"acquirer_data\":{\"arn\":null},\"created_at\":1597078866,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\"}"; + JSONObject request = new JSONObject("{" + + "\"amount\":\"100\"," + + "\"speed\":\"normal\"," + + "\"notes\":{\"notes_key_1\":\"BeammeupScotty.\"," + + "\"notes_key_2\":\"Engage\"}," + + "\"receipt\":\"ReceiptNo.31\"}"); + + String mockedResponseJson = "{" + + "\"id\":"+REFUND_ID+"," + + "\"entity\":\"refund\"," + + "\"amount\":500100," + + "\"receipt\":\"ReceiptNo.31\"," + + "\"currency\":\"INR\"," + + "\"payment_id\":\"pay_FCXKPFtYfPXJPy\"," + + "\"notes\":[],\"acquirer_data\":{\"arn\":null}," + + "\"created_at\":1597078866,\"batch_id\":null," + + "\"status\":\"processed\"," + + "\"speed_processed\":\"normal\"}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -111,7 +222,21 @@ public void refund() throws Exception{ @Test public void FetchAllRefunds() throws RazorpayException{ JSONObject request = new JSONObject("{}"); - String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"rfnd_IDQbLKwiy0aHrA\",\"entity\":\"refund\",\"amount\":100,\"currency\":\"INR\",\"payment_id\":\"pay_I3eaMwGV0462JA\",\"notes\":[],\"receipt\":null,\"acquirer_data\":{\"arn\":\"10000000000000\"},\"created_at\":1635134062,\"batch_id\":null,\"status\":\"processed\",\"speed_processed\":\"normal\",\"speed_requested\":\"normal\"}]}"; + String mockedResponseJson = "{" + + "\"entity\":\"collection\"," + + "\"count\":1,\"items\":[{\"id\":\"rfnd_IDQbLKwiy0aHrA\"," + + "\"entity\":\"refund\"," + + "\"amount\":100," + + "\"currency\":\"INR\"," + + "\"payment_id\":\"pay_I3eaMwGV0462JA\"," + + "\"notes\":[]," + + "\"receipt\":null," + + "\"acquirer_data\":{\"arn\":\"10000000000000\"}," + + "\"created_at\":1635134062," + + "\"batch_id\":null," + + "\"status\":\"processed\"," + + "\"speed_processed\":\"normal\"," + + "\"speed_requested\":\"normal\"}]}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -133,8 +258,42 @@ public void FetchAllRefunds() throws RazorpayException{ */ @Test public void transfers() throws RazorpayException{ - JSONObject request = new JSONObject("{\"transfers\":[{\"account\":\"acc_CPRsN1LkFccllA\",\"amount\":100,\"currency\":\"INR\",\"notes\":{\"name\":\"GauravKumar\",\"roll_no\":\"IEC2011025\"},\"linked_account_notes\":[\"roll_no\"],\"on_hold\":true,\"on_hold_until\":1671222870}]}"); - String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"trf_ItzBst0oybrcNx\",\"entity\":\"transfer\",\"status\":\"pending\",\"source\":\"pay_IOyKpYsPTMSWph\",\"recipient\":\"acc_I0QRP7PpvaHhpB\",\"amount\":100,\"currency\":\"INR\",\"amount_reversed\":0,\"notes\":{\"name\":\"GauravKumar\",\"roll_no\":\"IEC2011025\"},\"linked_account_notes\":[\"roll_no\"],\"on_hold\":true,\"on_hold_until\":1671222870,\"recipient_settlement_id\":null,\"created_at\":1644426157,\"processed_at\":null,\"error\":{\"code\":null,\"description\":null,\"reason\":null,\"field\":null,\"step\":null,\"id\":\"trf_ItzBst0oybrcNx\",\"source\":null,\"metadata\":null}}]}"; + JSONObject request = new JSONObject("{" + + "\"transfers\":[{\"account\":\"acc_CPRsN1LkFccllA\"," + + "\"amount\":100," + + "\"currency\":\"INR\"," + + "\"notes\":{\"name\":\"GauravKumar\"," + + "\"roll_no\":\"IEC2011025\"}," + + "\"linked_account_notes\":[\"roll_no\"]," + + "\"on_hold\":true," + + "\"on_hold_until\":1671222870}]}"); + + String mockedResponseJson = "{" + + "\"entity\":\"collection\"," + + "\"count\":1," + + "\"items\":[{\"id\":\"trf_ItzBst0oybrcNx\"," + + "\"entity\":\"transfer\"," + + "\"status\":\"pending\"," + + "\"source\":\"pay_IOyKpYsPTMSWph\"," + + "\"recipient\":\"acc_I0QRP7PpvaHhpB\"," + + "\"amount\":100," + + "\"currency\":\"INR\"," + + "\"amount_reversed\":0," + + "\"notes\":{\"name\":\"GauravKumar\"," + + "\"roll_no\":\"IEC2011025\"}," + + "\"linked_account_notes\":[\"roll_no\"]," + + "\"on_hold\":true," + + "\"on_hold_until\":1671222870," + + "\"recipient_settlement_id\":null," + + "\"created_at\":1644426157," + + "\"processed_at\":null," + + "\"error\":{\"code\":null," + + "\"description\":null," + + "\"reason\":null," + + "\"field\":null," + + "\"step\":null," + + "\"id\":\"trf_ItzBst0oybrcNx\"," + + "\"source\":null,\"metadata\":null}}]}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -156,7 +315,28 @@ public void transfers() throws RazorpayException{ @Test public void fetchAllTransfers() throws RazorpayException{ - String mockedResponseJson = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"trf_EAznuJ9cDLnF7Y\",\n \"entity\": \"transfer\",\n \"source\": \"pay_E9up5WhIfMYnKW\",\n \"recipient\": \"acc_CMaomTz4o0FOFz\",\n \"amount\": 1000,\n \"currency\": \"INR\",\n \"amount_reversed\": 100,\n \"notes\": [],\n \"fees\": 3,\n \"tax\": 0,\n \"on_hold\": false,\n \"on_hold_until\": null,\n \"recipient_settlement_id\": null,\n \"created_at\": 1580454666,\n \"linked_account_notes\": [],\n \"processed_at\": 1580454666\n }\n ]\n}"; + String mockedResponseJson = "{\n " + + "\"entity\": \"collection\",\n" + + "\"count\": 1,\n" + + "\"items\": [\n" + + "{\n " + + "\"id\": \"trf_EAznuJ9cDLnF7Y\",\n" + + "\"entity\": \"transfer\",\n" + + "\"source\": \"pay_E9up5WhIfMYnKW\",\n" + + "\"recipient\": \"acc_CMaomTz4o0FOFz\",\n" + + "\"amount\": 1000,\n" + + "\"currency\": \"INR\",\n" + + "\"amount_reversed\": 100,\n" + + "\"notes\": [],\n" + + "\"fees\": 3,\n" + + "\"tax\": 0,\n" + + "\"on_hold\": false,\n" + + "\"on_hold_until\": null,\n" + + "\"recipient_settlement_id\": null,\n" + + "\"created_at\": 1580454666,\n" + + "\"linked_account_notes\": [],\n" + + "\"processed_at\": 1580454666\n" + + "}\n ]\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -178,7 +358,47 @@ public void fetchAllTransfers() throws RazorpayException{ @Test public void fetchBankTransfers() throws RazorpayException{ - String mockedResponseJson = "{\n \"id\": \"bt_Di5iqCElVyRlCb\",\n \"entity\": \"bank_transfer\",\n \"payment_id\": "+PAYMENT_ID+",\n \"mode\": \"NEFT\",\n \"bank_reference\": \"157414364471\",\n \"amount\": 239000,\n \"payer_bank_account\": {\n \"id\": \"ba_Di5iqSxtYrTzPU\",\n \"entity\": \"bank_account\",\n \"ifsc\": \"UTIB0003198\",\n \"bank_name\": \"Axis Bank\",\n \"name\": \"Acme Corp\",\n \"notes\": [],\n \"account_number\": \"765432123456789\"\n },\n \"virtual_account_id\": \"va_Di5gbNptcWV8fQ\",\n \"virtual_account\": {\n \"id\": \"va_Di5gbNptcWV8fQ\",\n \"name\": \"Acme Corp\",\n \"entity\": \"virtual_account\",\n \"status\": \"closed\",\n \"description\": \"Virtual Account created for MS ABC Exports\",\n \"amount_expected\": 2300,\n \"notes\": {\n \"material\": \"teakwood\"\n },\n \"amount_paid\": 239000,\n \"customer_id\": \"cust_DOMUFFiGdCaCUJ\",\n \"receivers\": [\n {\n \"id\": \"ba_Di5gbQsGn0QSz3\",\n \"entity\": \"bank_account\",\n \"ifsc\": \"RATN0VAAPIS\",\n \"bank_name\": \"RBL Bank\",\n \"name\": \"Acme Corp\",\n \"notes\": [],\n \"account_number\": \"1112220061746877\"\n }\n ],\n \"close_by\": 1574427237,\n \"closed_at\": 1574164078,\n \"created_at\": 1574143517\n }\n}"; + String mockedResponseJson = "{\n" + + "\"id\": \"bt_Di5iqCElVyRlCb\",\n" + + "\"entity\": \"bank_transfer\",\n" + + "\"payment_id\": "+PAYMENT_ID+",\n" + + "\"mode\": \"NEFT\",\n" + + "\"bank_reference\": \"157414364471\",\n" + + "\"amount\": 239000,\n \"payer_bank_account\": {\n" + + "\"id\": \"ba_Di5iqSxtYrTzPU\",\n" + + "\"entity\": \"bank_account\",\n" + + "\"ifsc\": \"UTIB0003198\",\n" + + "\"bank_name\": \"Axis Bank\",\n" + + "\"name\": \"Acme Corp\",\n" + + "\"notes\": [],\n" + + "\"account_number\": \"765432123456789\"\n" + + "},\n \"virtual_account_id\": \"va_Di5gbNptcWV8fQ\",\n" + + "\"virtual_account\": {\n" + + "\"id\": \"va_Di5gbNptcWV8fQ\",\n" + + "\"name\": \"Acme Corp\",\n" + + "\"entity\": \"virtual_account\",\n" + + "\"status\": \"closed\",\n" + + "\"description\": \"Virtual Account created for MS ABC Exports\",\n" + + "\"amount_expected\": 2300,\n" + + "\"notes\": {\n" + + "\"material\": \"teakwood\"\n" + + "},\n" + + "\"amount_paid\": 239000,\n" + + "\"customer_id\": \"cust_DOMUFFiGdCaCUJ\",\n" + + "\"receivers\": [\n" + + " {\n " + + "\"id\": \"ba_Di5gbQsGn0QSz3\",\n" + + "\"entity\": \"bank_account\",\n" + + "\"ifsc\": \"RATN0VAAPIS\",\n " + + "\"bank_name\": \"RBL Bank\",\n" + + "\"name\": \"Acme Corp\",\n" + + "\"notes\": [],\n " + + "\"account_number\": \"1112220061746877\"\n" + + "}\n" + + "],\n" + + "\"close_by\": 1574427237,\n" + + "\"closed_at\": 1574164078,\n" + + "\"created_at\": 1574143517\n}\n}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -201,8 +421,40 @@ public void fetchBankTransfers() throws RazorpayException{ @Test public void createJsonPayment() throws RazorpayException { - JSONObject request = new JSONObject("{\"amount\":\"100\",\"currency\":\"INR\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"9123456789\",\"order_id\":\"order_ItZMEZjpBD6dhT\",\"method\":\"upi\"}"); - String mockedResponseJson = "{\"entity\":\"payment\",\"type\":\"respawn\",\"request\":{\"url\":\"https://api.razorpay.com/v1/payments?key_id=rzp_test_pNL6H0AmbBEyjD\",\"method\":\"POST\",\"content\":{\"amount\":\"100\",\"currency\":\"INR\",\"email\":\"gaurav.kumar@example.com\",\"contact\":\"9123456789\",\"order_id\":\"order_ItYKzxCxnKAKlD\",\"method\":\"upi\",\"card\":{\"number\":\"4854980604708430\",\"cvv\":\"123\",\"expiry_month\":\"12\",\"expiry_year\":\"21\",\"name\":\"GauravKumar\"},\"_\":{\"library\":\"s2s\"},\"upi\":{\"flow\":\"collect\",\"type\":\"default\"}}},\"image\":null,\"theme\":\"#3594E2\",\"method\":\"upi\",\"version\":\"1\",\"missing\":[\"vpa\"],\"base\":\"api.razorpay.com\"}"; + JSONObject request = new JSONObject("{" + + "\"amount\":\"100\"," + + "\"currency\":\"INR\"," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"9123456789\"," + + "\"order_id\":\"order_ItZMEZjpBD6dhT\"," + + "\"method\":\"upi\"}"); + + String mockedResponseJson = "{" + + "\"entity\":\"payment\"," + + "\"type\":\"respawn\"," + + "\"request\":" + + "{\"url\":\"https://api.razorpay.com/v1/payments?key_id=rzp_test_pNL6H0AmbBEyjD\"," + + "\"method\":\"POST\"," + + "\"content\":" + + "{\"amount\":\"100\"," + + "\"currency\":\"INR\"," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"9123456789\"," + + "\"order_id\":\"order_ItYKzxCxnKAKlD\"," + + "\"method\":\"upi\"," + + "\"card\":" + + "{\"number\":\"4854980604708430\"," + + "\"cvv\":\"123\"," + + "\"expiry_month\":\"12\"," + + "\"expiry_year\":\"21\"," + + "\"name\":\"GauravKumar\"}," + + "\"_\":{\"library\":\"s2s\"}," + + "\"upi\":{\"flow\":\"collect\"," + + "\"type\":\"default\"}}}," + + "\"image\":null,\"theme\":\"#3594E2\"," + + "\"method\":\"upi\"," + + "\"version\":\"1\"," + + "\"missing\":[\"vpa\"],\"base\":\"api.razorpay.com\"}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); From a60502e8f1ecdf229c6daa044572afab30000b0b Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 17 Feb 2022 17:18:25 +0530 Subject: [PATCH 51/78] implement qr_code with unit test --- src/main/java/com/razorpay/QrCodeClient.java | 15 +- .../java/com/razorpay/QrCodeClientTest.java | 215 ++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/razorpay/QrCodeClientTest.java diff --git a/src/main/java/com/razorpay/QrCodeClient.java b/src/main/java/com/razorpay/QrCodeClient.java index 0ccf9b02..4251944b 100644 --- a/src/main/java/com/razorpay/QrCodeClient.java +++ b/src/main/java/com/razorpay/QrCodeClient.java @@ -19,15 +19,28 @@ public QrCode create(JSONObject request) throws RazorpayException { public QrCode fetch(String id) throws RazorpayException { return get(String.format(Constants.QRCODE_FETCH, id), null); } - + + /** + * It is wrapper of fetchAll with parameter here sending null defines fetchAll + * with a default values without filteration + * @throws RazorpayException + */ public List fetchAll() throws RazorpayException { return fetchAll(null); } + /** + * This method get list of QrCodes filtered by parameters @request + * @throws RazorpayException + */ public List fetchAll(JSONObject request) throws RazorpayException { return getCollection(Constants.QRCODE_LIST, request); } + public List fetchAllPayments(String id) throws RazorpayException { + return fetchAllPayments(id,null); + } + public List fetchAllPayments(String id,JSONObject request) throws RazorpayException { return getCollection(Constants.QRCODE_LIST+"/"+id+"/"+Constants.QRCODE_FETCH_PAYMENT, request); } diff --git a/src/test/java/com/razorpay/QrCodeClientTest.java b/src/test/java/com/razorpay/QrCodeClientTest.java new file mode 100644 index 00000000..0eaf35e4 --- /dev/null +++ b/src/test/java/com/razorpay/QrCodeClientTest.java @@ -0,0 +1,215 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class QrCodeClientTest extends BaseTest{ + + @InjectMocks + protected QrCodeClient qrCodeClient = new QrCodeClient(TEST_SECRET_KEY); + + + private static final String QRCODE_ID = "qr_HMsVL8HOpbMcjU"; + + private static final String CUSTOMER_ID = "cust_HKsR5se84c5LTO"; + + /** + * Qrcode is created using the customer and amount details. + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException { + + JSONObject request = new JSONObject("{\n" + + " \"type\": \"upi_qr\",\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"fixed_amount\": true,\n" + + " \"payment_amount\": 300,\n" + + " \"description\": \"For Store 1\",\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " }\n" + + "}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+QRCODE_ID+",\n" + + " \"entity\": \"qr_code\",\n" + + " \"created_at\": 1623660301,\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"type\": \"upi_qr\",\n" + + " \"image_url\": \"https://rzp.io/i/BWcUVrLp\",\n" + + " \"payment_amount\": 300,\n" + + " \"status\": \"active\",\n" + + " \"description\": \"For Store 1\",\n" + + " \"fixed_amount\": true,\n" + + " \"payments_amount_received\": 0,\n" + + " \"payments_count_received\": 0,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " },\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + QrCode fetch = qrCodeClient.create(request); + assertNotNull(fetch); + assertEquals("qr_code",fetch.get("entity")); + assertEquals(QRCODE_ID,fetch.get("id")); + assertTrue(fetch.has("close_by")); + assertTrue(fetch.has("fixed_amount")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all the QrCode details using qr code id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\": "+QRCODE_ID+",\n" + + " \"entity\": \"qr_code\",\n" + + " \"created_at\": 1623915088,\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"type\": \"upi_qr\",\n" + + " \"image_url\": \"https://rzp.io/i/oCswTOcCo\",\n" + + " \"payment_amount\": 300,\n" + + " \"status\": \"active\",\n" + + " \"description\": \"For Store 1\",\n" + + " \"fixed_amount\": true,\n" + + " \"payments_amount_received\": 0,\n" + + " \"payments_count_received\": 0,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " },\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838,\n" + + " \"closed_at\": null,\n" + + " \"close_reason\": null\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + QrCode fetch = qrCodeClient.fetch(QRCODE_ID); + assertNotNull(fetch); + assertEquals("upi_qr",fetch.get("type")); + assertEquals(QRCODE_ID,fetch.get("id")); + assertEquals(CUSTOMER_ID,fetch.get("customer_id")); + assertTrue(fetch.has("close_by")); + assertTrue(fetch.has("fixed_amount")); + } catch (IOException e) { + assertTrue(false); + } + + } + + /** + * Details of all the Qrcode can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 2,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"qr_HO2jGkWReVBMNu\",\n" + + " \"entity\": \"qr_code\",\n" + + " \"created_at\": 1623914648,\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"type\": \"upi_qr\",\n" + + " \"image_url\": \"https://rzp.io/i/w2CEwYmkAu\",\n" + + " \"payment_amount\": 300,\n" + + " \"status\": \"active\",\n" + + " \"description\": \"For Store 1\",\n" + + " \"fixed_amount\": true,\n" + + " \"payments_amount_received\": 0,\n" + + " \"payments_count_received\": 0,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " },\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838,\n" + + " \"closed_at\": null,\n" + + " \"close_reason\": null\n" + + " },\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = qrCodeClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("type")); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("customer_id")); + assertTrue(fetch.get(0).has("close_by")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Close a QR Code. A customer cannot make payments for the closed QR codes. + * @throws RazorpayException + */ + @Test + public void close() throws RazorpayException{ + + String mockedResponseJson = "{\n" + + " \"id\": "+QRCODE_ID+",\n" + + " \"entity\": \"qr_code\",\n" + + " \"created_at\": 1623660301,\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"type\": \"upi_qr\",\n" + + " \"image_url\": \"https://rzp.io/i/BWcUVrLp\",\n" + + " \"payment_amount\": 300,\n" + + " \"status\": \"closed\",\n" + + " \"description\": \"For Store 1\",\n" + + " \"fixed_amount\": true,\n" + + " \"payments_amount_received\": 0,\n" + + " \"payments_count_received\": 0,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " },\n" + + " \"customer_id\": "+CUSTOMER_ID+",\n" + + " \"close_by\": 1681615838,\n" + + " \"closed_at\": 1623660445,\n" + + " \"close_reason\": \"on_demand\"\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + QrCode fetch = qrCodeClient.close(QRCODE_ID); + assertNotNull(fetch); + assertEquals("upi_qr",fetch.get("type")); + assertEquals(QRCODE_ID,fetch.get("id")); + assertEquals(CUSTOMER_ID,fetch.get("customer_id")); + assertTrue(fetch.has("close_by")); + assertTrue(fetch.has("fixed_amount")); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 00adf1287a5047a6edc2d632c4c4778662475182 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 17 Feb 2022 17:25:07 +0530 Subject: [PATCH 52/78] revert apiclient changes --- src/main/java/com/razorpay/ApiClient.java | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index c3ee5fde..d8d71266 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -59,7 +59,7 @@ public void delete(String path, JSONObject requestObject) throws RazorpayExcepti } ArrayList getCollection(String path, JSONObject requestObject) - throws RazorpayException { + throws RazorpayException { Response response = ApiUtils.getRequest(path, requestObject, auth); return processCollectionResponse(response); } @@ -78,8 +78,9 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa } private ArrayList parseCollectionResponse(JSONObject jsonObject) - throws RazorpayException { - ArrayList modelList = new ArrayList(); + throws RazorpayException { + + ArrayList modelList = new ArrayList(); if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { JSONArray jsonArray = jsonObject.getJSONArray("items"); try { @@ -102,10 +103,10 @@ private ArrayList parseCollectionResponse(JSONObject jsonO * and will return entity name with the help of @EntityNameURLMapping class */ private String getEntityNameFromURL(HttpUrl url) { - String param = url.pathSegments().get(1); + String param = url.pathSegments().get(1); return EntityNameURLMapping.getEntityName(param); } - + T processResponse(Response response) throws RazorpayException { if (response == null) { @@ -123,12 +124,12 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); - } - + String entityName = getEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); + } + return parseResponse(responseJson); } @@ -137,7 +138,7 @@ T processResponse(Response response) throws RazorpayException } ArrayList processCollectionResponse(Response response) - throws RazorpayException { + throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } From b6abb4d749ca5edabc6e2530b88dac5348080129 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 17 Feb 2022 17:26:04 +0530 Subject: [PATCH 53/78] revert apiclient changes --- src/main/java/com/razorpay/ApiClient.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index d8d71266..c3ee5fde 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -59,7 +59,7 @@ public void delete(String path, JSONObject requestObject) throws RazorpayExcepti } ArrayList getCollection(String path, JSONObject requestObject) - throws RazorpayException { + throws RazorpayException { Response response = ApiUtils.getRequest(path, requestObject, auth); return processCollectionResponse(response); } @@ -78,9 +78,8 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa } private ArrayList parseCollectionResponse(JSONObject jsonObject) - throws RazorpayException { - - ArrayList modelList = new ArrayList(); + throws RazorpayException { + ArrayList modelList = new ArrayList(); if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { JSONArray jsonArray = jsonObject.getJSONArray("items"); try { @@ -103,10 +102,10 @@ private ArrayList parseCollectionResponse(JSONObject jsonO * and will return entity name with the help of @EntityNameURLMapping class */ private String getEntityNameFromURL(HttpUrl url) { - String param = url.pathSegments().get(1); + String param = url.pathSegments().get(1); return EntityNameURLMapping.getEntityName(param); } - + T processResponse(Response response) throws RazorpayException { if (response == null) { @@ -124,12 +123,12 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); - } - + String entityName = getEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); + } + return parseResponse(responseJson); } @@ -138,7 +137,7 @@ T processResponse(Response response) throws RazorpayException } ArrayList processCollectionResponse(Response response) - throws RazorpayException { + throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } From d5eb46c205837ea05238b5fc10462e8000f31650 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 18 Feb 2022 12:57:29 +0530 Subject: [PATCH 54/78] json format --- .../java/com/razorpay/OrderClientTest.java | 105 ++++++++++++++++-- 1 file changed, 98 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java index 2fec1a76..ec08a755 100644 --- a/src/test/java/com/razorpay/OrderClientTest.java +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -22,8 +22,27 @@ public class OrderClientTest extends BaseTest{ */ @Test public void create() throws RazorpayException { - JSONObject request = new JSONObject("{amount:50000,currency:\"INR\",receipt:\"receipt#1\",notes:{key1:\"value3\",key2:\"value2\"}}"); - String mockedResponseJson = "{\"id\":\"order_EKwxwAgItmmXdp\",\"entity\":\"order\",\"amount\":50000,\"amount_paid\":0,\"amount_due\":50000,\"currency\":\"INR\",\"receipt\":\"receipt#1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582628071}"; + JSONObject request = new JSONObject("{" + + "amount:50000," + + "currency:\"INR\"," + + "receipt:\"receipt#1\"," + + "notes:" + + "{key1:\"value3\"," + + "key2:\"value2\"}}"); + + String mockedResponseJson = "{" + + "\"id\":\"order_EKwxwAgItmmXdp\"," + + "\"entity\":\"order\"," + + "\"amount\":50000," + + "\"amount_paid\":0," + + "\"amount_due\":50000," + + "\"currency\":\"INR\"," + + "\"receipt\":\"receipt#1\"," + + "\"offer_id\":null," + + "\"status\":\"created\"," + + "\"attempts\":0," + + "\"notes\":[]," + + "\"created_at\":1582628071}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -44,7 +63,21 @@ public void create() throws RazorpayException { */ @Test public void fetchAll() throws RazorpayException{ - String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"order_EKzX2WiEWbMxmx\",\"entity\":\"order\",\"amount\":1234,\"amount_paid\":0,\"amount_due\":1234,\"currency\":\"INR\",\"receipt\":\"ReceiptNo.1\",\"offer_id\":null,\"status\":\"created\",\"attempts\":0,\"notes\":[],\"created_at\":1582637108}]}"; + String mockedResponseJson = "{" + + "\"entity\":\"collection\"," + + "\"count\":1,\"items\":" + + "[{\"id\":\"order_EKzX2WiEWbMxmx\"," + + "\"entity\":\"order\"," + + "\"amount\":1234," + + "\"amount_paid\":0," + + "\"amount_due\":1234," + + "\"currency\":\"INR\"," + + "\"receipt\":\"ReceiptNo.1\"," + + "\"offer_id\":null," + + "\"status\":\"created\"," + + "\"attempts\":0," + + "\"notes\":[]," + + "\"created_at\":1582637108}]}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -64,7 +97,17 @@ public void fetchAll() throws RazorpayException{ */ @Test public void fetch() throws RazorpayException{ - String mockedResponseJson = "{\"id\":"+ORDER_ID+",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"status\":\"attempted\",\"attempts\":1,\"notes\":[],\"created_at\":1572505143}"; + String mockedResponseJson = "{\"id\":"+ORDER_ID+"," + + "\"entity\":\"order\"," + + "\"amount\":2200," + + "\"amount_paid\":0," + + "\"amount_due\":2200," + + "\"currency\":\"INR\"," + + "\"receipt\":\"Receipt#211\"," + + "\"status\":\"attempted\"," + + "\"attempts\":1," + + "\"notes\":[]," + + "\"created_at\":1572505143}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -85,7 +128,34 @@ public void fetch() throws RazorpayException{ */ @Test public void fetchPayments() throws RazorpayException{ - String mockedResponseJson = "{\"entity\":\"collection\",\"count\":1,\"items\":[{\"id\":\"pay_DaaSOvhgcOfzgR\",\"entity\":\"payment\",\"amount\":2200,\"currency\":\"INR\",\"status\":\"captured\",\"order_id\":\"order_DaaS6LOUAASb7Y\",\"invoice_id\":null,\"international\":false,\"method\":\"card\",\"amount_refunded\":0,\"refund_status\":null,\"captured\":true,\"description\":\"Beansineveryimaginableflavour\",\"card_id\":\"card_DZon6fd8J3IcA2\",\"bank\":null,\"wallet\":null,\"vpa\":null,\"email\":\"gaurav.kumar@example.com\",\"contact\":\"+919999999988\",\"notes\":[],\"fee\":44,\"tax\":0,\"error_code\":null,\"error_description\":null,\"created_at\":1572505160}]}"; + String mockedResponseJson = "{" + + "\"entity\":\"collection\"," + + "\"count\":1," + + "\"items\":[{\"id\":\"pay_DaaSOvhgcOfzgR\"," + + "\"entity\":\"payment\"," + + "\"amount\":2200," + + "\"currency\":\"INR\"," + + "\"status\":\"captured\"," + + "\"order_id\":\"order_DaaS6LOUAASb7Y\"," + + "\"invoice_id\":null," + + "\"international\":false," + + "\"method\":\"card\"," + + "\"amount_refunded\":0," + + "\"refund_status\":null," + + "\"captured\":true," + + "\"description\":\"Beansineveryimaginableflavour\"," + + "\"card_id\":\"card_DZon6fd8J3IcA2\"," + + "\"bank\":null," + + "\"wallet\":null," + + "\"vpa\":null," + + "\"email\":\"gaurav.kumar@example.com\"," + + "\"contact\":\"+919999999988\"," + + "\"notes\":[]," + + "\"fee\":44," + + "\"tax\":0," + + "\"error_code\":null," + + "\"error_description\":null," + + "\"created_at\":1572505160}]}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); @@ -105,8 +175,29 @@ public void fetchPayments() throws RazorpayException{ */ @Test public void edit() throws RazorpayException { - JSONObject request = new JSONObject("{\"notes\":{\"key1\":\"value3\",\"key2\":\"value2\"}}"); - String mockedResponseJson = "{\"id\":"+ORDER_ID+",\"entity\":\"order\",\"amount\":2200,\"amount_paid\":0,\"amount_due\":2200,\"currency\":\"INR\",\"receipt\":\"Receipt#211\",\"offer_id\":null,\"status\":\"attempted\",\"attempts\":1,\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"},\"created_at\":1572505143}"; + JSONObject request = new JSONObject("{" + + "\"notes\":{" + + "\"key1\":\"value3\"," + + "\"key2\":\"value2\"" + + "}}"); + + String mockedResponseJson = "{" + + "\"id\":"+ORDER_ID+"," + + "\"entity\":\"order\"," + + "\"amount\":2200," + + "\"amount_paid\":0," + + "\"amount_due\":2200," + + "\"currency\":\"INR\"," + + "\"receipt\":\"Receipt#211\"," + + "\"offer_id\":null," + + "\"status\":\"attempted\"," + + "\"attempts\":1," + + "\"notes\":{" + + "\"notes_key_1\":\"Tea,EarlGrey,Hot\"," + + "\"notes_key_2\":\"Tea,EarlGrey…decaf.\"" + + "}," + + "\"created_at\":1572505143" + + "}"; try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); From 6bdf29086622e6470d1e46959e5bba825ea528c2 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 13:36:54 +0530 Subject: [PATCH 55/78] refactoring code --- src/main/java/com/razorpay/ApiClient.java | 41 +++++++++++------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 94a57da4..3a8c613a 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; @@ -153,17 +152,9 @@ ArrayList processCollectionResponse(Response response) } catch (IOException e) { throw new RazorpayException(e.getMessage()); } + + populateEntity(response, responseJson, "items"); - if(responseJson.has("items")){ - JSONArray jsonArray = responseJson.getJSONArray("items"); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - if(!jsonObj.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - jsonObj.put("entity",entityName); - } - } - } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { return parseCollectionResponse(responseJson); @@ -173,28 +164,36 @@ ArrayList processCollectionResponse(Response response) return null; } + private void populateEntity(Response response, JSONObject responseJson, String key) { + if(responseJson.has(key)){ + JSONArray jsonArray = responseJson.getJSONArray(key); + for (Object obj : jsonArray) { + JSONObject jsonObj = (JSONObject) obj; + if(!jsonObj.has(ENTITY)) { + jsonObj.put("entity", getEntityNameFromURL(response.request().url())); + } + } + } + } + private void processDeleteResponse(Response response) throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } - int statusCode = response.code(); - String responseBody = null; - JSONObject responseJson = null; - + String string = null; try { - responseBody = response.body().string(); - if(responseBody.startsWith("[")) { - responseJson = new JSONObject("{}"); - }else { - responseJson = new JSONObject(responseBody); + string = response.body().string(); + if (string.startsWith("[")) { + string = "{}"; } } catch (IOException e) { throw new RazorpayException(e.getMessage()); } + JSONObject jsonObject = new JSONObject(string); if (statusCode < STATUS_OK || statusCode >= STATUS_MULTIPLE_CHOICE) { - throwException(statusCode, responseJson); + throwException(statusCode, jsonObject); } } From 1b8e60cde0beabd4e492614e2edd726407137253 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 13:44:57 +0530 Subject: [PATCH 56/78] update refund api with test cases --- src/main/java/com/razorpay/Constants.java | 1 + src/main/java/com/razorpay/RefundClient.java | 12 + .../java/com/razorpay/RefundClientTest.java | 235 ++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 src/test/java/com/razorpay/RefundClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..c1fcd98c 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -29,6 +29,7 @@ public class Constants { static final String REFUND_GET = "refunds/%s"; static final String REFUND_LIST = "refunds"; static final String REFUND_CREATE = "refunds"; + static final String REFUND_EDIT = "refunds/%s"; static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; diff --git a/src/main/java/com/razorpay/RefundClient.java b/src/main/java/com/razorpay/RefundClient.java index f04857a1..9c3de874 100755 --- a/src/main/java/com/razorpay/RefundClient.java +++ b/src/main/java/com/razorpay/RefundClient.java @@ -25,4 +25,16 @@ public Refund fetch(String id) throws RazorpayException { public List fetchAll() throws RazorpayException { return fetchAll(null); } + + public List fetchMultipleRefund(String id) throws RazorpayException { + return fetchMultipleRefund(id,null); + } + + public List fetchMultipleRefund(String id,JSONObject request) throws RazorpayException { + return getCollection(Constants.PAYMENT_LIST+"/"+id+"/"+Constants.REFUND_LIST, request); + } + + public Refund edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.REFUND_EDIT, id), request); + } } diff --git a/src/test/java/com/razorpay/RefundClientTest.java b/src/test/java/com/razorpay/RefundClientTest.java new file mode 100644 index 00000000..fa45cf9e --- /dev/null +++ b/src/test/java/com/razorpay/RefundClientTest.java @@ -0,0 +1,235 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class RefundClientTest extends BaseTest{ + + @InjectMocks + protected RefundClient refundClient = new RefundClient(TEST_SECRET_KEY); + + private static final String REFUND_ID = "rfnd_FP8QHiV938haTz"; + + /** + * Refund is created using the payment id and amount details. + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + JSONObject request = new JSONObject("{" + + "\"amount\":\"100\"," + + "\"speed\":\"normal\"," + + "\"notes\":{\"notes_key_1\":\"BeammeupScotty.\"," + + "\"notes_key_2\":\"Engage\"}," + + "\"receipt\":\"ReceiptNo.31\"}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+REFUND_ID+",\n" + + " \"entity\": \"refund\",\n" + + " \"amount\": 500100,\n" + + " \"receipt\": \"Receipt No. 31\",\n" + + " \"currency\": \"INR\",\n" + + " \"payment_id\": \"pay_FCXKPFtYfPXJPy\",\n" + + " \"notes\": [],\n" + + " \"acquirer_data\": {\n" + + " \"arn\": null\n" + + " },\n" + + " \"created_at\": 1597078866,\n" + + " \"batch_id\": null,\n" + + " \"status\": \"processed\",\n" + + " \"speed_processed\": \"normal\"\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Refund fetch = refundClient.create(request); + assertNotNull(fetch); + assertEquals(REFUND_ID,fetch.get("id")); + assertEquals("refund",fetch.get("entity")); + assertEquals(500100,(int)fetch.get("amount")); + assertEquals("INR",fetch.get("currency")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all refund details using refund id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\": "+REFUND_ID+",\n" + + " \"entity\": \"refund\",\n" + + " \"amount\": 300100,\n" + + " \"currency\": \"INR\",\n" + + " \"payment_id\": \"pay_FIKOnlyii5QGNx\",\n" + + " \"notes\": {\n" + + " \"comment\": \"Comment for refund\"\n" + + " },\n" + + " \"receipt\": null,\n" + + " \"acquirer_data\": {\n" + + " \"arn\": \"10000000000000\"\n" + + " },\n" + + " \"created_at\": 1597078124,\n" + + " \"batch_id\": null,\n" + + " \"status\": \"processed\",\n" + + " \"speed_processed\": \"normal\",\n" + + " \"speed_requested\": \"optimum\"\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Refund fetch = refundClient.fetch(REFUND_ID); + assertNotNull(fetch); + assertEquals(REFUND_ID,fetch.get("id")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all the refund can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"rfnd_FFX6AnnIN3puqW\",\n" + + " \"entity\": \"refund\",\n" + + " \"amount\": 88800,\n" + + " \"currency\": \"INR\",\n" + + " \"payment_id\": \"pay_FFX5FdEYx8jPwA\",\n" + + " \"notes\": {\n" + + " \"comment\": \"Issuing an instant refund\"\n" + + " },\n" + + " \"receipt\": null,\n" + + " \"acquirer_data\": {},\n" + + " \"created_at\": 1594982363,\n" + + " \"batch_id\": null,\n" + + " \"status\": \"processed\",\n" + + " \"speed_processed\": \"optimum\",\n" + + " \"speed_requested\": \"optimum\"\n" + + " }\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = refundClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("currency")); + assertTrue(fetch.get(0).has("payment_id")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of mutiple refunds for a payment can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchMultipleRefund() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"rfnd_FP8DDKxqJif6ca\",\n" + + " \"entity\": \"refund\",\n" + + " \"amount\": 300100,\n" + + " \"currency\": \"INR\",\n" + + " \"payment_id\": \"pay_FIKOnlyii5QGNx\",\n" + + " \"notes\": {\n" + + " \"comment\": \"Comment for refund\"\n" + + " },\n" + + " \"receipt\": null,\n" + + " \"acquirer_data\": {\n" + + " \"arn\": \"10000000000000\"\n" + + " },\n" + + " \"created_at\": 1597078124,\n" + + " \"batch_id\": null,\n" + + " \"status\": \"processed\",\n" + + " \"speed_processed\": \"normal\",\n" + + " \"speed_requested\": \"optimum\"\n" + + " }\n" + + " ]\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = refundClient.fetchMultipleRefund(REFUND_ID); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("currency")); + assertTrue(fetch.get(0).has("payment_id")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Update an refund details using refund id with object of that properties + * @throws RazorpayException + */ + @Test + public void edit() throws RazorpayException{ + JSONObject request = new JSONObject("" + + "{\"notes\":" + + "{\"notes_key_1\":\"BeammeupScotty.\"," + + "\"notes_key_2\":\"Engage\"}}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+REFUND_ID+",\n" + + " \"entity\": \"refund\",\n" + + " \"amount\": 300100,\n" + + " \"currency\": \"INR\",\n" + + " \"payment_id\": \"pay_FIKOnlyii5QGNx\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty.\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"receipt\": null,\n" + + " \"acquirer_data\": {\n" + + " \"arn\": \"10000000000000\"\n" + + " },\n" + + " \"created_at\": 1597078124,\n" + + " \"batch_id\": null,\n" + + " \"status\": \"processed\",\n" + + " \"speed_processed\": \"normal\",\n" + + " \"speed_requested\": \"optimum\"\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Refund fetch = refundClient.edit(REFUND_ID, request); + assertNotNull(fetch); + assertEquals(REFUND_ID,fetch.get("id")); + assertEquals("refund",fetch.get("entity")); + assertEquals(300100,(int)fetch.get("amount")); + assertEquals("INR",fetch.get("currency")); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From d34f55607ce875a33d654aabdfa0eee9de53dc25 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 15:11:54 +0530 Subject: [PATCH 57/78] url changes --- src/main/java/com/razorpay/Constants.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 4e1201d1..c5932b21 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -40,11 +40,8 @@ public class Constants { static final String INVOICE_LIST = "invoices"; static final String INVOICE_CANCEL = "invoices/%s/cancel"; - static final String ITEM_CREATE = "items"; - static final String ITEM_GET = "items/%s"; - static final String ITEM_LIST = "items"; - static final String ITEM_EDIT = "items/%s"; - static final String ITEM_DELETE = "items/%s"; + static final String ITEMS = "items"; + static final String ITEM = "items/%s"; static final String CARD_GET = "cards/%s"; From 436f99843f577705a5931a6b6d269ff800c1e5de Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 16:15:39 +0530 Subject: [PATCH 58/78] url issue resolve --- src/main/java/com/razorpay/Constants.java | 7 +++---- src/main/java/com/razorpay/RefundClient.java | 10 +++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index c1fcd98c..ffbb90a9 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -26,10 +26,9 @@ public class Constants { static final String PAYMENT_REFUND_LIST = "payments/%s/refunds"; static final String PAYMENT_REFUND_GET = "payments/%s/refunds/%s"; - static final String REFUND_GET = "refunds/%s"; - static final String REFUND_LIST = "refunds"; - static final String REFUND_CREATE = "refunds"; - static final String REFUND_EDIT = "refunds/%s"; + static final String REFUND = "refunds/%s"; + static final String REFUNDS = "refunds"; + static final String REFUND_MULTIPLE = "payments/%s/refunds"; static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; diff --git a/src/main/java/com/razorpay/RefundClient.java b/src/main/java/com/razorpay/RefundClient.java index 9c3de874..78bc5345 100755 --- a/src/main/java/com/razorpay/RefundClient.java +++ b/src/main/java/com/razorpay/RefundClient.java @@ -11,15 +11,15 @@ public class RefundClient extends ApiClient { } public Refund create(JSONObject request) throws RazorpayException { - return post(Constants.REFUND_CREATE, request); + return post(Constants.REFUNDS, request); } public List fetchAll(JSONObject request) throws RazorpayException { - return getCollection(Constants.REFUND_LIST, request); + return getCollection(Constants.REFUNDS, request); } public Refund fetch(String id) throws RazorpayException { - return get(String.format(Constants.REFUND_GET, id), null); + return get(String.format(Constants.REFUND, id), null); } public List fetchAll() throws RazorpayException { @@ -31,10 +31,10 @@ public List fetchMultipleRefund(String id) throws RazorpayException { } public List fetchMultipleRefund(String id,JSONObject request) throws RazorpayException { - return getCollection(Constants.PAYMENT_LIST+"/"+id+"/"+Constants.REFUND_LIST, request); + return getCollection(String.format(Constants.REFUND_MULTIPLE, id), request); } public Refund edit(String id, JSONObject request) throws RazorpayException { - return patch(String.format(Constants.REFUND_EDIT, id), request); + return patch(String.format(Constants.REFUND, id), request); } } From 93aa97d8196be32cca7a616a59cf9a158b0e5c0f Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 18:03:24 +0530 Subject: [PATCH 59/78] bookmark --- src/main/java/com/razorpay/ItemClient.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/razorpay/ItemClient.java b/src/main/java/com/razorpay/ItemClient.java index 2637e327..010cfc96 100644 --- a/src/main/java/com/razorpay/ItemClient.java +++ b/src/main/java/com/razorpay/ItemClient.java @@ -11,11 +11,11 @@ public class ItemClient extends ApiClient{ } public Item create(JSONObject request) throws RazorpayException { - return post(Constants.ITEM_CREATE, request); + return post(Constants.ITEMS, request); } public Item fetch(String id) throws RazorpayException { - return get(String.format(Constants.ITEM_GET, id), null); + return get(String.format(Constants.ITEM, id), null); } public List fetchAll() throws RazorpayException { @@ -23,14 +23,14 @@ public List fetchAll() throws RazorpayException { } public Item edit(String id, JSONObject request) throws RazorpayException { - return patch(String.format(Constants.ITEM_EDIT, id), request); + return patch(String.format(Constants.ITEM, id), request); } public List fetchAll(JSONObject request) throws RazorpayException { - return getCollection(Constants.ITEM_LIST, request); + return getCollection(Constants.ITEMS, request); } public void delete(String id) throws RazorpayException { - delete(String.format(Constants.ITEM_DELETE, id), null); + delete(String.format(Constants.ITEM, id), null); } } \ No newline at end of file From 57af519d3172f85ad2c47cfe6cd710571e493f6a Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 18:42:50 +0530 Subject: [PATCH 60/78] parsecollection resolve --- src/main/java/com/razorpay/ApiClient.java | 67 ++++++++++------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 25a2f5b6..c6e20efa 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -77,35 +77,20 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa throw new RazorpayException("Unable to parse response"); } - private ArrayList parseCollectionResponse(JSONObject jsonObject) + private ArrayList parseCollectionResponse(JSONArray jsonArray) throws RazorpayException { ArrayList modelList = new ArrayList(); - if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { - - JSONArray jsonArray = new JSONArray(); - - if(jsonObject.has("items")) { - jsonArray = jsonObject.getJSONArray("items"); - } - - if(jsonObject.has("payment_links")) { - jsonArray = jsonObject.getJSONArray("payment_links"); - } - - try { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - T t = parseResponse(jsonObj); - modelList.add(t); - } - return modelList; - } catch (RazorpayException e) { - throw e; + try { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + T t = parseResponse(jsonObj); + modelList.add(t); } + return modelList; + } catch (RazorpayException e) { + throw e; } - - throw new RazorpayException("Unable to parse response"); } /* @@ -163,28 +148,32 @@ ArrayList processCollectionResponse(Response response) } catch (IOException e) { throw new RazorpayException(e.getMessage()); } - - if(responseJson.has("payment_links")){ - responseJson.put("entity","collection"); - JSONArray jsonArray = responseJson.getJSONArray("payment_links"); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - if(!jsonObj.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - jsonObj.put("entity",entityName); - } - - } - } - + + String collectionName = null; + collectionName = responseJson.has("payment_links")? + "payment_links": "items"; + + JSONArray collection = responseJson.getJSONArray(collectionName); + populateEntityInCollection(response, collection); + if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - return parseCollectionResponse(responseJson); + return parseCollectionResponse(collection); } throwException(statusCode, responseJson); return null; } + private void populateEntityInCollection(Response response, JSONArray jsonArray) { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + if(!jsonObj.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + jsonObj.put("entity",entityName); + } + } + } + private void processDeleteResponse(Response response) throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); From 674e2106d64a7a0f6313baa95304493ce8acf438 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 22 Feb 2022 18:53:22 +0530 Subject: [PATCH 61/78] parse collection resolve --- src/main/java/com/razorpay/ApiClient.java | 78 +++++++++++------------ 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 3a8c613a..f558c0bf 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; @@ -76,25 +77,20 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa throw new RazorpayException("Unable to parse response"); } - private ArrayList parseCollectionResponse(JSONObject jsonObject) - throws RazorpayException { + private ArrayList parseCollectionResponse(JSONArray jsonArray) + throws RazorpayException { ArrayList modelList = new ArrayList(); - if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { - JSONArray jsonArray = jsonObject.getJSONArray("items"); - try { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - T t = parseResponse(jsonObj); - modelList.add(t); - } - return modelList; - } catch (RazorpayException e) { - throw e; + try { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + T t = parseResponse(jsonObj); + modelList.add(t); } + return modelList; + } catch (RazorpayException e) { + throw e; } - - throw new RazorpayException("Unable to parse response"); } /* @@ -123,12 +119,12 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); - } - + String entityName = getEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); + } + return parseResponse(responseJson); } @@ -137,7 +133,7 @@ T processResponse(Response response) throws RazorpayException } ArrayList processCollectionResponse(Response response) - throws RazorpayException { + throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } @@ -152,27 +148,29 @@ ArrayList processCollectionResponse(Response response) } catch (IOException e) { throw new RazorpayException(e.getMessage()); } - - populateEntity(response, responseJson, "items"); + String collectionName = null; + collectionName = responseJson.has("payment_links")? + "payment_links": "items"; + + JSONArray collection = responseJson.getJSONArray(collectionName); + populateEntityInCollection(response, collection); if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - return parseCollectionResponse(responseJson); + return parseCollectionResponse(collection); } throwException(statusCode, responseJson); return null; } - private void populateEntity(Response response, JSONObject responseJson, String key) { - if(responseJson.has(key)){ - JSONArray jsonArray = responseJson.getJSONArray(key); - for (Object obj : jsonArray) { - JSONObject jsonObj = (JSONObject) obj; - if(!jsonObj.has(ENTITY)) { - jsonObj.put("entity", getEntityNameFromURL(response.request().url())); - } - } + private void populateEntityInCollection(Response response, JSONArray jsonArray) { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + if(!jsonObj.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + jsonObj.put("entity",entityName); + } } } @@ -180,20 +178,20 @@ private void processDeleteResponse(Response response) throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } + int statusCode = response.code(); - String string = null; + String responseBody = null; + JSONObject responseJson = null; + try { - string = response.body().string(); - if (string.startsWith("[")) { - string = "{}"; - } + responseBody = response.body().string(); + responseJson = new JSONObject(responseBody); } catch (IOException e) { throw new RazorpayException(e.getMessage()); } - JSONObject jsonObject = new JSONObject(string); if (statusCode < STATUS_OK || statusCode >= STATUS_MULTIPLE_CHOICE) { - throwException(statusCode, jsonObject); + throwException(statusCode, responseJson); } } From 33edb83e3f67f5d6a194307cd963e905e8c687a4 Mon Sep 17 00:00:00 2001 From: ersinghlovepreet Date: Thu, 24 Feb 2022 12:33:40 +0530 Subject: [PATCH 62/78] Added subscriptions api's and test cases --- src/main/java/com/razorpay/Constants.java | 6 +- .../java/com/razorpay/SubscriptionClient.java | 22 +- src/test/java/com/razorpay/BaseTest.java | 5 + .../com/razorpay/SubscriptionClientTest.java | 388 ++++++++++++++++++ 4 files changed, 419 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/razorpay/SubscriptionClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..0f77f662 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -61,10 +61,14 @@ public class Constants { static final String PLAN_LIST = "plans"; static final String SUBSCRIPTION_CREATE = "subscriptions"; - static final String SUBSCRIPTION_GET = "subscriptions/%s"; + static final String SUBSCRIPTION = "subscriptions/%s"; static final String SUBSCRIPTION_LIST = "subscriptions"; static final String SUBSCRIPTION_CANCEL = "subscriptions/%s/cancel"; static final String SUBSCRIPTION_ADDON_CREATE = "subscriptions/%s/addons"; + static final String SUBSCRIPTION_PENDING_UPDATE = "subscriptions/%s/retrieve_scheduled_changes"; + static final String SUBSCRIPTION_CANCEL_SCHEDULED_UPDATE = "subscriptions/%s/cancel_scheduled_changes"; + static final String PAUSE_SUBSCRIPTION = "subscriptions/%s/pause"; + static final String RESUME_SUBSCRIPTION = "subscriptions/%s/resume"; static final String ADDON_GET = "addons/%s"; static final String ADDON_DELETE = "addons/%s"; diff --git a/src/main/java/com/razorpay/SubscriptionClient.java b/src/main/java/com/razorpay/SubscriptionClient.java index 1be423fa..a4a97036 100644 --- a/src/main/java/com/razorpay/SubscriptionClient.java +++ b/src/main/java/com/razorpay/SubscriptionClient.java @@ -15,7 +15,7 @@ public Subscription create(JSONObject request) throws RazorpayException { } public Subscription fetch(String id) throws RazorpayException { - return get(String.format(Constants.SUBSCRIPTION_GET, id), null); + return get(String.format(Constants.SUBSCRIPTION, id), null); } public List fetchAll() throws RazorpayException { @@ -33,4 +33,24 @@ public Subscription cancel(String id) throws RazorpayException { public Addon createAddon(String id, JSONObject request) throws RazorpayException { return post(String.format(Constants.SUBSCRIPTION_ADDON_CREATE, id), request); } + + public Subscription update(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants.SUBSCRIPTION, id), request); + } + + public Subscription fetchPendingUpdate(String id) throws RazorpayException { + return get(String.format(Constants.SUBSCRIPTION_PENDING_UPDATE, id), null); + } + + public Subscription cancelPendingUpdate(String id) throws RazorpayException { + return post(String.format(Constants.SUBSCRIPTION_CANCEL_SCHEDULED_UPDATE, id), null); + } + + public Subscription pause(String id, JSONObject request) throws RazorpayException { + return post(String.format(Constants.PAUSE_SUBSCRIPTION, id), request); + } + + public Subscription resume(String id, JSONObject request) throws RazorpayException { + return post(String.format(Constants.RESUME_SUBSCRIPTION, id), request); + } } diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 52eaad71..72aa73cc 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -61,4 +61,9 @@ protected void mockResponseFromExternalClient(String response) throws IOExceptio when(rb.string()).thenReturn(parse.toString()); when(mockedResponse.body()).thenReturn(rb); } + + protected OkHttpClient getOkHttpClient() + { + return okHttpClient; + } } \ No newline at end of file diff --git a/src/test/java/com/razorpay/SubscriptionClientTest.java b/src/test/java/com/razorpay/SubscriptionClientTest.java new file mode 100644 index 00000000..f7c7204f --- /dev/null +++ b/src/test/java/com/razorpay/SubscriptionClientTest.java @@ -0,0 +1,388 @@ +package com.razorpay; + +import okhttp3.Request; +import okio.Buffer; +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class SubscriptionClientTest extends BaseTest { + + public static final String TEST_PLAN_ID = "testPlanId"; + public static final String TEST_SUBSCRIPTION_ID = "testSubId"; + public static final String TEST_SUBSCRIPTION_ID_2 = "testSubId"; + public static final String PLAN_ID = "plan_id"; + public static final String SUBSCRIPTION_ID = "id"; + public static final String ADDON_ID = "id"; + public static final String ADDON_SUBSCRIPTION_ID = "subscription_id"; + public static final String TEST_ADDON_ID = "ao_00000000000001"; + public static final String ADDON_ITEM_ID = "item_00000000000001"; + @InjectMocks + private SubscriptionClient subscriptionClient = new SubscriptionClient(TEST_SECRET_KEY); + + @Test + public void testCreate() throws IOException, RazorpayException { + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.create(new JSONObject(getRequest())); + assertEquals(TEST_PLAN_ID, subscription.get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + String subscriptionCreate = getHost(Constants.SUBSCRIPTION_CREATE); + verifySentRequest(true, getRequest(), subscriptionCreate); + } + + private String getHost(String url) { + return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; + } + + public void verifySentRequest(boolean hasBody, String request, String requestPath) { + ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); + Mockito.verify(getOkHttpClient()).newCall(req.capture()); + if(hasBody) { + assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); + } + assertEquals(requestPath, req.getValue().url().toString()); + } + + @Test(expected = RazorpayException.class) + public void testCreateWithException() throws IOException, RazorpayException { + + String mockedResponseJson = getMockedErrorResponse(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(400); + Subscription subscription = subscriptionClient.create(new JSONObject(getRequest())); + assertEquals(TEST_PLAN_ID, subscription.get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + } + + @Test + public void testFetch() throws IOException, RazorpayException { + + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.fetch(TEST_SUBSCRIPTION_ID); + assertEquals(TEST_PLAN_ID, subscription.get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + verifySentRequest(false, null, getHost(String.format(Constants.SUBSCRIPTION, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testFetchAll() throws IOException, RazorpayException { + String mockedResponseJson = getSubscriptionCollectionMockedResponse(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List subscriptionList = subscriptionClient.fetchAll(); + assertEquals(TEST_PLAN_ID, subscriptionList.get(0).get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscriptionList.get(0).get(SUBSCRIPTION_ID)); + assertEquals(TEST_PLAN_ID, subscriptionList.get(1).get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID_2, subscriptionList.get(1).get(SUBSCRIPTION_ID)); + verifySentRequest(false, null, getHost(Constants.SUBSCRIPTION_LIST)); + } + + private String getSubscriptionCollectionMockedResponse() { + return "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 2,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"" + TEST_SUBSCRIPTION_ID + "\",\n" + + " \"entity\": \"subscription\",\n" + + " \"plan_id\": \"" + TEST_PLAN_ID + "\",\n" + + " \"customer_id\": null,\n" + + " \"status\": \"active\",\n" + + " \"current_start\": 1645527920,\n" + + " \"current_end\": 1647887400,\n" + + " \"ended_at\": null,\n" + + " \"quantity\": 1,\n" + + " \"notes\": [\n" + + " \n" + + " ],\n" + + " \"charge_at\": 1647887400,\n" + + " \"start_at\": 1645527920,\n" + + " \"end_at\": 1653157800,\n" + + " \"auth_attempts\": 0,\n" + + " \"total_count\": 4,\n" + + " \"paid_count\": 1,\n" + + " \"customer_notify\": true,\n" + + " \"created_at\": 1645527865,\n" + + " \"expire_by\": null,\n" + + " \"short_url\": \"https:\\/\\/rzp.io\\/i\\/NkOtrmtV61\",\n" + + " \"has_scheduled_changes\": false,\n" + + " \"change_scheduled_at\": null,\n" + + " \"source\": \"dashboard\",\n" + + " \"payment_method\": \"card\",\n" + + " \"offer_id\": null,\n" + + " \"remaining_count\": 3\n" + + " },\n" + + " {\n" + + " \"id\": \"" + TEST_SUBSCRIPTION_ID_2 + "\",\n" + + " \"entity\": \"subscription\",\n" + + " \"plan_id\": \"" + TEST_PLAN_ID + "\",\n" + + " \"customer_id\": null,\n" + + " \"status\": \"active\",\n" + + " \"current_start\": 1645525263,\n" + + " \"current_end\": 1647887400,\n" + + " \"ended_at\": null,\n" + + " \"quantity\": 5,\n" + + " \"notes\": [\n" + + " \n" + + " ],\n" + + " \"charge_at\": 1647887400,\n" + + " \"start_at\": 1645525263,\n" + + " \"end_at\": 1658428200,\n" + + " \"auth_attempts\": 0,\n" + + " \"total_count\": 6,\n" + + " \"paid_count\": 1,\n" + + " \"customer_notify\": false,\n" + + " \"created_at\": 1645523724,\n" + + " \"expire_by\": null,\n" + + " \"short_url\": \"https:\\/\\/rzp.io\\/i\\/UI21N7A\",\n" + + " \"has_scheduled_changes\": false,\n" + + " \"change_scheduled_at\": null,\n" + + " \"source\": \"dashboard\",\n" + + " \"payment_method\": \"card\",\n" + + " \"offer_id\": null,\n" + + " \"remaining_count\": 5\n" + + " }\n" + + " ]\n" + + "}"; + } + + @Test + public void testTestFetchAllFilteredByPlan() throws IOException, RazorpayException { + + String mockedResponseJson = getSubscriptionCollectionMockedResponse(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List subscriptionList = + subscriptionClient.fetchAll(new JSONObject(getFetchAllFilteredRequestPlanIdAndCount2())); + //as count 1 in filter + assertEquals(2, subscriptionList.size()); + assertEquals(TEST_PLAN_ID, subscriptionList.get(0).get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscriptionList.get(0).get(SUBSCRIPTION_ID)); + String host = getHost(Constants.SUBSCRIPTION_LIST)+"?count=1&plan_id="+TEST_PLAN_ID; + verifySentRequest(false, null, host); + } + + @Test + public void testCancel() throws IOException, RazorpayException { + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + mockURL(Arrays.asList("v1", "subscriptions")); + Subscription subscription = subscriptionClient.cancel(TEST_SUBSCRIPTION_ID); + assertEquals(TEST_PLAN_ID, subscription.get(PLAN_ID)); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + verifySentRequest(false, null, getHost(String.format(Constants.SUBSCRIPTION_CANCEL, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testCreateAddon() throws IOException, RazorpayException { + String mockedResponseJson = getAddonMockedResponse(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Addon addon = subscriptionClient.createAddon(TEST_SUBSCRIPTION_ID, new JSONObject(getCreateAddonRequest())); + assertEquals(TEST_SUBSCRIPTION_ID, addon.get(ADDON_SUBSCRIPTION_ID)); + assertEquals(TEST_ADDON_ID, addon.get(ADDON_ID)); + verifySentRequest(true, getCreateAddonRequest(), getHost(String.format(Constants.SUBSCRIPTION_ADDON_CREATE, TEST_SUBSCRIPTION_ID))); + } + + + @Test + public void testUpdate() throws IOException, RazorpayException { + String mockedResponseJson = getResponse(TEST_PLAN_ID, TEST_SUBSCRIPTION_ID, 2); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.update(TEST_SUBSCRIPTION_ID, new JSONObject(getRequest())); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + assertEquals(2, (int) subscription.get("quantity")); + verifySentRequest(true, getRequest(), getHost(String.format(Constants.SUBSCRIPTION, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testFetchPendingUpdate() throws IOException, RazorpayException { + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.fetchPendingUpdate(TEST_SUBSCRIPTION_ID); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + assertEquals(1, (int) subscription.get("quantity")); + verifySentRequest(false, null, getHost(String.format(Constants.SUBSCRIPTION_PENDING_UPDATE, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testCancelPendingUpdate() throws IOException, RazorpayException { + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.cancelPendingUpdate(TEST_SUBSCRIPTION_ID); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + assertEquals(1, (int) subscription.get("quantity")); + verifySentRequest(false, null, getHost(String.format(Constants.SUBSCRIPTION_CANCEL_SCHEDULED_UPDATE, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testPause() throws RazorpayException, IOException { + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.pause(TEST_SUBSCRIPTION_ID, new JSONObject(getRequest())); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + assertEquals(1, (int) subscription.get("quantity")); + verifySentRequest(true, getRequest(), getHost(String.format(Constants.PAUSE_SUBSCRIPTION, TEST_SUBSCRIPTION_ID))); + } + + @Test + public void testResume() throws IOException, RazorpayException { + + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.resume(TEST_SUBSCRIPTION_ID, new JSONObject(getRequest())); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + assertEquals(1, (int) subscription.get("quantity")); + verifySentRequest(true, getRequest(), getHost(String.format(Constants.RESUME_SUBSCRIPTION, TEST_SUBSCRIPTION_ID))); + } + + private String getAddonMockedResponse() { + return "{\n" + + " \"id\":\"" + TEST_ADDON_ID + "\",\n" + + " \"entity\":\"addon\",\n" + + " \"item\":{\n" + + " \"id\":\"" + ADDON_ITEM_ID + "\",\n" + + " \"active\":true,\n" + + " \"name\":\"Extra appala (papadum)\",\n" + + " \"description\":\"1 extra oil fried appala with meals\",\n" + + " \"amount\":30000,\n" + + " \"unit_amount\":30000,\n" + + " \"currency\":\"INR\",\n" + + " \"type\":\"addon\",\n" + + " \"unit\":null,\n" + + " \"tax_inclusive\":false,\n" + + " \"hsn_code\":null,\n" + + " \"sac_code\":null,\n" + + " \"tax_rate\":null,\n" + + " \"tax_id\":null,\n" + + " \"tax_group_id\":null,\n" + + " \"created_at\":1581597318,\n" + + " \"updated_at\":1581597318\n" + + " },\n" + + " \"quantity\":2,\n" + + " \"created_at\":1581597318,\n" + + " \"subscription_id\":\"" + TEST_SUBSCRIPTION_ID + "\",\n" + + " \"invoice_id\":null\n" + + "}"; + } + + private String getCreateAddonRequest() { + return "{\n" + + " \"item\":{\n" + + " \"name\":\"Extra appala (papadum)\",\n" + + " \"amount\":30000,\n" + + " \"currency\":\"INR\",\n" + + " \"description\":\"1 extra oil fried appala with meals\"\n" + + " },\n" + + " \"quantity\":2\n" + + "}"; + } + private String getMockedErrorResponse() { + return "{\n" + + " \"error\": {\n" + + " \"code\": \"BAD_REQUEST_ERROR\",\n" + + " \"description\": \"Either end_at or total_count should be sent and not both.\"\n" + + " }\n" + + "}"; + } + + private String getFetchAllFilteredRequestPlanIdAndCount2() { + return "{\n" + + " \"plan_id\": \"" + TEST_PLAN_ID + "\",\n" + + " \"count\": 1\n" + + "}"; + } + + private String getRequest() { + return "{\n" + + " \"plan_id\":\"" + TEST_PLAN_ID + "\",\n" + + " \"total_count\":6,\n" + + " \"quantity\":1,\n" + + " \"start_at\":1735689600,\n" + + " \"expire_by\":1893456000,\n" + + " \"customer_notify\":1,\n" + + " \"addons\":[\n" + + " {\n" + + " \"item\":{\n" + + " \"name\":\"Delivery charges\",\n" + + " \"amount\":30000,\n" + + " \"currency\":\"INR\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"offer_id\":\"{offer_id}\",\n" + + " \"notes\":{\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + } + + private String getMockedResponseJson() { + return getResponse(TEST_PLAN_ID, TEST_SUBSCRIPTION_ID, 1); + } + + private String getResponse(String testPlanId, String testSubscriptionId, int quantity) { + return "{\n" + + " \"end_at\": 1653157800,\n" + + " \"paid_count\": 1,\n" + + " \"notes\": [\n" + + " \n" + + " ],\n" + + " \"created_at\": 1645527865,\n" + + " \"source\": \"dashboard\",\n" + + " \"start_at\": 1645527920,\n" + + " \"current_end\": 1647887400,\n" + + " \"charge_at\": 1647887400,\n" + + " \"short_url\": \"dummy\",\n" + + " \"change_scheduled_at\": null,\n" + + " \"id\": \"" + testSubscriptionId + "\",\n" + + " \"expire_by\": null,\n" + + " \"payment_method\": \"card\",\n" + + " \"quantity\": " + quantity + ",\n" + + " \"has_scheduled_changes\": false,\n" + + " \"remaining_count\": 3,\n" + + " \"total_count\": 4,\n" + + " \"offer_id\": null,\n" + + " \"customer_notify\": true,\n" + + " \"auth_attempts\": 0,\n" + + " \"customer_id\": null,\n" + + " \"entity\": \"subscription\",\n" + + " \"plan_id\": \"" + testPlanId + "\",\n" + + " \"ended_at\": null,\n" + + " \"status\": \"active\",\n" + + " \"current_start\": 1645527920\n" + + "}"; + } + + private static String bodyToString(final Request request) { + + try { + final Request copy = request.newBuilder().build(); + final Buffer buffer = new Buffer(); + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "did not work"; + } + } + +} \ No newline at end of file From 233153fcda82952414ad5370cba9997ceef41686 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 25 Feb 2022 10:04:09 +0530 Subject: [PATCH 63/78] implement settlement with test cases --- src/main/java/com/razorpay/ApiClient.java | 68 ++-- src/main/java/com/razorpay/Constants.java | 6 + .../com/razorpay/EntityNameURLMapping.java | 3 +- .../java/com/razorpay/RazorpayClient.java | 2 + src/main/java/com/razorpay/Settlement.java | 10 + .../java/com/razorpay/SettlementClient.java | 66 ++++ .../com/razorpay/SettlementClientTest.java | 299 ++++++++++++++++++ 7 files changed, 428 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/razorpay/Settlement.java create mode 100644 src/main/java/com/razorpay/SettlementClient.java create mode 100644 src/test/java/com/razorpay/SettlementClientTest.java diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..16128125 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -59,7 +59,7 @@ public void delete(String path, JSONObject requestObject) throws RazorpayExcepti } ArrayList getCollection(String path, JSONObject requestObject) - throws RazorpayException { + throws RazorpayException { Response response = ApiUtils.getRequest(path, requestObject, auth); return processCollectionResponse(response); } @@ -77,25 +77,20 @@ private T parseResponse(JSONObject jsonObject) throws Razorpa throw new RazorpayException("Unable to parse response"); } - private ArrayList parseCollectionResponse(JSONObject jsonObject) - throws RazorpayException { + private ArrayList parseCollectionResponse(JSONArray jsonArray) + throws RazorpayException { ArrayList modelList = new ArrayList(); - if (jsonObject.has(ENTITY) && COLLECTION.equals(jsonObject.getString(ENTITY))) { - JSONArray jsonArray = jsonObject.getJSONArray("items"); - try { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - T t = parseResponse(jsonObj); - modelList.add(t); - } - return modelList; - } catch (RazorpayException e) { - throw e; + try { + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + T t = parseResponse(jsonObj); + modelList.add(t); } + return modelList; + } catch (RazorpayException e) { + throw e; } - - throw new RazorpayException("Unable to parse response"); } /* @@ -103,10 +98,10 @@ private ArrayList parseCollectionResponse(JSONObject jsonO * and will return entity name with the help of @EntityNameURLMapping class */ private String getEntityNameFromURL(HttpUrl url) { - String param = url.pathSegments().get(1); + String param = url.pathSegments().get(1); return EntityNameURLMapping.getEntityName(param); } - + T processResponse(Response response) throws RazorpayException { if (response == null) { @@ -124,12 +119,14 @@ T processResponse(Response response) throws RazorpayException } if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - + if(!responseJson.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); - } - + String entityName = getEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); + }else if(responseJson.get("entity").toString().equals("settlement.ondemand")){ + responseJson.put("entity","settlement"); + } + return parseResponse(responseJson); } @@ -138,7 +135,7 @@ T processResponse(Response response) throws RazorpayException } ArrayList processCollectionResponse(Response response) - throws RazorpayException { + throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } @@ -154,14 +151,35 @@ ArrayList processCollectionResponse(Response response) throw new RazorpayException(e.getMessage()); } + String collectionName = null; + collectionName = responseJson.has("payment_links")? + "payment_links": "items"; + + JSONArray collection = responseJson.getJSONArray(collectionName); + populateEntityInCollection(response, collection); + if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - return parseCollectionResponse(responseJson); + return parseCollectionResponse(collection); } throwException(statusCode, responseJson); return null; } + private void populateEntityInCollection(Response response, JSONArray jsonArray) { + + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + + if(!jsonObj.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + jsonObj.put("entity",entityName); + }else if(jsonObj.get("entity").toString().equals("settlement.ondemand")){ + jsonObj.put("entity","settlement"); + } + } + } + private void processDeleteResponse(Response response) throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..fac0db51 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -30,6 +30,12 @@ public class Constants { static final String REFUND_LIST = "refunds"; static final String REFUND_CREATE = "refunds"; + static final String SETTLEMENTS = "settlements"; + static final String SETTLEMENT = "settlements/%s"; + static final String SETTLEMENTS_REPORTS = "settlements/recon/combined"; + static final String SETTLEMENTS_INSTANT = "settlements/ondemand"; + static final String SETTLEMENT_INSTANT = "settlements/ondemand/%s"; + static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; static final String ORDER_LIST = "orders"; diff --git a/src/main/java/com/razorpay/EntityNameURLMapping.java b/src/main/java/com/razorpay/EntityNameURLMapping.java index 0cad70b2..74159b5c 100644 --- a/src/main/java/com/razorpay/EntityNameURLMapping.java +++ b/src/main/java/com/razorpay/EntityNameURLMapping.java @@ -11,7 +11,8 @@ public enum EntityNameURLMapping { INVOICES("invoice"), - PAYMENTS("payment"); + PAYMENTS("payment"), + SETTLEMENTS("settlement"); private String entity; diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index abea7d3b..b469296e 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -16,6 +16,7 @@ public class RazorpayClient { public SubscriptionClient Subscriptions; public AddonClient Addons; public PlanClient Plans; + public SettlementClient Settlement; public VirtualAccountClient VirtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { @@ -35,6 +36,7 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R Subscriptions = new SubscriptionClient(auth); Addons = new AddonClient(auth); Plans = new PlanClient(auth); + Settlement = new SettlementClient(auth); VirtualAccounts = new VirtualAccountClient(auth); } diff --git a/src/main/java/com/razorpay/Settlement.java b/src/main/java/com/razorpay/Settlement.java new file mode 100644 index 00000000..33effdc4 --- /dev/null +++ b/src/main/java/com/razorpay/Settlement.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class Settlement extends Entity { + + public Settlement(JSONObject jsonObject) { + super(jsonObject); + } +} \ No newline at end of file diff --git a/src/main/java/com/razorpay/SettlementClient.java b/src/main/java/com/razorpay/SettlementClient.java new file mode 100644 index 00000000..e8f9bf40 --- /dev/null +++ b/src/main/java/com/razorpay/SettlementClient.java @@ -0,0 +1,66 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +public class SettlementClient extends ApiClient { + + SettlementClient(String auth) { + super(auth); + } + + /** + * It is wrapper of fetchAll with parameter here sending null defines fetchAll + * with a default values without filteration + * @throws RazorpayException + */ + public List fetchAll() throws RazorpayException { + return fetchAll(null); + } + + /** + * This method get list of Settlements filtered by parameters @request + * @throws RazorpayException + */ + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.SETTLEMENTS, request); + } + + public Settlement fetch(String id) throws RazorpayException { + return get(String.format(Constants.SETTLEMENT, id), null); + } + + public List reports(JSONObject request) throws RazorpayException { + return getCollection(Constants.SETTLEMENTS_REPORTS, request); + } + + public List reports() throws RazorpayException { + return reports(null); + } + + public Settlement create(JSONObject request) throws RazorpayException { + return post(Constants.SETTLEMENTS_INSTANT, request); + } + + /** + * It is wrapper of fetchAllDemand with parameter here sending null defines fetchAllDemand + * with a default values without filteration + * @throws RazorpayException + */ + public List fetchAllDemand() throws RazorpayException { + return fetchAllDemand(null); + } + + /** + * This method get list of demand Settlements filtered by parameters @request + * @throws RazorpayException + */ + public List fetchAllDemand(JSONObject request) throws RazorpayException { + return getCollection(Constants.SETTLEMENTS_INSTANT, request); + } + + public Settlement fetchDemandSettlement(String id) throws RazorpayException { + return get(String.format(Constants.SETTLEMENT_INSTANT, id), null); + } +} diff --git a/src/test/java/com/razorpay/SettlementClientTest.java b/src/test/java/com/razorpay/SettlementClientTest.java new file mode 100644 index 00000000..0301d8cb --- /dev/null +++ b/src/test/java/com/razorpay/SettlementClientTest.java @@ -0,0 +1,299 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class SettlementClientTest extends BaseTest{ + + @InjectMocks + protected SettlementClient settlementClient = new SettlementClient(TEST_SECRET_KEY); + + private static final String SETTLEMENT_ID = "setl_DGlQ1Rj8os78Ec"; + + /** + * Details of all the Settlement can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 2,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"setl_DGlQ1Rj8os78Ec\",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount\": 9973635,\n" + + " \"status\": \"processed\",\n" + + " \"fees\": 471699,\n" + + " \"tax\": 42070,\n" + + " \"utr\": \"1568176960vxp0rj\",\n" + + " \"created_at\": 1568176960\n" + + " },\n" + + " {\n" + + " \"id\": \"setl_4xbSwsPABDJ8oK\",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount\": 50000,\n" + + " \"status\": \"processed\",\n" + + " \"fees\": 123,\n" + + " \"tax\": 12,\n" + + " \"utr\": \"RZRP173069230702\",\n" + + " \"created_at\": 1509622306\n" + + " }\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = settlementClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("amount")); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("fees")); + assertTrue(fetch.get(0).has("tax")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all the Settlement details using settlement id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\": "+SETTLEMENT_ID+",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount\": 9973635,\n" + + " \"status\": \"processed\",\n" + + " \"fees\": 471699,\n" + + " \"tax\": 42070,\n" + + " \"utr\": \"1568176960vxp0rj\",\n" + + " \"created_at\": 1568176960\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Settlement fetch = settlementClient.fetch(SETTLEMENT_ID); + assertNotNull(fetch); + assertEquals(SETTLEMENT_ID,fetch.get("id")); + assertEquals("settlement",fetch.get("entity")); + assertEquals("processed",fetch.get("status")); + assertEquals("1568176960vxp0rj",fetch.get("utr")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Settlement report for a month can be retrieved. + * @throws RazorpayException + */ + @Test + public void reports() throws RazorpayException{ + JSONObject request = new JSONObject("{year:2020,month:9}"); + + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 4,\n" + + " \"items\": [\n" + + " {\n" + + " \"entity_id\": \"pay_DEXrnipqTmWVGE\",\n" + + " \"entity\": \"settlement\",\n"+ + " \"type\": \"payment\",\n" + + " \"debit\": 0,\n" + + " \"credit\": 97100,\n" + + " \"amount\": 100000,\n" + + " \"currency\": \"INR\",\n" + + " \"fee\": 2900,\n" + + " \"tax\": 0,\n" + + " \"on_hold\": false,\n" + + " \"settled\": true,\n" + + " \"created_at\": 1567692556,\n" + + " \"settled_at\": 1568176960,\n" + + " \"settlement_id\": \"setl_DGlQ1Rj8os78Ec\",\n" + + " \"posted_at\": null,\n" + + " \"credit_type\": \"default\",\n" + + " \"description\": \"Recurring Payment via Subscription\",\n" + + " \"notes\": \"{}\",\n" + + " \"payment_id\": null,\n" + + " \"settlement_utr\": \"1568176960vxp0rj\",\n" + + " \"order_id\": \"order_DEXrnRiR3SNDHA\",\n" + + " \"order_receipt\": null,\n" + + " \"method\": \"card\",\n" + + " \"card_network\": \"MasterCard\",\n" + + " \"card_issuer\": \"KARB\",\n" + + " \"card_type\": \"credit\",\n" + + " \"dispute_id\": null\n" + + " },\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = settlementClient.reports(request); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("card_network")); + assertTrue(fetch.get(0).has("order_id")); + assertTrue(fetch.get(0).has("method")); + assertTrue(fetch.get(0).has("card_type")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Settlement is created using the amount details. + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + JSONObject request = new JSONObject("{\"amount\":200000,\"settle_full_balance\":false,\"description\":\"Needthistomakevendorpayments.\",\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"}}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+SETTLEMENT_ID+",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount_requested\": 200000,\n" + + " \"amount_settled\": 0,\n" + + " \"amount_pending\": 199410,\n" + + " \"amount_reversed\": 0,\n" + + " \"fees\": 590,\n" + + " \"tax\": 90,\n" + + " \"currency\": \"INR\",\n" + + " \"settle_full_balance\": false,\n" + + " \"status\": \"initiated\",\n" + + " \"description\": \"Need this to make vendor payments.\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\": 1596771429,\n" + + " \"ondemand_payouts\": {\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"setlodp_FNj7g2cbvw8ueO\",\n" + + " \"entity\": \"settlement.ondemand_payout\",\n" + + " \"initiated_at\": null,\n" + + " \"processed_at\": null,\n" + + " \"reversed_at\": null,\n" + + " \"amount\": 200000,\n" + + " \"amount_settled\": null,\n" + + " \"fees\": 590,\n" + + " \"tax\": 90,\n" + + " \"utr\": null,\n" + + " \"status\": \"created\",\n" + + " \"created_at\": 1596771429\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Settlement fetch = settlementClient.create(request); + assertNotNull(fetch); + assertEquals(SETTLEMENT_ID,fetch.get("id")); + assertEquals("initiated",fetch.get("status")); + assertTrue(fetch.has("notes")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all on-demand Settlement can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAllDemand() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"setlod_FNj7g2YS5J67Rz\",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount_requested\": 200000,\n" + + " \"amount_settled\": 199410,\n" + + " \"amount_pending\": 0,\n" + + " \"amount_reversed\": 0,\n" + + " \"fees\": 590,\n" + + " \"tax\": 90,\n" + + " \"currency\": \"INR\",\n" + + " \"settle_full_balance\": false,\n" + + " \"status\": \"processed\",\n" + + " \"description\": \"Need this to make vendor payments.\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\": 1596771429\n" + + " },\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = settlementClient.fetchAllDemand(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("amount_requested")); + assertTrue(fetch.get(0).has("amount_pending")); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all on-demand Settlement details using settlement id. + * @throws RazorpayException + */ + @Test + public void fetchDemandSettlement() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\": "+SETTLEMENT_ID+",\n" + + " \"entity\": \"settlement.ondemand\",\n" + + " \"amount_requested\": 200000,\n" + + " \"amount_settled\": 199410,\n" + + " \"amount_pending\": 0,\n" + + " \"amount_reversed\": 0,\n" + + " \"fees\": 590,\n" + + " \"tax\": 90,\n" + + " \"currency\": \"INR\",\n" + + " \"settle_full_balance\": false,\n" + + " \"status\": \"processed\",\n" + + " \"description\": \"Need this to make vendor payments.\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\": 1596771429\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Settlement fetch = settlementClient.fetchDemandSettlement(SETTLEMENT_ID); + assertNotNull(fetch); + assertEquals(SETTLEMENT_ID,fetch.get("id")); + assertEquals("processed",fetch.get("status")); + assertEquals(200000,(int)fetch.get("amount_requested")); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 06a5c42810f3a025182a5cef478e0736a34d169e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 14:52:33 +0530 Subject: [PATCH 64/78] implement virtual-account & unit test --- src/main/java/com/razorpay/Constants.java | 3 + .../com/razorpay/VirtualAccountClient.java | 12 + src/test/java/com/razorpay/BaseTest.java | 34 ++ .../razorpay/VirtualAccountClientTest.java | 436 ++++++++++++++++++ 4 files changed, 485 insertions(+) create mode 100644 src/test/java/com/razorpay/VirtualAccountClientTest.java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 35839f75..ef9d50e7 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -75,4 +75,7 @@ public class Constants { static final String VIRTUAL_ACCOUNT_EDIT = "virtual_accounts/%s"; static final String VIRTUAL_ACCOUNT_CLOSE = "virtual_accounts/%s/close"; static final String VIRTUAL_ACCOUNT_PAYMENTS = "virtual_accounts/%s/payments"; + static final String VIRTUAL_ACCOUNT_RECEIVERS = "virtual_accounts/%s/receivers"; + static final String VIRTUAL_ACCOUNT_ALLOWEDPAYERS = "virtual_accounts/%s/allowed_payers"; + static final String VIRTUAL_ACCOUNT_DELETE_ALLOWEDPAYERS = "virtual_accounts/%s/allowed_payers/%s"; } diff --git a/src/main/java/com/razorpay/VirtualAccountClient.java b/src/main/java/com/razorpay/VirtualAccountClient.java index c8aeccce..88ce3380 100644 --- a/src/main/java/com/razorpay/VirtualAccountClient.java +++ b/src/main/java/com/razorpay/VirtualAccountClient.java @@ -41,4 +41,16 @@ public List fetchPayments(String id) throws RazorpayException { public List fetchPayments(String id, JSONObject request) throws RazorpayException { return getCollection(String.format(Constants.VIRTUAL_ACCOUNT_PAYMENTS, id), request); } + + public VirtualAccount addReceiver(String id, JSONObject request) throws RazorpayException { + return post(String.format(Constants.VIRTUAL_ACCOUNT_RECEIVERS, id), request); + } + + public VirtualAccount addAllowedPayers(String id, JSONObject request) throws RazorpayException { + return post(String.format(Constants.VIRTUAL_ACCOUNT_ALLOWEDPAYERS, id), request); + } + + public void deleteAllowedPayer(String virtual_id, String payer_id) throws RazorpayException { + delete(String.format(Constants.VIRTUAL_ACCOUNT_DELETE_ALLOWEDPAYERS, virtual_id, payer_id), null); + } } diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 52eaad71..5ca51894 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -1,16 +1,20 @@ package com.razorpay; import okhttp3.*; +import okio.Buffer; import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.Before; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.io.IOException; import java.lang.reflect.Field; import java.util.List; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,4 +65,34 @@ protected void mockResponseFromExternalClient(String response) throws IOExceptio when(rb.string()).thenReturn(parse.toString()); when(mockedResponse.body()).thenReturn(rb); } + + protected OkHttpClient getOkHttpClient() + { + return okHttpClient; + } + + public void verifySentRequest(boolean hasBody, String request, String requestPath) { + ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); + Mockito.verify(getOkHttpClient()).newCall(req.capture()); + if(hasBody) { + assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); + } + assertEquals(requestPath, req.getValue().url().toString()); + } + + private static String bodyToString(final Request request) { + + try { + final Request copy = request.newBuilder().build(); + final Buffer buffer = new Buffer(); + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "did not work"; + } + } + + String getHost(String url) { + return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; + } } \ No newline at end of file diff --git a/src/test/java/com/razorpay/VirtualAccountClientTest.java b/src/test/java/com/razorpay/VirtualAccountClientTest.java new file mode 100644 index 00000000..78ac0fef --- /dev/null +++ b/src/test/java/com/razorpay/VirtualAccountClientTest.java @@ -0,0 +1,436 @@ +package com.razorpay; + +import okhttp3.Request; +import okio.Buffer; +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class VirtualAccountClientTest extends BaseTest{ + + @InjectMocks + protected VirtualAccountClient virtualAccountClient = new VirtualAccountClient(TEST_SECRET_KEY); + + private static final String VIRTUAL_ACCOUNT_ID = "va_DlGmm7jInLudH9"; + + /** + * VirtualAccount is created using the bank-account and customer details. + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + + String x = "{\"receivers\":" + + "{\"types\":[\"bank_account\"]}," + + "\"allowed_payers\":[{\"type\":\"bank_account\"," + + "\"bank_account\":{\"ifsc\":\"UTIB0000013\"," + + "\"account_number\":\"914010012345679\"}}," + + "{\"type\":\"bank_account\"," + + "\"bank_account\":{\"ifsc\":\"UTIB0000014\"," + + "\"account_number\":\"914010012345680\"}}]," + + "\"description\":\"VirtualAccountcreatedforRaftarSoft\"," + + "\"customer_id\":\"cust_CaVDm8eDRSXYME\"," + + "\"close_by\":1681615838," + + "\"notes\":{\"project_name\":\"BankingSoftware\"}}"; + + JSONObject request = new JSONObject(x); + + String mockedResponseJson = "{\n" + + " \"id\":\"va_DlGmm7jInLudH9\",\n" + + " \"name\":\"Acme Corp\",\n" + + " \"entity\":\"virtual_account\",\n" + + " \"status\":\"active\",\n" + + " \"description\":\"Virtual Account created for Raftar Soft\",\n" + + " \"amount_expected\":null,\n" + + " \"notes\":{\n" + + " \"project_name\":\"Banking Software\"\n" + + " },\n" + + " \"amount_paid\":0,\n" + + " \"customer_id\":\"cust_CaVDm8eDRSXYME\",\n" + + " \"receivers\":[\n" + + " {\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"entity\":\"bank_account\",\n" + + " \"ifsc\":\"RATN0VAAPIS\",\n" + + " \"bank_name\": \"RBL Bank\",\n" + + " \"name\":\"Acme Corp\",\n" + + " \"notes\":[],\n" + + " \"account_number\":\"2223330099089860\"\n" + + " }\n" + + " ],\n" + + " \"allowed_payers\": [\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000013\",\n" + + " \"account_number\": \"914010012345679\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_Cmtnm5tSj6agUW\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000014\",\n" + + " \"account_number\": \"914010012345680\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"close_by\":1681615838,\n" + + " \"closed_at\":null,\n" + + " \"created_at\":1574837626\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + VirtualAccount fetch = virtualAccountClient.create(request); + assertNotNull(fetch); + assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); + assertEquals("active",fetch.get("status")); + assertEquals("Acme Corp",fetch.get("name")); + assertTrue(fetch.has("allowed_payers")); + String virtualAccountCreate = getHost(Constants.VIRTUAL_ACCOUNT_CREATE); + verifySentRequest(true, String.valueOf(request), virtualAccountCreate); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all the virtualAccount details using virtualAccount id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\": "+VIRTUAL_ACCOUNT_ID+",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"entity\": \"virtual_account\",\n" + + " \"status\": \"active\",\n" + + " \"description\": \"Virtual Account for Raftar Soft\",\n" + + " \"amount_expected\": 5000,\n" + + " \"notes\": [],\n" + + " \"amount_paid\": null,\n" + + " \"customer_id\": \"cust_9xnHzNGIEY4TAV\",\n" + + " \"receivers\": [\n" + + " {\n" + + " \"id\": \"ba_D6Vw76RrHA3DC9\",\n" + + " \"entity\": \"bank_account\",\n" + + " \"ifsc\": \"RATN0VAAPIS\",\n" + + " \"bank_name\": \"RBL Bank\",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"notes\": [],\n" + + " \"account_number\": \"2223330025991681\"\n" + + " }\n" + + " ],\n" + + " \"allowed_payers\": [\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000013\",\n" + + " \"account_number\": \"914010012345679\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_Cmtnm5tSj6agUW\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000014\",\n" + + " \"account_number\": \"914010012345680\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"close_by\": null,\n" + + " \"closed_at\": 1568109789,\n" + + " \"created_at\": 1565939036\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + VirtualAccount fetch = virtualAccountClient.fetch(VIRTUAL_ACCOUNT_ID); + assertNotNull(fetch); + assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); + assertEquals("active",fetch.get("status")); + assertEquals("Acme Corp",fetch.get("name")); + assertTrue(fetch.has("allowed_payers")); + verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_GET, VIRTUAL_ACCOUNT_ID))); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all the virtualAccount can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"va_Di5gbNptcWV8fQ\",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"entity\": \"virtual_account\",\n" + + " \"status\": \"closed\",\n" + + " \"description\": \"Virtual Account created for M/S ABC Exports\",\n" + + " \"amount_expected\": 2300,\n" + + " \"notes\": {\n" + + " \"material\": \"teakwood\"\n" + + " },\n" + + " \"amount_paid\": 239000,\n" + + " \"customer_id\": \"cust_DOMUFFiGdCaCUJ\",\n" + + " \"receivers\": [\n" + + " {\n" + + " \"id\": \"ba_Di5gbQsGn0QSz3\",\n" + + " \"entity\": \"bank_account\",\n" + + " \"ifsc\": \"RATN0VAAPIS\",\n" + + " \"bank_name\": \"RBL Bank\",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"notes\": [],\n" + + " \"account_number\": \"1112220061746877\"\n" + + " }\n" + + " ],\n" + + " \"allowed_payers\": [\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000013\",\n" + + " \"account_number\": \"914010012345679\"\n" + + " }\n" + + " },\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_Cmtnm5tSj6agUW\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000014\",\n" + + " \"account_number\": \"914010012345680\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"close_by\": 1574427237,\n" + + " \"closed_at\": 1574164078,\n" + + " \"created_at\": 1574143517\n" + + " },\n" + + " ]\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = virtualAccountClient.fetchAll(); + assertNotNull(fetch); + assertTrue(fetch.get(0).has("id")); + assertTrue(fetch.get(0).has("entity")); + assertTrue(fetch.get(0).has("name")); + assertTrue(fetch.get(0).has("status")); + verifySentRequest(false, null, getHost(Constants.VIRTUAL_ACCOUNT_LIST)); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Close a virtualAccount using virtualAccount id + * @throws RazorpayException + */ + @Test + public void close() throws RazorpayException{ + String mockedResponseJson = "{\n" + + " \"id\":"+VIRTUAL_ACCOUNT_ID+",\n" + + " \"name\":\"Acme Corp\",\n" + + " \"entity\":\"virtual_account\",\n" + + " \"status\":\"closed\",\n" + + " \"description\":\"Virtual Account created for M/S ABC Exports\",\n" + + " \"amount_expected\":null,\n" + + " \"notes\":{\n" + + " \"material\":\"teakwood\"\n" + + " },\n" + + " \"amount_paid\":239000,\n" + + " \"customer_id\":\"cust_DOMUFFiGdCaCUJ\",\n" + + " \"receivers\":[\n" + + " {\n" + + " \"id\":\"vpa_CkTmLXqVYPkbxx\",\n" + + " \"entity\":\"vpa\",\n" + + " \"username\": \"rpy.payto00000468657501\",\n" + + " \"handle\": \"icici\",\n" + + " \"address\": \"rpy.payto00000468657501@icici\"\n" + + " }\n" + + " ],\n" + + " \"close_by\":1574427237,\n" + + " \"closed_at\":1574164078,\n" + + " \"created_at\":1574143517\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + VirtualAccount fetch = virtualAccountClient.close(VIRTUAL_ACCOUNT_ID); + assertNotNull(fetch); + assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); + assertEquals("closed",fetch.get("status")); + assertEquals("Acme Corp",fetch.get("name")); + assertTrue(fetch.has("receivers")); + verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_CLOSE, VIRTUAL_ACCOUNT_ID))); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Add Receiver to an Existing Virtual Account + * @throws RazorpayException + */ + @Test + public void addReceiver() throws RazorpayException{ + JSONObject request = new JSONObject("{\"types\":[\"vpa\"],\"vpa\":{\"descriptor\":\"gaurikumar\"}}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+VIRTUAL_ACCOUNT_ID+",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"entity\": \"virtual_account\",\n" + + " \"status\": \"active\",\n" + + " \"description\": \"\",\n" + + " \"amount_expected\": null,\n" + + " \"notes\": [],\n" + + " \"amount_paid\": 0,\n" + + " \"customer_id\": \"cust_DzbSeP2RJD1ZHg\",\n" + + " \"receivers\": [\n" + + " {\n" + + " \"id\": \"ba_DzcFjVqAMSCEIW\",\n" + + " \"entity\": \"bank_account\",\n" + + " \"ifsc\":\"RATN0VAAPIS\",\n" + + " \"bank_name\": \"RBL Bank\",\n" + + " \"name\": \"Acme Corp\",\n" + + " \"notes\": [],\n" + + " \"account_number\": \"2223333232194699\"\n" + + " },\n" + + " {\n" + + " \"id\": \"vpa_DzcZR5ofjCUKAx\",\n" + + " \"entity\": \"vpa\",\n" + + " \"username\": \"rpy.payto00000gaurikumar\",\n" + + " \"handle\": \"icici\",\n" + + " \"address\": \"rpy.payto00000gaurikumar@icici\"\n" + + " }\n" + + " ],\n" + + " \"close_by\": null,\n" + + " \"closed_at\": null,\n" + + " \"created_at\": 1577969986\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + VirtualAccount fetch = virtualAccountClient.addReceiver(VIRTUAL_ACCOUNT_ID, request); + assertNotNull(fetch); + assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); + assertEquals("cust_DzbSeP2RJD1ZHg",fetch.get("customer_id")); + assertEquals("Acme Corp",fetch.get("name")); + assertTrue(fetch.has("receivers")); + verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_RECEIVERS, VIRTUAL_ACCOUNT_ID))); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Add an Allowed Payer Account + * @throws RazorpayException + */ + @Test + public void addAllowedPayers() throws RazorpayException{ + JSONObject request = new JSONObject("{\"type\":\"bank_account\"," + + "\"bank_account\":" + + "{\"ifsc\":\"UTIB0000013\"," + + "\"account_number\":\"914010012345679\"}}"); + + String mockedResponseJson = "{\n" + + " \"id\":\"va_DlGmm7jInLudH9\",\n" + + " \"name\":\"Acme Corp\",\n" + + " \"entity\":\"virtual_account\",\n" + + " \"status\":\"active\",\n" + + " \"description\":\"Virtual Account created for Raftar Soft\",\n" + + " \"amount_expected\":null,\n" + + " \"notes\":{\n" + + " \"project_name\":\"Banking Software\"\n" + + " },\n" + + " \"amount_paid\":0,\n" + + " \"customer_id\":\"cust_DzbSeP2RJD1ZHg\",\n" + + " \"receivers\":[\n" + + " {\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"entity\":\"bank_account\",\n" + + " \"ifsc\":\"RATN0VAAPIS\",\n" + + " \"bank_name\": \"RBL Bank\",\n" + + " \"name\":\"Acme Corp\",\n" + + " \"notes\":[],\n" + + " \"account_number\":\"2223330099089860\"\n" + + " }\n" + + " ],\n" + + " \"allowed_payers\": [\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"id\":\"ba_DlGmm9mSj8fjRM\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000013\",\n" + + " \"account_number\": \"914010012345679\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"close_by\":1681615838,\n" + + " \"closed_at\":null,\n" + + " \"created_at\":1574837626\n" + + "}"; + + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + VirtualAccount fetch = virtualAccountClient.addAllowedPayers(VIRTUAL_ACCOUNT_ID, request); + assertNotNull(fetch); + assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); + assertEquals("cust_DzbSeP2RJD1ZHg",fetch.get("customer_id")); + assertEquals("Acme Corp",fetch.get("name")); + assertTrue(fetch.has("allowed_payers")); + verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_ALLOWEDPAYERS, VIRTUAL_ACCOUNT_ID))); + } catch (IOException e) { + assertTrue(false); + } + } + + public void verifySentRequest(boolean hasBody, String request, String requestPath) { + ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); + Mockito.verify(getOkHttpClient()).newCall(req.capture()); + if(hasBody) { + assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); + } + assertEquals(requestPath, req.getValue().url().toString()); + } + + private static String bodyToString(final Request request) { + + try { + final Request copy = request.newBuilder().build(); + final Buffer buffer = new Buffer(); + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "did not work"; + } + } + + String getHost(String url) { + return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; + } +} \ No newline at end of file From bbcbc48c165f0f31d80a518af2de7690f0b9d5ab Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 14:55:30 +0530 Subject: [PATCH 65/78] revert basetest --- src/test/java/com/razorpay/BaseTest.java | 29 ------------------------ 1 file changed, 29 deletions(-) diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 5ca51894..72aa73cc 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -1,20 +1,16 @@ package com.razorpay; import okhttp3.*; -import okio.Buffer; import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.Before; -import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.io.IOException; import java.lang.reflect.Field; import java.util.List; -import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -70,29 +66,4 @@ protected OkHttpClient getOkHttpClient() { return okHttpClient; } - - public void verifySentRequest(boolean hasBody, String request, String requestPath) { - ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); - Mockito.verify(getOkHttpClient()).newCall(req.capture()); - if(hasBody) { - assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); - } - assertEquals(requestPath, req.getValue().url().toString()); - } - - private static String bodyToString(final Request request) { - - try { - final Request copy = request.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "did not work"; - } - } - - String getHost(String url) { - return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; - } } \ No newline at end of file From 8573e9ef4f333d8b5a4508c1dc709746474a6757 Mon Sep 17 00:00:00 2001 From: ersinghlovepreet Date: Mon, 28 Feb 2022 15:46:42 +0530 Subject: [PATCH 66/78] Added api Subscription offer removal and test cases --- src/main/java/com/razorpay/ApiClient.java | 8 ++++---- src/main/java/com/razorpay/Constants.java | 1 + src/main/java/com/razorpay/SubscriptionClient.java | 4 ++++ .../java/com/razorpay/SubscriptionClientTest.java | 13 +++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 7c38c572..557bcc92 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.List; import org.apache.commons.text.WordUtils; import org.json.JSONArray; @@ -53,9 +52,9 @@ public T patch(String path, JSONObject requestObject) throws return processResponse(response); } - public void delete(String path, JSONObject requestObject) throws RazorpayException { + public T delete(String path, JSONObject requestObject) throws RazorpayException { Response response = ApiUtils.deleteRequest(path, requestObject, auth); - processDeleteResponse(response); + return processDeleteResponse(response); } ArrayList getCollection(String path, JSONObject requestObject) @@ -162,7 +161,7 @@ ArrayList processCollectionResponse(Response response) return null; } - private void processDeleteResponse(Response response) throws RazorpayException { + private T processDeleteResponse(Response response) throws RazorpayException { if (response == null) { throw new RazorpayException("Invalid Response from server"); } @@ -181,6 +180,7 @@ private void processDeleteResponse(Response response) throws RazorpayException { if (statusCode < STATUS_OK || statusCode >= STATUS_MULTIPLE_CHOICE) { throwException(statusCode, responseJson); } + return parseResponse(responseJson); } private void throwException(int statusCode, JSONObject responseJson) throws RazorpayException { diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 0f77f662..746beb75 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -69,6 +69,7 @@ public class Constants { static final String SUBSCRIPTION_CANCEL_SCHEDULED_UPDATE = "subscriptions/%s/cancel_scheduled_changes"; static final String PAUSE_SUBSCRIPTION = "subscriptions/%s/pause"; static final String RESUME_SUBSCRIPTION = "subscriptions/%s/resume"; + static final String SUBSCRIPTION_OFFER = "subscriptions/%s/%s"; static final String ADDON_GET = "addons/%s"; static final String ADDON_DELETE = "addons/%s"; diff --git a/src/main/java/com/razorpay/SubscriptionClient.java b/src/main/java/com/razorpay/SubscriptionClient.java index a4a97036..56aaba96 100644 --- a/src/main/java/com/razorpay/SubscriptionClient.java +++ b/src/main/java/com/razorpay/SubscriptionClient.java @@ -53,4 +53,8 @@ public Subscription pause(String id, JSONObject request) throws RazorpayExceptio public Subscription resume(String id, JSONObject request) throws RazorpayException { return post(String.format(Constants.RESUME_SUBSCRIPTION, id), request); } + + public Subscription deleteSubscriptionOffer(String subId, String offerId) throws RazorpayException { + return delete(String.format(Constants.SUBSCRIPTION_OFFER, subId, offerId), null); + } } diff --git a/src/test/java/com/razorpay/SubscriptionClientTest.java b/src/test/java/com/razorpay/SubscriptionClientTest.java index f7c7204f..6a343b2e 100644 --- a/src/test/java/com/razorpay/SubscriptionClientTest.java +++ b/src/test/java/com/razorpay/SubscriptionClientTest.java @@ -13,6 +13,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class SubscriptionClientTest extends BaseTest { @@ -25,6 +26,7 @@ public class SubscriptionClientTest extends BaseTest { public static final String ADDON_SUBSCRIPTION_ID = "subscription_id"; public static final String TEST_ADDON_ID = "ao_00000000000001"; public static final String ADDON_ITEM_ID = "item_00000000000001"; + public static final String TEST_OFFER = "TEST_OFFER"; @InjectMocks private SubscriptionClient subscriptionClient = new SubscriptionClient(TEST_SECRET_KEY); @@ -254,6 +256,17 @@ public void testResume() throws IOException, RazorpayException { verifySentRequest(true, getRequest(), getHost(String.format(Constants.RESUME_SUBSCRIPTION, TEST_SUBSCRIPTION_ID))); } + @Test + public void testDeleteSubscriptionOffer() throws IOException, RazorpayException { + + String mockedResponseJson = getMockedResponseJson(); + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Subscription subscription = subscriptionClient.deleteSubscriptionOffer(TEST_SUBSCRIPTION_ID, TEST_OFFER); + assertEquals(TEST_SUBSCRIPTION_ID, subscription.get(SUBSCRIPTION_ID)); + verifySentRequest(false, null, getHost(String.format(Constants.SUBSCRIPTION_OFFER, TEST_SUBSCRIPTION_ID,TEST_OFFER))); + } + private String getAddonMockedResponse() { return "{\n" + " \"id\":\"" + TEST_ADDON_ID + "\",\n" + From 65cbbfd20c5b1db6c6c1706b15c82d217b77d447 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 16:13:30 +0530 Subject: [PATCH 67/78] json format and populateEntity --- src/main/java/com/razorpay/ApiClient.java | 16 ++++++++++------ .../java/com/razorpay/SettlementClientTest.java | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 16128125..11b8d264 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -120,12 +120,7 @@ T processResponse(Response response) throws RazorpayException if (statusCode >= STATUS_OK && statusCode < STATUS_MULTIPLE_CHOICE) { - if(!responseJson.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - responseJson.put("entity",entityName); - }else if(responseJson.get("entity").toString().equals("settlement.ondemand")){ - responseJson.put("entity","settlement"); - } + populateEntityInResponse(responseJson, response); return parseResponse(responseJson); } @@ -134,6 +129,15 @@ T processResponse(Response response) throws RazorpayException return null; } + private void populateEntityInResponse(JSONObject responseJson, Response response) { + if(!responseJson.has(ENTITY)) { + String entityName = getEntityNameFromURL(response.request().url()); + responseJson.put("entity",entityName); + }else if(responseJson.get("entity").toString().equals("settlement.ondemand")){ + responseJson.put("entity","settlement"); + } + } + ArrayList processCollectionResponse(Response response) throws RazorpayException { if (response == null) { diff --git a/src/test/java/com/razorpay/SettlementClientTest.java b/src/test/java/com/razorpay/SettlementClientTest.java index 0301d8cb..3a2dca1a 100644 --- a/src/test/java/com/razorpay/SettlementClientTest.java +++ b/src/test/java/com/razorpay/SettlementClientTest.java @@ -158,7 +158,11 @@ public void reports() throws RazorpayException{ */ @Test public void create() throws RazorpayException{ - JSONObject request = new JSONObject("{\"amount\":200000,\"settle_full_balance\":false,\"description\":\"Needthistomakevendorpayments.\",\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\",\"notes_key_2\":\"Tea,EarlGrey…decaf.\"}}"); + JSONObject request = new JSONObject("{\"amount\":200000," + + "\"settle_full_balance\":false," + + "\"description\":\"Needthistomakevendorpayments.\"," + + "\"notes\":{\"notes_key_1\":\"Tea,EarlGrey,Hot\"," + + "\"notes_key_2\":\"Tea,EarlGrey…decaf.\"}}"); String mockedResponseJson = "{\n" + " \"id\": "+SETTLEMENT_ID+",\n" + From 2e8a5a1a0e170e8a0edb265b28332fe669875ef2 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 16:43:32 +0530 Subject: [PATCH 68/78] code refactor --- src/main/java/com/razorpay/ApiClient.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/com/razorpay/ApiClient.java b/src/main/java/com/razorpay/ApiClient.java index 11b8d264..7a9bfb66 100755 --- a/src/main/java/com/razorpay/ApiClient.java +++ b/src/main/java/com/razorpay/ApiClient.java @@ -171,16 +171,8 @@ ArrayList processCollectionResponse(Response response) } private void populateEntityInCollection(Response response, JSONArray jsonArray) { - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObj = jsonArray.getJSONObject(i); - - if(!jsonObj.has(ENTITY)) { - String entityName = getEntityNameFromURL(response.request().url()); - jsonObj.put("entity",entityName); - }else if(jsonObj.get("entity").toString().equals("settlement.ondemand")){ - jsonObj.put("entity","settlement"); - } + populateEntityInResponse(jsonArray.getJSONObject(i),response); } } From b69521cf3b8767a2d019619189cd25e7c265d69e Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 19:14:08 +0530 Subject: [PATCH 69/78] add javadoc and format json --- .../java/com/razorpay/AddonClientTest.java | 82 +++++++++++++++++-- 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java index c4555110..28ff6a42 100644 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -6,8 +6,7 @@ import java.io.IOException; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; public class AddonClientTest extends BaseTest{ @@ -16,33 +15,100 @@ public class AddonClientTest extends BaseTest{ private static final String ADDON_ID = "ao_00000000000001"; + /** + * Retrieve all the addon details using addon id. + * @throws RazorpayException + */ @Test public void fetch() throws RazorpayException { - String json = "{\n \"id\":\"ao_00000000000001\",\n \"entity\":\"addon\",\n \"item\":{\n \"id\":\"item_00000000000001\",\n \"active\":true,\n \"name\":\"Extra appala (papadum)\",\n \"description\":\"1 extra oil fried appala with meals\",\n \"amount\":30000,\n \"unit_amount\":30000,\n \"currency\":\"INR\",\n \"type\":\"addon\",\n \"unit\":null,\n \"tax_inclusive\":false,\n \"hsn_code\":null,\n \"sac_code\":null,\n \"tax_rate\":null,\n \"tax_id\":null,\n \"tax_group_id\":null,\n \"created_at\":1581597318,\n \"updated_at\":1581597318\n },\n \"quantity\":2,\n \"created_at\":1581597318,\n \"subscription_id\":\"sub_00000000000001\",\n \"invoice_id\":null\n}"; + String json = "{\n \"id\":"+ADDON_ID+",\n" + + "\"entity\":\"addon\",\n" + + "\"item\":{\n" + + "\"id\":\"item_00000000000001\",\n" + + "\"active\":true,\n" + + "\"name\":\"Extra appala (papadum)\",\n" + + "\"description\":\"1 extra oil fried appala with meals\",\n" + + "\"amount\":30000,\n" + + "\"unit_amount\":30000,\n" + + "\"currency\":\"INR\",\n" + + "\"type\":\"addon\",\n" + + "\"unit\":null,\n" + + "\"tax_inclusive\":false,\n" + + "\"hsn_code\":null,\n" + + "\"sac_code\":null,\n" + + "\"tax_rate\":null,\n" + + "\"tax_id\":null,\n" + + "\"tax_group_id\":null,\n" + + "\"created_at\":1581597318,\n" + + "\"updated_at\":1581597318\n" + + "},\n \"quantity\":2,\n" + + "\"created_at\":1581597318,\n" + + "\"subscription_id\":\"sub_00000000000001\",\n" + + "\"invoice_id\":null\n}"; try { mockResponseFromExternalClient(json); mockResponseHTTPCodeFromExternalClient(200); Addon fetch = client.fetch(ADDON_ID); assertNotNull(fetch); assertEquals(ADDON_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertEquals("30000",fetch.get("amount")); + assertTrue(fetch.get("active")); + assertTrue(fetch.get("unit_amount")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } - } + } + /** + * Details of all the addon can be retrieved. + * @throws RazorpayException + */ @Test public void fetchAll() throws RazorpayException { - String json = "{\n \"entity\": \"collection\",\n \"count\": 1,\n \"items\": [\n {\n \"id\": \"ao_00000000000002\",\n \"entity\": \"addon\",\n \"item\": {\n \"id\": \"item_00000000000002\",\n \"active\": true,\n \"name\": \"Extra sweet\",\n \"description\": \"1 extra sweet of the day with meals\",\n \"amount\": 90000,\n \"unit_amount\": 90000,\n \"currency\": \"INR\",\n \"type\": \"addon\",\n \"unit\": null,\n \"tax_inclusive\": false,\n \"hsn_code\": null,\n \"sac_code\": null,\n \"tax_rate\": null,\n \"tax_id\": null,\n \"tax_group_id\": null,\n \"created_at\": 1581597318,\n \"updated_at\": 1581597318\n },\n \"quantity\": 1,\n \"created_at\": 1581597318,\n \"subscription_id\": \"sub_00000000000001\",\n \"invoice_id\": \"inv_00000000000001\"\n }\n ]\n}"; + String json = "{\n " + + "\"entity\": \"collection\",\n" + + "\"count\": 1,\n" + + "\"items\": [\n {\n" + + "\"id\": "+ADDON_ID+",\n" + + "\"entity\": \"addon\",\n" + + "\"item\": {\n" + + "\"id\": \"item_00000000000002\",\n" + + "\"active\": true,\n" + + "\"name\": \"Extra sweet\",\n" + + "\"description\": \"1 extra sweet of the day with meals\",\n" + + "\"amount\": 90000,\n" + + "\"unit_amount\": 90000,\n" + + "\"currency\": \"INR\",\n " + + "\"type\": \"addon\",\n " + + "\"unit\": null,\n " + + "\"tax_inclusive\": false,\n " + + "\"hsn_code\": null,\n " + + "\"sac_code\": null,\n " + + "\"tax_rate\": null,\n" + + "\"tax_id\": null,\n " + + "\"tax_group_id\": null,\n" + + "\"created_at\": 1581597318,\n " + + "\"updated_at\": 1581597318\n" + + "},\n" + + "\"quantity\": 1,\n " + + "\"created_at\": 1581597318,\n" + + "\"subscription_id\": \"sub_00000000000001\",\n" + + "\"invoice_id\": \"inv_00000000000001\"\n" + + "}\n ]\n}"; try { mockResponseFromExternalClient(json); mockResponseHTTPCodeFromExternalClient(200); List fetch = client.fetchAll(); assertNotNull(fetch); - assertEquals(true,fetch.get(0).has("subscription_id")); + assertEquals(true,fetch.get(0).has("id")); + assertEquals(true,fetch.get(0).has("entity")); + assertEquals(true,fetch.get(0).has("items")); + assertEquals(true,fetch.get(0).has("hsn_code")); } catch (IOException e) { - e.printStackTrace(); + assertTrue(false); } } } From f8613e7ccd83ee79be8d72b78388d3607b778395 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 19:19:45 +0530 Subject: [PATCH 70/78] fetchall comment --- src/main/java/com/razorpay/AddonClient.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/AddonClient.java b/src/main/java/com/razorpay/AddonClient.java index 9dff37bf..13ad4730 100644 --- a/src/main/java/com/razorpay/AddonClient.java +++ b/src/main/java/com/razorpay/AddonClient.java @@ -15,11 +15,19 @@ public Addon fetch(String id) throws RazorpayException { return get(String.format(Constants.ADDON_GET, id), null); } - + /** + * It is wrapper of fetchAll with parameter here sending null defines fetchAll + * with a default values without filteration + * @throws RazorpayException + */ public List fetchAll() throws RazorpayException { return fetchAll(null); } + /** + * This method get list of Addons filtered by parameters @request + * @throws RazorpayException + */ public List fetchAll(JSONObject request) throws RazorpayException { return getCollection(Constants.ADDON_LIST, request); } From a848374f78896c38e4f0a3b47a38e86501ecf484 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 28 Feb 2022 19:35:05 +0530 Subject: [PATCH 71/78] use constant variables --- .../razorpay/VirtualAccountClientTest.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/razorpay/VirtualAccountClientTest.java b/src/test/java/com/razorpay/VirtualAccountClientTest.java index 78ac0fef..b1feb90f 100644 --- a/src/test/java/com/razorpay/VirtualAccountClientTest.java +++ b/src/test/java/com/razorpay/VirtualAccountClientTest.java @@ -19,6 +19,10 @@ public class VirtualAccountClientTest extends BaseTest{ protected VirtualAccountClient virtualAccountClient = new VirtualAccountClient(TEST_SECRET_KEY); private static final String VIRTUAL_ACCOUNT_ID = "va_DlGmm7jInLudH9"; + private static final String CUSTOMER_ID = "cust_DzbSeP2RJD1ZHg"; + private static final String CORP_NAME = "Acme Corp"; + private static final String ACTIVE_STATUS = "active"; + private static final String CLOSED_STATUS = "closed"; /** * VirtualAccount is created using the bank-account and customer details. @@ -27,7 +31,7 @@ public class VirtualAccountClientTest extends BaseTest{ @Test public void create() throws RazorpayException{ - String x = "{\"receivers\":" + + JSONObject request = new JSONObject("{\"receivers\":" + "{\"types\":[\"bank_account\"]}," + "\"allowed_payers\":[{\"type\":\"bank_account\"," + "\"bank_account\":{\"ifsc\":\"UTIB0000013\"," + @@ -38,9 +42,7 @@ public void create() throws RazorpayException{ "\"description\":\"VirtualAccountcreatedforRaftarSoft\"," + "\"customer_id\":\"cust_CaVDm8eDRSXYME\"," + "\"close_by\":1681615838," + - "\"notes\":{\"project_name\":\"BankingSoftware\"}}"; - - JSONObject request = new JSONObject(x); + "\"notes\":{\"project_name\":\"BankingSoftware\"}}"); String mockedResponseJson = "{\n" + " \"id\":\"va_DlGmm7jInLudH9\",\n" + @@ -94,8 +96,8 @@ public void create() throws RazorpayException{ VirtualAccount fetch = virtualAccountClient.create(request); assertNotNull(fetch); assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); - assertEquals("active",fetch.get("status")); - assertEquals("Acme Corp",fetch.get("name")); + assertEquals(ACTIVE_STATUS,fetch.get("status")); + assertEquals(CORP_NAME,fetch.get("name")); assertTrue(fetch.has("allowed_payers")); String virtualAccountCreate = getHost(Constants.VIRTUAL_ACCOUNT_CREATE); verifySentRequest(true, String.valueOf(request), virtualAccountCreate); @@ -160,8 +162,8 @@ public void fetch() throws RazorpayException{ VirtualAccount fetch = virtualAccountClient.fetch(VIRTUAL_ACCOUNT_ID); assertNotNull(fetch); assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); - assertEquals("active",fetch.get("status")); - assertEquals("Acme Corp",fetch.get("name")); + assertEquals(ACTIVE_STATUS,fetch.get("status")); + assertEquals(CORP_NAME,fetch.get("name")); assertTrue(fetch.has("allowed_payers")); verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_GET, VIRTUAL_ACCOUNT_ID))); } catch (IOException e) { @@ -280,8 +282,8 @@ public void close() throws RazorpayException{ VirtualAccount fetch = virtualAccountClient.close(VIRTUAL_ACCOUNT_ID); assertNotNull(fetch); assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); - assertEquals("closed",fetch.get("status")); - assertEquals("Acme Corp",fetch.get("name")); + assertEquals(CLOSED_STATUS,fetch.get("status")); + assertEquals(CORP_NAME,fetch.get("name")); assertTrue(fetch.has("receivers")); verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_CLOSE, VIRTUAL_ACCOUNT_ID))); } catch (IOException e) { @@ -336,8 +338,8 @@ public void addReceiver() throws RazorpayException{ VirtualAccount fetch = virtualAccountClient.addReceiver(VIRTUAL_ACCOUNT_ID, request); assertNotNull(fetch); assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); - assertEquals("cust_DzbSeP2RJD1ZHg",fetch.get("customer_id")); - assertEquals("Acme Corp",fetch.get("name")); + assertEquals(CUSTOMER_ID,fetch.get("customer_id")); + assertEquals(CORP_NAME,fetch.get("name")); assertTrue(fetch.has("receivers")); verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_RECEIVERS, VIRTUAL_ACCOUNT_ID))); } catch (IOException e) { @@ -397,12 +399,12 @@ public void addAllowedPayers() throws RazorpayException{ try { mockResponseFromExternalClient(mockedResponseJson); mockResponseHTTPCodeFromExternalClient(200); - VirtualAccount fetch = virtualAccountClient.addAllowedPayers(VIRTUAL_ACCOUNT_ID, request); - assertNotNull(fetch); - assertEquals(VIRTUAL_ACCOUNT_ID,fetch.get("id")); - assertEquals("cust_DzbSeP2RJD1ZHg",fetch.get("customer_id")); - assertEquals("Acme Corp",fetch.get("name")); - assertTrue(fetch.has("allowed_payers")); + VirtualAccount response = virtualAccountClient.addAllowedPayers(VIRTUAL_ACCOUNT_ID, request); + assertNotNull(response); + assertEquals(VIRTUAL_ACCOUNT_ID,response.get("id")); + assertEquals(CUSTOMER_ID,response.get("customer_id")); + assertEquals(CORP_NAME,response.get("name")); + assertTrue(response.has("allowed_payers")); verifySentRequest(false, null, getHost(String.format(Constants.VIRTUAL_ACCOUNT_ALLOWEDPAYERS, VIRTUAL_ACCOUNT_ID))); } catch (IOException e) { assertTrue(false); From ece0338f373f11ee282270a2086550d0784c9f63 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 2 Mar 2022 16:59:09 +0530 Subject: [PATCH 72/78] addon testcase issue fix --- src/main/java/com/razorpay/Constants.java | 1 - src/test/java/com/razorpay/AddonClientTest.java | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index db5af948..0e0fcd61 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -78,7 +78,6 @@ public class Constants { static final String ITEM = "items/%s"; static final String CARD_GET = "cards/%s"; - static final String FETCH_CARD_DETAILS = "payments/%s/card"; static final String CUSTOMER_CREATE = "customers"; static final String CUSTOMER_GET = "customers/%s"; diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java index 28ff6a42..d25fa5cd 100644 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -1,5 +1,6 @@ package com.razorpay; +import org.json.JSONObject; import org.junit.Test; import org.mockito.InjectMocks; @@ -51,11 +52,12 @@ public void fetch() throws RazorpayException { mockResponseHTTPCodeFromExternalClient(200); Addon fetch = client.fetch(ADDON_ID); assertNotNull(fetch); + JSONObject item = fetch.toJson().getJSONObject("item"); assertEquals(ADDON_ID,fetch.get("id")); - assertEquals("INR",fetch.get("currency")); - assertEquals("30000",fetch.get("amount")); - assertTrue(fetch.get("active")); - assertTrue(fetch.get("unit_amount")); + assertEquals("INR",item.get("currency")); + assertEquals(30000,item.get("amount")); + assertTrue(item.getBoolean("active")); + assertTrue(item.has("unit_amount")); } catch (IOException e) { assertTrue(false); } @@ -85,7 +87,7 @@ public void fetchAll() throws RazorpayException { "\"type\": \"addon\",\n " + "\"unit\": null,\n " + "\"tax_inclusive\": false,\n " + - "\"hsn_code\": null,\n " + + "\"hsn_code\": 123,\n " + "\"sac_code\": null,\n " + "\"tax_rate\": null,\n" + "\"tax_id\": null,\n " + @@ -105,8 +107,8 @@ public void fetchAll() throws RazorpayException { assertNotNull(fetch); assertEquals(true,fetch.get(0).has("id")); assertEquals(true,fetch.get(0).has("entity")); - assertEquals(true,fetch.get(0).has("items")); - assertEquals(true,fetch.get(0).has("hsn_code")); + assertEquals(true,fetch.get(0).has("item")); + assertEquals(true,fetch.get(0).toJson().getJSONObject("item").has("hsn_code")); } catch (IOException e) { assertTrue(false); } From ed872a53fa5c06fc64060e3d4963dd462445b8b1 Mon Sep 17 00:00:00 2001 From: ersinghlovepreet Date: Wed, 2 Mar 2022 20:26:57 +0530 Subject: [PATCH 73/78] refactor test cases --- .../java/com/razorpay/RazorpayClient.java | 64 +++++++++---------- .../java/com/razorpay/AddonClientTest.java | 4 ++ src/test/java/com/razorpay/BaseTest.java | 30 ++++++++- .../java/com/razorpay/CardClientTest.java | 4 ++ .../java/com/razorpay/CustomerClientTest.java | 12 ++++ .../com/razorpay/FundAccountClientTest.java | 4 ++ .../java/com/razorpay/InvoiceClientTest.java | 16 +++++ .../java/com/razorpay/ItemClientTest.java | 8 +++ .../java/com/razorpay/OrderClientTest.java | 10 +++ .../java/com/razorpay/PaymentClientTest.java | 14 ++++ .../java/com/razorpay/PaymentLinkTest.java | 12 ++++ .../java/com/razorpay/QrCodeClientTest.java | 8 +++ .../java/com/razorpay/RefundClientTest.java | 10 +++ .../com/razorpay/SettlementClientTest.java | 12 ++++ .../com/razorpay/SubscriptionClientTest.java | 25 -------- .../razorpay/VirtualAccountClientTest.java | 24 ------- 16 files changed, 175 insertions(+), 82 deletions(-) diff --git a/src/main/java/com/razorpay/RazorpayClient.java b/src/main/java/com/razorpay/RazorpayClient.java index cb56245e..a42bbcdd 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -6,22 +6,22 @@ public class RazorpayClient { - public PaymentClient Payments; - public RefundClient Refunds; - public OrderClient Orders; - public InvoiceClient Invoices; - public CardClient Cards; - public CustomerClient Customers; - public TransferClient Transfers; - public SubscriptionClient Subscriptions; - public AddonClient Addons; - public PlanClient Plans; - public SettlementClient Settlement; - public QrCodeClient QrCode; - public PaymentLinkClient PaymentLink; - public ItemClient Items; - public FundAccountClient FundAccount; - public VirtualAccountClient VirtualAccounts; + public PaymentClient payments; + public RefundClient refunds; + public OrderClient orders; + public InvoiceClient invoices; + public CardClient cards; + public CustomerClient customers; + public TransferClient transfers; + public SubscriptionClient subscriptions; + public AddonClient addons; + public PlanClient plans; + public SettlementClient settlement; + public QrCodeClient qrCode; + public PaymentLinkClient paymentLink; + public ItemClient items; + public FundAccountClient fundAccount; + public VirtualAccountClient virtualAccounts; public RazorpayClient(String key, String secret) throws RazorpayException { this(key, secret, false); @@ -30,22 +30,22 @@ public RazorpayClient(String key, String secret) throws RazorpayException { public RazorpayClient(String key, String secret, Boolean enableLogging) throws RazorpayException { ApiUtils.createHttpClientInstance(enableLogging); String auth = Credentials.basic(key, secret); - Payments = new PaymentClient(auth); - Refunds = new RefundClient(auth); - Orders = new OrderClient(auth); - Invoices = new InvoiceClient(auth); - Cards = new CardClient(auth); - Customers = new CustomerClient(auth); - Transfers = new TransferClient(auth); - Subscriptions = new SubscriptionClient(auth); - Addons = new AddonClient(auth); - Plans = new PlanClient(auth); - Settlement = new SettlementClient(auth); - QrCode = new QrCodeClient(auth); - PaymentLink = new PaymentLinkClient(auth); - Items = new ItemClient(auth); - FundAccount = new FundAccountClient(auth); - VirtualAccounts = new VirtualAccountClient(auth); + payments = new PaymentClient(auth); + refunds = new RefundClient(auth); + orders = new OrderClient(auth); + invoices = new InvoiceClient(auth); + cards = new CardClient(auth); + customers = new CustomerClient(auth); + transfers = new TransferClient(auth); + subscriptions = new SubscriptionClient(auth); + addons = new AddonClient(auth); + plans = new PlanClient(auth); + settlement = new SettlementClient(auth); + qrCode = new QrCodeClient(auth); + paymentLink = new PaymentLinkClient(auth); + items = new ItemClient(auth); + fundAccount = new FundAccountClient(auth); + virtualAccounts = new VirtualAccountClient(auth); } public RazorpayClient addHeaders(Map headers) { diff --git a/src/test/java/com/razorpay/AddonClientTest.java b/src/test/java/com/razorpay/AddonClientTest.java index d25fa5cd..3bcd6658 100644 --- a/src/test/java/com/razorpay/AddonClientTest.java +++ b/src/test/java/com/razorpay/AddonClientTest.java @@ -58,6 +58,8 @@ public void fetch() throws RazorpayException { assertEquals(30000,item.get("amount")); assertTrue(item.getBoolean("active")); assertTrue(item.has("unit_amount")); + String addonCreate = getHost(String.format(Constants.ADDON_GET, ADDON_ID)); + verifySentRequest(false, null, addonCreate); } catch (IOException e) { assertTrue(false); } @@ -109,6 +111,8 @@ public void fetchAll() throws RazorpayException { assertEquals(true,fetch.get(0).has("entity")); assertEquals(true,fetch.get(0).has("item")); assertEquals(true,fetch.get(0).toJson().getJSONObject("item").has("hsn_code")); + String addonList = getHost(Constants.ADDON_LIST); + verifySentRequest(false, null, addonList); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/BaseTest.java b/src/test/java/com/razorpay/BaseTest.java index 72aa73cc..bcc8aeed 100644 --- a/src/test/java/com/razorpay/BaseTest.java +++ b/src/test/java/com/razorpay/BaseTest.java @@ -1,16 +1,19 @@ package com.razorpay; import okhttp3.*; +import okio.Buffer; import org.apache.commons.lang3.reflect.FieldUtils; import org.json.JSONObject; import org.junit.Before; -import org.mockito.InjectMocks; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.io.IOException; import java.lang.reflect.Field; import java.util.List; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -66,4 +69,29 @@ protected OkHttpClient getOkHttpClient() { return okHttpClient; } + + protected String getHost(String url) { + return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; + } + + protected void verifySentRequest(boolean hasBody, String request, String requestPath) { + ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); + Mockito.verify(getOkHttpClient()).newCall(req.capture()); + if(hasBody) { + assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); + } + assertEquals(requestPath, req.getValue().url().toString()); + } + + private static String bodyToString(final Request request) { + + try { + final Request copy = request.newBuilder().build(); + final Buffer buffer = new Buffer(); + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "did not work"; + } + } } \ No newline at end of file diff --git a/src/test/java/com/razorpay/CardClientTest.java b/src/test/java/com/razorpay/CardClientTest.java index 5cf3daa7..9c56b1e3 100644 --- a/src/test/java/com/razorpay/CardClientTest.java +++ b/src/test/java/com/razorpay/CardClientTest.java @@ -31,6 +31,8 @@ public void fetch() throws RazorpayException { assertNotNull(fetch); assertEquals(CARD_ID,fetch.get("id")); assertTrue(fetch.has("international")); + String addonCreate = getHost(String.format(Constants.CARD_GET, CARD_ID)); + verifySentRequest(false, null, addonCreate); } catch (IOException e) { assertTrue(false); } @@ -52,6 +54,8 @@ public void fetchCardDetails() throws RazorpayException { assertEquals(CARD_ID,fetch.get("id")); assertTrue(fetch.has("name")); assertTrue(fetch.has("network")); + String fetchCardDetails = getHost(String.format(Constants.FETCH_CARD_DETAILS, PAYMENT_ID)); + verifySentRequest(false, null, fetchCardDetails); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index c6d98f00..e88dae66 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -56,6 +56,8 @@ public void create() throws RazorpayException{ Customer customer = customerClient.create(request); assertNotNull(customer); assertEquals(CUSTOMER_ID,customer.get("id")); + String createRequest = getHost(Constants.CUSTOMER_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -84,6 +86,8 @@ public void fetch() throws RazorpayException { Customer fetch = customerClient.fetch(CUSTOMER_ID); assertNotNull(fetch); assertEquals(CUSTOMER_ID,fetch.get("id")); + String fetchRequest = getHost(String.format(Constants.CUSTOMER_GET, CUSTOMER_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -119,6 +123,8 @@ public void fetchAll() throws RazorpayException { List fetch = customerClient.fetchAll(); assertNotNull(fetch); assertEquals(true,fetch.get(0).has("id")); + String fetchRequest = getHost(Constants.CUSTOMER_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -159,6 +165,8 @@ public void edit() throws RazorpayException { Customer fetch = customerClient.edit(CUSTOMER_ID,request); assertNotNull(fetch); assertEquals(CUSTOMER_ID,fetch.get("id")); + String editRequest = getHost(String.format(Constants.CUSTOMER_EDIT,CUSTOMER_ID)); + verifySentRequest(true, request.toString(), editRequest); } catch (IOException e) { assertTrue(false); } @@ -206,6 +214,8 @@ public void fetchTokens() throws RazorpayException{ Token fetch = customerClient.fetchToken(CUSTOMER_ID,TOKEN_ID); assertNotNull(fetch); assertEquals(TOKEN_ID,fetch.get("id")); + String fetchToken = getHost(String.format(Constants.TOKEN_GET,CUSTOMER_ID,TOKEN_ID)); + verifySentRequest(false, null, fetchToken); } catch (IOException e) { assertTrue(false); } @@ -261,6 +271,8 @@ public void fetchToken() throws RazorpayException{ List fetch = customerClient.fetchTokens(CUSTOMER_ID); assertNotNull(fetch); assertEquals(true,fetch.get(0).has("id")); + String fetchToken = getHost(String.format(Constants.TOKEN_LIST,CUSTOMER_ID)); + verifySentRequest(false, null, fetchToken); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/FundAccountClientTest.java b/src/test/java/com/razorpay/FundAccountClientTest.java index dfb22728..d6d445bf 100644 --- a/src/test/java/com/razorpay/FundAccountClientTest.java +++ b/src/test/java/com/razorpay/FundAccountClientTest.java @@ -48,6 +48,8 @@ public void create() throws RazorpayException { FundAccount fundaccount = fundAccountClient.create(request); assertNotNull(fundaccount); assertEquals(FUNDACCOUNT_ID,fundaccount.get("id")); + String createRequest = getHost(Constants.FUND_ACCOUNT_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -79,6 +81,8 @@ public void fetch() throws RazorpayException { FundAccount fetch = fundAccountClient.fetch(FUNDACCOUNT_ID); assertNotNull(fetch); assertEquals(FUNDACCOUNT_ID,fetch.get("id")); + String fetchRequest = getHost(String.format(Constants.FUND_ACCOUNT_FETCH,FUNDACCOUNT_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/InvoiceClientTest.java b/src/test/java/com/razorpay/InvoiceClientTest.java index 897e9708..4273d2db 100644 --- a/src/test/java/com/razorpay/InvoiceClientTest.java +++ b/src/test/java/com/razorpay/InvoiceClientTest.java @@ -35,6 +35,8 @@ public void create() throws RazorpayException { assertEquals("invoice",invoice.get("entity")); assertTrue(invoice.has("customer_details")); assertTrue(invoice.has("short_url")); + String createRequest = getHost(Constants.INVOICE_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -56,6 +58,8 @@ public void fetchAll() throws RazorpayException { assertNotNull(fetch); assertTrue(fetch.get(0).has("type")); assertTrue(fetch.get(0).has("receipt")); + String fetchRequest = getHost(Constants.INVOICE_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -78,6 +82,8 @@ public void fetch() throws RazorpayException { assertEquals(INVOICE_ID,fetch.get("id")); assertTrue(fetch.has("customer_details")); assertTrue(fetch.has("issued_at")); + String fetchRequest = getHost(String.format(Constants.INVOICE_GET,INVOICE_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -101,6 +107,8 @@ public void cancel() throws RazorpayException { assertEquals("pending",fetch.get("email_status")); assertTrue(fetch.has("customer_details")); assertTrue(fetch.has("issued_at")); + String cancelRequest = getHost(String.format(Constants.INVOICE_CANCEL,INVOICE_ID)); + verifySentRequest(false, null, cancelRequest); } catch (IOException e) { assertTrue(false); } @@ -123,6 +131,8 @@ public void notifyBy() throws RazorpayException { assertNotNull(fetch); assertTrue(fetch.has("success")); assertTrue(fetch.has("entity")); + String notifyByRequest = getHost(String.format(Constants.INVOICE_NOTIFY,INVOICE_ID,"sms")); + verifySentRequest(false, null, notifyByRequest); } catch (IOException e) { assertTrue(false); } @@ -147,6 +157,8 @@ public void createRegistrationLink() throws RazorpayException { assertTrue(fetch.has("razorpay_payment_id")); assertTrue(fetch.has("razorpay_order_id")); assertTrue(fetch.has("razorpay_signature")); + String createRegistrationLinkRequest = getHost(Constants.SUBSCRIPTION_REGISTRATION_LINK); + verifySentRequest(true, request.toString(), createRegistrationLinkRequest); } catch (IOException e) { assertTrue(false); } @@ -169,6 +181,8 @@ public void issue() throws RazorpayException { assertEquals("invoice",fetch.get("entity")); assertTrue(fetch.has("invoice_number")); assertTrue(fetch.has("receipt")); + String issueRequest = getHost(String.format(Constants.INVOICE_ISSUE,INVOICE_ID)); + verifySentRequest(false, null, issueRequest); } catch (IOException e) { assertTrue(false); } @@ -191,6 +205,8 @@ public void edit() throws RazorpayException { assertEquals("invoice",invoice.get("entity")); assertTrue(invoice.has("invoice_number")); assertTrue(invoice.has("receipt")); + String editRequest = getHost(String.format(Constants.INVOICE_GET,INVOICE_ID)); + verifySentRequest(true, request.toString(), editRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/ItemClientTest.java b/src/test/java/com/razorpay/ItemClientTest.java index 21402349..229e4c45 100644 --- a/src/test/java/com/razorpay/ItemClientTest.java +++ b/src/test/java/com/razorpay/ItemClientTest.java @@ -48,6 +48,8 @@ public void create() throws RazorpayException { assertTrue(item.has("active")); assertTrue(item.has("name")); assertTrue(item.has("name")); + String createRequest = getHost(Constants.ITEMS); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -78,6 +80,8 @@ public void fetch() throws RazorpayException { assertEquals("item",fetch.get("entity")); assertTrue(fetch.has("amount")); assertTrue(fetch.has("currency")); + String fetchRequest = getHost(String.format(Constants.ITEM,ITEM_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -111,6 +115,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("entity")); assertTrue(fetch.get(0).has("id")); assertTrue(fetch.get(0).has("active")); + String fetchRequest = getHost(Constants.ITEMS); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -147,6 +153,8 @@ public void edit() throws RazorpayException{ assertEquals("item",item.get("entity")); assertTrue(item.has("amount")); assertTrue(item.has("description")); + String editRequest = getHost(String.format(Constants.ITEM, ITEM_ID)); + verifySentRequest(true, request.toString(), editRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/OrderClientTest.java b/src/test/java/com/razorpay/OrderClientTest.java index ec08a755..364bb00e 100644 --- a/src/test/java/com/razorpay/OrderClientTest.java +++ b/src/test/java/com/razorpay/OrderClientTest.java @@ -52,6 +52,8 @@ public void create() throws RazorpayException { assertEquals("order",fetch.get("entity")); assertTrue(fetch.has("amount")); assertTrue(fetch.has("amount_paid")); + String createRequest = getHost(Constants.ORDER_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -86,6 +88,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("entity")); assertTrue(fetch.get(0).has("amount")); assertTrue(fetch.get(0).has("amount_paid")); + String fetchRequest = getHost(Constants.ORDER_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -117,6 +121,8 @@ public void fetch() throws RazorpayException{ assertTrue(fetch.has("entity")); assertTrue(fetch.has("amount")); assertTrue(fetch.has("amount_paid")); + String fetchRequest = getHost(String.format(Constants.ORDER_GET,ORDER_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -164,6 +170,8 @@ public void fetchPayments() throws RazorpayException{ assertTrue(fetch.get(0).has("id")); assertTrue(fetch.get(0).has("amount")); assertTrue(fetch.get(0).has("currency")); + String fetchRequest = getHost(String.format(Constants.ORDER_PAYMENT_LIST, ORDER_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -205,6 +213,8 @@ public void edit() throws RazorpayException { assertNotNull(fetch); assertEquals(ORDER_ID,fetch.get("id")); assertEquals(ORDER_ID,fetch.get("id")); + String editRequest = getHost(String.format(Constants.ORDER_EDIT, ORDER_ID)); + verifySentRequest(true, request.toString(), editRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index 6ecf17d3..8adccdd5 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -64,6 +64,8 @@ public void fetch() throws RazorpayException{ assertEquals(PAYMENT_ID,fetch.get("id")); assertTrue(fetch.has("status")); assertTrue(fetch.has("currency")); + String fetchRequest = getHost(String.format(Constants.PAYMENT_GET, PAYMENT_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -117,6 +119,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("id")); assertTrue(fetch.get(0).has("entity")); assertTrue(fetch.get(0).has("amount")); + String fetchRequest = getHost(Constants.PAYMENT_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -173,6 +177,8 @@ public void capture() throws RazorpayException{ assertEquals(PAYMENT_ID,fetch.get("id")); assertTrue(fetch.has("entity")); assertTrue(fetch.has("amount")); + String captureRequest = getHost(String.format(Constants.PAYMENT_CAPTURE, PAYMENT_ID)); + verifySentRequest(true, request.toString(), captureRequest); } catch (IOException e) { assertTrue(false); } @@ -210,6 +216,8 @@ public void refund() throws Exception{ assertEquals(REFUND_ID,fetch.get("id")); assertEquals("INR",fetch.get("currency")); assertTrue(fetch.has("payment_id")); + String refundRequest = getHost(String.format(Constants.PAYMENT_REFUND, PAYMENT_ID)); + verifySentRequest(true, request.toString(), refundRequest); } catch (IOException e) { assertTrue(false); } @@ -246,6 +254,8 @@ public void FetchAllRefunds() throws RazorpayException{ assertTrue(fetch.get(0).has("amount")); assertTrue(fetch.get(0).has("payment_id")); assertTrue(fetch.get(0).has("notes")); + String refundRequest = getHost(String.format(Constants.PAYMENT_REFUND_LIST, PAYMENT_ID)); + verifySentRequest(false, null, refundRequest); } catch (IOException e) { assertTrue(false); } @@ -303,6 +313,8 @@ public void transfers() throws RazorpayException{ assertTrue(fetch.get(0).has("source")); assertTrue(fetch.get(0).has("recipient")); assertTrue(fetch.get(0).has("currency")); + String transferRequest = getHost(String.format(Constants.PAYMENT_TRANSFER_CREATE, PAYMENT_ID)); + verifySentRequest(true, request.toString(), transferRequest); } catch (IOException e) { assertTrue(false); } @@ -345,6 +357,8 @@ public void fetchAllTransfers() throws RazorpayException{ assertTrue(fetch.get(0).has("source")); assertTrue(fetch.get(0).has("recipient")); assertTrue(fetch.get(0).has("amount")); + String transferRequest = getHost(String.format(Constants.PAYMENT_TRANSFER_GET, PAYMENT_ID)); + verifySentRequest(false, null, transferRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/PaymentLinkTest.java b/src/test/java/com/razorpay/PaymentLinkTest.java index 78345f7b..18d3efae 100644 --- a/src/test/java/com/razorpay/PaymentLinkTest.java +++ b/src/test/java/com/razorpay/PaymentLinkTest.java @@ -35,6 +35,8 @@ public void create() throws RazorpayException{ assertEquals("INR",fetch.get("currency")); assertTrue(fetch.has("amount_paid")); assertTrue(fetch.has("upi_link")); + String createRequest = getHost(Constants.PAYMENTLINK_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -58,6 +60,8 @@ public void fetch() throws RazorpayException{ assertEquals("INR",fetch.get("currency")); assertTrue(fetch.has("amount_paid")); assertTrue(fetch.has("upi_link")); + String fetchRequest = getHost(String.format(Constants.PAYMENTLINK_GET, PAYMENTLINK_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -81,6 +85,8 @@ public void cancel() throws RazorpayException{ assertEquals("INR",fetch.get("currency")); assertTrue(fetch.has("callback_method")); assertTrue(fetch.has("cancelled_at")); + String cancelRequest = getHost(String.format(Constants.PAYMENTLINK_CANCEL, PAYMENTLINK_ID)); + verifySentRequest(false, null, cancelRequest); } catch (IOException e) { assertTrue(false); } @@ -102,6 +108,8 @@ public void notifyBy() throws RazorpayException{ assertNotNull(fetch); assertEquals("payment_link",fetch.get("entity")); assertTrue(fetch.get("success")); + String notifyByRequest = getHost(String.format(Constants.PAYMENTLINK_NOTIFYBY, PAYMENTLINK_ID, "sms")); + verifySentRequest(false, null, notifyByRequest); } catch (IOException e) { assertTrue(false); } @@ -125,6 +133,8 @@ public void edit() throws RazorpayException{ assertTrue(fetch.has("accept_partial")); assertTrue(fetch.has("order_id")); assertTrue(fetch.has("payments")); + String fetchRequest = getHost(String.format(Constants.PAYMENTLINK_EDIT, PAYMENTLINK_ID)); + verifySentRequest(true, request.toString(), fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -146,6 +156,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("reminders")); assertTrue(fetch.get(0).has("created_at")); assertTrue(fetch.get(0).has("currency")); + String fetchRequest = getHost(Constants.PAYMENTLINK_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/QrCodeClientTest.java b/src/test/java/com/razorpay/QrCodeClientTest.java index 0eaf35e4..4f756467 100644 --- a/src/test/java/com/razorpay/QrCodeClientTest.java +++ b/src/test/java/com/razorpay/QrCodeClientTest.java @@ -69,6 +69,8 @@ public void create() throws RazorpayException { assertEquals(QRCODE_ID,fetch.get("id")); assertTrue(fetch.has("close_by")); assertTrue(fetch.has("fixed_amount")); + String createRequest = getHost(Constants.QRCODE_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -113,6 +115,8 @@ public void fetch() throws RazorpayException{ assertEquals(CUSTOMER_ID,fetch.get("customer_id")); assertTrue(fetch.has("close_by")); assertTrue(fetch.has("fixed_amount")); + String fetchRequest = getHost(String.format(Constants.QRCODE_FETCH, QRCODE_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -163,6 +167,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("id")); assertTrue(fetch.get(0).has("customer_id")); assertTrue(fetch.get(0).has("close_by")); + String fetchRequest = getHost(Constants.QRCODE_LIST); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -208,6 +214,8 @@ public void close() throws RazorpayException{ assertEquals(CUSTOMER_ID,fetch.get("customer_id")); assertTrue(fetch.has("close_by")); assertTrue(fetch.has("fixed_amount")); + String closeRequest = getHost(String.format(Constants.QRCODE_CLOSE,QRCODE_ID)); + verifySentRequest(false, null, closeRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/RefundClientTest.java b/src/test/java/com/razorpay/RefundClientTest.java index fa45cf9e..07278326 100644 --- a/src/test/java/com/razorpay/RefundClientTest.java +++ b/src/test/java/com/razorpay/RefundClientTest.java @@ -55,6 +55,8 @@ public void create() throws RazorpayException{ assertEquals("refund",fetch.get("entity")); assertEquals(500100,(int)fetch.get("amount")); assertEquals("INR",fetch.get("currency")); + String createRequest = getHost(Constants.REFUNDS); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -91,6 +93,8 @@ public void fetch() throws RazorpayException{ Refund fetch = refundClient.fetch(REFUND_ID); assertNotNull(fetch); assertEquals(REFUND_ID,fetch.get("id")); + String fetchRequest = getHost(String.format(Constants.REFUND,REFUND_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -136,6 +140,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("amount")); assertTrue(fetch.get(0).has("currency")); assertTrue(fetch.get(0).has("payment_id")); + String fetchRequest = getHost(Constants.REFUNDS); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -182,6 +188,8 @@ public void fetchMultipleRefund() throws RazorpayException{ assertTrue(fetch.get(0).has("amount")); assertTrue(fetch.get(0).has("currency")); assertTrue(fetch.get(0).has("payment_id")); + String fetchRequest = getHost(String.format(Constants.REFUND_MULTIPLE,REFUND_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -228,6 +236,8 @@ public void edit() throws RazorpayException{ assertEquals("refund",fetch.get("entity")); assertEquals(300100,(int)fetch.get("amount")); assertEquals("INR",fetch.get("currency")); + String editRequest = getHost(String.format(Constants.REFUND,REFUND_ID)); + verifySentRequest(true, request.toString(), editRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/SettlementClientTest.java b/src/test/java/com/razorpay/SettlementClientTest.java index 3a2dca1a..eae8d426 100644 --- a/src/test/java/com/razorpay/SettlementClientTest.java +++ b/src/test/java/com/razorpay/SettlementClientTest.java @@ -58,6 +58,8 @@ public void fetchAll() throws RazorpayException{ assertTrue(fetch.get(0).has("id")); assertTrue(fetch.get(0).has("fees")); assertTrue(fetch.get(0).has("tax")); + String fetchRequest = getHost(Constants.SETTLEMENTS); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -89,6 +91,8 @@ public void fetch() throws RazorpayException{ assertEquals("settlement",fetch.get("entity")); assertEquals("processed",fetch.get("status")); assertEquals("1568176960vxp0rj",fetch.get("utr")); + String fetchRequest = getHost(String.format(Constants.SETTLEMENT,SETTLEMENT_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -147,6 +151,8 @@ public void reports() throws RazorpayException{ assertTrue(fetch.get(0).has("order_id")); assertTrue(fetch.get(0).has("method")); assertTrue(fetch.get(0).has("card_type")); + String reportRequest = getHost(Constants.SETTLEMENTS_REPORTS)+"?month=9&year=2020"; + verifySentRequest(false, null, reportRequest); } catch (IOException e) { assertTrue(false); } @@ -212,6 +218,8 @@ public void create() throws RazorpayException{ assertEquals(SETTLEMENT_ID,fetch.get("id")); assertEquals("initiated",fetch.get("status")); assertTrue(fetch.has("notes")); + String createRequest = getHost(Constants.SETTLEMENTS_INSTANT); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -258,6 +266,8 @@ public void fetchAllDemand() throws RazorpayException{ assertTrue(fetch.get(0).has("entity")); assertTrue(fetch.get(0).has("amount_requested")); assertTrue(fetch.get(0).has("amount_pending")); + String fetchRequest = getHost(Constants.SETTLEMENTS_INSTANT); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } @@ -296,6 +306,8 @@ public void fetchDemandSettlement() throws RazorpayException{ assertEquals(SETTLEMENT_ID,fetch.get("id")); assertEquals("processed",fetch.get("status")); assertEquals(200000,(int)fetch.get("amount_requested")); + String fetchRequest = getHost(String.format(Constants.SETTLEMENT_INSTANT,SETTLEMENT_ID)); + verifySentRequest(false, null, fetchRequest); } catch (IOException e) { assertTrue(false); } diff --git a/src/test/java/com/razorpay/SubscriptionClientTest.java b/src/test/java/com/razorpay/SubscriptionClientTest.java index 6a343b2e..4fd2971f 100644 --- a/src/test/java/com/razorpay/SubscriptionClientTest.java +++ b/src/test/java/com/razorpay/SubscriptionClientTest.java @@ -42,19 +42,6 @@ public void testCreate() throws IOException, RazorpayException { verifySentRequest(true, getRequest(), subscriptionCreate); } - private String getHost(String url) { - return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; - } - - public void verifySentRequest(boolean hasBody, String request, String requestPath) { - ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); - Mockito.verify(getOkHttpClient()).newCall(req.capture()); - if(hasBody) { - assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); - } - assertEquals(requestPath, req.getValue().url().toString()); - } - @Test(expected = RazorpayException.class) public void testCreateWithException() throws IOException, RazorpayException { @@ -386,16 +373,4 @@ private String getResponse(String testPlanId, String testSubscriptionId, int qua "}"; } - private static String bodyToString(final Request request) { - - try { - final Request copy = request.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "did not work"; - } - } - } \ No newline at end of file diff --git a/src/test/java/com/razorpay/VirtualAccountClientTest.java b/src/test/java/com/razorpay/VirtualAccountClientTest.java index b1feb90f..7a29fdd2 100644 --- a/src/test/java/com/razorpay/VirtualAccountClientTest.java +++ b/src/test/java/com/razorpay/VirtualAccountClientTest.java @@ -411,28 +411,4 @@ public void addAllowedPayers() throws RazorpayException{ } } - public void verifySentRequest(boolean hasBody, String request, String requestPath) { - ArgumentCaptor req = ArgumentCaptor.forClass(Request.class); - Mockito.verify(getOkHttpClient()).newCall(req.capture()); - if(hasBody) { - assertEquals(new JSONObject(request).toString(), new JSONObject(bodyToString(req.getAllValues().get(0))).toString()); - } - assertEquals(requestPath, req.getValue().url().toString()); - } - - private static String bodyToString(final Request request) { - - try { - final Request copy = request.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "did not work"; - } - } - - String getHost(String url) { - return Constants.SCHEME + "://" + Constants.HOSTNAME + "/" + Constants.VERSION + "/" + url; - } } \ No newline at end of file From 7b39a55ad55803ace3e52cb05e39c71bcdad5a4a Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Mar 2022 17:42:08 +0530 Subject: [PATCH 74/78] recurring payment with unittest case --- src/main/java/com/razorpay/Constants.java | 1 + src/main/java/com/razorpay/PaymentClient.java | 4 ++ .../java/com/razorpay/PaymentClientTest.java | 43 ++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 0e0fcd61..4aaf3fe7 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -27,6 +27,7 @@ public class Constants { static final String FETCH_DOWNTIME_LIST = "payments/downtimes"; static final String FETCH_DOWNTIME_GET = "payments/downtimes"; static final String PAYMENT_JSON_CREATE = "payments/create/json"; + static final String PAYMENT_RECURRING = "payments/create/recurring"; static final String PAYMENTLINK_CREATE = "payment_links"; static final String PAYMENTLINK_LIST = "payment_links"; diff --git a/src/main/java/com/razorpay/PaymentClient.java b/src/main/java/com/razorpay/PaymentClient.java index caefc959..1882038a 100755 --- a/src/main/java/com/razorpay/PaymentClient.java +++ b/src/main/java/com/razorpay/PaymentClient.java @@ -97,4 +97,8 @@ public Payment createJsonPayment(JSONObject request) throws RazorpayException { return post(Constants.PAYMENT_JSON_CREATE, request); } + public Payment createRecurringPayment(JSONObject request) throws RazorpayException { + return post(Constants.PAYMENT_RECURRING, request); + } + } diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index 6ecf17d3..b10af3a4 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -17,7 +17,10 @@ public class PaymentClientTest extends BaseTest{ private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; private static final String REFUND_ID = "rfnd_FP8QHiV938haTz"; - + + private static final String ORDER_ID = "order_J2bVDDGFwgGJbW"; + + private static final String SIGNATURE = "aa64f4fafe6b0c3febce374c1176bbf91bf8077a25501efc0558d60b4a68bead"; /** * Retrieve payment details of respective customer using payment id. * @throws RazorpayException @@ -468,4 +471,42 @@ public void createJsonPayment() throws RazorpayException { assertTrue(false); } } + + @Test + public void createRecurringPayment() throws RazorpayException { + + JSONObject request = new JSONObject("{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9876543567\",\n" + + " \"amount\": 10000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_J2bmbRQxkC3YTv\",\n" + + " \"customer_id\": \"cust_DzYEzfJLV03rkp\",\n" + + " \"token\": \"token_Ip8u7q7FA77Q30\",\n" + + " \"recurring\": \"1\",\n" + + " \"notes\": {\n" + + " \"note_key_1\": \"Tea. Earl grey. Hot.\",\n" + + " \"note_key_2\": \"Tea. Earl grey. Decaf.\"\n" + + " },\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\"\n" + + "}"); + + String mockedResponseJson = "{\n" + + " \"entity\": \"payment\",\n" + + " \"razorpay_payment_id\": \"pay_IDRP0tbirMSsbn\",\n" + + " \"razorpay_order_id\": \"order_J2bVDDGFwgGJbW\",\n" + + " \"razorpay_signature\": \"aa64f4fafe6b0c3febce374c1176bbf91bf8077a25501efc0558d60b4a68bead\"\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Payment fetch = paymentClient.createRecurringPayment(request); + assertNotNull(fetch); + assertEquals(PAYMENT_ID,fetch.get("razorpay_payment_id")); + assertEquals(ORDER_ID,fetch.get("razorpay_order_id")); + assertEquals(SIGNATURE,fetch.get("razorpay_signature")); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file From 34268e0e58c5bf03dbfb90a4ca303329ce85d7a0 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Thu, 3 Mar 2022 22:44:41 +0530 Subject: [PATCH 75/78] plan & transfer unittest --- .../java/com/razorpay/PlanClientTest.java | 200 +++++++++++++++++ .../java/com/razorpay/TransferClientTest.java | 207 ++++++++++++++++++ 2 files changed, 407 insertions(+) create mode 100644 src/test/java/com/razorpay/PlanClientTest.java create mode 100644 src/test/java/com/razorpay/TransferClientTest.java diff --git a/src/test/java/com/razorpay/PlanClientTest.java b/src/test/java/com/razorpay/PlanClientTest.java new file mode 100644 index 00000000..c50f824a --- /dev/null +++ b/src/test/java/com/razorpay/PlanClientTest.java @@ -0,0 +1,200 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class PlanClientTest extends BaseTest{ + + @InjectMocks + protected PlanClient planClient = new PlanClient(TEST_SECRET_KEY); + + private static final String PLAN_ID = "plan_00000000000001"; + + /** + * Create plan with currency and amount details + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + JSONObject request = new JSONObject("{\n" + + " period: \"weekly\",\n" + + " interval: 1,\n" + + " item: {\n" + + " name: \"Test plan - Weekly\",\n" + + " amount: 69900,\n" + + " currency: \"INR\",\n" + + " description: \"Description for the test plan\"\n" + + " },\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"); + + String mockedResponseJson = "{\n" + + " \"id\":"+PLAN_ID+",\n" + + " \"entity\":\"plan\",\n" + + " \"interval\":1,\n" + + " \"period\":\"weekly\",\n" + + " \"item\":{\n" + + " \"id\":\"item_00000000000001\",\n" + + " \"active\":true,\n" + + " \"name\":\"Test plan - Weekly\",\n" + + " \"description\":\"Description for the test plan - Weekly\",\n" + + " \"amount\":69900,\n" + + " \"unit_amount\":69900,\n" + + " \"currency\":\"INR\",\n" + + " \"type\":\"plan\",\n" + + " \"unit\":null,\n" + + " \"tax_inclusive\":false,\n" + + " \"hsn_code\":null,\n" + + " \"sac_code\":null,\n" + + " \"tax_rate\":null,\n" + + " \"tax_id\":null,\n" + + " \"tax_group_id\":null,\n" + + " \"created_at\":1580219935,\n" + + " \"updated_at\":1580219935\n" + + " },\n" + + " \"notes\":{\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\":1580219935\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Plan fetch = planClient.create(request); + assertNotNull(fetch); + JSONObject item = fetch.toJson().getJSONObject("item"); + assertEquals(PLAN_ID,fetch.get("id")); + assertEquals("plan",fetch.get("entity")); + assertTrue(item.has("amount")); + assertTrue(item.has("unit_amount")); + String createRequest = getHost(Constants.PLAN_CREATE); + verifySentRequest(true, request.toString(), createRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Retrieve all the Plans details using plan id. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + + String json = "{\n" + + " \"id\":"+PLAN_ID+",\n" + + " \"entity\":\"plan\",\n" + + " \"interval\":1,\n" + + " \"period\":\"weekly\",\n" + + " \"item\":{\n" + + " \"id\":\"item_00000000000001\",\n" + + " \"active\":true,\n" + + " \"name\":\"Test plan - Weekly\",\n" + + " \"description\":\"Description for the test plan - Weekly\",\n" + + " \"amount\":69900,\n" + + " \"unit_amount\":69900,\n" + + " \"currency\":\"INR\",\n" + + " \"type\":\"plan\",\n" + + " \"unit\":null,\n" + + " \"tax_inclusive\":false,\n" + + " \"hsn_code\":null,\n" + + " \"sac_code\":null,\n" + + " \"tax_rate\":null,\n" + + " \"tax_id\":null,\n" + + " \"tax_group_id\":null,\n" + + " \"created_at\":1580220492,\n" + + " \"updated_at\":1580220492\n" + + " },\n" + + " \"notes\":{\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\":1580220492\n" + + "}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Plan fetch = planClient.fetch(PLAN_ID); + assertNotNull(fetch); + JSONObject item = fetch.toJson().getJSONObject("item"); + assertEquals(PLAN_ID,fetch.get("id")); + assertEquals("INR",item.get("currency")); + assertEquals(69900,item.get("amount")); + assertTrue(item.getBoolean("active")); + assertTrue(item.has("unit_amount")); + String planFetch = getHost(String.format(Constants.PLAN_GET, PLAN_ID)); + verifySentRequest(false, null, planFetch); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all the plans can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + + String json = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": "+PLAN_ID+",\n" + + " \"entity\": \"plan\",\n" + + " \"interval\": 1,\n" + + " \"period\": \"weekly\",\n" + + " \"item\": {\n" + + " \"id\": \"item_00000000000001\",\n" + + " \"active\": true,\n" + + " \"name\": \"Test plan - Weekly\",\n" + + " \"description\": \"Description for the test plan - Weekly\",\n" + + " \"amount\": 69900,\n" + + " \"unit_amount\": 69900,\n" + + " \"currency\": \"INR\",\n" + + " \"type\": \"plan\",\n" + + " \"unit\": null,\n" + + " \"tax_inclusive\": false,\n" + + " \"hsn_code\": null,\n" + + " \"sac_code\": null,\n" + + " \"tax_rate\": null,\n" + + " \"tax_id\": null,\n" + + " \"tax_group_id\": null,\n" + + " \"created_at\": 1580220492,\n" + + " \"updated_at\": 1580220492\n" + + " },\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"created_at\": 1580220492\n" + + " }\n" + + " ]\n" + + "}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = planClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + assertEquals(true,fetch.get(0).has("entity")); + assertEquals(true,fetch.get(0).has("item")); + assertEquals(true,fetch.get(0).toJson().getJSONObject("item").has("hsn_code")); + String planList = getHost(Constants.PLAN_LIST); + verifySentRequest(false, null, planList); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/razorpay/TransferClientTest.java b/src/test/java/com/razorpay/TransferClientTest.java new file mode 100644 index 00000000..40579812 --- /dev/null +++ b/src/test/java/com/razorpay/TransferClientTest.java @@ -0,0 +1,207 @@ +package com.razorpay; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.InjectMocks; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.*; + +public class TransferClientTest extends BaseTest{ + + @InjectMocks + protected TransferClient transferClient = new TransferClient(TEST_SECRET_KEY); + + private static final String TRANSFER_ID = "trf_E9uhYLFLLZ2pks"; + + private static final String PAYMENT_ID = "pay_IDRP0tbirMSsbn"; + + /** + * Create transfer with currency and amount details + * @throws RazorpayException + */ + @Test + public void create() throws RazorpayException{ + + JSONObject request = new JSONObject("{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\"\n" + + "}"); + + String mockedResponseJson = "{\n" + + " \"id\": "+TRANSFER_ID+",\n" + + " \"entity\": \"transfer\",\n" + + " \"source\": \"acc_CJoeHMNpi0nC7k\",\n" + + " \"recipient\": \"acc_CPRsN1LkFccllA\",\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"amount_reversed\": 0,\n" + + " \"notes\": [],\n" + + " \"fees\": 1,\n" + + " \"tax\": 0,\n" + + " \"on_hold\": false,\n" + + " \"on_hold_until\": null,\n" + + " \"recipient_settlement_id\": null,\n" + + " \"created_at\": 1580219046,\n" + + " \"linked_account_notes\": [],\n" + + " \"processed_at\": 1580219046\n" + + "}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Transfer fetch = transferClient.create(request); + assertNotNull(fetch); + assertEquals(TRANSFER_ID,fetch.get("id")); + assertTrue(fetch.has("amount")); + assertTrue(fetch.has("currency")); + String createRequest = getHost(Constants.TRANSFER_CREATE); + verifySentRequest(true, request.toString(), createRequest); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all the transfers can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetch() throws RazorpayException{ + + String json = "{\n" + + " \"id\": "+TRANSFER_ID+",\n" + + " \"entity\": \"transfer\",\n" + + " \"source\": \"pay_E6j30Iu1R7XbIG\",\n" + + " \"recipient\": \"acc_CMaomTz4o0FOFz\",\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"amount_reversed\": 0,\n" + + " \"notes\": [],\n" + + " \"fees\": 1,\n" + + " \"tax\": 0,\n" + + " \"on_hold\": false,\n" + + " \"on_hold_until\": null,\n" + + " \"recipient_settlement_id\": null,\n" + + " \"created_at\": 1579691505,\n" + + " \"linked_account_notes\": [],\n" + + " \"processed_at\": 1579691505\n" + + "}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Transfer fetch = transferClient.fetch(TRANSFER_ID); + assertNotNull(fetch); + assertEquals(TRANSFER_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("amount_reversed")); + String addonCreate = getHost(String.format(Constants.TRANSFER_GET, TRANSFER_ID)); + verifySentRequest(false, null, addonCreate); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Details of all the transfers can be retrieved. + * @throws RazorpayException + */ + @Test + public void fetchAll() throws RazorpayException{ + + String json = "{\n" + + " \"entity\": \"collection\",\n" + + " \"count\": 1,\n" + + " \"items\": [\n" + + " {\n" + + " \"id\": \"trf_DGSTeXzBkEVh48\",\n" + + " \"entity\": \"transfer\",\n" + + " \"source\": \"pay_DGSRhvMbOqeCe7\",\n" + + " \"recipient\": \"acc_CMaomTz4o0FOFz\",\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"amount_reversed\": 0,\n" + + " \"notes\": [],\n" + + " \"fees\": 2,\n" + + " \"tax\": 0,\n" + + " \"on_hold\": false,\n" + + " \"on_hold_until\": null,\n" + + " \"recipient_settlement_id\": \"setl_DHYJ3dRPqQkAgV\",\n" + + " \"recipient_settlement\": {\n" + + " \"id\": \"setl_DHYJ3dRPqQkAgV\",\n" + + " \"entity\": \"settlement\",\n" + + " \"amount\": 500,\n" + + " \"status\": \"failed\",\n" + + " \"fees\": 0,\n" + + " \"tax\": 0,\n" + + " \"utr\": \"CN0038699836\",\n" + + " \"created_at\": 1568349124\n" + + " },\n" + + " \"created_at\": 1568110256,\n" + + " \"linked_account_notes\": [],\n" + + " \"processed_at\": null\n" + + " }\n" + + " ]\n" + + "}"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + List fetch = transferClient.fetchAll(); + assertNotNull(fetch); + assertEquals(true,fetch.get(0).has("id")); + assertEquals(true,fetch.get(0).has("entity")); + assertEquals(true,fetch.get(0).has("amount_reversed")); + assertEquals(true,fetch.get(0).toJson().getJSONObject("recipient_settlement").has("amount")); + String transferList = getHost(Constants.TRANSFER_LIST); + verifySentRequest(false, null, transferList); + } catch (IOException e) { + assertTrue(false); + } + } + + /** + * Update an transfer details using transfer id with object of that properties + * @throws RazorpayException + */ + @Test + public void edit() throws RazorpayException{ + + JSONObject request = new JSONObject("{\n" + + " \"on_hold\": \"1\",\n" + + " \"on_hold_until\": \"1679691505\"\n" + + "}"); + + String json = "{\n" + + " \"id\": "+TRANSFER_ID+",\n" + + " \"entity\": \"transfer\",\n" + + " \"source\": \"pay_EAeSM2Xul8xYRo\",\n" + + " \"recipient\": \"acc_CMaomTz4o0FOFz\",\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"amount_reversed\": 0,\n" + + " \"notes\": [],\n" + + " \"fees\": 1,\n" + + " \"tax\": 0,\n" + + " \"on_hold\": true,\n" + + " \"on_hold_until\": 1679691505,\n" + + " \"recipient_settlement_id\": null,\n" + + " \"created_at\": 1580459321,\n" + + " \"linked_account_notes\": [],\n" + + " \"processed_at\": 1580459321\n" + + "}\n"; + try { + mockResponseFromExternalClient(json); + mockResponseHTTPCodeFromExternalClient(200); + Transfer fetch = transferClient.edit(TRANSFER_ID,request); + assertNotNull(fetch); + assertEquals(TRANSFER_ID,fetch.get("id")); + assertEquals("INR",fetch.get("currency")); + assertTrue(fetch.has("amount_reversed")); + String editRequest = getHost(String.format(Constants.TRANSFER_EDIT, TRANSFER_ID)); + verifySentRequest(true, request.toString(), editRequest); + } catch (IOException e) { + assertTrue(false); + } + } +} \ No newline at end of file From 1ea1477a87c9a9f248a9d88336da5ca28f08f996 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 4 Mar 2022 11:14:47 +0530 Subject: [PATCH 76/78] add verify in testcase --- src/test/java/com/razorpay/PaymentClientTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/com/razorpay/PaymentClientTest.java b/src/test/java/com/razorpay/PaymentClientTest.java index e6074b76..260482b7 100644 --- a/src/test/java/com/razorpay/PaymentClientTest.java +++ b/src/test/java/com/razorpay/PaymentClientTest.java @@ -481,6 +481,8 @@ public void createJsonPayment() throws RazorpayException { assertEquals("payment",fetch.get("entity")); assertTrue(fetch.has("request")); assertTrue(fetch.has("base")); + String createRequest = getHost(Constants.PAYMENT_JSON_CREATE); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } @@ -519,6 +521,8 @@ public void createRecurringPayment() throws RazorpayException { assertEquals(PAYMENT_ID,fetch.get("razorpay_payment_id")); assertEquals(ORDER_ID,fetch.get("razorpay_order_id")); assertEquals(SIGNATURE,fetch.get("razorpay_signature")); + String createRequest = getHost(Constants.PAYMENT_RECURRING); + verifySentRequest(true, request.toString(), createRequest); } catch (IOException e) { assertTrue(false); } From 1972bdac41d794cf27caa5875879d51f006eb0ce Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Mar 2022 10:11:37 +0530 Subject: [PATCH 77/78] doc update --- README.md | 373 +------- documents/addon.md | 190 ++++ documents/card.md | 612 ++++++++++++ documents/customers.md | 167 ++++ documents/emandate.md | 493 ++++++++++ documents/fund.md | 83 ++ documents/invoice.md | 547 +++++++++++ documents/item.md | 187 ++++ documents/order.md | 232 +++++ documents/papernach.md | 715 ++++++++++++++ documents/payment.md | 478 ++++++++++ documents/paymentLink.md | 1038 +++++++++++++++++++++ documents/paymentVerfication.md | 86 ++ documents/plan.md | 184 ++++ documents/qrcode.md | 446 +++++++++ documents/refund.md | 329 +++++++ documents/registerEmandate.md | 457 +++++++++ documents/registerNach.md | 660 +++++++++++++ documents/settlement.md | 471 ++++++++++ documents/subscription.md | 756 +++++++++++++++ documents/token.md | 203 ++++ documents/transfer.md | 629 +++++++++++++ documents/upi.md | 555 +++++++++++ documents/virtualAccount.md | 610 ++++++++++++ pom.xml | 2 +- src/main/java/com/razorpay/Constants.java | 1 - 26 files changed, 10155 insertions(+), 349 deletions(-) create mode 100644 documents/addon.md create mode 100644 documents/card.md create mode 100644 documents/customers.md create mode 100644 documents/emandate.md create mode 100644 documents/fund.md create mode 100644 documents/invoice.md create mode 100644 documents/item.md create mode 100644 documents/order.md create mode 100644 documents/papernach.md create mode 100644 documents/payment.md create mode 100644 documents/paymentLink.md create mode 100644 documents/paymentVerfication.md create mode 100644 documents/plan.md create mode 100644 documents/qrcode.md create mode 100644 documents/refund.md create mode 100644 documents/registerEmandate.md create mode 100644 documents/registerNach.md create mode 100644 documents/settlement.md create mode 100644 documents/subscription.md create mode 100644 documents/token.md create mode 100644 documents/transfer.md create mode 100644 documents/upi.md create mode 100644 documents/virtualAccount.md diff --git a/README.md b/README.md index 755e3d5c..30d02679 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add this dependency to your project's POM: com.razorpay razorpay-java - 1.3.9 + 1.4.0 ``` @@ -30,7 +30,7 @@ Add this dependency to your project's POM: Add this dependency to your project's build file: ```groovy -compile "com.razorpay:razorpay-java:1.3.9" +compile "com.razorpay:razorpay-java:1.4.0" ``` ## Usage @@ -39,7 +39,7 @@ Instantiate `RazorpayClient` with `key_id` & `key_secret`. You can obtain the ke ```java // Initialize client -RazorpayClient razorpayClient = new RazorpayClient("key_id", "key_secret"); +RazorpayClient instance = new RazorpayClient("key_id", "key_secret"); ``` * Add custom headers to request (optional) ```java @@ -47,370 +47,49 @@ Map headers = new HashMap(); razorpayClient.addHeaders(headers); ``` -### [Payments](https://docs.razorpay.com/docs/return-objects#payment-entity) -* Fetch all payments -```java -List payments = razorpayClient.Payments.fetchAll(); -``` - -* Fetch a particular payment: -```java -Payment payment = razorpayClient.Payments.fetch("payment_id"); -// The the Entity.get("attribute_key") method has flexible return types depending on the attribute -int amount = payment.get("amount"); -String id = payment.get("id"); -Date createdAt = payment.get("created_at"); -``` - -* Capturing a payment: -```java -JSONObject options = new JSONObject(); -options.put("amount", 1000); -razorpayClient.Payments.capture("payment_id", options); -// Note: Amount should be same as the original amount while creating the payment. The amount should be in paise. -``` - -* Refund a payment: -```java -// For full refunds -JSONObject refundRequest = new JSONObject(); -refundRequest.put("payment_id", ); -Refund refund = razorpayClient.Payments.refund(refundRequest); - -// For partial refunds -JSONObject refundRequest = new JSONObject(); -refundRequest.put("amount", ); -refundRequest.put("payment_id", ); -Refund refund = razorpay.Payments.refund(refundRequest); -// Note: Amount to be refunded should be less than or equal to the original amount.The amount should be in paise. -``` - -* Fetch all refunds for a payment: -```java -JSONObject refundRequest = new JSONObject(); -refundRequest.put("payment_id", ); -List refund = razorpayClient.Payments.fetchAllRefunds(refundRequest); -``` - -* Fetch refund for a payment: -```java -Refund refund = razorpayClient.Payments.fetchRefund("refund_id"); -``` +## Supported Resources +- [Addon](documents/addon.md) -* Create Transfer for a payment: -```java -JSONObject request = new JSONObject(); - -JSONArray transfers = new JSONArray(); - -JSONObject transfer = new JSONObject(); -transfer.put("amount", ); // The amount should be in paise. -transfer.put("currency", "INR"); -transfer.put("account", ); +- [Item](documents/item.md) -transfers.put(transfer); -request.put("transfers", transfers); - -List transfers = razorpayClient.Payments.transfer("payment_id", request); -``` +- [Customer](documents/customers.md) -* Fetch all transfers for a payment: -```java -List transfers = razorpayClient.Payments.fetchAllTransfers("payment_id"); -``` - -* Fetch payment bank transfer -```java -BankTransfer bankTransfer = razorpayClient.Payments.fetchBankTransfers("payment_id"); -``` - -### [Refunds](https://docs.razorpay.com/docs/return-objects#refund-entity) - -* Fetch all refunds: -```java -List refunds = razorpayClient.Refunds.fetchAll(); -``` - -* Fetch a particular refund: -```java -Refund refund = razorpayClient.Refunds.fetch("refund_id"); -``` +- [Token](documents/token.md) -### [Orders](https://docs.razorpay.com/docs/return-objects#order-entity) +- [Order](documents/order.md) -* Create a new order: -```java -JSONObject options = new JSONObject(); -options.put("amount", 5000); // Note: The amount should be in paise. -options.put("currency", "INR"); -options.put("receipt", "txn_123456"); -Order order = razorpayClient.Orders.create(options); -``` +- [Payments](documents/payment.md) -* Fetch a particular order: -```java -Order order = razorpayClient.Orders.fetch("order_id"); -``` -* Fetch all orders: -```java -List orders = razorpayClient.Orders.fetchAll(); -``` -* Fetch payments for an order: -```java -List payments = razorpayClient.Orders.fetchPayments("order_id"); -``` +- [Settlements](documents/settlement.md) -### Verification -You can use the Utils class to verify the signature received in response to a payment made using Orders API -```java -JSONObject options = new JSONObject(); -options.put("razorpay_order_id", ""); -options.put("razorpay_payment_id", ""); -options.put("razorpay_signature", ""); -Utils.verifyPaymentSignature(paymentResponse, ""); -``` -You can also verify the signature of the received webhook: -```java -Utils.verifyWebhookSignature("", "", ""); -``` +- [Refunds](documents/refund.md) -### [Invoices](https://docs.razorpay.com/v1/page/invoices) +- [Invoice](documents/invoice.md) -* Create a new invoice: -```java -JSONObject lineItem = new JSONObject(); -lineItem.put("amount", 100); // Note: The amount should be in paise. -lineItem.put("name", "name_invoice"); +- [Subscriptions](documents/subscription.md) -JSONArray lineItems = new JSONArray(); -lineItems.put(lineItem); +- [Payment Links](documents/paymentLink.md) -JSONObject request = new JSONObject(); -request.put("line_items", lineItems); -request.put("date", 1480768625); // Timestamp in seconds -request.put("currency", "INR"); -request.put("sms_notify", "0"); +- [Smart Collect](documents/virtualAccount.md) -Invoice invoice = razorpayClient.Invoices.create(request); -``` -* Fetch a particular invoice: -```java -Invoice invoice = razorpayClient.Invoices.fetch("invoice_id"); -``` -* Fetch all invoices: -```java -List invoices = razorpayClient.Invoices.fetchAll(); -``` -* Cancel a particular invoice: -```java -Invoice invoice = razorpayClient.Invoices.cancel("invoice_id"); -``` +- [Route](documents/transfer.md) -### [Cards](https://docs.razorpay.com/v1/page/cards) +- [QR Code](documents/qrcode.md) -* Fetch card details: -```java -Card card = razorpayClient.Cards.fetch(id); -``` +- [Emandate](documents/emandate.md) -### [Customers](https://docs.razorpay.com/v1/page/card-saving) +- [Cards](documents/card.md) -* Create new customer -```java -JSONObject request = new JSONObject(); -request.put("name", ); -request.put("email", ); -Customer customer = razorpayClient.Customers.create(request); -``` +- [Paper NACH](documents/papernach.md) -* Fetch customer details -```java -Customer customer = razorpayClient.Customers.fetch(customerId); -``` +- [UPI](documents/upi.md) -* Edit customer -```java -JSONObject request = new JSONObject(); -request.put("name", ); -request.put("email", ); -Customer customer = razorpayClient.Customers.edit(customerId, request); -``` +- [Register Emandate and Charge First Payment Together](documents/registerEmandate.md) -### [Tokens](https://docs.razorpay.com/v1/page/card-saving) +- [Register NACH and Charge First Payment Together](documents/registerNach.md) -* Fetch tokens for a customer -```java -List tokens = razorpayClient.Customers.fetchTokens(customerId); -``` -* Get a Token -```java -Token token = razorpayClient.Customers.fetchToken(customerId, tokenId); -``` -* Delete a Token -```java -razorpayClient.Customers.deleteToken(customerId, tokenId); -``` - -### [Transfers](https://docs.razorpay.com/v1/page/marketplace) - -* Create direct Transfer -```java -JSONObject request = new JSONObject(); -request.put("amount", ); // The amount should be in paise. -request.put("currency", "INR"); -request.put("account", ); - -Transfer transfer = razorpayClient.Transfers.create(request); -``` - -* Edit a Transfer -```java -JSONObject request = new JSONObject(); -request.put("on_hold", true); // The amount should be in paise. -Transfer transfer = razorpayClient.Transfers.edit(request); -``` - -* Create reversal of a Transfer -```java -JSONObject request = new JSONObject(); -request.put("amount", ); // The amount should be in paise. - -Reversal reversal = razorpayClient.Transfers.reversal("transfer_id", request); -``` - -* Fetch a particular transfer -```java -Transfer transfer = razorpayClient.Transfers.fetch("transfer_id"); -``` - -* Fetch all transfers -```java -List transfers = razorpayClient.Transfers.fetchAll(); -``` - -### [Subscriptions](https://razorpay.com/docs/subscriptions/) - -* Create a plan -```java -JSONObject request = new JSONObject(); -request.put("period", "weekly"); -request.put("interval", 1); - -JSONObject item = new JSONObject(); -item.put("name", "Test Weekly 1 plan"); -item.put("description", "Description for the weekly 1 plan"); -item.put("amount", 600); -item.put("currency", "INR"); -request.put("item", item); - -Plan plan = razorpayClient.Plans.create(request); -``` - -* Fetch a plan -```java -Plan plan = razorpayClient.Plans.fetch(""); -``` - -* Fetch all plans -```java -List listPlans = razorpayClient.Plans.fetchAll(); -``` - -* Create a subscription -```java -JSONObject request = new JSONObject(); -request.put("plan_id", ""); -request.put("customer_notify", 1); -request.put("total_count", 6); -request.put("start_at", 1495995837); - -JSONArray addons = new JSONArray(); -JSONObject addon = new JSONObject(); -JSONObject item = new JSONObject(); -item.put("name", "Delivery charges"); -item.put("amount", 30000); -item.put("currency", "INR"); -addon.put("item", item); -addons.put(addon); -request.put("addons", addons); - -Subscription subscription = razorpayClient.Subscriptions.create(request); -``` - -* Fetch a subscription -```java -Subscription subscription = razorpayClient.Subscriptions.fetch(""); -``` - -* Fetch all subscription -```java -List listSubscriptions = razorpayClient.Subscriptions.fetchAll(); -``` - -* Cancel a subscription -```java -Subscription subscription = razorpayClient.Subscriptions.cancel(""); -``` - -* Add addon -```java -JSONObject request = new JSONObject(); -request.put("quantity", 2); - -JSONObject addonItem = new JSONObject(); -addonItem.put("name", "Extra Chair"); -addonItem.put("amount", 30000); -addonItem.put("currency", "INR"); -request.put("item", addonItem); - -Addon addon = razorpayClient.Subscriptions.createAddon(, request); -``` - -* Fetch Addon -```java -Addon addon = razorpayClient.Addons.fetch(); -``` - -* Delete Addon -```java -razorpayClient.Addons.delete(); -``` - -### Virtual Accounts - -* Create a virtual account -```java -JSONObject request = new JSONObject(); -JSONArray receiverTypeArray = new JSONArray(); -receiverTypeArray.put("bank_account"); -request.put("receiver_types", receiverTypeArray); -JSONObject notes = new JSONObject(); -notes.put("receiver_key", "receiver_value"); -request.put("notes", notes); -request.put("description", "First Virtual Account"); - -VirtualAccount virtualAccount = razorpayClient.VirtualAccounts.create(request); -``` - -* Fetch Virtual Account -```java -VirtualAccount virtualAccount = razorpayClient.VirtualAccounts.fetch(""); -``` - -* Fetch all Virtual Accounts -```java -List virtualAccountList = razorpayClient.VirtualAccounts.fetchAll(); -``` - -* Close Virtual Account -```java -VirtualAccount virtualAccount = razorpayClient.VirtualAccounts.close(""); -``` - -* List Virtual Account payments -```java -List paymentList = razorpayClient.VirtualAccounts.fetchPayments("virtual_account_id"); -``` +- [Payment Verification](documents/paymentVerfication.md) +--- * Make custom requests diff --git a/documents/addon.md b/documents/addon.md new file mode 100644 index 00000000..447e7ef0 --- /dev/null +++ b/documents/addon.md @@ -0,0 +1,190 @@ +## Addons + +### Create an addon + +```java +String SubscriptionId = "sub_I55auG9GnbsR8u"; +String json = "{\n" + + " item:{\n" + + " name:\"Extra appala (papadum)\",\n" + + " amount:30000,\n" + + " currency:\"INR\",\n" + + " description:\"1 extra oil fried appala with meals\"\n" + + " },\n" + + " quantity:2\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Subscription subscription = instance.Subscriptions.createAddon(SubscriptionId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| SubscriptionId* | boolean | The subscription ID to which the add-on is being added. | +| items* | object | Details of the add-on you want to create. | +| quantity* | integer | This specifies the number of units of the add-on to be charged to the customer. | + +**Response:** +```json +{ + "id":"ao_00000000000001", + "entity":"addon", + "item":{ + "id":"item_00000000000001", + "active":true, + "name":"Extra appala (papadum)", + "description":"1 extra oil fried appala with meals", + "amount":30000, + "unit_amount":30000, + "currency":"INR", + "type":"addon", + "unit":null, + "tax_inclusive":false, + "hsn_code":null, + "sac_code":null, + "tax_rate":null, + "tax_id":null, + "tax_group_id":null, + "created_at":1581597318, + "updated_at":1581597318 + }, + "quantity":2, + "created_at":1581597318, + "subscription_id":"sub_00000000000001", + "invoice_id":null +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all addons + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List addon = instance.Addons.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "ao_00000000000002", + "entity": "addon", + "item": { + "id": "item_00000000000002", + "active": true, + "name": "Extra sweet", + "description": "1 extra sweet of the day with meals", + "amount": 90000, + "unit_amount": 90000, + "currency": "INR", + "type": "addon", + "unit": null, + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "tax_id": null, + "tax_group_id": null, + "created_at": 1581597318, + "updated_at": 1581597318 + }, + "quantity": 1, + "created_at": 1581597318, + "subscription_id": "sub_00000000000001", + "invoice_id": "inv_00000000000001" + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch an addon + +```java +String AddonId = "ao_00000000000001"; + +Addon addon = instance.Addons.fetch(AddonId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------| +| AddonId* | string | addon id to be fetched | + +**Response:** +```json +{ + "id":"ao_00000000000001", + "entity":"addon", + "item":{ + "id":"item_00000000000001", + "active":true, + "name":"Extra appala (papadum)", + "description":"1 extra oil fried appala with meals", + "amount":30000, + "unit_amount":30000, + "currency":"INR", + "type":"addon", + "unit":null, + "tax_inclusive":false, + "hsn_code":null, + "sac_code":null, + "tax_rate":null, + "tax_id":null, + "tax_group_id":null, + "created_at":1581597318, + "updated_at":1581597318 + }, + "quantity":2, + "created_at":1581597318, + "subscription_id":"sub_00000000000001", + "invoice_id":null +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete an addon + +```java +String AddonId = "ao_00000000000001"; + +instance.Addons.delete(AddonId) +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| AddonId* | string | addon id to be deleted | + +**Response:** +```json +[] +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/subscriptions/#add-ons)** \ No newline at end of file diff --git a/documents/card.md b/documents/card.md new file mode 100644 index 00000000..20c865e9 --- /dev/null +++ b/documents/card.md @@ -0,0 +1,612 @@ +## Cards + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: \"9123456780\",\n" + + " fail_existing: \"0\",\n" + + " notes:{\n" + + " note_key_1: \"September\",\n" + + " note_key_2: \"Make it so.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| fail_existing | string | If a customer with the same details already exists, the request throws an exception by default. Possible value is `0` or `1`| +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create Order + +```java +String json = "{\n" + + " \"amount\":100,\n" + + " \"currency\":\"INR\",\n" + + " \"customer_id\":\"cust_4xbQrmEoA5WJ01\",\n" + + " \"method\":\"card\",\n" + + " \"token\":{\n" + + " \"max_amount\":5000,\n" + + " \"expire_at\":2709971120,\n" + + " \"frequency\":\"monthly\"\n" + + " },\n" + + " \"receipt\":\"Receipt No. 1\",\n" + + " \"notes\":{\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey... decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| customerId* | string | The id of the customer to be fetched | +| receipt | string | Your system order reference id. | +| method* | string | Payment method used to make the registration transaction. Possible value is `card`. | +| token | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/cards/authorization-transaction/#112-create-an-order) are supported | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":100, + "amount_paid":0, + "amount_due":100, + "currency":"INR", + "receipt":"Receipt No. 1", + "method":"card", + "description":null, + "customer_id":"cust_4xbQrmEoA5WJ01", + "token":{ + "max_amount":5000, + "expire_at":2709971120, + "frequency":"monthly" + }, + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1565172642 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " type: \"link\",\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " description: \"Registration Link for Gaurav Kumar\",\n" + + " subscription_registration: {\n" + + " method: \"card\",\n" + + " max_amount: 500,\n" + + " expire_at: 1609423824\n" + + " },\n" + + " receipt: \"Receipt No. 1\",\n" + + " email_notify: 1,\n" + + " sms_notify: 1,\n" + + " expire_by: 1580479824,\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey... decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| customer | object | Details of the customer to whom the registration link will be sent. | +| type* | string | the value is `link`. | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| description* | string | A brief description of the payment. | +| subscription_registration | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/cards/authorization-transaction/#121-create-a-registration-link) are supported | +| receipt | string | Your system order reference id. | +| sms_notify | boolean | SMS notifications are to be sent by Razorpay (default : 1) | +| email_notify | boolean | Email notifications are to be sent by Razorpay (default : 1) | +| expire_by | integer | The timestamp, in Unix format, till when the customer can make the authorization payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "inv_FHrXGIpd3N17DX", + "entity": "invoice", + "receipt": "Receipt No. 24", + "invoice_number": "Receipt No. 24", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrXGJNngJyEAe", + "line_items": [], + "payment_id": null, + "status": "issued", + "expire_by": 4102444799, + "issued_at": 1595491014, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": "pending", + "email_status": "pending", + "date": 1595491014, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/VSriCfn", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491014, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +## Create an order to charge the customer + +```java +String json = "{\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " customer_id: \"cust_4xbQrmEoA5WJ01\",\n" + + " method: \"card\",\n" + + " token: {\n" + + " max_amount: 5000,\n" + + " expire_at: 2709971120,\n" + + " frequency: \"monthly\"\n" + + " },\n" + + " receipt: \"Receipt No. 1\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey... decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| customerId* | string | The id of the customer to be fetched | +| method* | string | Payment method used to make the registration transaction. Possible value is `card`. | +| receipt | string | Your system order reference id. | +| token | array | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/cards/subsequent-payments/#31-create-an-order-to-charge-the-customer) are supported | +| notes | array | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":100, + "amount_paid":0, + "amount_due":100, + "currency":"INR", + "receipt":"Receipt No. 1", + "method":"card", + "description":null, + "customer_id":"cust_4xbQrmEoA5WJ01", + "token":{ + "max_amount":5000, + "expire_at":2709971120, + "frequency":"monthly" + }, + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1565172642 +} +``` +------------------------------------------------------------------------------------------------------- + +## Create a recurring payment + +```java + String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + + JSONObject request = new JSONObject(json); + + Payment payment = instance.Payments.createRecurringPayment(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address | +| contact* | string | The customer's phone number | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| orderId* | string | The id of the order to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | +| recurring* | boolean | Possible values is `0` or `1` | +| description | string | A brief description of the payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/cards/authorization-transaction/#113-create-an-authorization-payment) for authorization payment + +------------------------------------------------------------------------------------------------------- + +## Send/Resend notifications + +```java +String InvoiceId = "inv_FHrXGIpd3N17DX"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId,"sms"); +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | +| medium* | string | Possible values are `sms` or `email` | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +## Cancel registration link + +```java +String InvoiceId = "inv_FHrXGIpd3N17DX"; + +instance.Invoices.cancel(InvoiceId) +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | + +**Response:** +```json +{ + "id": "inv_FHrfRupD2ouKIt", + "entity": "invoice", + "receipt": "Receipt No. 1", + "invoice_number": "Receipt No. 1", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrfRw4TZU5Q2L", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 4102444799, + "issued_at": 1595491479, + "paid_at": null, + "cancelled_at": 1595491488, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491479, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/QlfexTj", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491480, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +## Fetch token by payment id + +```java +String PaymentId = "pay_FHfqtkRzWvxky4"; + +Payment payment = instance.Payments.fetch(PaymentId) +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| paymentId* | string | The id of the payment to be fetched | + +**Response:** +```json +{ + "id": "pay_FHfqtkRzWvxky4", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": "order_FHfnswDdfu96HQ", + "invoice_id": null, + "international": false, + "method": "card", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": null, + "card_id": "card_F0zoXUp4IPPGoI", + "bank": null, + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_FHfn3rIiM1Z8nr", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "auth_code": "541898" + }, + "created_at": 1595449871 +} +``` +------------------------------------------------------------------------------------------------------- + +## Fetch tokens by customer id + +```java +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +List tokens = instance.Customers.fetchTokens(CustomerId) +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"token_HouA2OQR5Z2jTL", + "entity":"token", + "token":"2JPRk664pZHUWG", + "bank":null, + "wallet":null, + "method":"card", + "card":{ + "entity":"card", + "name":"Gaurav Kumar", + "last4":"8950", + "network":"Visa", + "type":"credit", + "issuer":"STCB", + "international":false, + "emi":false, + "sub_type":"consumer", + "expiry_month":12, + "expiry_year":2021, + "flows":{ + "otp":true, + "recurring":true + } + }, + "recurring":true, + "recurring_details":{ + "status":"confirmed", + "failure_reason":null + }, + "auth_type":null, + "mrn":null, + "used_at":1629779657, + "created_at":1629779657, + "expired_at":1640975399, + "dcc_enabled":false, + "billing_address":null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch card + +```java +String CardId = "card_F0zoXUp4IPPGoI"; + +Card card=instance.Cards.fetch(CardId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------|---------|------------------------------------------------------------------------------| +| CardId* | string | card id to be fetched | + +**Response** +```json +{ + "id": "card_F0zoXUp4IPPGoI", + "entity": "card", + "international": false, + "last4": 1111, + "name": "sample name", + "network": "Visa", + "type": "debit" +} +``` +------------------------------------------------------------------------------------------------------- + +## Delete tokens + +```java +String CustomerId = "cust_Hwq7Ba6TDXl1ga"; + +String TokenId = "token_1Aa00000000001"; + +Customer customer = instance.Customers.deleteToken(CustomerId,TokenId) +``` +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/cards/authorization-transaction/)** \ No newline at end of file diff --git a/documents/customers.md b/documents/customers.md new file mode 100644 index 00000000..878d2bb0 --- /dev/null +++ b/documents/customers.md @@ -0,0 +1,167 @@ +## Customer + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " fail_existing: 0,\n" + + " gstin: \"29XAbbA4369J1PA\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id" : "cust_1Aa00000000004", + "entity": "customer", + "name" : "Gaurav Kumar", + "email" : "gaurav.kumar@example.com", + "contact" : "9123456780", + "gstin": "29XAbbA4369J1PA", + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at ": 1234567890 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Edit customer +```java +String CustomerId = "cust_1Aa00000000003"; + +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"Gaurav.Kumar@example.com\",\n" + + " contact: 9000000000\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.edit(CustomerId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be updated | +| email | string | Email of the customer | +| name | string | Name of the customer | +| contact | string | Contact number of the customer | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all customer +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List customer = instance.Customers.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"cust_1Aa00000000001", + "entity":"customer", + "name":"Gaurav Kumar", + "email":"gaurav.kumar@example.com", + "contact":"9876543210", + "gstin":"29XAbbA4369J1PA", + "notes":{ + "note_key_1":"September", + "note_key_2":"Make it so." + }, + "created_at ":1234567890 + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch a customer +```java +String CustomerId = "cust_1Aa00000000001"; + +Customer customer = instance.Customers.fetch(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "id" : "cust_1Aa00000000001", + "entity": "customer", + "name" : "Saurav Kumar", + "email" : "Saurav.kumar@example.com", + "contact" : "+919000000000", + "gstin":"29XAbbA4369J1PA", + "notes" : [], + "created_at ": 1234567890 +} +``` + +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/customers/)** \ No newline at end of file diff --git a/documents/emandate.md b/documents/emandate.md new file mode 100644 index 00000000..275ef914 --- /dev/null +++ b/documents/emandate.md @@ -0,0 +1,493 @@ +## Emandates + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " fail_existing: 0,\n" + + " gstin: \"29XAbbA4369J1PA\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create order + +```java +String json = "{\n" + + " amount: 0,\n" + + " currency: \"INR\",\n" + + " method: \"emandate\",\n" + + " customer_id: \"cust_1Aa00000000001\",\n" + + " receipt: \"Receipt No. 1\",\n" + + " notes: {\n" + + " notes_key_1: \"Beam me up Scotty\",\n" + + " notes_key_2: \"Engage\"\n" + + " },\n" + + " token: {\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 9999900,\n" + + " expire_at: 4102444799,\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 1121431121541121,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0000001\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| method* | string | The authorization method. In this case the value will be `emandate` | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | +| token | object | A key-value pair | + +**Response:** +Create order response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/#112-create-an-order) +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/#113-create-an-authorization-payment) for authorization payment + +------------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " type: \"link\",\n" + + " amount: 0,\n" + + " currency: \"INR\",\n" + + " description: \"12 p.m. Meals\",\n" + + " subscription_registration: {\n" + + " method: \"emandate\",\n" + + " auth_type: \"netbanking\",\n" + + " expire_at: 1580480689,\n" + + " max_amount: 50000,\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 11214311215411,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " receipt: \"Receipt no. 1\",\n" + + " expire_by: 1880480689,\n" + + " sms_notify: 1,\n" + + " email_notify: 1,\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| customer | object | Details of the customer to whom the registration link will be sent. | +| type* | string | In this case, the value is `link`. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| amount* | integer | The payment amount in the smallest currency sub-unit. | +| description* | string | A description that appears on the hosted page. For example, `12:30 p.m. Thali meals (Gaurav Kumar`). | +| subscription_registration | object | Details of the authorization payment. | +| notes | object | A key-value pair | + +**Response:** +Create registration link response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/#121-create-a-registration-link) +------------------------------------------------------------------------------------------------------- + +### Send/Resend notifications + +```java +String InvoiceId = "inv_FHrfRupD2ouKIt"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId, medium); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be notified | +| medium* | string | `sms`/`email`, Medium through which notification should be sent. | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Cancel a registration link + +```java +String InvoiceId = "inv_FHrfRupD2ouKIt"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be cancelled | + +**Response:** +```json +{ + "id": "inv_FHrfRupD2ouKIt", + "entity": "invoice", + "receipt": "Receipt No. 1", + "invoice_number": "Receipt No. 1", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrfRw4TZU5Q2L", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 4102444799, + "issued_at": 1595491479, + "paid_at": null, + "cancelled_at": 1595491488, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491479, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/QlfexTj", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491480, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch token by payment ID + +```java +String PaymentId = "pay_FHf9a7AO0iXM9I"; + +Payment payment = instance.Payments.fetch(PaymentId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|--------|-----------------------------------| +| PaymentId* | string | Id of the payment to be retrieved | + +**Response:** +```json +{ + "id": "pay_FHf9a7AO0iXM9I", + "entity": "payment", + "amount": 0, + "currency": "INR", + "status": "captured", + "order_id": "order_FHf9OwSeyetnKC", + "invoice_id": "inv_FHf9P2hhXEti7i", + "international": false, + "method": "emandate", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": null, + "card_id": null, + "bank": "HDFC", + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_FHf9aAZR9hWJkq", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": {}, + "created_at": 1595447410 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch tokens by customer ID + +```java +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +Customer customer = instance.Customers.fetchTokens(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "token_FHf94Uym9tdYFJ", + "entity": "token", + "token": "2wDPM7VAlXtjAR", + "bank": "HDFC", + "wallet": null, + "method": "emandate", + "vpa": null, + "recurring": true, + "recurring_details": { + "status": "confirmed", + "failure_reason": null + }, + "auth_type": "netbanking", + "mrn": null, + "used_at": 1595447381, + "created_at": 1595447381, + "bank_details": { + "beneficiary_name": "Gaurav Kumar", + "account_number": "1121431121541121", + "ifsc": "HDFC0000001", + "account_type": "savings" + }, + "max_amount": 9999900, + "expired_at": 1689971140, + "dcc_enabled": false + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete token + +```java +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +String TokenId = "token_FHf94Uym9tdYFJ"; + +Customer customer = instance.Customers.deleteToken(customerId, tokenId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an order to charge the customer + +```java + +String json = "{\n" + + " \"amount\":1000,\n" + + " \"currency\":\"INR\",\n" + + " \"receipt\":\"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":1000, + "amount_paid":0, + "amount_due":1000, + "currency":"INR", + "receipt":"Receipt No. 1", + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1579782776 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create a Recurring Payment + +```java +String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.createRecurringPayment(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address. | +| contact* | string | The customer's phone number. | +| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| order_id* | string | The unique identifier of the order created. | +| customer_id* | string | The `customer_id` for the customer you want to charge. | +| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| +| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| +| description* | string | A user-entered description for the payment.| +| notes* | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/)** \ No newline at end of file diff --git a/documents/fund.md b/documents/fund.md new file mode 100644 index 00000000..21bb7c21 --- /dev/null +++ b/documents/fund.md @@ -0,0 +1,83 @@ +## Funds + +### Create a fund account +```java +String json = "{\n" + + " \"customer_id\":\"cust_Aa000000000001\",\n" + + " \"account_type\":\"bank_account\",\n" + + " \"bank_account\":{\n" + + " \"name\":\"Gaurav Kumar\",\n" + + " \"account_number\":\"11214311215411\",\n" + + " \"ifsc\":\"HDFC0000053\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +FundAccount fundaccount = instance.FundAccount.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | +| account_type* | string | The bank_account to be linked to the customer ID | +| bank_account* | object | A key-value pair | + +**Response:** +```json +{ + "id":"fa_Aa00000000001", + "entity":"fund_account", + "customer_id":"cust_Aa000000000001", + "account_type":"bank_account", + "bank_account":{ + "name":"Gaurav Kumar", + "account_number":"11214311215411", + "ifsc":"HDFC0000053", + "bank_name":"HDFC Bank" + }, + "active":true, + "created_at":1543650891 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all fund accounts + +```java +String CustomerId = "cust_Aa000000000001"; + +FundAccount fundaccount = instance.FundAccount.fetch(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "id":"fa_Aa00000000001", + "entity":"fund_account", + "customer_id":"cust_Aa000000000001", + "account_type":"bank_account", + "bank_account":{ + "name":"Gaurav Kumar", + "account_number":"11214311215411", + "ifsc":"HDFC0000053", + "bank_name":"HDFC Bank" + }, + "active":true, + "created_at":1543650891 +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/payments/customers/customer-fund-account-api/)** \ No newline at end of file diff --git a/documents/invoice.md b/documents/invoice.md new file mode 100644 index 00000000..6fc27886 --- /dev/null +++ b/documents/invoice.md @@ -0,0 +1,547 @@ +## Invoices + +### Create Invoice + +Request #1 +In this example, an invoice is created using the customer and item details. Here, the customer and item are created while creating the invoice. +```java +String json = "{\n" + + " type: \"invoice\",\n" + + " description: \"Invoice for the month of January 2020\",\n" + + " partial_payment: true,\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9999999999,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " billing_address: {\n" + + " line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + + " line2: \"Hosur Road\",\n" + + " zipcode: 560068,\n" + + " city: \"Bengaluru\",\n" + + " state: \"Karnataka\",\n" + + " country: \"in\"\n" + + " },\n" + + " shipping_address: {\n" + + " line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + + " line2: \"Hosur Road\",\n" + + " zipcode: 560068,\n" + + " city: \"Bengaluru\",\n" + + " state: \"Karnataka\",\n" + + " country: \"in\"\n" + + " }\n" + + " },\n" + + " line_items: [\n" + + " {\n" + + " name: \"Master Cloud Computing in 30 Days\",\n" + + " description: \"Book by Ravena Ravenclaw\",\n" + + " amount: 399,\n" + + " currency: \"USD\",\n" + + " quantity: 1\n" + + " }\n" + + " ],\n" + + " sms_notify: 1,\n" + + " email_notify: 1,\n" + + " currency: \"USD\",\n" + + " expire_by: 1589765167\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Invoices.create(request); +``` + +Request #2 +In this example, an invoice is created using existing `customer_id` and `item_id` +```java +String json = "{\n" + + " type: \"invoice\",\n" + + " date: 1589994898,\n" + + " customer_id: \"cust_E7q0trFqXgExmT\",\n" + + " line_items: [\n" + + " {\n" + + " \"item_id\": \"item_DRt61i2NnL8oy6\"\n" + + " }\n" + + " ]\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|type* | string | entity type (here its invoice) | +|description | string | A brief description of the invoice. | +|customer_id | string | customer id for which invoice need be raised | +|customer | object | customer details in a object format | + +**Response:** +For create invoice response please click [here](https://razorpay.com/docs/api/invoices/#create-an-invoice) + +------------------------------------------------------------------------------------------------------- + +### Fetch all invoices + +```java +List invoice = instance.Invoices.fetchAll(); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|type | string | entity type (here its invoice) | +|payment_id | string | The unique identifier of the payment made by the customer against the invoice. | +|customer_id | string | The unique identifier of the customer. | +|receipt | string | The unique receipt number that you entered for internal purposes. | + +**Response:** +For fetch all invoice response please click [here](https://razorpay.com/docs/api/invoices/#fetch-multiple-invoices) + +------------------------------------------------------------------------------------------------------- + +### Fetch invoice + +```java +String InvoiceId = "inv_E7q0tqkxBRzdau"; + +Invoice invoice = instance.Invoices.fetch(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | + +**Response:** +```json +{ + "id": "inv_E7q0tqkxBRzdau", + "entity": "invoice", + "receipt": null, + "invoice_number": null, + "customer_id": "cust_E7q0trFqXgExmT", + "customer_details": { + "id": "cust_E7q0trFqXgExmT", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9999999999", + "gstin": null, + "billing_address": { + "id": "addr_E7q0ttqh4SGhAC", + "type": "billing_address", + "primary": true, + "line1": "Ground & 1st Floor, SJR Cyber Laskar", + "line2": "Hosur Road", + "zipcode": "560068", + "city": "Bengaluru", + "state": "Karnataka", + "country": "in" + }, + "shipping_address": { + "id": "addr_E7q0ttKwVA1h2V", + "type": "shipping_address", + "primary": true, + "line1": "Ground & 1st Floor, SJR Cyber Laskar", + "line2": "Hosur Road", + "zipcode": "560068", + "city": "Bengaluru", + "state": "Karnataka", + "country": "in" + }, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9999999999" + }, + "order_id": "order_E7q0tvRpC0WJwg", + "line_items": [ + { + "id": "li_E7q0tuPNg84VbZ", + "item_id": null, + "ref_id": null, + "ref_type": null, + "name": "Master Cloud Computing in 30 Days", + "description": "Book by Ravena Ravenclaw", + "amount": 399, + "unit_amount": 399, + "gross_amount": 399, + "tax_amount": 0, + "taxable_amount": 399, + "net_amount": 399, + "currency": "INR", + "type": "invoice", + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "unit": null, + "quantity": 1, + "taxes": [] + } + ], + "payment_id": null, + "status": "issued", + "expire_by": 1589765167, + "issued_at": 1579765167, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": "pending", + "email_status": "pending", + "date": 1579765167, + "terms": null, + "partial_payment": true, + "gross_amount": 399, + "tax_amount": 0, + "taxable_amount": 399, + "amount": 399, + "amount_paid": 0, + "amount_due": 399, + "currency": "INR", + "currency_symbol": "₹", + "description": "Invoice for the month of January 2020", + "notes": [], + "comment": null, + "short_url": "https://rzp.io/i/2wxV8Xs", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "invoice", + "group_taxes_discounts": false, + "created_at": 1579765167 +} +``` +------------------------------------------------------------------------------------------------------- + +### Update invoice + +```java +String json = "{\n" + + " line_items: [\n" + + " {\n" + + " id: \"li_DAweOizsysoJU6\",\n" + + " name: \"Book / English August - Updated name and quantity\",\n" + + " quantity: 1\n" + + " },\n" + + " {\n" + + " name: \"Book / A Wild Sheep Chase\",\n" + + " amount: 200,\n" + + " currency: \"INR\",\n" + + " quantity: 1\n" + + " }\n" + + " ],\n" + + " notes: {\n" + + " \"updated-key\": \"An updated note.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.edit(invoiceId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| invoiceId* | string | The id of the invoice to be fetched | + +**Response:** +For update invoice response please click [here](https://razorpay.com/docs/api/invoices/#update-an-invoice) + +------------------------------------------------------------------------------------------------------- + +### Issue an invoice + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +Invoice invoice = instance.Invoices.issue(invoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be issued | + +**Response:** +```json +{ + "id": "inv_DAweOiQ7amIUVd", + "entity": "invoice", + "receipt": "#0961", + "invoice_number": "#0961", + "customer_id": "cust_DAtUWmvpktokrT", + "customer_details": { + "id": "cust_DAtUWmvpktokrT", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9977886633", + "gstin": null, + "billing_address": { + "id": "addr_DAtUWoxgu91obl", + "type": "billing_address", + "primary": true, + "line1": "318 C-Wing, Suyog Co. Housing Society Ltd.", + "line2": "T.P.S Road, Vazira, Borivali", + "zipcode": "400092", + "city": "Mumbai", + "state": "Maharashtra", + "country": "in" + }, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9977886633" + }, + "order_id": "order_DBG3P8ZgDd1dsG", + "line_items": [ + { + "id": "li_DAweOizsysoJU6", + "item_id": null, + "name": "Book / English August - Updated name and quantity", + "description": "150 points in Quidditch", + "amount": 400, + "unit_amount": 400, + "gross_amount": 400, + "tax_amount": 0, + "taxable_amount": 400, + "net_amount": 400, + "currency": "INR", + "type": "invoice", + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "unit": null, + "quantity": 1, + "taxes": [] + }, + { + "id": "li_DAwjWQUo07lnjF", + "item_id": null, + "name": "Book / A Wild Sheep Chase", + "description": null, + "amount": 200, + "unit_amount": 200, + "gross_amount": 200, + "tax_amount": 0, + "taxable_amount": 200, + "net_amount": 200, + "currency": "INR", + "type": "invoice", + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "unit": null, + "quantity": 1, + "taxes": [] + } + ], + "payment_id": null, + "status": "issued", + "expire_by": 1567103399, + "issued_at": 1566974805, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": null, + "email_status": null, + "date": 1566891149, + "terms": null, + "partial_payment": false, + "gross_amount": 600, + "tax_amount": 0, + "taxable_amount": 600, + "amount": 600, + "amount_paid": 0, + "amount_due": 600, + "currency": "INR", + "currency_symbol": "₹", + "description": "This is a test invoice.", + "notes": { + "updated-key": "An updated note." + }, + "comment": null, + "short_url": "https://rzp.io/i/K8Zg72C", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "invoice", + "group_taxes_discounts": false, + "created_at": 1566906474, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete an invoice + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +instance.Invoices.delete(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be deleted | + +**Response:** +``` +[] +``` +------------------------------------------------------------------------------------------------------- + +### Cancel an invoice + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be cancelled | + +**Response:** +```json +{ + "id": "inv_E7q0tqkxBRzdau", + "entity": "invoice", + "receipt": null, + "invoice_number": null, + "customer_id": "cust_E7q0trFqXgExmT", + "customer_details": { + "id": "cust_E7q0trFqXgExmT", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9972132594", + "gstin": null, + "billing_address": { + "id": "addr_E7q0ttqh4SGhAC", + "type": "billing_address", + "primary": true, + "line1": "Ground & 1st Floor, SJR Cyber Laskar", + "line2": "Hosur Road", + "zipcode": "560068", + "city": "Bengaluru", + "state": "Karnataka", + "country": "in" + }, + "shipping_address": { + "id": "addr_E7q0ttKwVA1h2V", + "type": "shipping_address", + "primary": true, + "line1": "Ground & 1st Floor, SJR Cyber Laskar", + "line2": "Hosur Road", + "zipcode": "560068", + "city": "Bengaluru", + "state": "Karnataka", + "country": "in" + }, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9972132594" + }, + "order_id": "order_E7q0tvRpC0WJwg", + "line_items": [ + { + "id": "li_E7q0tuPNg84VbZ", + "item_id": null, + "ref_id": null, + "ref_type": null, + "name": "Master Cloud Computing in 30 Days", + "description": "Book by Ravena Ravenclaw", + "amount": 399, + "unit_amount": 399, + "gross_amount": 399, + "tax_amount": 0, + "taxable_amount": 399, + "net_amount": 399, + "currency": "INR", + "type": "invoice", + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "unit": null, + "quantity": 1, + "taxes": [] + } + ], + "payment_id": null, + "status": "cancelled", + "expire_by": null, + "issued_at": 1579765167, + "paid_at": null, + "cancelled_at": 1579768206, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1579765167, + "terms": null, + "partial_payment": false, + "gross_amount": 399, + "tax_amount": 0, + "taxable_amount": 399, + "amount": 399, + "amount_paid": 0, + "amount_due": 399, + "currency": "INR", + "currency_symbol": "₹", + "description": null, + "notes": [], + "comment": null, + "short_url": "https://rzp.io/i/2wxV8Xs", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "invoice", + "group_taxes_discounts": false, + "created_at": 1579765167, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Send notification + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| invoiceId* | string | The id of the invoice to be notified | +| medium* | string | `sms`/`email`, Medium through which notification should be sent. | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/invoices)** \ No newline at end of file diff --git a/documents/item.md b/documents/item.md new file mode 100644 index 00000000..0a292fd0 --- /dev/null +++ b/documents/item.md @@ -0,0 +1,187 @@ +## items + +### Create item + +```java +String json = "{\n" + + " \"name\": \"Book / English August\",\n" + + " \"description\": \"An indian story, Booker prize winner.\",\n" + + " \"amount\": 20000,\n" + + " \"currency\": \"INR\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Item item = instance.Items.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| name* | string | Name of the item. | +| description | string | A brief description of the item. | +| amount | integer | Amount of the order to be paid | +| currency | string | Currency of the order. Currently only `INR` is supported. | + +**Response:** +```json +{ + "id": "item_7Oxp4hmm6T4SCn", + "active": true, + "name": "Book / English August", + "description": "An indian story, Booker prize winner.", + "amount": 20000, + "currency": "INR" +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch all items + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List item = instance.Items.fetchAll(options); +``` +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the item were created | +| to | timestamp | timestamp before which the item were created | +| count | integer | number of item to fetch (default: 10) | +| skip | integer | number of item to be skipped (default: 0) | +| name | string | Name of the item. | +| description | string | A brief description of the item. | +| amount | integer | Amount of the order to be paid | +| currency | string | Currency of the order. Currently only `INR` is supported. | +| active | boolean | Possible values is `0` or `1` | + +**Response:** +```json +{ + "entity": "collection", + "count": 3, + "items": [ + { + "id": "item_7Oy8OMV6BdEAac", + "active": true, + "name": "Book / Ignited Minds", + "description": null, + "amount": 15000, + "currency": "INR" + }, + { + "id": "item_7Oxp4hmm6T4SCn", + "active": true, + "name": "Book / English August", + "description": "An indian story, Booker prize winner.", + "amount": 20000, + "currency": "INR" + }, + { + "id": "item_7OxoGnoxCuUKbo", + "active": true, + "name": "Book / English August", + "description": null, + "amount": 20000, + "currency": "INR" + } + ] +} +``` +------------------------------------------------------------------------------------------------------- +### Fetch particular item + +```java +String ItemId = "item_7Oxp4hmm6T4SCn"; + +Item item = instance.Items.fetch(ItemId) +``` +**Parameters** + +| Name | Type | Description | +|---------|--------|-------------------------------------| +| ItemId* | string | The id of the item to be fetched | + +**Response:** +```json +{ + "id": "item_7Oxp4hmm6T4SCn", + "active": true, + "name": "Book / English August", + "description": "An indian story, Booker prize winner.", + "amount": 20000, + "currency": "INR" +} +``` + +------------------------------------------------------------------------------------------------------- + +### Update item + +```java +String ItemId = "item_7Oy8OMV6BdEAac"; + +String json = "{\n" + + " \"name\": \"Book / Ignited Minds - Updated name!\",\n" + + " \"description\": \"New descirption too. :).\",\n" + + " \"amount\": 20000,\n" + + " \"currency\": \"INR\",\n" + + " \"active\": true\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Item item = instance.Items.edit(ItemId, request); +``` +**Parameters** + +| Name | Type | Description | +|-------------|--------|-------------------------------------| +| ItemId* | string | The id of the item to be fetched | +| name | string | Name of the item. | +| description | string | A brief description of the item. | +| amount | integer | Amount of the order to be paid | +| currency | string | Currency of the order. Currently only `INR` is supported. | +| active | boolean | Possible values is `0` or `1` | + +**Response:** +```json +{ + "id": "item_7Oy8OMV6BdEAac", + "active": true, + "name": "Book / Ignited Minds - Updated name!", + "description": "New descirption too. :)", + "amount": 15000, + "currency": "INR" +} +``` +------------------------------------------------------------------------------------------------------- +### Delete item + +```js +instance.Items.delete(itemId) +``` +**Parameters** + +| Name | Type | Description | +|----------|--------|-------------------------------------| +| itemId* | string | The id of the item to be fetched | + +**Response:** +```json +[] +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/items)** \ No newline at end of file diff --git a/documents/order.md b/documents/order.md new file mode 100644 index 00000000..4c26a51c --- /dev/null +++ b/documents/order.md @@ -0,0 +1,232 @@ +## Orders + +### Create order + +```java +String json = "{\n" + + " amount: 50000,\n" + + " currency: \"INR\",\n" + + " receipt: \"receipt#1\",\n" + + " notes: {\n" + + " key1: \"value3\",\n" + + " key2: \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(json) +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | + +**Response:** + +```json +{ + "id": "order_EKwxwAgItmmXdp", + "entity": "order", + "amount": 50000, + "amount_paid": 0, + "amount_due": 50000, + "currency": "INR", + "receipt": "receipt#1", + "offer_id": null, + "status": "created", + "attempts": 0, + "notes": [], + "created_at": 1582628071 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch all orders + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List order = instance.Orders.fetchAll(options); +``` + +**Parameters** + +| Name | Type | Description | +|------------|-----------|--------------------------------------------------------------| +| from | timestamp | timestamp after which the orders were created | +| to | timestamp | timestamp before which the orders were created | +| count | integer | number of orders to fetch (default: 10) | +| skip | integer | number of orders to be skipped (default: 0) | +| authorized | boolean | Orders for which orders are currently in authorized state. | +| receipt | string | Orders with the provided value for receipt. | + +**Response:** + +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "order_EKzX2WiEWbMxmx", + "entity": "order", + "amount": 1234, + "amount_paid": 0, + "amount_due": 1234, + "currency": "INR", + "receipt": "Receipt No. 1", + "offer_id": null, + "status": "created", + "attempts": 0, + "notes": [], + "created_at": 1582637108 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch particular order + +```js +String OrderId = "order_DaaS6LOUAASb7Y"; + +Order order = instance.Orders.fetch(OrderId); +``` +**Parameters** + +| Name | Type | Description | +|----------|--------|-------------------------------------| +| OrderId* | string | The id of the order to be fetched | + +**Response:** + +```json +{ + "id":"order_DaaS6LOUAASb7Y", + "entity":"order", + "amount":2200, + "amount_paid":0, + "amount_due":2200, + "currency":"INR", + "receipt":"Receipt #211", + "status":"attempted", + "attempts":1, + "notes":[], + "created_at":1572505143 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch payments for an order + +```java +String OrderId = "order_DaaS6LOUAASb7Y"; + +Order order = instance.Orders.fetchPayments(OrderId); +``` +**Parameters** + +| Name | Type | Description | +|----------|--------|-------------------------------------| +| OrderId* | string | The id of the order to be retrieve payment info | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"pay_DaaSOvhgcOfzgR", + "entity":"payment", + "amount":2200, + "currency":"INR", + "status":"captured", + "order_id":"order_DaaS6LOUAASb7Y", + "invoice_id":null, + "international":false, + "method":"card", + "amount_refunded":0, + "refund_status":null, + "captured":true, + "description":"Beans in every imaginable flavour", + "card_id":"card_DZon6fd8J3IcA2", + "bank":null, + "wallet":null, + "vpa":null, + "email":"gaurav.kumar@example.com", + "contact":"+919999999988", + "notes":[], + "fee":44, + "tax":0, + "error_code":null, + "error_description":null, + "created_at":1572505160 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Update order + +```java +String OrderId = "order_DaaS6LOUAASb7Y"; + +String json = {\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.edit(OrderId,request); +``` +**Parameters** + +| Name | Type | Description | +|----------|--------|-------------------------------------| +| orderId* | string | The id of the order to be retrieve payment info | +| notes* | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_DaaS6LOUAASb7Y", + "entity":"order", + "amount":2200, + "amount_paid":0, + "amount_due":2200, + "currency":"INR", + "receipt":"Receipt #211", + "offer_id":null, + "status":"attempted", + "attempts":1, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1572505143 +} +``` +------------------------------------------------------------------------------------------------------- + + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/orders/)** \ No newline at end of file diff --git a/documents/papernach.md b/documents/papernach.md new file mode 100644 index 00000000..3160af6c --- /dev/null +++ b/documents/papernach.md @@ -0,0 +1,715 @@ +## Paper NACH + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " fail_existing: 0,\n" + + " gstin: \"29XAbbA4369J1PA\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create order + +```java +String json = "{\n" + + " amount: 0,\n" + + " currency: \"INR\",\n" + + " method: \"emandate\",\n" + + " customer_id: \"cust_1Aa00000000001\",\n" + + " receipt: \"Receipt No. 1\",\n" + + " notes: {\n" + + " notes_key_1: \"Beam me up Scotty\",\n" + + " notes_key_2: \"Engage\"\n" + + " },\n" + + " token: {\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 9999900,\n" + + " expire_at: 4102444799,\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 1121431121541121,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0000001\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| method* | string | The authorization method. In this case the value will be `emandate` | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | +| token | object | A key-value pair | + +All parameters listed [here](https://razorpay.com/docs/api/route/#create-transfers-from-payments) are supported + +**Response:** +```json +{ + "id":"order_1Aa00000000001", + "entity":"order", + "amount":0, + "amount_paid":0, + "amount_due":0, + "currency":"INR", + "receipt":"rcptid #10", + "offer_id":null, + "offers":{ + "entity":"collection", + "count":0, + "items":[ + + ] + }, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Beam me up Scotty", + "notes_key_2":"Engage" + }, + "created_at":1579775420, + "token":{ + "method":"nach", + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "recurring_status":null, + "failure_reason":null, + "currency":"INR", + "max_amount":10000000, + "auth_type":"physical", + "expire_at":1580480689, + "nach":{ + "create_form":true, + "form_reference1":"Recurring Payment for Gaurav Kumar", + "form_reference2":"Method Paper NACH", + "prefilled_form":"https://rzp.io/i/bitw", + "upload_form_url":"https://rzp.io/i/gts", + "description":"Paper NACH Gaurav Kumar" + }, + "bank_account":{ + "ifsc":"HDFC0000001", + "bank_name":"HDFC Bank", + "name":"Gaurav Kumar", + "account_number":"11214311215411", + "account_type":"savings", + "beneficiary_email":"gaurav.kumar@example.com", + "beneficiary_mobile":"9876543210" + }, + "first_payment_amount":0 + } +} +``` + +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/paper-nach/authorization-transaction/#113-create-an-authorization-payment) for authorization payment + +------------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " amount: 0,\n" + + " currency: \"INR\",\n" + + " type: \"link\",\n" + + " description: \"12 p.m. Meals\",\n" + + " subscription_registration: {\n" + + " method: \"nach\",\n" + + " auth_type: \"physical\",\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 11214311215411,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0001233\"\n" + + " },\n" + + " nach: {\n" + + " form_reference1: \"Recurring Payment for Gaurav Kumar\",\n" + + " form_reference2: \"Method Paper NACH\"\n" + + " },\n" + + " expire_at: 1947483647,\n" + + " max_amount: 50000\n" + + " },\n" + + " receipt: \"Receipt No. 1\",\n" + + " sms_notify: 1,\n" + + " email_notify: 1,\n" + + " expire_by: 1647483647,\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** +All parameters listed [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/authorization-transaction/#121-create-a-registration-link) are supported + +**Response:** +```json +{ + "id": "inv_FHrZiAubEzDdaq", + "entity": "invoice", + "receipt": "Receipt No. 1", + "invoice_number": "Receipt No. 1", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrZiBOkWHZPOp", + "line_items": [], + "payment_id": null, + "status": "issued", + "expire_by": 1647483647, + "issued_at": 1595491154, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491154, + "terms": null, + "partial_payment": false, + "gross_amount": 0, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 0, + "amount_paid": 0, + "amount_due": 0, + "currency": "INR", + "currency_symbol": "₹", + "description": "12 p.m. Meals", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/bzDYbNg", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491154, + "idempotency_key": null, + "token": { + "method": "nach", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "recurring_status": null, + "failure_reason": null, + "currency": "INR", + "max_amount": 50000, + "auth_type": "physical", + "expire_at": 1947483647, + "nach": { + "create_form": true, + "form_reference1": "Recurring Payment for Gaurav Kumar", + "form_reference2": "Method Paper NACH", + "prefilled_form": "https://rzp.io/i/exdIzYN", + "upload_form_url": "https://rzp.io/i/bzDYbNg", + "description": "12 p.m. Meals" + }, + "bank_account": { + "ifsc": "HDFC0001233", + "bank_name": "HDFC Bank", + "name": "Gaurav Kumar", + "account_number": "11214311215411", + "account_type": "savings", + "beneficiary_email": "gaurav.kumar@example.com", + "beneficiary_mobile": "9123456780" + }, + "first_payment_amount": 0 + }, + "nach_form_url": "https://rzp.io/i/exdIzYN" +} +``` +------------------------------------------------------------------------------------------------------- + +### Send/Resend notifications + +```java +String InvoiceId = "inv_FHrZiAubEzDdaq"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(invoiceId, medium); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be notified | +| medium* | string | `sms`/`email`, Medium through which notification should be sent. | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Cancel a registration link + +```java +String InvoiceId = "inv_FHrZiAubEzDdaq"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be cancelled | + +**Response:** +```json +{ + "id": "inv_FHrZiAubEzDdaq", + "entity": "invoice", + "receipt": "Receipt No. 27", + "invoice_number": "Receipt No. 27", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrZiBOkWHZPOp", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 1647483647, + "issued_at": 1595491154, + "paid_at": null, + "cancelled_at": 1595491339, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491154, + "terms": null, + "partial_payment": false, + "gross_amount": 0, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 0, + "amount_paid": 0, + "amount_due": 0, + "currency": "INR", + "currency_symbol": "₹", + "description": "12 p.m. Meals", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/bzDYbNg", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491154, + "idempotency_key": null, + "token": { + "method": "nach", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "recurring_status": null, + "failure_reason": null, + "currency": "INR", + "max_amount": 50000, + "auth_type": "physical", + "expire_at": 1947483647, + "nach": { + "create_form": true, + "form_reference1": "Recurring Payment for Gaurav Kumar", + "form_reference2": "Method Paper NACH", + "prefilled_form": "https://rzp.io/i/tSYd5aV", + "upload_form_url": "https://rzp.io/i/bzDYbNg", + "description": "12 p.m. Meals" + }, + "bank_account": { + "ifsc": "HDFC0001233", + "bank_name": "HDFC Bank", + "name": "Gaurav Kumar", + "account_number": "11214311215411", + "account_type": "savings", + "beneficiary_email": "gaurav.kumar@example.com", + "beneficiary_mobile": "9123456780" + }, + "first_payment_amount": 0 + }, + "nach_form_url": "https://rzp.io/i/tSYd5aV" +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch Payment ID using Order ID + +```java +String OrderId = "order_FHrZiBOkWHZPOp"; + +Order order = instance.Orders.fetchPayments(orderId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| orderId* | string | Order id for which payment id need to be fetched | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"pay_1Aa00000000003", + "entity":"payment", + "amount":0, + "currency":"INR", + "status":"captured", + "order_id":"order_1Aa00000000003", + "invoice_id":"inv_1Aa00000000003", + "international":false, + "method":"nach", + "amount_refunded":0, + "refund_status":null, + "captured":true, + "description":"12 p.m. Meals", + "card_id":null, + "bank":"HDFC", + "wallet":null, + "vpa":null, + "email":"gaurav.kumar@example.com", + "contact":"99876543210", + "customer_id":"cust_1Aa00000000002", + "token_id":"token_1Aa00000000003", + "notes":{ + "note_key 1":"Beam me up Scotty", + "note_key 2":"Tea. Earl Gray. Hot." + }, + "fee":0, + "tax":0, + "error_code":null, + "error_description":null, + "created_at":1580109147 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch token by payment ID + +```java +String PaymentId = "pay_1Aa00000000003"; + +instance.Payments.fetch(PaymentId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|--------|-----------------------------------| +| PaymentId* | string | Id of the payment to be retrieved | + +**Response:** +```json +{ + "id": "pay_EnLNTjINiPkMEZ", + "entity": "payment", + "amount": 0, + "currency": "INR", + "status": "captured", + "order_id": "order_EnLLfglmKksr4K", + "invoice_id": "inv_EnLLfgCzRfcMuh", + "international": false, + "method": "nach", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Invoice #inv_EnLLfgCzRfcMuh", + "card_id": null, + "bank": "UTIB", + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_EnLNTnn7uyRg5V", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": {}, + "created_at": 1588827564 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch tokens by customer ID + +```java +String CustomerId = "inv_EnLLfgCzRfcMuh"; + +Customer customer = instance.Customers.fetchTokens(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "token_EhYgIE3pOyMQpD", + "entity": "token", + "token": "3mQ5Czc6APNppI", + "bank": "HDFC", + "wallet": null, + "method": "nach", + "vpa": null, + "recurring": true, + "recurring_details": { + "status": "confirmed", + "failure_reason": null + }, + "auth_type": "physical", + "mrn": null, + "used_at": 1587564373, + "created_at": 1587564373, + "dcc_enabled": false + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete token + +```java +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +String TokenId = "token_EhYgIE3pOyMQpD"; + +instance.Customers.deleteToken(customerId, tokenId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an order to charge the customer + +```java +String json = "{\n" + + " amount: 1000,\n" + + " currency: \"INR\",\n" + + " receipt: \"Receipt No. 1\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":1000, + "amount_paid":0, + "amount_due":1000, + "currency":"INR", + "receipt":"Receipt No. 1", + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1579782776 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create a Recurring Payment + +```java +String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.createRecurringPayment(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address. | +| contact* | string | The customer's phone number. | +| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| order_id* | string | The unique identifier of the order created. | +| customer_id* | string | The `customer_id` for the customer you want to charge. | +| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| +| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| +| description* | string | A user-entered description for the payment.| +| notes* | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/authorization-transaction/)** \ No newline at end of file diff --git a/documents/payment.md b/documents/payment.md new file mode 100644 index 00000000..db2b825b --- /dev/null +++ b/documents/payment.md @@ -0,0 +1,478 @@ +## Payments + +### Capture payment + +```java +String PaymentId = "pay_G8VQzjPLoAvm6D"; +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.capture(PaymentId, request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|--------------------------------------------------------------------------------| +| PaymentId* | string | Id of the payment to capture | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency | string | The currency of the payment (defaults to INR) | + +**Response:** +```json +{ + "id": "pay_G8VQzjPLoAvm6D", + "entity": "payment", + "amount": 1000, + "currency": "INR", + "status": "captured", + "order_id": "order_G8VPOayFxWEU28", + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Purchase Shoes", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gaurav.kumar@exampleupi", + "email": "gaurav.kumar@example.com", + "contact": "+919999999999", + "customer_id": "cust_DitrYCFtCIokBO", + "notes": [], + "fee": 24, + "tax": 4, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "033814379298" + }, + "created_at": 1606985209 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all payments + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List payment = instance.Payments.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 2, + "items": [ + { + "id": "pay_G8VaL2Z68LRtDs", + "entity": "payment", + "amount": 900, + "currency": "INR", + "status": "captured", + "order_id": "order_G8VXfKDWDEOHHd", + "invoice_id": null, + "international": false, + "method": "netbanking", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Purchase Shoes", + "card_id": null, + "bank": "KKBK", + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919999999999", + "customer_id": "cust_DitrYCFtCIokBO", + "notes": [], + "fee": 22, + "tax": 4, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "bank_transaction_id": "0125836177" + }, + "created_at": 1606985740 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a payment + +```java +String PaymentId = "pay_G8VQzjPLoAvm6D"; + +Payment payment = instance.Payments.fetch(PaymentId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|--------|-----------------------------------| +| PaymentId* | string | Id of the payment to be retrieved | + +**Response:** +```json +{ + "id": "pay_G8VQzjPLoAvm6D", + "entity": "payment", + "amount": 1000, + "currency": "INR", + "status": "captured", + "order_id": "order_G8VPOayFxWEU28", + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Purchase Shoes", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gaurav.kumar@exampleupi", + "email": "gaurav.kumar@example.com", + "contact": "+919999999999", + "customer_id": "cust_DitrYCFtCIokBO", + "notes": [], + "fee": 24, + "tax": 4, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "033814379298" + }, + "created_at": 1606985209 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch payments for an order + +```java +String OrderId = "order_DovFx48wjYEr2I"; + +Order order = instance.Orders.fetchPayments(OrderId) +``` +**Parameters** + +| Name | Type | Description | +|----------|--------|-------------------------------------| +| OrderId* | string | The id of the order to be retrieve payment info | + +**Response:** +```json +{ + "count": 1, + "entity": "collection", + "items": [ + { + "id": "pay_DovGQXOkPBJjjU", + "entity": "payment", + "amount": 600, + "currency": "INR", + "status": "captured", + "order_id": "order_DovFx48wjYEr2I", + "method": "netbanking", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "A Wild Sheep Chase is a novel by Japanese author Haruki Murakami", + "card_id": null, + "bank": "SBIN", + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "9364591752", + "fee": 70, + "tax": 10, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "notes": [], + "acquirer_data": { + "bank_transaction_id": "0125836177" + }, + "created_at": 1400826750 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Update a payment + +```java +String PaymentId = "pay_CBYy6tLmJTzn3Q"; +String json = "{\n" + + " \"notes\": {\n" + + " \"key1\": \"value1\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.edit(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|--------------------------------------| +| PaymentId* | string | Id of the payment to update | +| notes* | object | A key-value pair | + +**Response:** +```json +{ + "id": "pay_CBYy6tLmJTzn3Q", + "entity": "payment", + "amount": 1000, + "currency": "INR", + "status": "authorized", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "netbanking", + "amount_refunded": 0, + "refund_status": null, + "captured": false, + "description": null, + "card_id": null, + "bank": "UTIB", + "wallet": null, + "vpa": null, + "email": "testme@acme.com", + "notes": { + "key1": "value1", + "key2": "value2" + }, + "fee": null, + "tax": null, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "bank_transaction_id": "0125836177" + }, + "created_at": 1553504328 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch expanded card or emi details for payments + +Request #1: Card + +```java +JSONObject request = new JSONObject({'expand[]':'card'}); + +List payment = instance.Payments.fetchAll(request); +``` + +Request #2: EMI + +```java +JSONObject request = new JSONObject({'expand[]':'emi'}); + +List payment = instance.payments.fetchAll(request); +``` + +**Response:**
+For expanded card or emi details for payments response please click [here](https://razorpay.com/docs/api/payments/#fetch-expanded-card-or-emi-details-for-payments) + +------------------------------------------------------------------------------------------------------- + +### Fetch card details with paymentId + +```java +String PaymentId = "pay_CBYy6tLmJTzn3Q"; + +Card card = instance.Cards.fetchCardDetails(PaymentId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|--------------------------------------| +| PaymentId* | string | Id of the payment to update | + +**Response:** +```json +{ + "id": "card_6krZ6bcjoeqyV9", + "entity": "card", + "name": "Gaurav", + "last4": "3335", + "network": "Visa", + "type": "debit", + "issuer": "SBIN", + "international": false, + "emi": null, + "sub_type": "business" +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch Payment Downtime Details + +```js +List payment = instance.Payments.fetchPaymentDowntime(); +``` +**Response:**
+For payment downtime response please click [here](https://razorpay.com/docs/api/payments/downtime/#fetch-payment-downtime-details) + +------------------------------------------------------------------------------------------------------- + +### Fetch Payment Downtime + +```java +String DowntimeId = "down_F7LroRQAAFuswd"; + +instance.Payments.fetchPaymentDowntimeById(DowntimeId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|--------------------------------------| +| DowntimeId* | string | Id to fetch payment downtime | + +**Response:** +For payment downtime by id response please click [here](https://razorpay.com/docs/api/payments/downtime/#fetch-payment-downtime-details-by-id) +------------------------------------------------------------------------------------------------------- + +### Payment capture settings API + +```java +String json = "{\n" + + " amount:50000,\n" + + " currency: 'INR',\n" + + " receipt: 'rcptid_11',\n" + + " payment: {\n" + + " capture : 'automatic',\n" + + " capture_options : {\n" + + " automatic_expiry_period : 12,\n" + + " manual_expiry_period : 7200,\n" + + " refund_speed : 'optimum'\n" + + " } \n" + + " }\n" + + "}"; +JSONObject request = new JSONObject(json); + +instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|--------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| receipt | string | Your system order reference id. | +| payment | object | please refer this [doc](https://razorpay.com/docs/payments/payments/capture-settings/api/) for params | + +**Response:**
+```json +{ + "id": "order_DBJOWzybf0sJbb", + "entity": "order", + "amount": 50000, + "amount_paid": 0, + "amount_due": 50000, + "currency": "INR", + "receipt": "rcptid_11", + "status": "created", + "attempts": 0, + "notes": [], + "created_at": 1566986570 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create Payment Json + +```js +String json = "{\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " order_id: \"order_EAkbvXiCJlwhHR\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9090909090,\n" + + " method: \"card\",\n" + + " card:{\n" + + " number: 4111111111111111,\n" + + " name: \"Gaurav\",\n" + + " expiry_month: 11,\n" + + " expiry_year: 23,\n" + + " cvv: 100\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +instance.Payments.createJsonPayment(request); +``` + +**Parameters:** + please refer this [doc](https://razorpay.com/docs/payment-gateway/s2s-integration/payment-methods/) for params + +**Response:**
+```json +{ + "razorpay_payment_id": "pay_FVmAstJWfsD3SO", + "next": [ + { + "action": "redirect", + "url": "https://api.razorpay.com/v1/payments/FVmAtLUe9XZSGM/authorize" + }, + { + "action": "otp_generate", + "url": "https://api.razorpay.com/v1/payments/pay_FVmAstJWfsD3SO/otp_generate?track_id=FVmAtLUe9XZSGM&key_id=" + } + ] +} +``` + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/payments/)** \ No newline at end of file diff --git a/documents/paymentLink.md b/documents/paymentLink.md new file mode 100644 index 00000000..ebbad1db --- /dev/null +++ b/documents/paymentLink.md @@ -0,0 +1,1038 @@ +## Payment Links + +### Create payment link + +Request #1 +Standard Payment Link + +```java +String json = "{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"notes\": {\n" + + " \"policy_name\": \"Jeevan Bima\"\n" + + " },\n" + + " \"callback_url\": \"https://example-callback-url.com/\",\n" + + " \"callback_method\": \"get\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +Request #2 +UPI Payment Link + +```java +String json = "{\n" + + " \"upi_link\": true,\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"notes\": {\n" + + " \"policy_name\": \"Jeevan Bima\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|upi_link* | boolean | boolean Must be set to true // to creating UPI Payment Link only | +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|description | string | A brief description of the Payment Link | +|reference_id | string | AReference number tagged to a Payment Link. | +|customer | object | name, email, contact | +|expire_by | integer | Timestamp, in Unix, at which the Payment Link will expire. By default, a Payment Link will be valid for six months from the date of creation. | +|notify | object | sms or email (boolean) | +|notes | json object | 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, "note_key": "Beam me up Scotty” | + +**Response:** +For create payment link response please click [here](https://razorpay.com/docs/api/payment-links/#create-payment-link) + +------------------------------------------------------------------------------------------------------- + +### Fetch all payment link + +```java +List paymentlink = instance.PaymentLink.fetchAll(); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|payment_id | string | Unique identifier of the payment associated with the Payment Link. | +|reference_id | string | The unique reference number entered by you while creating the Payment Link. | + +**Response:** +For fetch all payment link response please click [here](https://razorpay.com/docs/api/payment-links/#all-payment-links) + +------------------------------------------------------------------------------------------------------- + +### Fetch specific payment link + +```java +String PaymentLinkId = "plink_FMbhpT6nqDjDei"; + +instance.PaymentLink.fetch(PaymentLinkId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| paymentLinkId* | string | Unique identifier of the Payment Link. | + +**Response:** +For fetch specific payment link response please click [here](https://razorpay.com/docs/api/payment-links/#specific-payment-links-by-id) + +------------------------------------------------------------------------------------------------------- + +### Update payment link + +```java +String PaymentLinkId = "plink_FMbhpT6nqDjDei"; + +String json = "{\n" + + " \"reference_id\": \"TS35\",\n" + + " \"expire_by\": 1653347540,\n" + + " \"reminder_enable\":false,\n" + + " \"notes\":{\n" + + " \"policy_name\": \"Jeevan Saral\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink paymentlink = instance.PaymentLink.edit(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| paymentLinkId* | string | The unique identifier of the Payment Link that needs to be updated. | +| accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values: true - Customer can make partial payments. false (default) - Customer cannot make partial payments. | +| reference_id | string | Adds a unique reference number to an existing link. | +| expire_by | integer | Timestamp, in Unix format, when the payment links should expire. | +| notes | string | object 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, "note_key": "Beam me up Scotty”. | + +**Response:** +For updating payment link response please click [here](https://razorpay.com/docs/api/payment-links/#update-payment-link) + +------------------------------------------------------------------------------------------------------- + +### Cancel a payment link + +```java +String PaymentLinkId = "plink_FMbhpT6nqDjDei"; + +PaymentLink paymentlink = instance.PaymentLink.cancel(PaymentLinkId,medium); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| paymentLinkId* | string | Unique identifier of the Payment Link. | + +**Response:** +For canceling payment link response please click [here](https://razorpay.com/docs/api/payment-links/#cancel-payment-link) +------------------------------------------------------------------------------------------------------- + +### Send notification + +```java +String PaymentLinkId = "plink_FMbhpT6nqDjDei"; + +String medium = "email"; + +PaymentLink paymentlink = instance.PaymentLink.notifyBy(PaymentLinkId,medium); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| paymentLinkId* | string | Unique identifier of the Payment Link that should be resent. | +| medium* | string | `sms`/`email`,Medium through which the Payment Link must be resent. Allowed values are: | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Transfer payments received using payment links + +```java +String json = "{\n" + + " \"amount\": 20000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": false,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"order\": [\n" + + " {\n" + + " \"account\": \"acc_CNo3jSI8OkFJJJ\",\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"notes\": {\n" + + " \"branch\": \"Acme Corp Bangalore North\",\n" + + " \"name\": \"Saurav Kumar\",\n" + + " \"linked_account_notes\": [\n" + + " \"branch\"\n" + + " ]\n" + + " }\n" + + " }\n" + + " ]\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|options* | array | Options to configure the transfer in the Payment Link. Parent parameter under which the order child parameter must be passed. | + +**Response:** +```json +{ + "accept_partial": false, + "amount": 1500, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596526969, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "deleted_at": 0, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 0, + "id": "plink_FMbhpT6nqDjDei", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#aasasw8", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/ORor1MT", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596526969, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Offers on payment links + +```java +String json = "{\n" + + " \"amount\": 3400,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": false,\n" + + " \"reference_id\": \"#425\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": false,\n" + + " \"options\": {\n" + + " \"order\": {\n" + + " \"offers\": [\n" + + " \"offer_F4WMTC3pwFKnzq\",\n" + + " \"offer_F4WJHqvGzw8dWF\"\n" + + " ]\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|description | string | A brief description of the Payment Link | +|reference_id | string | AReference number tagged to a Payment Link. | +|customer | array | name, email, contact | +|expire_by | integer | Timestamp, in Unix, at which the Payment Link will expire. By default, a Payment Link will be valid for six months from the date of creation. | +|notify | object | sms or email (boolean) | +|options* | array | Options to associate the offer_id with the Payment Link. Parent parameter under which the order child parameter must be passed. | + +**Response:** +```json +{ + "accept_partial": false, + "amount": 3400, + "amount_paid": 0, + "cancelled_at": 0, + "created_at": 1600183040, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 0, + "id": "plink_FdLt0WBldRyE5t", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#425", + "reminder_enable": false, + "reminders": [], + "short_url": "https://rzp.io/i/CM5ohDC", + "status": "created", + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Managing reminders for payment links + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#425\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": false\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|expire_by | integer | Timestamp, in Unix, at which the Payment Link will expire. By default, a Payment Link will be valid for six months from the date of creation. | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | + +**Response:** +```json +{ + "amount": 340000, + "amount_due": 340000, + "amount_paid": 0, + "billing_end": null, + "billing_start": null, + "cancelled_at": null, + "comment": null, + "created_at": 1592579126, + "currency": "INR", + "currency_symbol": "₹", + "customer_details": { + "billing_address": null, + "contact": "9900990099", + "customer_contact": "9900990099", + "customer_email": "gaurav.kumar@example.com", + "customer_name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "gstin": null, + "id": "cust_F4WNtqj1xb0Duv", + "name": "Gaurav Kumar", + "shipping_address": null + }, + "customer_id": "cust_F4WNtqj1xb0Duv", + "date": 1592579126, + "description": "Salon at Home Service", + "email_status": null, + "entity": "invoice", + "expire_by": 1608390326, + "expired_at": null, + "first_payment_min_amount": 0, + "gross_amount": 340000, + "group_taxes_discounts": false, + "id": "inv_F4WfpZLk1ct35b", + "invoice_number": null, + "issued_at": 1592579126, + "line_items": [], + "notes": [], + "order_id": "order_F4WfpxUzWmYOTl", + "paid_at": null, + "partial_payment": false, + "payment_id": null, + "receipt": "5757", + "reminder_enable": false, + "short_url": "https://rzp.io/i/vitLptM", + "sms_status": null, + "status": "issued", + "tax_amount": 0, + "taxable_amount": 0, + "terms": null, + "type": "link", + "user_id": "", + "view_less": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Rename labels in checkout section + +```java +String json = "{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"partial_payment\": {\n" + + " \"min_amount_label\": \"Minimum Money to be paid\",\n" + + " \"partial_amount_label\": \"Pay in parts\",\n" + + " \"partial_amount_description\": \"Pay at least ₹100\",\n" + + " \"full_amount_label\": \"Pay the entire amount\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|expire_by | integer | Timestamp, in Unix, at which the Payment Link will expire. By default, a Payment Link will be valid for six months from the date of creation. | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | 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. | + +**Response:** +```json +{ + "accept_partial": true, + "amount": 1000, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596193199, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "deleted_at": 0, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 100, + "id": "plink_FL4vbXVKfW7PAz", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#42321", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/F4GC9z1", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596193199, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Change Business name + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#2234542\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"name\": \"Lacme Corp\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | Option to customize the business name. Parent parameter under which the checkout child parameter must be passed.| + +**Response:** +```json +{ + "accept_partial": true, + "amount": 1000, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596187657, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 100, + "id": "plink_FL3M2gJFs1Jkma", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#2234542", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/at2OOsR", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596187657, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Prefill checkout fields + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#417\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"prefill\": {\n" + + " \"method\": \"card\",\n" + + " \"card[name]\": \"Gaurav Kumar\",\n" + + " \"card[number]\": \"4111111111111111\",\n" + + " \"card[expiry]\": \"12/21\",\n" + + " \"card[cvv]\": \"123\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | array | Options to customize Checkout. Parent parameter under which the checkout and prefill child parameters must be passed.| + +**Response:** +For prefill checkout fields response please click [here](https://razorpay.com/docs/payment-links/api/new/advanced-options/customize/prefill/) + +------------------------------------------------------------------------------------------------------- + +### Customize payment methods + +```java +String json = "{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"method\": {\n" + + " \"netbanking\": \"1\",\n" + + " \"card\": \"1\",\n" + + " \"upi\": \"0\",\n" + + " \"wallet\": \"0\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | Options to display or hide payment methods on the Checkout section. Parent parameter under which the checkout and method child parameters must be passed.| + +**Response:** +```json +{ + "accept_partial": true, + "amount": 1000, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596188371, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "deleted_at": 0, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 100, + "id": "plink_FL3YbdvN2Cj6gh", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#543422", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/wKiXKud", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596188371, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Set checkout fields as read-only + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#20\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"readonly\": {\n" + + " \"email\": \"1\",\n" + + " \"contact\": \"1\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | Options to set contact and email as read-only fields on Checkout. Parent parameter under which the checkout and readonly child parameters must be passed.| + +**Response:** +```json +{ + "accept_partial": true, + "amount": 1000, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596190845, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "deleted_at": 0, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 100, + "id": "plink_FL4GA1t6FBcaVR", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#19129", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/QVwUglR", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596190845, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Implement thematic changes in payment links checkout section + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#423212\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"theme\": {\n" + + " \"hide_topbar\": true\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | Options to show or hide the top bar. Parent parameter under which the checkout and theme child parameters must be passed.| + +**Response:** +```json +{ + "accept_partial": true, + "amount": 1000, + "amount_paid": 0, + "callback_method": "", + "callback_url": "", + "cancelled_at": 0, + "created_at": 1596187814, + "currency": "INR", + "customer": { + "contact": "+919999999999", + "email": "gaurav.kumar@example.com", + "name": "Gaurav Kumar" + }, + "description": "Payment for policy no #23456", + "expire_by": 0, + "expired_at": 0, + "first_min_partial_amount": 100, + "id": "plink_FL3Oncr7XxXFf6", + "notes": null, + "notify": { + "email": true, + "sms": true + }, + "payments": null, + "reference_id": "#423212", + "reminder_enable": true, + "reminders": [], + "short_url": "https://rzp.io/i/j45EmLE", + "source": "", + "source_id": "", + "status": "created", + "updated_at": 1596187814, + "user_id": "" +} +``` +------------------------------------------------------------------------------------------------------- + +### Rename labels in payment details section + +```java +String json = "{\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"reference_id\": \"#421\",\n" + + " \"description\": \"Payment for policy no #23456\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": \"+919999999999\",\n" + + " \"email\": \"gaurav.kumar@example.com\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"partial_payment\": {\n" + + " \"min_amount_label\": \"Minimum Money to be paid\",\n" + + " \"partial_amount_label\": \"Pay in parts\",\n" + + " \"partial_amount_description\": \"Pay at least ₹100\",\n" + + " \"full_amount_label\": \"Pay the entire amount\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +PaymentLink payment = instance.PaymentLink.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +|amount* | integer | Amount to be paid using the Payment Link. | +|currency | string | A three-letter ISO code for the currency in which you want to accept the payment. For example, INR. | +|accept_partial | boolean | Indicates whether customers can make partial payments using the Payment Link. Possible values:true - Customer can make partial payments.false (default) - Customer cannot make partial payments. | +|first_min_partial_amount | integer | | +|description | string | A brief description of the Payment Link | +|customer | object | name, email, contact | +|notify | object | sms or email (boolean) | +|reminder_enable | boolean | To disable reminders for a Payment Link, pass reminder_enable as false | +|options* | object | Parent parameter under which the hosted_page and label child parameters must be passed.| + +**Response:** +For rename labels in payment details section response please click [here](https://razorpay.com/docs/payment-links/api/new/advanced-options/customize/rename-payment-details-labels/) + +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/payment-links/)** \ No newline at end of file diff --git a/documents/paymentVerfication.md b/documents/paymentVerfication.md new file mode 100644 index 00000000..dce210e8 --- /dev/null +++ b/documents/paymentVerfication.md @@ -0,0 +1,86 @@ +## payment verification + +```java +import com.razorpay.Utils; +``` + +### Verify payment verification + +```java +String secret = "EnLs21M47BllR3X8PSFtjtbd"; + +JSONObject options = new JSONObject(); +options.put("razorpay_order_id", "order_IEIaMR65cu6nz3"); +options.put("razorpay_payment_id", "pay_IH4NVgf4Dreq1l"); +options.put("razorpay_signature", "0d4e745a1838664ad6c9c9902212a32d627d68e917290b0ad5f08ff4561bc50f"); + +boolean status = Utils.verifyPaymentSignature(options, secret); +``` + +**Parameters:** + + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| razorpay_order_id* | string | The id of the order to be fetched | +| razorpay_payment_id* | string | The id of the payment to be fetched | +| razorpay_signature* | string | Signature returned by the Checkout. This is used to verify the payment. | +| secret* | string | your api secret as secret | + +------------------------------------------------------------------------------------------------------- +### Verify subscription verification + +```js +String secret = "EnLs21M47BllR3X8PSFtjtbd"; + +JSONObject options = new JSONObject(); +options.put("razorpay_subscription_id", "sub_ID6MOhgkcoHj9I"); +options.put("razorpay_payment_id", "pay_IDZNwZZFtnjyym"); +options.put("razorpay_signature", "601f383334975c714c91a7d97dd723eb56520318355863dcf3821c0d07a17693"); + +boolean status = Utils.verifySubscription(options, secret); +``` + +**Parameters:** + + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| razorpay_subscription_id* | string | The id of the subscription to be fetched | +| razorpay_payment_id* | string | The id of the payment to be fetched | +| razorpay_signature* | string | Signature returned by the Checkout. This is used to verify the payment. | +| secret* | string | your api secret as secret | + +------------------------------------------------------------------------------------------------------- +### Verify paymentlink verification + +```js +String secret = "EnLs21M47BllR3X8PSFtjtbd"; + +JSONObject options = new JSONObject(); +options.put("payment_link_reference_id", "TSsd1989"); +options.put("razorpay_payment_id", "pay_IH3d0ara9bSsjQ"); +options.put("payment_link_status", "paid"); +options.put("payment_link_id", "plink_IH3cNucfVEgV68"); +options.put("razorpay_signature", "07ae18789e35093e51d0a491eb9922646f3f82773547e5b0f67ee3f2d3bf7d5b"); + +boolean status = Utils.verifyPaymentLink(options, secret); +``` + +**Parameters:** + + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| payment_link_id* | string | The id of the paymentlink to be fetched | +| razorpay_payment_id* | string | The id of the payment to be fetched | +| payment_link_reference_id* | string | A reference number tagged to a Payment Link | +| payment_link_status* | string | Current status of the link | +| razorpay_signature* | string | Signature returned by the Checkout. This is used to verify the payment. | +| secret* | string | your api secret as secret | + +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
\ No newline at end of file diff --git a/documents/plan.md b/documents/plan.md new file mode 100644 index 00000000..386c3bec --- /dev/null +++ b/documents/plan.md @@ -0,0 +1,184 @@ +## Plans + +### Create plan + +```java +String json = "{\n" + + " period: \"weekly\",\n" + + " interval: 1,\n" + + " item: {\n" + + " name: \"Test plan - Weekly\",\n" + + " amount: 69900,\n" + + " currency: \"INR\",\n" + + " description: \"Description for the test plan\"\n" + + " },\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Plan plan = razorpayclient.Plans.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| period* | string | Used together with `interval` to define how often the customer should be charged.Possible values:
1.`daily`
2.`weekly`
3.`monthly`
4.`yearly` | +| interval* | string | Used together with `period` to define how often the customer should be charged | +| items* | array | Details of the plan. For more details please refer [here](https://razorpay.com/docs/api/subscriptions/#create-a-plan) | +| notes | array | Notes you can enter for the contact for future reference. | + +**Response:** +```json +{ + "id":"plan_00000000000001", + "entity":"plan", + "interval":1, + "period":"weekly", + "item":{ + "id":"item_00000000000001", + "active":true, + "name":"Test plan - Weekly", + "description":"Description for the test plan - Weekly", + "amount":69900, + "unit_amount":69900, + "currency":"INR", + "type":"plan", + "unit":null, + "tax_inclusive":false, + "hsn_code":null, + "sac_code":null, + "tax_rate":null, + "tax_id":null, + "tax_group_id":null, + "created_at":1580219935, + "updated_at":1580219935 + }, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1580219935 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all plans + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +instance.Plans.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "plan_00000000000001", + "entity": "plan", + "interval": 1, + "period": "weekly", + "item": { + "id": "item_00000000000001", + "active": true, + "name": "Test plan - Weekly", + "description": "Description for the test plan - Weekly", + "amount": 69900, + "unit_amount": 69900, + "currency": "INR", + "type": "plan", + "unit": null, + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "tax_id": null, + "tax_group_id": null, + "created_at": 1580220492, + "updated_at": 1580220492 + }, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1580220492 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch particular plan + +```java +String PlanId = "plan_00000000000001"; + +instance.Plans.fetch(PlanId) +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| PlanId | string | The id of the plan to be fetched | + +**Response:** +```json +{ + "id":"plan_00000000000001", + "entity":"plan", + "interval":1, + "period":"weekly", + "item":{ + "id":"item_00000000000001", + "active":true, + "name":"Test plan - Weekly", + "description":"Description for the test plan - Weekly", + "amount":69900, + "unit_amount":69900, + "currency":"INR", + "type":"plan", + "unit":null, + "tax_inclusive":false, + "hsn_code":null, + "sac_code":null, + "tax_rate":null, + "tax_id":null, + "tax_group_id":null, + "created_at":1580220492, + "updated_at":1580220492 + }, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1580220492 +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/subscriptions/#plans)** \ No newline at end of file diff --git a/documents/qrcode.md b/documents/qrcode.md new file mode 100644 index 00000000..156e43ac --- /dev/null +++ b/documents/qrcode.md @@ -0,0 +1,446 @@ +## Qr Codes + +### Create Qr code + +```java +String json = "{\n" + + " type: \"upi_qr\",\n" + + " name: \"Store_1\",\n" + + " usage: \"single_use\",\n" + + " fixed_amount: true,\n" + + " payment_amount: 300,\n" + + " description: \"For Store 1\",\n" + + " customer_id: \"cust_HKsR5se84c5LTO\",\n" + + " close_by: 1681615838,\n" + + " notes: {\n" + + " purpose: \"Test UPI QR code notes\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +QrCode qrcode = instance.qrCode.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| type* | string | The type of QR code i.e, `upi_qr`/`bharat_qr` | +| name | string | Label entered to identify the QR code. | +| usage* | string | Indicates if the QR code should be allowed to accept single payment or multiple payments i.e, `single_use`/`multiple_use` | +| fixed_amount | boolean | Indicates if the QR should accept payments of specific amounts or any amount. | +| payment_amount(* mandatory if fixed_amount is true) | integer | Indicates if the QR should accept payments of specific amounts or any amount. | +| customer_id | string | Unique identifier of the customer the QR code is linked with | +| description | string | A brief description about the QR code. | +| close_by | integer | 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. | +| notes | object | Key-value pair that can be used to store additional information about the QR code. Maximum 15 key-value pairs, 256 characters (maximum) each. | + +**Response:** +```json +{ + "id": "qr_HMsVL8HOpbMcjU", + "entity": "qr_code", + "created_at": 1623660301, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/BWcUVrLp", + "payment_amount": 300, + "status": "active", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create Qr code with GST + +```java +String json = "{\n" + + " type: \"upi_qr\",\n" + + " name: \"Store_1\",\n" + + " usage: \"single_use\",\n" + + " fixed_amount: true,\n" + + " payment_amount: 300,\n" + + " description: \"For Store 1\",\n" + + " customer_id: \"cust_HKsR5se84c5LTO\",\n" + + " close_by: 1681615838,\n" + + " notes: {\n" + + " purpose: \"Test UPI QR code notes\"\n" + + " },\n" + + " tax_invoice: {\n" + + " number: \"INV001\",\n" + + " date: 1589994898,\n" + + " customer_name: \"Gaurav Kumar\",\n" + + " business_gstin: \"06AABCU9605R1ZR\",\n" + + " gst_amount: 4000,\n" + + " cess_amount: 0,\n" + + " supply_type: \"interstate\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +QrCode qrcode = instance.qrCode.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| type* | string | The type of QR code i.e, `upi_qr`/`bharat_qr` | +| name | string | Label entered to identify the QR code. | +| usage* | string | Indicates if the QR code should be allowed to accept single payment or multiple payments i.e, `single_use`/`multiple_use` | +| fixed_amount | boolean | Indicates if the QR should accept payments of specific amounts or any amount. | +| payment_amount(* mandatory if fixed_amount is true) | integer | Indicates if the QR should accept payments of specific amounts or any amount. | +| customer_id | string | Unique identifier of the customer the QR code is linked with | +| description | string | A brief description about the QR code. | +| close_by | integer | 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. | +| notes | object | Key-value pair that can be used to store additional information about the QR code. Maximum 15 key-value pairs, 256 characters (maximum) each. | +| tax_invoice | object | This block contains information about the invoices. If not provided, the transaction will default to non-GST compliant UPI flow. | + +**Response:** +```json +{ + "id": "qr_HMsVL8HOpbMcjU", + "entity": "qr_code", + "created_at": 1623660301, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/BWcUVrLp", + "payment_amount": 300, + "status": "active", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838, + "tax_invoice": { + "number": "INV001", + "date": 1589994898, + "customer_name": "Gaurav Kumar", + "business_gstin": "06AABCU9605R1ZR", + "gst_amount": 4000, + "cess_amount": 0, + "supply_type": "interstate" + } +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all Qr code + +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List qrcode = instance.QrCode.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "qr_HO2jGkWReVBMNu", + "entity": "qr_code", + "created_at": 1623914648, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/w2CEwYmkAu", + "payment_amount": 300, + "status": "active", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838, + "closed_at": null, + "close_reason": null + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch a Qr code + +```java +String QrCodeId = "qr_HO2r1MDprYtWRT"; + +QrCode qrcode = instance.qrCode.fetch(QrCodeId); +``` + +**Parameters:** + +| Name | Type | Description | +|----------|---------|------------------------------------------------------------------------------| +| QrCodeId | string | The id of the qr code to be fetched | + +**Response:** +```json +{ + "id": "qr_HO2r1MDprYtWRT", + "entity": "qr_code", + "created_at": 1623915088, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/oCswTOcCo", + "payment_amount": 300, + "status": "active", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838, + "closed_at": null, + "close_reason": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Qr code for customer id + +```java +String CustomerId = "cust_HKsR5se84c5LTO"; + +JSONObject request = new JSONObject("{\"customer_id\":"+CustomerId+"}"); + +List qrcode = instance.QrCode.fetchAll(request) +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to which qr code need to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "qr_HMsgvioW64f0vh", + "entity": "qr_code", + "created_at": 1623660959, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/DTa2eQR", + "payment_amount": 300, + "status": "active", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch a Qr code for payment id + +```java + String PaymentId = "pay_FVmAstJWfsD3SO"; + + JSONObject request = new JSONObject("{\"payment_id\":"+PaymentId+"}"); + +List qrcode = instance.QrCode.fetchAll(request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| PaymentId* | string | The id of the payment to which qr code need to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "qr_HMsqRoeVwKbwAF", + "entity": "qr_code", + "created_at": 1623661499, + "name": "Fresh Groceries", + "usage": "multiple_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/eI9XD54Q", + "payment_amount": null, + "status": "active", + "description": "Buy fresh groceries", + "fixed_amount": false, + "payments_amount_received": 1000, + "payments_count_received": 1, + "notes": [], + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1624472999, + "close_reason": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch Payments for a QR Code + +```java +String QrCodeId = "qr_HMsVL8HOpbMcjU"; + +String json = "{\n" + + "\"count\" : 1\n" + + "}"; +JSONObject options = new JSONObject(json); + +List qrcode = instance.qrCode.fetchAllPayments(QrCodeId, options) +``` + +**Parameters:** + +| Name | Type | Description | +|-----------|---------|------------------------------------------------------------------------------| +| QrCodeId* | string | The id of the qr code to which payment where made | +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "pay_HMtDKn3TnF4D8x", + "entity": "payment", + "amount": 500, + "currency": "INR", + "status": "captured", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "QRv2 Payment", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gauri.kumari@okhdfcbank", + "email": "gauri.kumari@example.com", + "contact": "+919999999999", + "customer_id": "cust_HKsR5se84c5LTO", + "notes": [], + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "116514257019" + }, + "created_at": 1623662800 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Close a QR Code + +```js +String QrCodeId = "qr_HMsVL8HOpbMcjU"; + +QrCode qrcode = instance.QrCode.close(QrCodeId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------|---------|------------------------------------------------------------------------------| +| QrCodeId* | string | The id of the qr code to be closed | + +**Response:** +```json +{ + "id": "qr_HMsVL8HOpbMcjU", + "entity": "qr_code", + "created_at": 1623660301, + "name": "Store_1", + "usage": "single_use", + "type": "upi_qr", + "image_url": "https://rzp.io/i/BWcUVrLp", + "payment_amount": 300, + "status": "closed", + "description": "For Store 1", + "fixed_amount": true, + "payments_amount_received": 0, + "payments_count_received": 0, + "notes": { + "purpose": "Test UPI QR code notes" + }, + "customer_id": "cust_HKsR5se84c5LTO", + "close_by": 1681615838, + "closed_at": 1623660445, + "close_reason": "on_demand" +} +``` +------------------------------------------------------------------------------------------------------- + + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/qr-codes/)** \ No newline at end of file diff --git a/documents/refund.md b/documents/refund.md new file mode 100644 index 00000000..537e8db8 --- /dev/null +++ b/documents/refund.md @@ -0,0 +1,329 @@ +## Refunds + +### Create a normal refund + +```java +String PaymentId = "pay_FCXKPFtYfPXJPy"; + +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"speed\": \"normal\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty.\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"receipt\": \"Receipt No. 31\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.refund(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment | +| amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | +| speed | string | Here, it must be normal | +| notes | array | A key-value pair | +| receipt | string | A unique identifier provided by you for your internal reference. | + +**Response:** +```json +{ + "id": "rfnd_FP8QHiV938haTz", + "entity": "refund", + "amount": 500100, + "receipt": "Receipt No. 31", + "currency": "INR", + "payment_id": "pay_FCXKPFtYfPXJPy", + "notes": [], + "acquirer_data": { + "arn": null + }, + "created_at": 1597078866, + "batch_id": null, + "status": "processed", + "speed_processed": "normal" +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an instant refund + +```java + +String PaymentId = "pay_FCXKPFtYfPXJPy"; + +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"speed\": \"optimum\",\n" + + " \"receipt\": \"Receipt No. 31\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.refund(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment | +| amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| speed* | string | Here, it must be optimum | +| receipt | string | A unique identifier provided by you for your internal reference. | + +**Response:** +```json +{ + "id": "rfnd_FP8R8EGjGbPkVb", + "entity": "refund", + "amount": 500100, + "currency": "INR", + "payment_id": "pay_FC8MmhMBZPKDHF", + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "receipt": "Receipt No. 31", + "acquirer_data": { + "arn": null + }, + "created_at": 1597078914, + "batch_id": null, + "status": "processed", + "speed_requested": "optimum" +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch multiple refunds for a payment + +```java +String PaymentId = "pay_FIKOnlyii5QGNx"; + +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List payment = instance.Payments.fetchAllRefunds(paymentId,option); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-----------|--------------------------------------------------| +| PaymentId* | string | The id of the payment | +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Refund:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "rfnd_FP8DDKxqJif6ca", + "entity": "refund", + "amount": 300100, + "currency": "INR", + "payment_id": "pay_FIKOnlyii5QGNx", + "notes": { + "comment": "Comment for refund" + }, + "receipt": null, + "acquirer_data": { + "arn": "10000000000000" + }, + "created_at": 1597078124, + "batch_id": null, + "status": "processed", + "speed_processed": "normal", + "speed_requested": "optimum" + } + ] +} + ``` +------------------------------------------------------------------------------------------------------- + +### Fetch a specific refund for a payment +```java +String PaymentId = "pay_FIKOnlyii5QGNx"; + +String RefundId = "rfnd_FP8DDKxqJif6ca"; + +Payment payment = instance.Payments.fetchRefund(paymentId,refundId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | +| RefundId* | string | The id of the refund to be fetched | + +**Response:** +```json +{ + "id": "rfnd_FP8DDKxqJif6ca", + "entity": "refund", + "amount": 300100, + "currency": "INR", + "payment_id": "pay_FIKOnlyii5QGNx", + "notes": { + "comment": "Comment for refund" + }, + "receipt": null, + "acquirer_data": { + "arn": "10000000000000" + }, + "created_at": 1597078124, + "batch_id": null, + "status": "processed", + "speed_processed": "normal", + "speed_requested": "optimum" +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all refunds +```java +List refund = instance.Refunds.fetchAll(); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 2, + "items": [ + { + "id": "rfnd_FFX6AnnIN3puqW", + "entity": "refund", + "amount": 88800, + "currency": "INR", + "payment_id": "pay_FFX5FdEYx8jPwA", + "notes": { + "comment": "Issuing an instant refund" + }, + "receipt": null, + "acquirer_data": {}, + "created_at": 1594982363, + "batch_id": null, + "status": "processed", + "speed_processed": "optimum", + "speed_requested": "optimum" + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch particular refund +```java +String RefundId = "rfnd_EqWThTE7dd7utf"; + +List refund = instance.Refunds.fetch(RefundId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| refundId* | string | The id of the refund to be fetched | + +**Response:** +```json +{ + "id": "rfnd_EqWThTE7dd7utf", + "entity": "refund", + "amount": 6000, + "currency": "INR", + "payment_id": "pay_EpkFDYRirena0f", + "notes": { + "comment": "Issuing an instant refund" + }, + "receipt": null, + "acquirer_data": { + "arn": "10000000000000" + }, + "created_at": 1589521675, + "batch_id": null, + "status": "processed", + "speed_processed": "optimum", + "speed_requested": "optimum" +} +``` +------------------------------------------------------------------------------------------------------- + +### Update the refund +```java +String RefundId = "rfnd_EqWThTE7dd7utf"; + +String json "{\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty.\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Refund refund = instance.Refunds.edit(RefundId,request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| refundId* | string | The id of the refund to be fetched | +| notes* | array | A key-value pair | + +**Response:** +```json +{ + "id": "rfnd_FP8DDKxqJif6ca", + "entity": "refund", + "amount": 300100, + "currency": "INR", + "payment_id": "pay_FIKOnlyii5QGNx", + "notes": { + "notes_key_1": "Beam me up Scotty.", + "notes_key_2": "Engage" + }, + "receipt": null, + "acquirer_data": { + "arn": "10000000000000" + }, + "created_at": 1597078124, + "batch_id": null, + "status": "processed", + "speed_processed": "normal", + "speed_requested": "optimum" +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/refunds/)** \ No newline at end of file diff --git a/documents/registerEmandate.md b/documents/registerEmandate.md new file mode 100644 index 00000000..6c66e348 --- /dev/null +++ b/documents/registerEmandate.md @@ -0,0 +1,457 @@ +## Register emandate and charge first payment together + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " fail_existing: 0,\n" + + " gstin: \"29XAbbA4369J1PA\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| fail_existing | string | If a customer with the same details already exists, the request throws an exception by default. Possible value is `0` or `1`| +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create order + +```java +String json = "{\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " method: \"emandate\",\n" + + " receipt: \"Receipt No. 5\",\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Engage\"\n" + + " },\n" + + " token: {\n" + + " first_payment_amount: 10000,\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 9999900,\n" + + " expire_at: 4102444799,\n" + + " notes: {\n" + + " \"note_key 1\": \"Tea, Earl Grey… decaf.\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " },\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 11214311215411,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0001233\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| customerId* | string | The id of the customer to be fetched | +| method* | string | Payment method used to make the registration transaction. Possible value is `emandate`. | +| receipt | string | Your system order reference id. | +| token | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#112-create-an-order) are supported | +| notes | object | A key-value pair | + +**Response:** +For create order response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#112-create-an-order) + +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#113-create-an-authorization-payment) for authorization payment + +----------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " type: \"link\",\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " description: \"Registration Link for Gaurav Kumar\",\n" + + " subscription_registration: {\n" + + " first_payment_amount: 100,\n" + + " method: \"emandate\",\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 50000,\n" + + " expire_at: 1634215992,\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 11214311215411,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " receipt: \"Receipt No. 5\",\n" + + " email_notify: 1,\n" + + " sms_notify: 1,\n" + + " expire_by: 1634215992,\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|---------------------------------------------------------------| +| customer | object | Details of the customer to whom the registration link will be sent. | +| type* | object | the value is `link`. | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| description* | string | A brief description of the payment. | +| subscription_registration | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#121-create-a-registration-link) are supported | +| receipt | string | Your system order reference id. | +| sms_notify | boolean | SMS notifications are to be sent by Razorpay (default : 1) | +| email_notify | boolean | Email notifications are to be sent by Razorpay (default : 1) | +| expire_by | integer | The timestamp, in Unix format, till when the customer can make the authorization payment. | +| notes | object | A key-value pair | + +**Response:** +For create registration link response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#12-using-a-registration-link) +------------------------------------------------------------------------------------------------------- + +## Create an order to charge the customer + +```java +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":1000, + "amount_paid":0, + "amount_due":1000, + "currency":"INR", + "receipt":"Receipt No. 1", + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1579782776 +} +``` +------------------------------------------------------------------------------------------------------- + +## Create a recurring payment + +```java +String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.createRecurringPayment(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address | +| contact* | string | The customer's phone number | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| orderId* | string | The id of the order to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | +| recurring* | boolean | Possible values is `0` or `1` | +| description | string | A brief description of the payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + +## Send/Resend notifications + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +``` +**Parameters:** + +| Name | Type |Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | +| medium* | string | Possible values are `sms` or `email` | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +## Cancel registration link + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | + +**Response:** +```json +{ + "id": "inv_FHrfRupD2ouKIt", + "entity": "invoice", + "receipt": "Receipt No. 1", + "invoice_number": "Receipt No. 1", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrfRw4TZU5Q2L", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 4102444799, + "issued_at": 1595491479, + "paid_at": null, + "cancelled_at": 1595491488, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491479, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/QlfexTj", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491480, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +## Fetch token by payment id + +```java +String PaymentId = "pay_1Aa00000000001"; + +Payment payment = instance.Payments.fetch(PaymentId) +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | + +**Response:** +For fetch token by payment id response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#21-fetch-token-by-payment-id) + +------------------------------------------------------------------------------------------------------- + +## Fetch tokens by customer id + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +List token = instance.Customers.fetchTokens(CustomerId); +``` +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "token_FHf94Uym9tdYFJ", + "entity": "token", + "token": "2wDPM7VAlXtjAR", + "bank": "HDFC", + "wallet": null, + "method": "emandate", + "vpa": null, + "recurring": true, + "recurring_details": { + "status": "confirmed", + "failure_reason": null + }, + "auth_type": "netbanking", + "mrn": null, + "used_at": 1595447381, + "created_at": 1595447381, + "bank_details": { + "beneficiary_name": "Gaurav Kumar", + "account_number": "1121431121541121", + "ifsc": "HDFC0000001", + "account_type": "savings" + }, + "max_amount": 9999900, + "expired_at": 1689971140, + "dcc_enabled": false + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +## Delete tokens + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +String TokenId = "token_FHf94Uym9tdYFJ"; + +instance.Customers.deleteToken(CustomerId, TokenId); +``` +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/)** \ No newline at end of file diff --git a/documents/registerNach.md b/documents/registerNach.md new file mode 100644 index 00000000..65f3d2b0 --- /dev/null +++ b/documents/registerNach.md @@ -0,0 +1,660 @@ +## Register nach and charge first payment together + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " fail_existing: 0,\n" + + " gstin: \"29XAbbA4369J1PA\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| fail_existing | string | If a customer with the same details already exists, the request throws an exception by default. Possible value is `0` or `1`| +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create Order + +```java +String json = "{\n" + +" amount: 100,\n" + +" currency: \"INR\",\n" + +" method: \"emandate\",\n" + +" receipt: \"Receipt No. 5\",\n" + +" notes: {\n" + +" \"note_key 1\": \"Beam me up Scotty\",\n" + +" \"note_key 2\": \"Engage\"\n" + +" },\n" + +" token: {\n" + +" first_payment_amount: 10000,\n" + +" auth_type: \"netbanking\",\n" + +" max_amount: 9999900,\n" + +" expire_at: 4102444799,\n" + +" notes: {\n" + +" \"note_key 1\": \"Tea, Earl Grey… decaf.\",\n" + +" \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + +" },\n" + +" bank_account: {\n" + +" beneficiary_name: \"Gaurav Kumar\",\n" + +" account_number: 11214311215411,\n" + +" account_type: \"savings\",\n" + +" ifsc_code: \"HDFC0001233\"\n" + +" }\n" + +" }\n" + +"}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| customerId* | string | The id of the customer to be fetched | +| method* | string | Payment method used to make the registration transaction. Possible value is `nach`. | +| receipt | string | Your system order reference id. | +| token | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/auto-debit/#112-create-an-order) are supported | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000001", + "entity":"order", + "amount":0, + "amount_paid":0, + "amount_due":0, + "currency":"INR", + "receipt":"rcptid #10", + "offer_id":null, + "offers":{ + "entity":"collection", + "count":0, + "items":[] + }, + "status":"created", + "attempts":0, + "notes": { + "notes_key_1": "Beam me up Scotty", + "notes_key_2": "Engage" + }, + "created_at":1579775420, + "token":{ + "method":"nach", + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "recurring_status":null, + "failure_reason":null, + "currency":"INR", + "max_amount":10000000, + "auth_type":"physical", + "expire_at":1580480689, + "nach":{ + "create_form":true, + "form_reference1":"Recurring Payment for Gaurav Kumar", + "form_reference2":"Method Paper NACH", + "prefilled_form":"https://rzp.io/i/bitw", + "upload_form_url":"https://rzp.io/i/gts", + "description":"Paper NACH Gaurav Kumar" + }, + "bank_account":{ + "ifsc":"HDFC0000001", + "bank_name":"HDFC Bank", + "name":"Gaurav Kumar", + "account_number":"11214311215411", + "account_type":"savings", + "beneficiary_email":"gaurav.kumar@example.com", + "beneficiary_mobile":"9876543210" + }, + "first_payment_amount":10000 + } +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/paper-nach/auto-debit/#113-create-an-authorization-payment) for authorization payment + +----------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " type: \"link\",\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " description: \"Registration Link for Gaurav Kumar\",\n" + + " subscription_registration: {\n" + + " first_payment_amount: 100,\n" + + " method: \"emandate\",\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 50000,\n" + + " expire_at: 1634215992,\n" + + " bank_account: {\n" + + " beneficiary_name: \"Gaurav Kumar\",\n" + + " account_number: 11214311215411,\n" + + " account_type: \"savings\",\n" + + " ifsc_code: \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " receipt: \"Receipt No. 5\",\n" + + " email_notify: 1,\n" + + " sms_notify: 1,\n" + + " expire_by: 1634215992,\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|---------------------------------------------------------------| +| customer | object | Details of the customer to whom the registration link will be sent. | +| type* | object | the value is `link`. | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| description* | string | A brief description of the payment. | +| subscription_registration | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/auto-debit/#121-create-a-registration-link) are supported | +| receipt | string | Your system order reference id. | +| sms_notify | boolean | SMS notifications are to be sent by Razorpay (default : 1) | +| email_notify | boolean | Email notifications are to be sent by Razorpay (default : 1) | +| expire_by | integer | The timestamp, in Unix format, till when the customer can make the authorization payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "inv_FHrZiAubEzDdaq", + "entity": "invoice", + "receipt": "Receipt No. 27", + "invoice_number": "Receipt No. 27", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrZiBOkWHZPOp", + "line_items": [], + "payment_id": null, + "status": "issued", + "expire_by": 1647483647, + "issued_at": 1595491154, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491154, + "terms": null, + "partial_payment": false, + "gross_amount": 0, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 0, + "amount_paid": 0, + "amount_due": 0, + "currency": "INR", + "currency_symbol": "₹", + "description": "12 p.m. Meals", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/bzDYbNg", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491154, + "idempotency_key": null, + "token": { + "method": "nach", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "recurring_status": null, + "failure_reason": null, + "currency": "INR", + "max_amount": 50000, + "auth_type": "physical", + "expire_at": 1947483647, + "nach": { + "create_form": true, + "form_reference1": "Recurring Payment for Gaurav Kumar", + "form_reference2": "Method Paper NACH", + "prefilled_form": "https://rzp.io/i/exdIzYN", + "upload_form_url": "https://rzp.io/i/bzDYbNg", + "description": "12 p.m. Meals" + }, + "bank_account": { + "ifsc": "HDFC0001233", + "bank_name": "HDFC Bank", + "name": "Gaurav Kumar", + "account_number": "11214311215411", + "account_type": "savings", + "beneficiary_email": "gaurav.kumar@example.com", + "beneficiary_mobile": "9123456780" + }, + "first_payment_amount": 0 + }, + "nach_form_url": "https://rzp.io/i/exdIzYN" +} +``` +------------------------------------------------------------------------------------------------------- + +## Create an order to charge the customer + +```java +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":1000, + "amount_paid":0, + "amount_due":1000, + "currency":"INR", + "receipt":"Receipt No. 1", + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1579782776 +} +``` +------------------------------------------------------------------------------------------------------- + +## Create a recurring payment + +```java +String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.createRecurringPayment(request); +``` +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address | +| contact* | string | The customer's phone number | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | +| orderId* | string | The id of the order to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | +| recurring* | boolean | Possible values is `0` or `1` | +| description | string | A brief description of the payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + +## Send/Resend notifications + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +``` +**Parameters:** + +| Name | Type |Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | +| medium* | string | Possible values are `sms` or `email` | + +**Response:** +```json +{ + "success": true +} +``` + +------------------------------------------------------------------------------------------------------- + +## Cancel registration link + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be fetched | + +**Response:** +```json +{ + "id": "inv_FHrZiAubEzDdaq", + "entity": "invoice", + "receipt": "Receipt No. 27", + "invoice_number": "Receipt No. 27", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrZiBOkWHZPOp", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 1647483647, + "issued_at": 1595491154, + "paid_at": null, + "cancelled_at": 1595491339, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491154, + "terms": null, + "partial_payment": false, + "gross_amount": 0, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 0, + "amount_paid": 0, + "amount_due": 0, + "currency": "INR", + "currency_symbol": "₹", + "description": "12 p.m. Meals", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/bzDYbNg", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491154, + "idempotency_key": null, + "token": { + "method": "nach", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "recurring_status": null, + "failure_reason": null, + "currency": "INR", + "max_amount": 50000, + "auth_type": "physical", + "expire_at": 1947483647, + "nach": { + "create_form": true, + "form_reference1": "Recurring Payment for Gaurav Kumar", + "form_reference2": "Method Paper NACH", + "prefilled_form": "https://rzp.io/i/tSYd5aV", + "upload_form_url": "https://rzp.io/i/bzDYbNg", + "description": "12 p.m. Meals" + }, + "bank_account": { + "ifsc": "HDFC0001233", + "bank_name": "HDFC Bank", + "name": "Gaurav Kumar", + "account_number": "11214311215411", + "account_type": "savings", + "beneficiary_email": "gaurav.kumar@example.com", + "beneficiary_mobile": "9123456780" + }, + "first_payment_amount": 0 + }, + "nach_form_url": "https://rzp.io/i/tSYd5aV" +} +``` +------------------------------------------------------------------------------------------------------- + +## Fetch token by payment id + +```java +String PaymentId = "pay_1Aa00000000001"; + +Payment payment = instance.Payments.fetch(PaymentId) +``` +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | + +**Response:** +```json +{ + "id": "pay_EnLNTjINiPkMEZ", + "entity": "payment", + "amount": 0, + "currency": "INR", + "status": "captured", + "order_id": "order_EnLLfglmKksr4K", + "invoice_id": "inv_EnLLfgCzRfcMuh", + "international": false, + "method": "nach", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "Invoice #inv_EnLLfgCzRfcMuh", + "card_id": null, + "bank": "UTIB", + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_EnLNTnn7uyRg5V", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": {}, + "created_at": 1588827564 +} +``` +------------------------------------------------------------------------------------------------------- + +## Fetch tokens by customer id + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +List token = instance.Customers.fetchTokens(CustomerId); +``` +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "token_EhYgIE3pOyMQpD", + "entity": "token", + "token": "3mQ5Czc6APNppI", + "bank": "HDFC", + "wallet": null, + "method": "nach", + "vpa": null, + "recurring": true, + "recurring_details": { + "status": "confirmed", + "failure_reason": null + }, + "auth_type": "physical", + "mrn": null, + "used_at": 1587564373, + "created_at": 1587564373, + "dcc_enabled": false + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +## Delete tokens + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +String TokenId = "token_FHf94Uym9tdYFJ"; + +instance.Customers.deleteToken(CustomerId, TokenId); +``` +**Parameters:** + +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/auto-debit/)** \ No newline at end of file diff --git a/documents/settlement.md b/documents/settlement.md new file mode 100644 index 00000000..6b6290fc --- /dev/null +++ b/documents/settlement.md @@ -0,0 +1,471 @@ +## Settlements + +### Fetch all settlements + +```java +List settlement = razorpayclient.Settlement.fetchAll(); +``` + +**Parameters:** + + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the settlement were created | +| to | timestamp | timestamp before which the settlement were created | +| count | integer | number of settlements to fetch (default: 10) | +| skip | integer | number of settlements to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "setl_DGlQ1Rj8os78Ec", + "entity": "settlement", + "amount": 9973635, + "status": "processed", + "fees": 471699, + "tax": 42070, + "utr": "1568176960vxp0rj", + "created_at": 1568176960 + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch a settlement + +```java +String SettlementId = "setl_DGlQ1Rj8os78Ec"; + +Settlement settlement = razorpayclient.Settlement.fetch(SettlementId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| SettlementId* | string | The id of the settlement to be fetched | + +**Response:** +```json +{ + "id": "setl_DGlQ1Rj8os78Ec", + "entity": "settlement", + "amount": 9973635, + "status": "processed", + "fees": 471699, + "tax": 42070, + "utr": "1568176960vxp0rj", + "created_at": 1568176960 +} +``` +------------------------------------------------------------------------------------------------------- + +### Settlement report for a month + +```java +String json = "{\n" + + "year: 2020,\n" + + "month: 9\n" + + "}"; + +JSONObject request = new JSONObject(json); + +List settlement = instance.Settlement.reports(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| year* | integer | The year the settlement was received in the `YYYY` format. For example, `2020` | +| month* | integer | The month the settlement was received in the `MM` format. For example, `09` | +| day | integer | The date the settlement was received in the `DD` format. For example, `01` | +| count | integer | number of settlements to fetch (default: 10) | +| skip | integer | number of settlements to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 4, + "items": [ + { + "entity_id": "pay_DEXrnipqTmWVGE", + "type": "payment", + "debit": 0, + "credit": 97100, + "amount": 100000, + "currency": "INR", + "fee": 2900, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1567692556, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": "Recurring Payment via Subscription", + "notes": "{}", + "payment_id": null, + "settlement_utr": "1568176960vxp0rj", + "order_id": "order_DEXrnRiR3SNDHA", + "order_receipt": null, + "method": "card", + "card_network": "MasterCard", + "card_issuer": "KARB", + "card_type": "credit", + "dispute_id": null + }, + { + "entity_id": "rfnd_DGRcGzZSLyEdg1", + "type": "refund", + "debit": 242500, + "credit": 0, + "amount": 242500, + "currency": "INR", + "fee": 0, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1568107224, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": null, + "notes": "{}", + "payment_id": "pay_DEXq1pACSqFxtS", + "settlement_utr": "1568176960vxp0rj", + "order_id": "order_DEXpmZgffXNvuI", + "order_receipt": null, + "method": "card", + "card_network": "MasterCard", + "card_issuer": "KARB", + "card_type": "credit", + "dispute_id": null + }, + { + "entity_id": "trf_DEUoCEtdsJgvl7", + "type": "transfer", + "debit": 100296, + "credit": 0, + "amount": 100000, + "currency": "INR", + "fee": 296, + "tax": 46, + "on_hold": false, + "settled": true, + "created_at": 1567681786, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": null, + "notes": null, + "payment_id": "pay_DEApNNTR6xmqJy", + "settlement_utr": "1568176960vxp0rj", + "order_id": null, + "order_receipt": null, + "method": null, + "card_network": null, + "card_issuer": null, + "card_type": null, + "dispute_id": null + }, + { + "entity_id": "adj_EhcHONhX4ChgNC", + "type": "adjustment", + "debit": 0, + "credit": 1012, + "amount": 1012, + "currency": "INR", + "fee": 0, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1567681786, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "description": "test reason", + "notes": null, + "payment_id": null, + "settlement_utr": null, + "order_id": null, + "order_receipt": null, + "method": null, + "card_network": null, + "card_issuer": null, + "card_type": null, + "dispute_id": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Settlement recon + +```java + +String json = "{\n" + + " year: 2020,\n" + + " month: 9,\n" + + " day:11\n" + + "}"; + +JSONObject request = new JSONObject(json); + +List settlement = instance.Settlement.reports(request); +``` +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| year* | integer | The year the settlement was received in the `YYYY` format. For example, `2020` | +| month* | integer | The month the settlement was received in the `MM` format. For example, `09` | +| day | integer | The day the settlement was received in the `DD` format. For example, | + +**Response:** +```json +{ + "entity": "collection", + "count": 4, + "items": [ + { + "entity_id": "pay_DEXrnipqTmWVGE", + "type": "payment", + "debit": 0, + "credit": 97100, + "amount": 100000, + "currency": "INR", + "fee": 2900, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1567692556, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": "Recurring Payment via Subscription", + "notes": "{}", + "payment_id": null, + "settlement_utr": "1568176960vxp0rj", + "order_id": "order_DEXrnRiR3SNDHA", + "order_receipt": null, + "method": "card", + "card_network": "MasterCard", + "card_issuer": "KARB", + "card_type": "credit", + "dispute_id": null + }, + { + "entity_id": "rfnd_DGRcGzZSLyEdg1", + "type": "refund", + "debit": 242500, + "credit": 0, + "amount": 242500, + "currency": "INR", + "fee": 0, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1568107224, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": null, + "notes": "{}", + "payment_id": "pay_DEXq1pACSqFxtS", + "settlement_utr": "1568176960vxp0rj", + "order_id": "order_DEXpmZgffXNvuI", + "order_receipt": null, + "method": "card", + "card_network": "MasterCard", + "card_issuer": "KARB", + "card_type": "credit", + "dispute_id": null + }, + { + "entity_id": "trf_DEUoCEtdsJgvl7", + "type": "transfer", + "debit": 100296, + "credit": 0, + "amount": 100000, + "currency": "INR", + "fee": 296, + "tax": 46, + "on_hold": false, + "settled": true, + "created_at": 1567681786, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "credit_type": "default", + "description": null, + "notes": null, + "payment_id": "pay_DEApNNTR6xmqJy", + "settlement_utr": "1568176960vxp0rj", + "order_id": null, + "order_receipt": null, + "method": null, + "card_network": null, + "card_issuer": null, + "card_type": null, + "dispute_id": null + }, + { + "entity_id": "adj_EhcHONhX4ChgNC", + "type": "adjustment", + "debit": 0, + "credit": 1012, + "amount": 1012, + "currency": "INR", + "fee": 0, + "tax": 0, + "on_hold": false, + "settled": true, + "created_at": 1567681786, + "settled_at": 1568176960, + "settlement_id": "setl_DGlQ1Rj8os78Ec", + "posted_at": null, + "description": "test reason", + "notes": null, + "payment_id": null, + "settlement_utr": null, + "order_id": null, + "order_receipt": null, + "method": null, + "card_network": null, + "card_issuer": null, + "card_type": null, + "dispute_id": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Create on-demand settlement + +```java +String json = "{\n" + + " \"amount\": 1221,\n" + + " \"settle_full_balance\": false,\n" + + " \"description\": \"Testing\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Settlement settlement = instance.Settlement.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| amount*| integer | Maximum amount that can be settled | +| settle_full_balance* | boolean | true or false | +| description | string | The description may not be greater than 30 characters | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "setlod_FNj7g2YS5J67Rz", + "entity": "settlement.ondemand", + "amount_requested": 200000, + "amount_settled": 0, + "amount_pending": 199410, + "amount_reversed": 0, + "fees": 590, + "tax": 90, + "currency": "INR", + "settle_full_balance": false, + "status": "initiated", + "description": "Need this to make vendor payments.", + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1596771429, + "ondemand_payouts": { + "entity": "collection", + "count": 1, + "items": [ + { + "id": "setlodp_FNj7g2cbvw8ueO", + "entity": "settlement.ondemand_payout", + "initiated_at": null, + "processed_at": null, + "reversed_at": null, + "amount": 200000, + "amount_settled": null, + "fees": 590, + "tax": 90, + "utr": null, + "status": "created", + "created_at": 1596771429 + } + ] + } +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all on-demand settlements + +```java +List settlement = instance.Settlement.fetchAllDemand(options) +``` +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:**
+For all on-demand settlements response please click [here](https://razorpay.com/docs/api/settlements/#fetch-all-on-demand-settlements) + +------------------------------------------------------------------------------------------------------- + +### Fetch on-demand settlement by ID + +```java +String SettlementId = "setlodp_FNj7g2cbvw8ueO"; + +instance.Settlement.fetchDemandSettlement(SettlementId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|--------|-----------------------------------| +| SettlementId* | string | Settlement Id of the On-demand settlement| + +**Response:** +For on-demand settlement by ID response please click [here](https://razorpay.com/docs/api/settlements/#fetch-on-demand-settlements-by-id) + +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/settlements/)** \ No newline at end of file diff --git a/documents/subscription.md b/documents/subscription.md new file mode 100644 index 00000000..4d772af7 --- /dev/null +++ b/documents/subscription.md @@ -0,0 +1,756 @@ +## Subscriptions + +### Create subscription + +```java +String json = "{\n" + + " plan_id: \"plan_7wAosPWtrkhqZw\",\n" + + " customer_notify: 1,\n" + + " quantity: 5,\n" + + " total_count: 6,\n" + + " start_at: 1495995837,\n" + + " addons: [\n" + + " {\n" + + " item: {\n" + + " name: \"Delivery charges\",\n" + + " amount: 30000,\n" + + " currency: \"INR\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " notes: {\n" + + " key1: \"value3\",\n" + + " key2: \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Subscription subscription = instance.Subscriptions.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| plan_id* | string | The unique identifier for a plan that should be linked to the subscription.| +| total_count* | string | The number of billing cycles for which the customer should be charged | +| customer_notify | boolean | Indicates whether the communication to the customer would be handled by you or us | +| quantity | integer | The number of times the customer should be charged the plan amount per invoice | +| start_at | integer | The timestamp, in Unix format, for when the subscription should start. If not passed, the subscription starts immediately after the authorization payment. | +| expire_by | integer | The timestamp, in Unix format, till when the customer can make the authorization payment. | +| addons | object | Object that contains details of any upfront amount you want to collect as part of the authorization transaction. | +| notes | object | Notes you can enter for the contact for future reference. | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "status": "created", + "current_start": null, + "current_end": null, + "ended_at": null, + "quantity": 1, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at": 1580453311, + "start_at": 1580626111, + "end_at": 1583433000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 0, + "customer_notify": true, + "created_at": 1580280581, + "expire_by": 1580626111, + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 5 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create subscription link + +```java +String json = "{\n" + + " plan_id: \"plan_HoYg68p5kmuvzD\",\n" + + " total_count: 12,\n" + + " quantity: 1,\n" + + " expire_by: 1633237807,\n" + + " customer_notify: 1,\n" + + " addons: [\n" + + " {\n" + + " item: {\n" + + " name: \"Delivery charges\",\n" + + " amount: 30000,\n" + + " currency: \"INR\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " notify_info: {\n" + + " notify_phone: 9123456789,\n" + + " notify_email: \"gaurav.kumar@example.com\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Subscription subscription = instance.Subscriptions.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| plan_id* | string | The unique identifier for a plan that should be linked to the subscription.| +| total_count* | string | The number of billing cycles for which the customer should be charged | +| customer_notify | boolean | Indicates whether the communication to the customer would be handled by you or us | +| quantity | integer | The number of times the customer should be charged the plan amount per invoice | +| start_at | integer | The timestamp, in Unix format, for when the subscription should start. If not passed, the subscription starts immediately after the authorization payment. | +| expire_by | integer | The timestamp, in Unix format, till when the customer can make the authorization payment. | +| addons | object | Object that contains details of any upfront amount you want to collect as part of the authorization transaction. | +| notes | object | Notes you can enter for the contact for future reference. | +| notify_info | object | The customer's email and phone number to which notifications are to be sent. (PN: Use this object only if you have set the `customer_notify` parameter to 1. That is, Razorpay sends notifications to the customer.) | + +**Response:** +```json +{ + "id":"sub_00000000000002", + "entity":"subscription", + "plan_id":"plan_00000000000001", + "status":"created", + "current_start":null, + "current_end":null, + "ended_at":null, + "quantity":1, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at":1580453311, + "start_at":1580453311, + "end_at":1587061800, + "auth_attempts":0, + "total_count":12, + "paid_count":0, + "customer_notify":true, + "created_at":1580283117, + "expire_by":1581013800, + "short_url":"https://rzp.io/i/m0y0f", + "has_scheduled_changes":false, + "change_scheduled_at":null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count":12 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all subscriptions + +```js +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List subscription = instance.Subscriptions.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | +| plan_id | string | The unique identifier of the plan for which you want to retrieve all the subscriptions | + +**Response:** +```json + +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "customer_id": "cust_D00000000000001", + "status": "active", + "current_start": 1577355871, + "current_end": 1582655400, + "ended_at": null, + "quantity": 1, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "charge_at": 1577385991, + "offer_id": "offer_JHD834hjbxzhd38d", + "start_at": 1577385991, + "end_at": 1603737000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 1, + "customer_notify": true, + "created_at": 1577356081, + "expire_by": 1577485991, + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "remaining_count": 5 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch particular subscription + +```java +String SubscriptionId = "sub_00000000000001"; + +Subscription subscription = instance.Subscriptions.fetch(SubscriptionId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be fetched | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "customer_id": "cust_D00000000000001", + "status": "active", + "current_start": 1577355871, + "current_end": 1582655400, + "ended_at": null, + "quantity": 1, + "notes":{ + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "charge_at": 1577385991, + "start_at": 1577385991, + "end_at": 1603737000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 1, + "customer_notify": true, + "created_at": 1577356081, + "expire_by": 1577485991, + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 5 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Cancel particular subscription + +```java +String json = "{\n" + + "\"cancel_at_cycle_end\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +Subscription subscription = instance.Subscription.cancel(subscriptionId,options) +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be cancelled | +| cancel_at_cycle_end | boolean | Possible values:
0 (default): Cancel the subscription immediately.
1: Cancel the subscription at the end of the current billing cycle. | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "customer_id": "cust_D00000000000001", + "status": "cancelled", + "current_start": 1580453311, + "current_end": 1581013800, + "ended_at": 1580288092, + "quantity": 1, + "notes":{ + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "charge_at": 1580453311, + "start_at": 1577385991, + "end_at": 1603737000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 1, + "customer_notify": true, + "created_at": 1580283117, + "expire_by": 1581013800, + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 5 +} +``` +------------------------------------------------------------------------------------------------------- + +### Update particular subscription + +```java + +String SubscriptionId = "sub_00000000000002"; + +Subscription subscription = instance.Subscription.update(SubscriptionId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| SubscriptionId* | string | The id of the subscription to be updated | +| options | object | All parameters listed [here](https://razorpay.com/docs/api/subscriptions/#update-a-subscription) for update | + +**Response:** +```json +{ + "id":"sub_00000000000002", + "entity":"subscription", + "plan_id":"plan_00000000000002", + "customer_id":"cust_00000000000002", + "status":"authenticated", + "current_start":null, + "current_end":null, + "ended_at":null, + "quantity":3, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at":1580453311, + "start_at":1580453311, + "end_at":1606588200, + "auth_attempts":0, + "total_count":6, + "paid_count":0, + "customer_notify":true, + "created_at":1580283807, + "expire_by":1580626111, + "short_url":"https://rzp.io/i/yeDkUKy", + "has_scheduled_changes":false, + "change_scheduled_at":null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count":6 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch details of pending update + +```java +String SubscriptionId = "sub_00000000000001"; + +Subscription subscription = instance.Subscription.fetchPendingUpdate(SubscriptionId); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|-----------|--------------------------------------------------| +| SubscriptionId* | string | The id of the subscription to fetch pending update | + +**Response:** +```json +{ + "id":"sub_00000000000001", + "entity":"subscription", + "plan_id":"plan_00000000000003", + "customer_id":"cust_00000000000001", + "status":"active", + "current_start":1580284732, + "current_end":1580841000, + "ended_at":null, + "quantity":25, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at":1580841000, + "start_at":1580284732, + "end_at":1611081000, + "auth_attempts":0, + "total_count":6, + "paid_count":1, + "customer_notify":true, + "created_at":1580284702, + "expire_by":1580626111, + "short_url":"https://rzp.io/i/fFWTkbf", + "has_scheduled_changes":true, + "change_scheduled_at":1557253800, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count":5 +} +``` +------------------------------------------------------------------------------------------------------- + +### Cancel a update + +```java +String SubscriptionId = "sub_00000000000001"; + +Subscription subscription = instance.Subscription.cancelPendingUpdate(SubscriptionId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| SubscriptionId* | string | The id of the subscription to be cancel an update | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000003", + "customer_id": "cust_00000000000001", + "status": "active", + "current_start": 1580284732, + "current_end": 1580841000, + "ended_at": null, + "quantity": 1, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "charge_at": 1580841000, + "start_at": 1580284732, + "end_at": 1611081000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 1, + "customer_notify": true, + "created_at": 1580284702, + "expire_by": 1580626111, + "short_url": "https://rzp.io/i/fFWTkbf", + "has_scheduled_changes": false, + "change_scheduled_at": 1527858600, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 5 +} +``` +------------------------------------------------------------------------------------------------------- + +### Pause a subscription + +```js +String SubscriptionId = "sub_00000000000001"; + +String json = "{\n" + + "pause_at : 'now'\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Subscription subscription = instance.Subscription.pause(SubscriptionId,request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be paused | +| pause_at | string | To pause the subscription, possible values: `now` | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "status": "paused", + "current_start": null, + "current_end": null, + "ended_at": null, + "quantity": 1, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at": null, + "start_at": 1580626111, + "end_at": 1583433000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 0, + "customer_notify": true, + "created_at": 1580280581, + "paused_at": 1590280581, + "expire_by": 1580626111, + "pause_initiated_by": "self", + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 6 +} +``` +------------------------------------------------------------------------------------------------------- + +### Resume a subscription + +```java +String SubscriptionId = "sub_00000000000001"; + +String json = "{\n" + + "resume_at : 'now'\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Subscription subscription = instance.Subscription.resume(SubscriptionId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be resumed | +| resume_at | string | To resume the subscription, possible values: `now` | + +**Response:** +```json +{ + "id": "sub_00000000000001", + "entity": "subscription", + "plan_id": "plan_00000000000001", + "status": "active", + "current_start": null, + "current_end": null, + "ended_at": null, + "quantity": 1, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "charge_at": 1580453311, + "start_at": 1580626111, + "end_at": 1583433000, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 0, + "customer_notify": true, + "created_at": 1580280581, + "paused_at": 1590280581, + "expire_by": 1580626111, + "pause_initiated_by": null, + "short_url": "https://rzp.io/i/z3b1R61A9", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "api", + "offer_id":"offer_JHD834hjbxzhd38d", + "remaining_count": 6 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all invoices for a subscription + +```java +String json = "{\n" + + "\"subscription_id\":subscriptionId\n" + + "}"; + +JSONObject request = new JSONObject(json); + +List invoice = instance.Invoices.fetchAll(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to fetch invoices | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "inv_00000000000003", + "entity": "invoice", + "receipt": null, + "invoice_number": null, + "customer_id": "cust_00000000000001", + "customer_details": { + "id": "cust_00000000000001", + "name": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": null, + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "+919876543210" + }, + "order_id": "order_00000000000002", + "subscription_id": "sub_00000000000001", + "line_items": [ + { + "id": "li_00000000000003", + "item_id": null, + "ref_id": null, + "ref_type": null, + "name": "Monthly Plan", + "description": null, + "amount": 99900, + "unit_amount": 99900, + "gross_amount": 99900, + "tax_amount": 0, + "taxable_amount": 99900, + "net_amount": 99900, + "currency": "INR", + "type": "plan", + "tax_inclusive": false, + "hsn_code": null, + "sac_code": null, + "tax_rate": null, + "unit": null, + "quantity": 1, + "taxes": [] + } + ], + "payment_id": "pay_00000000000002", + "status": "paid", + "expire_by": null, + "issued_at": 1593344888, + "paid_at": 1593344889, + "cancelled_at": null, + "expired_at": null, + "sms_status": null, + "email_status": null, + "date": 1593344888, + "terms": null, + "partial_payment": false, + "gross_amount": 99900, + "tax_amount": 0, + "taxable_amount": 99900, + "amount": 99900, + "amount_paid": 99900, + "amount_due": 0, + "currency": "INR", + "currency_symbol": "₹", + "description": null, + "notes": [], + "comment": null, + "short_url": "https://rzp.io/i/Ys4feGqEp", + "view_less": true, + "billing_start": 1594405800, + "billing_end": 1597084200, + "type": "invoice", + "group_taxes_discounts": false, + "created_at": 1593344888, + "idempotency_key": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete offer linked to a subscription + +```java +String SubscriptionId = "sub_I3GGEs7Xgmnozy"; + +String OfferId = "offer_JHD834hjbxzhd38d"; + +instance.Subscription.deleteSubscriptionOffer(SubscriptionId, OfferId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to offer need to be deleted | +| offerId* | string | The id of the offer linked to subscription | + +**Response:** +```json +{ + "id": "sub_I3GGEs7Xgmnozy", + "entity": "subscription", + "plan_id": "plan_HuXrfsI0ZZ3peu", + "customer_id": "cust_I3FToKbnExwDLu", + "status": "active", + "current_start": 1632914901, + "current_end": 1635445800, + "ended_at": null, + "quantity": 1, + "notes": [], + "charge_at": 1635445800, + "start_at": 1632914901, + "end_at": 1645986600, + "auth_attempts": 0, + "total_count": 6, + "paid_count": 1, + "customer_notify": true, + "created_at": 1632914246, + "expire_by": 1635532200, + "short_url": "https://rzp.io/i/SOvRWaYP81", + "has_scheduled_changes": false, + "change_scheduled_at": null, + "source": "dashboard", + "payment_method": "card", + "offer_id": null, + "remaining_count": 5 +} +``` +------------------------------------------------------------------------------------------------------- + +### Authentication Transaction + +Please refer this [doc](https://razorpay.com/docs/api/subscriptions/#authentication-transaction) for authentication of transaction + + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/subscriptions/#subscriptions)** \ No newline at end of file diff --git a/documents/token.md b/documents/token.md new file mode 100644 index 00000000..20e5dd18 --- /dev/null +++ b/documents/token.md @@ -0,0 +1,203 @@ +## Tokens + +### Fetch token by payment id + +```java +String Paymentid = "pay_FHfqtkRzWvxky4"; + +Payment payment = instance.Payments.fetch(Paymentids); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| paymentId* | string | The id of the payment to be fetched | + +**Response:** +```json +{ + "id": "pay_FHfqtkRzWvxky4", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": "order_FHfnswDdfu96HQ", + "invoice_id": null, + "international": false, + "method": "card", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": null, + "card_id": "card_F0zoXUp4IPPGoI", + "bank": null, + "wallet": null, + "vpa": null, + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_FHfn3rIiM1Z8nr", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "auth_code": "541898" + }, + "created_at": 1595449871 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch tokens by customer id + +```js +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +List customer = instance.Customers.fetchTokens(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"token_HouA2OQR5Z2jTL", + "entity":"token", + "token":"2JPRk664pZHUWG", + "bank":null, + "wallet":null, + "method":"card", + "card":{ + "entity":"card", + "name":"Gaurav Kumar", + "last4":"8950", + "network":"Visa", + "type":"credit", + "issuer":"STCB", + "international":false, + "emi":false, + "sub_type":"consumer", + "expiry_month":12, + "expiry_year":2021, + "flows":{ + "otp":true, + "recurring":true + } + }, + "recurring":true, + "recurring_details":{ + "status":"confirmed", + "failure_reason":null + }, + "auth_type":null, + "mrn":null, + "used_at":1629779657, + "created_at":1629779657, + "expired_at":1640975399, + "dcc_enabled":false, + "billing_address":null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch particular token +```js +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +String TokenId = "token_HouA2OQR5Z2jTL"; + +Customer customer = instance.Customers.fetchToken(CustomerId, TokenId) +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "id": "token_Hxe0skTXLeg9pF", + "entity": "token", + "token": "F85BgXnGVwcuqV", + "bank": null, + "wallet": null, + "method": "card", + "card": { + "entity": "card", + "name": "ankit", + "last4": "5449", + "network": "MasterCard", + "type": "credit", + "issuer": "UTIB", + "international": false, + "emi": false, + "sub_type": "consumer", + "expiry_month": 12, + "expiry_year": 2024, + "flows": { + "recurring": true + } + }, + "recurring": true, + "auth_type": null, + "mrn": null, + "used_at": 1632976165, + "created_at": 1631687852, + "expired_at": 1634215992, + "dcc_enabled": false +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete token + +```js +String CustomerId = "cust_DtHaBuooGHTuyZ"; + +String TokenId = "token_HouA2OQR5Z2jTL"; + +Customer customer = instance.Customers.deleteToken(CustomerId, TokenId) +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/upi/tokens/)** \ No newline at end of file diff --git a/documents/transfer.md b/documents/transfer.md new file mode 100644 index 00000000..df9f112b --- /dev/null +++ b/documents/transfer.md @@ -0,0 +1,629 @@ +## Transfers + +### Create transfers from payment + +```java +String PaymentId = "pay_E8JR8E0XyjUSZd"; +String json = "{\n" + + " \"transfers\": [\n" + + " {\n" + + " \"account\": 'acc_HgzcrXeSLfNP9U',\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"notes\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"roll_no\": \"IEC2011025\"\n" + + " },\n" + + " \"linked_account_notes\": [\n" + + " \"branch\"\n" + + " ],\n" + + " \"on_hold\": 1,\n" + + " \"on_hold_until\": 1671222870\n" + + " }\n" + + " ]\n" + + " }"; + +JSONObject request = new JSONObject(json); + +instance.Payments.transfer(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | +| transfers | object | All parameters listed [here](https://razorpay.com/docs/api/route/#create-transfers-from-payments) are supported | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "trf_E9uhYLFLLZ2pks", + "entity": "transfer", + "source": "pay_E8JR8E0XyjUSZd", + "recipient": "acc_CPRsN1LkFccllA", + "amount": 100, + "currency": "INR", + "amount_reversed": 0, + "notes": { + "name": "Gaurav Kumar", + "roll_no": "IEC2011025" + }, + "on_hold": true, + "on_hold_until": 1671222870, + "recipient_settlement_id": null, + "created_at": 1580218356, + "linked_account_notes": [ + "roll_no" + ], + "processed_at": 1580218357 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Create transfers from order + +```java +String json = "{\n" + + " amount: 2000,\n" + + " currency: \"INR\",\n" + + " transfers: [\n" + + " {\n" + + " account: \"acc_CPRsN1LkFccllA\",\n" + + " amount: 1000,\n" + + " currency: \"INR\",\n" + + " notes: {\n" + + " branch: \"Acme Corp Bangalore North\",\n" + + " name: \"Gaurav Kumar\"\n" + + " },\n" + + " linked_account_notes: [\n" + + " \"branch\"\n" + + " ],\n" + + " on_hold: 1,\n" + + " on_hold_until: 1671222870\n" + + " },\n" + + " {\n" + + " account: \"acc_CNo3jSI8OkFJJJ\",\n" + + " amount: 1000,\n" + + " currency: \"INR\",\n" + + " notes: {\n" + + " branch: \"Acme Corp Bangalore South\",\n" + + " name: \"Saurav Kumar\"\n" + + " },\n" + + " linked_account_notes: [\n" + + " \"branch\"\n" + + " ],\n" + + " on_hold: 0\n" + + " }\n" + + " ]\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| amount* | integer | The transaction amount, in paise | +| currency* | string | The currency of the payment (defaults to INR) | +| receipt | string | A unique identifier provided by you for your internal reference. | +| transfers | object | All parameters listed [here](https://razorpay.com/docs/api/route/#create-transfers-from-orders) are supported | + +**Response:** +```json +{ + "id": "order_E9uTczH8uWPCyQ", + "entity": "order", + "amount": 2000, + "amount_paid": 0, + "amount_due": 2000, + "currency": "INR", + "receipt": null, + "offer_id": null, + "status": "created", + "attempts": 0, + "notes": [], + "created_at": 1580217565, + "transfers": [ + { + "recipient": "acc_CPRsN1LkFccllA", + "amount": 1000, + "currency": "INR", + "notes": { + "branch": "Acme Corp Bangalore North", + "name": "Gaurav Kumar" + }, + "linked_account_notes": [ + "branch" + ], + "on_hold": true, + "on_hold_until": 1671222870 + }, + { + "recipient": "acc_CNo3jSI8OkFJJJ", + "amount": 1000, + "currency": "INR", + "notes": { + "branch": "Acme Corp Bangalore South", + "name": "Saurav Kumar" + }, + "linked_account_notes": [ + "branch" + ], + "on_hold": false, + "on_hold_until": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Direct transfers + +```java +String json = "{\n" + + "\account\": \"acc_CPRsN1LkFccllA\",\n + + "\"amount\": 500,\n" + + "\"currency\": \"INR\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Transfer transfer = instance.Transfers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| accountId* | string | The id of the account to be fetched | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| currency* | string | The currency of the payment (defaults to INR) | + +**Response:** +```json +{ + "id": "trf_E9utgtfGTcpcmm", + "entity": "transfer", + "source": "acc_CJoeHMNpi0nC7k", + "recipient": "acc_CPRsN1LkFccllA", + "amount": 100, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 1, + "tax": 0, + "on_hold": false, + "on_hold_until": null, + "recipient_settlement_id": null, + "created_at": 1580219046, + "linked_account_notes": [], + "processed_at": 1580219046 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch transfer for a payment + +```java +String PaymentId = "pay_E9up5WhIfMYnKW"; + +List payment = instance.Payments.fetchAllTransfers(PaymentId) +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "trf_EAznuJ9cDLnF7Y", + "entity": "transfer", + "source": "pay_E9up5WhIfMYnKW", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 1000, + "currency": "INR", + "amount_reversed": 100, + "notes": [], + "fees": 3, + "tax": 0, + "on_hold": false, + "on_hold_until": null, + "recipient_settlement_id": null, + "created_at": 1580454666, + "linked_account_notes": [], + "processed_at": 1580454666 + } + ] +} +``` +------------------------------------------------------------------------------------- + +### Fetch transfer + +```java +String TransferId = "trf_E7V62rAxJ3zYMo"; + +Transfer transfer = instance.Transfers.fetch(TransferId); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| transferId* | string | The id of the transfer to be fetched | + +**Response:** +```json +{ + "id": "trf_E7V62rAxJ3zYMo", + "entity": "transfer", + "source": "pay_E6j30Iu1R7XbIG", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 100, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 1, + "tax": 0, + "on_hold": false, + "on_hold_until": null, + "recipient_settlement_id": null, + "created_at": 1579691505, + "linked_account_notes": [], + "processed_at": 1579691505 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch transfers for a settlement + +```java +String RecipientSettlementId = "setl_DHYJ3dRPqQkAgV"; + +JSONObject request = new JSONObject("{\"recipient_settlement_id\":"+RecipientSettlementId+"}"); + +List transfer = instance.Transfers.fetchAll(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| recipientSettlementId* | string | The recipient settlement id obtained from the settlement.processed webhook payload. | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "trf_DGSTeXzBkEVh48", + "entity": "transfer", + "source": "pay_DGSRhvMbOqeCe7", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 500, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 2, + "tax": 0, + "on_hold": false, + "on_hold_until": null, + "recipient_settlement_id": "setl_DHYJ3dRPqQkAgV", + "created_at": 1568110256, + "linked_account_notes": [], + "processed_at": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch settlement details + +```java +String json = "{\n" + + "\"expand[]\" : \"recipient_settlement\" \n" + + "}"; +JSONObject request = new JSONObject(json); + +List transfer = instance.Transfers.fetchAll(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| expand* | string | Supported value is `recipient_settlement` | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "trf_DGSTeXzBkEVh48", + "entity": "transfer", + "source": "pay_DGSRhvMbOqeCe7", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 500, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 2, + "tax": 0, + "on_hold": false, + "on_hold_until": null, + "recipient_settlement_id": "setl_DHYJ3dRPqQkAgV", + "recipient_settlement": { + "id": "setl_DHYJ3dRPqQkAgV", + "entity": "settlement", + "amount": 500, + "status": "failed", + "fees": 0, + "tax": 0, + "utr": "CN0038699836", + "created_at": 1568349124 + }, + "created_at": 1568110256, + "linked_account_notes": [], + "processed_at": null + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Refund payments and reverse transfer from a linked account + +```java +String PaymentId = "pay_EAdwQDe4JrhOFX"; + +String json = "{\n" + + " amount : 100,\n" + + " reverse_all : 1\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.refund(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| reverse_all | boolean | 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.| + +**Response:** +```json +{ + "id": "rfnd_EAzovSwG8jBnGf", + "entity": "refund", + "amount": 100, + "currency": "INR", + "payment_id": "pay_EAdwQDe4JrhOFX", + "notes": [], + "receipt": null, + "acquirer_data": { + "rrn": null + }, + "created_at": 1580454723 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch payments of a linked account + +```java +String LinkedAccountId = "acc_CPRsN1LkFccllA"; + +JSONObject request = new JSONObject("{\"X-Razorpay-Account\":"+LinkedAccountId+"}"); + +List payment = instance.Payments.fetchAll(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| X-Razorpay-Account | string | The linked account id to fetch the payments received by linked account | + +**Response:** +```json +{ + "entity": "collection", + "count": 2, + "items": [ + { + "id": "pay_E9uth3WhYbh9QV", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": null, + "invoice_id": null, + "international": null, + "method": "transfer", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": null, + "card_id": null, + "bank": null, + "wallet": null, + "vpa": null, + "email": "", + "contact": null, + "notes": [], + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "created_at": 1580219046 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Reverse transfers from all linked accounts + +```java +String TransferId = "trf_EAznuJ9cDLnF7Y"; + +String json = "{\n" + + "amount:100\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Transfer transfer = instance.Transfers.reversal(TransferId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| TransferId* | string | The id of the transfer to be fetched | +| amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | + +**Response:** +```json +{ + "id": "rvrsl_EB0BWgGDAu7tOz", + "entity": "reversal", + "transfer_id": "trf_EAznuJ9cDLnF7Y", + "amount": 100, + "fee": 0, + "tax": 0, + "currency": "INR", + "notes": [], + "initiator_id": "CJoeHMNpi0nC7k", + "customer_refund_id": null, + "created_at": 1580456007 +} +``` +------------------------------------------------------------------------------------------------------- + +### Hold settlements for transfers +```java +String PaymentId = "pay_EB1R2s8D4vOAKG"; + +String json = "{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"on_hold\": \"1\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.transfer(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | +| transfers | array | All parameters listed here https://razorpay.com/docs/api/route/#hold-settlements-for-transfers are supported | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "trf_EB1VJ4Ux4GMmxQ", + "entity": "transfer", + "source": "pay_EB1R2s8D4vOAKG", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 100, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 1, + "tax": 0, + "on_hold": true, + "on_hold_until": null, + "recipient_settlement_id": null, + "created_at": 1580460652, + "linked_account_notes": [], + "processed_at": 1580460652 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Modify settlement hold for transfers +```java +String PaymentId = "pay_EAeSM2Xul8xYRo"; + +String json = "{\n" + + "\"on_hold\": \"1\",\n" + + "\"on_hold_until\": \"1679691505\"\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Transfer transfer = instance.Transfers.edit(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| PaymentId* | string | The id of the payment to be fetched | +| transfers | array | All parameters listed here https://razorpay.com/docs/api/route/#hold-settlements-for-transfers are supported | + +**Response:** +```json +{ + "id": "trf_EB17rqOUbzSCEE", + "entity": "transfer", + "source": "pay_EAeSM2Xul8xYRo", + "recipient": "acc_CMaomTz4o0FOFz", + "amount": 100, + "currency": "INR", + "amount_reversed": 0, + "notes": [], + "fees": 1, + "tax": 0, + "on_hold": true, + "on_hold_until": 1679691505, + "recipient_settlement_id": null, + "created_at": 1580459321, + "linked_account_notes": [], + "processed_at": 1580459321 +} +``` + +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/route/#transfers/)** \ No newline at end of file diff --git a/documents/upi.md b/documents/upi.md new file mode 100644 index 00000000..1f0459d9 --- /dev/null +++ b/documents/upi.md @@ -0,0 +1,555 @@ +## UPI + +### Create customer +```java +String json = "{\n" + + " name: \"Gaurav Kumar\",\n" + + " contact: 9123456780,\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Customer customer = instance.Customers.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| name* | string | Name of the customer | +| email | string | Email of the customer | +| contact | string | Contact number of the customer | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "cust_1Aa00000000003", + "entity": "customer", + "name": "Gaurav Kumar", + "email": "Gaurav.Kumar@example.com", + "contact": "9000000000", + "gstin": null, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1582033731 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Create order + +```java +String json = "{\n" + + " amount: 0,\n" + + " currency: \"INR\",\n" + + " method: \"upi\",\n" + + " customer_id: \"cust_1Aa00000000001\",\n" + + " receipt: \"Receipt No. 1\",\n" + + " notes: {\n" + + " notes_key_1: \"Beam me up Scotty\",\n" + + " notes_key_2: \"Engage\"\n" + + " },\n" + + " token: {\n" + + " auth_type: \"netbanking\",\n" + + " max_amount: 9999900,\n" + + " expire_at: 4102444799,\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| method* | string | The authorization method. In this case the value will be `emandate` | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | +| token | object | A key-value pair | + +**Response:** +```json +{ + "id": "order_1Aa00000000002", + "entity": "order", + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "receipt": "Receipt No. 1", + "offer_id": null, + "status": "created", + "attempts": 0, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + }, + "created_at": 1565172642 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an Authorization Payment + +Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/upi/authorization-transaction/#113-create-an-authorization-payment) for authorization payment + +------------------------------------------------------------------------------------------------------- + +### Create registration link + +```java +String json = "{\n" + + " customer: {\n" + + " name: \"Gaurav Kumar\",\n" + + " email: \"gaurav.kumar@example.com\",\n" + + " contact: 9123456780\n" + + " },\n" + + " type: \"link\",\n" + + " amount: 100,\n" + + " currency: \"INR\",\n" + + " description: \"Registration Link for Gaurav Kumar\",\n" + + " subscription_registration: {\n" + + " method: \"upi\",\n" + + " max_amount: 500,\n" + + " expire_at: 1634215992\n" + + " },\n" + + " receipt: \"Receipt No. 5\",\n" + + " email_notify: 1,\n" + + " sms_notify: 1,\n" + + " expire_by: 1634215992,\n" + + " notes: {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; +JSONObject request = new JSONObject(json); + +Invoice invoice = instance.Invoices.createRegistrationLink(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| customer | object | Details of the customer to whom the registration link will be sent. | +| type* | string | In this case, the value is `link`. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| amount* | integer | The payment amount in the smallest currency sub-unit. | +| description* | string | A description that appears on the hosted page. For example, `12:30 p.m. Thali meals (Gaurav Kumar`). | +| subscription_registration | object | Details of the authorization payment. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id": "inv_FHr1ekX0r2VCVK", + "entity": "invoice", + "receipt": "Receipt No. 23", + "invoice_number": "Receipt No. 23", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHr1ehR3nmNeXo", + "line_items": [], + "payment_id": null, + "status": "issued", + "expire_by": 4102444799, + "issued_at": 1595489219, + "paid_at": null, + "cancelled_at": null, + "expired_at": null, + "sms_status": "pending", + "email_status": "pending", + "date": 1595489219, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/ak1WxDB", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595489219, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Send/Resend notifications + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +String medium = "sms"; + +Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be notified | +| medium* | string | `sms`/`email`, Medium through which notification should be sent. | + +**Response:** +```json +{ + "success": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Cancel a registration link + +```java +String InvoiceId = "inv_DAweOiQ7amIUVd"; + +Invoice invoice = instance.Invoices.cancel(InvoiceId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| InvoiceId* | string | The id of the invoice to be cancelled | + +**Response:** +```json +{ + "id": "inv_FHrfRupD2ouKIt", + "entity": "invoice", + "receipt": "Receipt No. 1", + "invoice_number": "Receipt No. 1", + "customer_id": "cust_BMB3EwbqnqZ2EI", + "customer_details": { + "id": "cust_BMB3EwbqnqZ2EI", + "name": "Gaurav Kumar", + "email": "gaurav.kumar@example.com", + "contact": "9123456780", + "gstin": null, + "billing_address": null, + "shipping_address": null, + "customer_name": "Gaurav Kumar", + "customer_email": "gaurav.kumar@example.com", + "customer_contact": "9123456780" + }, + "order_id": "order_FHrfRw4TZU5Q2L", + "line_items": [], + "payment_id": null, + "status": "cancelled", + "expire_by": 4102444799, + "issued_at": 1595491479, + "paid_at": null, + "cancelled_at": 1595491488, + "expired_at": null, + "sms_status": "sent", + "email_status": "sent", + "date": 1595491479, + "terms": null, + "partial_payment": false, + "gross_amount": 100, + "tax_amount": 0, + "taxable_amount": 0, + "amount": 100, + "amount_paid": 0, + "amount_due": 100, + "currency": "INR", + "currency_symbol": "₹", + "description": "Registration Link for Gaurav Kumar", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "comment": null, + "short_url": "https://rzp.io/i/QlfexTj", + "view_less": true, + "billing_start": null, + "billing_end": null, + "type": "link", + "group_taxes_discounts": false, + "created_at": 1595491480, + "idempotency_key": null +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch token by payment ID + +```java +String PaymentId = "pay_1Aa00000000001"; + +Payment payment = instance.Payments.fetch(PaymentId) +``` + +**Parameters:** + +| Name | Type | Description | +|------------|--------|-----------------------------------| +| PaymentId* | string | Id of the payment to be retrieved | + +**Response:** +```json +{ + "id": "pay_FHfAzEJ51k8NLj", + "entity": "payment", + "amount": 100, + "currency": "INR", + "status": "captured", + "order_id": "order_FHfANdTUYeP8lb", + "invoice_id": null, + "international": false, + "method": "upi", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": null, + "card_id": null, + "bank": null, + "wallet": null, + "vpa": "gaurav.kumar@upi", + "email": "gaurav.kumar@example.com", + "contact": "+919876543210", + "customer_id": "cust_DtHaBuooGHTuyZ", + "token_id": "token_FHfAzGzREc1ug6", + "notes": { + "note_key 1": "Beam me up Scotty", + "note_key 2": "Tea. Earl Gray. Hot." + }, + "fee": 0, + "tax": 0, + "error_code": null, + "error_description": null, + "error_source": null, + "error_step": null, + "error_reason": null, + "acquirer_data": { + "rrn": "854977234911", + "upi_transaction_id": "D0BED5A062ECDB3E9B3A1071C96BB273" + }, + "created_at": 1595447490 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch tokens by customer ID + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +List token = instance.Customers.fetchTokens(CustomerId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "token_FHfAzGzREc1ug6", + "entity": "token", + "token": "9KHsdPaCELeQ0t", + "bank": null, + "wallet": null, + "method": "upi", + "vpa": { + "username": "gaurav.kumar", + "handle": "upi", + "name": null + }, + "recurring": true, + "recurring_details": { + "status": "confirmed", + "failure_reason": null + }, + "auth_type": null, + "mrn": null, + "used_at": 1595447490, + "created_at": 1595447490, + "start_time": 1595447455, + "dcc_enabled": false + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete token + +```java +String CustomerId = "cust_BMB3EwbqnqZ2EI"; + +String TokenId = "token_FHf94Uym9tdYFJ"; + +instance.Customers.deleteToken(CustomerId, TokenId); +``` + +**Parameters:** + +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| CustomerId* | string | The id of the customer to be fetched | +| TokenId* | string | The id of the token to be fetched | + +**Response:** +```json +{ + "deleted": true +} +``` +------------------------------------------------------------------------------------------------------- + +### Create an order to charge the customer + +```java +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Order order = instance.Orders.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| amount* | integer | Amount of the order to be paid | +| currency* | string | Currency of the order. Currently only `INR` is supported. | +| receipt | string | Your system order reference id. | +| notes | object | A key-value pair | + +**Response:** +```json +{ + "id":"order_1Aa00000000002", + "entity":"order", + "amount":1000, + "amount_paid":0, + "amount_due":1000, + "currency":"INR", + "receipt":"Receipt No. 1", + "offer_id":null, + "status":"created", + "attempts":0, + "notes":{ + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at":1579782776 +} +``` +------------------------------------------------------------------------------------------------------- + +### Create a recurring payment + +```java +String json = "{\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"9123456789\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_1Aa00000000002\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"token\": \"token_1Aa00000000001\",\n" + + " \"recurring\": \"1\",\n" + + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +Payment payment = instance.Payments.createRecurringPayment(request); +``` + +**Parameters:** + +| Name | Type | Description | +|-----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address. | +| contact* | string | The customer's phone number. | +| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| order_id* | string | The unique identifier of the order created. | +| customer_id* | string | The `customer_id` for the customer you want to charge. | +| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| +| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| +| description* | string | A user-entered description for the payment.| +| notes* | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | + +**Response:** +```json +{ + "razorpay_payment_id" : "pay_1Aa00000000001", + "razorpay_order_id" : "order_1Aa00000000001", + "razorpay_signature" : "9ef4dffbfd84f1318f6739a3ce19f9d85851857ae648f114332d8401e0949a3d" +} +``` +------------------------------------------------------------------------------------------------------- + + + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/api/recurring-payments/upi/authorization-transaction/)** \ No newline at end of file diff --git a/documents/virtualAccount.md b/documents/virtualAccount.md new file mode 100644 index 00000000..c77869be --- /dev/null +++ b/documents/virtualAccount.md @@ -0,0 +1,610 @@ +## Virtual account + +### Create a virtual account +```java +String json = "{\n" + + " receivers: {\n" + + " types: [\n" + + " \"bank_account\"\n" + + " ]\n" + + " },\n" + + " description: \"Virtual Account created for Raftar Soft\",\n" + + " customer_id: \"cust_CaVDm8eDRSXYME\",\n" + + " close_by: 1681615838,\n" + + " notes: {\n" + + " project_name: \"Banking Software\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| receivers* | object | Array that defines what receivers are available for this Virtual Account | +| description | string | A brief description of the virtual account. | +| customer_id | string | Unique identifier of the customer to whom the virtual account must be tagged. | +| close_by | integer | UNIX timestamp at which the virtual account is scheduled to be automatically closed. | +| notes | integer | Any custom notes you might want to add to the virtual account can be entered here. | + +**Response:** +```json +{ + "id":"va_DlGmm7jInLudH9", + "name":"Acme Corp", + "entity":"virtual_account", + "status":"active", + "description":"Virtual Account created for Raftar Soft", + "amount_expected":null, + "notes":{ + "project_name":"Banking Software" + }, + "amount_paid":0, + "customer_id":"cust_CaVDm8eDRSXYME", + "receivers":[ + { + "id":"ba_DlGmm9mSj8fjRM", + "entity":"bank_account", + "ifsc":"RATN0VAAPIS", + "bank_name": "RBL Bank", + "name":"Acme Corp", + "notes":[], + "account_number":"2223330099089860" + } + ], + "close_by":1681615838, + "closed_at":null, + "created_at":1574837626 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Create a virtual account with TPV + +```java + +String json = "{\n" + + " receivers: {\n" + + " types: [\n" + + " \"bank_account\"\n" + + " ]\n" + + " },\n" + + " allowed_payers: [\n" + + " {\n" + + " type: \"bank_account\",\n" + + " bank_account: {\n" + + " ifsc: \"RATN0VAAPIS\",\n" + + " account_number: 2223330027558515\n" + + " }\n" + + " }\n" + + " ],\n" + + " description: \"Virtual Account created for Raftar Soft\",\n" + + " customer_id: \"cust_HssUOFiOd2b1TJ\",\n" + + " notes: {\n" + + " project_name: \"Banking Software\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| receivers* | object | Array that defines what receivers are available for this Virtual Account | +| allowed_payers* | object | All parameters listed [here](https://razorpay.com/docs/api/smart-collect-tpv/#create-virtual-account) are supported | +| description | string | A brief description of the virtual account. | +| customer_id | string | Unique identifier of the customer to whom the virtual account must be tagged. | +| notes | integer | Any custom notes you might want to add to the virtual account can be entered here. | + +**Response:** +```json +{ + "id":"va_DlGmm7jInLudH9", + "name":"Acme Corp", + "entity":"virtual_account", + "status":"active", + "description":"Virtual Account created for Raftar Soft", + "amount_expected":null, + "notes":{ + "project_name":"Banking Software" + }, + "amount_paid":0, + "customer_id":"cust_CaVDm8eDRSXYME", + "receivers":[ + { + "id":"ba_DlGmm9mSj8fjRM", + "entity":"bank_account", + "ifsc":"RATN0VAAPIS", + "bank_name": "RBL Bank", + "name":"Acme Corp", + "notes":[], + "account_number":"2223330099089860" + } + ], + "allowed_payers": [ + { + "type": "bank_account", + "id":"ba_DlGmm9mSj8fjRM", + "bank_account": { + "ifsc": "UTIB0000013", + "account_number": "914010012345679" + } + }, + { + "type": "bank_account", + "id":"ba_Cmtnm5tSj6agUW", + "bank_account": { + "ifsc": "UTIB0000014", + "account_number": "914010012345680" + } + } + ], + "close_by":1681615838, + "closed_at":null, + "created_at":1574837626 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Create static/dynamic qr + +```java +String json = "{\n" + + " receivers: {\n" + + " types: [\n" + + " \"qr_code\"\n" + + " ]\n" + + " },\n" + + " description: \"First QR code\",\n" + + " amount_expected: 100,\n" + + " notes: {\n" + + " receiver_key: \"receiver_value\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); + +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| receivers* | array | Array that defines what receivers are available for this Virtual Account | +| description | string | A brief description of the payment. | +| amount_expected | integer | The maximum amount you expect to receive in this virtual account. Pass `69999` for ₹699.99. | +| notes | object | All keys listed [here](https://razorpay.com/docs/payments/payments/payment-methods/bharatqr/api/#create) are supported | + +**Response:** +```json +{ + "id": "va_4xbQrmEoA5WJ0G", + "name": "Acme Corp", + "entity": "virtual_account", + "status": "active", + "description": "First Payment by BharatQR", + "amount_expected": null, + "notes": { + "reference_key": "reference_value" + }, + "amount_paid": 0, + "customer_id": "cust_805c8oBQdBGPwS", + "receivers": [ + { + "id": "qr_4lsdkfldlteskf", + "entity": "qr_code", + "reference": "AgdeP8aBgZGckl", + "short_url": "https://rzp.io/i/PLs03pOc" + } + ], + "close_by": null, + "closed_at": null, + "created_at": 1607938184 +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch virtual account by id + +```java +String VirtualId = "va_4xbQrmEoA5WJ0G"; + +VirtualAccount virtualaccount = instance.VirtualAccounts.fetch(virtualId); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|---------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | + +**Response:** +For fetch virtual account by id response please click [here](https://razorpay.com/docs/api/smart-collect/#fetch-a-virtual-account-by-id) +------------------------------------------------------------------------------------------------------- + +### Fetch all virtual account +```java +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List virtualaccount = instance.VirtualAccounts.fetchAll(options); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "va_Di5gbNptcWV8fQ", + "name": "Acme Corp", + "entity": "virtual_account", + "status": "closed", + "description": "Virtual Account created for M/S ABC Exports", + "amount_expected": 2300, + "notes": { + "material": "teakwood" + }, + "amount_paid": 239000, + "customer_id": "cust_DOMUFFiGdCaCUJ", + "receivers": [ + { + "id": "ba_Di5gbQsGn0QSz3", + "entity": "bank_account", + "ifsc": "RATN0VAAPIS", + "bank_name": "RBL Bank", + "name": "Acme Corp", + "notes": [], + "account_number": "1112220061746877" + } + ], + "close_by": 1574427237, + "closed_at": 1574164078, + "created_at": 1574143517 + } + ] +} +``` +------------------------------------------------------------------------------------------------------- + +### Fetch payments for a virtual account +```java +String VirtualId = "va_DlGmm7jInLudH9"; + +String json = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject options = new JSONObject(json); + +List virtualaccount = instance.VirtualAccounts.fetchPayments(VirtualId,options); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-----------|--------------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | + +**Response:** +```json +{ + "entity": "collection", + "count": 1, + "items": [ + { + "id": "pay_Di5iqCqA1WEHq6", + "entity": "payment", + "amount": 239000, + "currency": "INR", + "status": "captured", + "order_id": null, + "invoice_id": null, + "international": false, + "method": "bank_transfer", + "amount_refunded": 0, + "refund_status": null, + "captured": true, + "description": "", + "card_id": null, + "bank": null, + "wallet": null, + "vpa": null, + "email": "saurav.kumar@example.com", + "contact": "+919972139994", + "customer_id": "cust_DOMUFFiGdCaCUJ", + "notes": [], + "fee": 2820, + "tax": 430, + "error_code": null, + "error_description": null, + "created_at": 1574143644 + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + +### Fetch payment details using id and transfer method +```java +String PaymentId = "pay_CmiztqmYJPtDAu"; + +Payment payment = instance.Payments.fetchBankTransfers(paymentId) +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| virtualId* | string | The id of the virtual to be updated | + +**Response:** +```json +{ + "id": "bt_Di5iqCElVyRlCb", + "entity": "bank_transfer", + "payment_id": "pay_Di5iqCqA1WEHq6", + "mode": "NEFT", + "bank_reference": "157414364471", + "amount": 239000, + "payer_bank_account": { + "id": "ba_Di5iqSxtYrTzPU", + "entity": "bank_account", + "ifsc": "UTIB0003198", + "bank_name": "Axis Bank", + "name": "Acme Corp", + "notes": [], + "account_number": "765432123456789" + }, + "virtual_account_id": "va_Di5gbNptcWV8fQ", + "virtual_account": { + "id": "va_Di5gbNptcWV8fQ", + "name": "Acme Corp", + "entity": "virtual_account", + "status": "closed", + "description": "Virtual Account created for M/S ABC Exports", + "amount_expected": 2300, + "notes": { + "material": "teakwood" + }, + "amount_paid": 239000, + "customer_id": "cust_DOMUFFiGdCaCUJ", + "receivers": [ + { + "id": "ba_Di5gbQsGn0QSz3", + "entity": "bank_account", + "ifsc": "RATN0VAAPIS", + "bank_name": "RBL Bank", + "name": "Acme Corp", + "notes": [], + "account_number": "1112220061746877" + } + ], + "close_by": 1574427237, + "closed_at": 1574164078, + "created_at": 1574143517 + } +} +``` +------------------------------------------------------------------------------------------------------- + +### Refund payments made to a virtual account +```java +String PaymentId = "pay_E54n391WnEAV9H"; + +String json = "{\n" + + " \"amount\": \"100\",\n" + + " \"speed\": \"normal\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty.\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"receipt\": \"Receipt No. 31\"\n" + + "}"; + +JSONObject options = new JSONObject(json); + +Payment payment = instance.Payments.refund(PaymentId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|-------|-----------|--------------------------------------------------| +| paymentId* | string | The id of the payment to be updated | +| amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | +| speed | string | Here, it must be normal | +| notes | array | A key-value pair | +| receipt | string | A unique identifier provided by you for your internal reference. | + +**Response:** +```json +{ + "id": "rfnd_E6j36ZEKvsWsEn", + "entity": "refund", + "amount": 100, + "currency": "INR", + "payment_id": "pay_E54n391WnEAV9H", + "notes": { + "key_1": "value1", + "key_2": "value2" + }, + "receipt": null, + "acquirer_data": { + "rrn": null + }, + "created_at": 1579522301 +} +``` +------------------------------------------------------------------------------------------------------- + +### Add receiver to an existing virtual account +```java +String VirtualId = "va_Di5gbNptcWV8fQ"; + +String json = "{\n" + + " types: [\n" + + " \"vpa\"\n" + + " ],\n" + + " vpa: {\n" + + " descriptor: \"gauravkumar\"\n" + + " }\n" + + "}"; + +JSONObject request = new JSONObject(json); + +VirtualAccount virtualaccount = instance.VirtualAccounts.addReceiver(VirtualId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-----------|--------------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | +| types* | object | The receiver type to be added to the virtual account. Possible values are `vpa` or `bank_account` | +| vpa | object | This is to be passed only when `vpa` is passed as the receiver types. | + +**Response:** +For add receiver to an existing virtual account response please click [here](https://razorpay.com/docs/api/smart-collect/#add-receiver-to-an-existing-virtual-account) + +------------------------------------------------------------------------------------------------------- + +### Add an Allowed Payer Account +```java +String VirtualId = "va_Di5gbNptcWV8fQ"; + +String json = "{\n" + +" types: \"bank_account\",\n" + +" bank_account: {\n" + +" ifsc: \"UTIB0000013\",\n" + +" account_number: 914010012345679\n" + +" }\n" + +"}"; + +JSONObject request = new JSONObject(json); +VirtualAccount virtualaccount = instance.VirtualAccounts.addAllowedPayers(VirtualId,request); +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-----------|--------------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | +| types* | object | The receiver type to be added to the virtual account. Possible values are `vpa` or `bank_account` | +| bank_account* | object | Indicates the bank account details such as `ifsc` and `account_number` | + +**Response:** +```json +{ + "id":"va_DlGmm7jInLudH9", + "name":"Acme Corp", + "entity":"virtual_account", + "status":"active", + "description":"Virtual Account created for Raftar Soft", + "amount_expected":null, + "notes":{ + "project_name":"Banking Software" + }, + "amount_paid":0, + "customer_id":"cust_CaVDm8eDRSXYME", + "receivers":[ + { + "id":"ba_DlGmm9mSj8fjRM", + "entity":"bank_account", + "ifsc":"RATN0VAAPIS", + "bank_name": "RBL Bank", + "name":"Acme Corp", + "notes":[], + "account_number":"2223330099089860" + } + ], + "allowed_payers": [ + { + "type": "bank_account", + "id":"ba_DlGmm9mSj8fjRM", + "bank_account": { + "ifsc": "UTIB0000013", + "account_number": "914010012345679" + } + } + ], + "close_by":1681615838, + "closed_at":null, + "created_at":1574837626 +} +``` +------------------------------------------------------------------------------------------------------- + +### Delete an Allowed Payer Account +```java +String VirtualId = "va_Di5gbNptcWV8fQ"; + +String AllowedPlayer = "ba_DlGmm9mSj8fjRM"; + +instance.VirtualAccounts.deleteAllowedPayer(VirtualId,AllowedPayersId) +``` + +**Parameters:** + +| Name | Type | Description | +|------------------|-----------|--------------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | +| AllowedPayersId* | string | The id of the allowed payers to be updated | + +**Response:** +```json +{} +``` +------------------------------------------------------------------------------------------------------- +### Close virtual account +```java +String VirtualId = "va_Di5gbNptcWV8fQ"; + +instance.VirtualAccounts.close(VirtualId) +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-----------|--------------------------------------------------| +| VirtualId* | string | The id of the virtual to be updated | + +**Response:** +For close virtual account response please click [here](https://razorpay.com/docs/api/smart-collect/#close-a-virtual-account) +------------------------------------------------------------------------------------------------------- + +**PN: * indicates mandatory fields** +
+
+**For reference click [here](https://razorpay.com/docs/smart-collect/api/)** \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2c6c4f8c..b9d5f065 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.razorpay razorpay-java - 1.3.9 + 1.4.0 jar razorpay-java diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index db5af948..d0551111 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -23,7 +23,6 @@ public class Constants { static final String PAYMENT_TRANSFER_GET = "payments/%s/transfers"; static final String PAYMENT_BANK_TRANSFER_GET = "payments/%s/bank_transfer"; static final String PAYMENT_EDIT = "payments/%s"; - static final String FETCH_CARD_DETAILS = "payments/%s/card"; static final String FETCH_DOWNTIME_LIST = "payments/downtimes"; static final String FETCH_DOWNTIME_GET = "payments/downtimes"; static final String PAYMENT_JSON_CREATE = "payments/create/json"; From 7ea6a0b19cc88a364db67df55857d1fa22385670 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 7 Mar 2022 21:28:48 +0530 Subject: [PATCH 78/78] update readme files --- documents/addon.md | 68 +++---- documents/card.md | 72 +++---- documents/customers.md | 46 ++--- documents/emandate.md | 188 +++++++++--------- documents/fund.md | 10 +- documents/invoice.md | 146 +++++++------- documents/item.md | 46 +++-- documents/order.md | 52 ++--- documents/papernach.md | 225 +++++++++++----------- documents/payment.md | 135 +++++++------ documents/paymentLink.md | 157 ++++++++------- documents/plan.md | 48 ++--- documents/qrcode.md | 125 ++++++------ documents/refund.md | 76 ++++---- documents/registerEmandate.md | 211 ++++++++++---------- documents/registerNach.md | 209 ++++++++++---------- documents/settlement.md | 34 ++-- documents/subscription.md | 178 ++++++++--------- documents/token.md | 26 +-- documents/transfer.md | 189 +++++++++--------- documents/upi.md | 214 ++++++++++---------- documents/virtualAccount.md | 216 +++++++++++---------- src/main/java/com/razorpay/Constants.java | 1 + 23 files changed, 1367 insertions(+), 1305 deletions(-) diff --git a/documents/addon.md b/documents/addon.md index 447e7ef0..cf015f3b 100644 --- a/documents/addon.md +++ b/documents/addon.md @@ -3,29 +3,31 @@ ### Create an addon ```java -String SubscriptionId = "sub_I55auG9GnbsR8u"; -String json = "{\n" + - " item:{\n" + - " name:\"Extra appala (papadum)\",\n" + - " amount:30000,\n" + - " currency:\"INR\",\n" + - " description:\"1 extra oil fried appala with meals\"\n" + +String subscriptionId = "sub_I55auG9GnbsR8u"; + +String jsonRequest = + "{\n" + + " \"item\": {\n" + + " \"name\": \"Extra appala (papadum)\",\n" + + " \"amount\": 30000,\n" + + " \"currency\": \"INR\",\n" + + " \"description\": \"1 extra oil fried appala with meals\"\n" + " },\n" + - " quantity:2\n" + + " \"quantity\": 2\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscriptions.createAddon(SubscriptionId,request); +Subscription subscription = instance.subscriptions.createAddon(subscriptionId,requestJson); ``` **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| SubscriptionId* | boolean | The subscription ID to which the add-on is being added. | -| items* | object | Details of the add-on you want to create. | -| quantity* | integer | This specifies the number of units of the add-on to be charged to the customer. | +| Name | Type | Description | +|-----------------|-----------|--------------------------------------------------| +| subscriptionId* | boolean | The subscription ID to which the add-on is being added. | +| items* | object | Details of the add-on you want to create. | +| quantity* | integer | This specifies the number of units of the add-on to be charged to the customer. | **Response:** ```json @@ -62,23 +64,23 @@ Subscription subscription = instance.Subscriptions.createAddon(SubscriptionId,re ### Fetch all addons ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List addon = instance.Addons.fetchAll(options); +List addon = instance.addons.fetchAll(requestJson); ``` **Parameters:** | Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| from | timestamp | timestamp after which the payments were created | -| to | timestamp | timestamp before which the payments were created | -| count | integer | number of payments to fetch (default: 10) | -| skip | integer | number of payments to be skipped (default: 0) | +|-------|-----------|---------------------------------------------------| +| from | timestamp | timestamp after which the payments were created | +| to | timestamp | timestamp before which the payments were created | +| count | integer | number of payments to fetch (default: 10) | +| skip | integer | number of payments to be skipped (default: 0) | **Response:** ```json @@ -121,16 +123,16 @@ List addon = instance.Addons.fetchAll(options); ### Fetch an addon ```java -String AddonId = "ao_00000000000001"; +String addonId = "ao_00000000000001"; -Addon addon = instance.Addons.fetch(AddonId); +Addon addon = instance.addons.fetch(addonId); ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------| -| AddonId* | string | addon id to be fetched | +| Name | Type | Description | +|----------|---------|------------------------------------| +| addonId* | string | addon id to be fetched | **Response:** ```json @@ -167,16 +169,16 @@ Addon addon = instance.Addons.fetch(AddonId); ### Delete an addon ```java -String AddonId = "ao_00000000000001"; +String addonId = "ao_00000000000001"; -instance.Addons.delete(AddonId) +instance.addons.delete(addonId) ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------------------------------------------------| -| AddonId* | string | addon id to be deleted | +| Name | Type | Description | +|----------|---------|------------------------------------------------------------------------------| +| addonId* | string | addon id to be deleted | **Response:** ```json diff --git a/documents/card.md b/documents/card.md index 20c865e9..67c7a21e 100644 --- a/documents/card.md +++ b/documents/card.md @@ -2,7 +2,7 @@ ### Create customer ```java -String json = "{\n" + +String jsonRequest = "{\n" + " name: \"Gaurav Kumar\",\n" + " email: \"gaurav.kumar@example.com\",\n" + " contact: \"9123456780\",\n" + @@ -13,9 +13,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(requestJson); ``` **Parameters:** @@ -49,7 +49,7 @@ Customer customer = instance.Customers.create(request); ### Create Order ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\":100,\n" + " \"currency\":\"INR\",\n" + " \"customer_id\":\"cust_4xbQrmEoA5WJ01\",\n" + @@ -66,9 +66,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -116,7 +116,7 @@ Order order = instance.Orders.create(request); ### Create registration link ```java -String json = "{\n" + +String JsonRequest = "{\n" + " customer: {\n" + " name: \"Gaurav Kumar\",\n" + " email: \"gaurav.kumar@example.com\",\n" + @@ -141,9 +141,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(request); -Invoice invoice = instance.Invoices.createRegistrationLink(request); +Invoice invoice = instance.invoices.createRegistrationLink(requestJson); ``` **Parameters:** @@ -225,7 +225,7 @@ Invoice invoice = instance.Invoices.createRegistrationLink(request); ## Create an order to charge the customer ```java -String json = "{\n" + +String jsonRequest = "{\n" + " amount: 100,\n" + " currency: \"INR\",\n" + " customer_id: \"cust_4xbQrmEoA5WJ01\",\n" + @@ -242,9 +242,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(JsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -291,7 +291,7 @@ Order order = instance.Orders.create(request); ## Create a recurring payment ```java - String json = "{\n" + + String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + @@ -307,9 +307,9 @@ Order order = instance.Orders.create(request); " }\n" + "}"; - JSONObject request = new JSONObject(json); + JSONObject requestJson = new JSONObject(jsonRequest); - Payment payment = instance.Payments.createRecurringPayment(request); + Payment payment = instance.payments.createRecurringPayment(requestJson); ``` **Parameters:** @@ -345,9 +345,11 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/cards/a ## Send/Resend notifications ```java -String InvoiceId = "inv_FHrXGIpd3N17DX"; +String invoiceId = "inv_FHrXGIpd3N17DX"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId,"sms"); +String medium = "sms"; + +Invoice invoice = instance.invoices.notifyBy(invoiceId,medium); ``` **Parameters:** @@ -367,15 +369,15 @@ Invoice invoice = instance.Invoices.notifyBy(InvoiceId,"sms"); ## Cancel registration link ```java -String InvoiceId = "inv_FHrXGIpd3N17DX"; +String invoiceId = "inv_FHrXGIpd3N17DX"; -instance.Invoices.cancel(InvoiceId) +instance.invoices.cancel(invoiceId) ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be fetched | +| invoiceId* | string | The id of the invoice to be fetched | **Response:** ```json @@ -440,9 +442,9 @@ instance.Invoices.cancel(InvoiceId) ## Fetch token by payment id ```java -String PaymentId = "pay_FHfqtkRzWvxky4"; +String paymentId = "pay_FHfqtkRzWvxky4"; -Payment payment = instance.Payments.fetch(PaymentId) +Payment payment = instance.payments.fetch(paymentId) ``` **Parameters:** @@ -496,15 +498,15 @@ Payment payment = instance.Payments.fetch(PaymentId) ## Fetch tokens by customer id ```java -String CustomerId = "cust_DtHaBuooGHTuyZ"; +String customerId = "cust_DtHaBuooGHTuyZ"; -List tokens = instance.Customers.fetchTokens(CustomerId) +List tokens = instance.customers.fetchTokens(customerId) ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | +| Name | Type | Description | +|-------------|---------|------------------------------------------------------------------------------| +| customerId* | string | The id of the customer to be fetched | **Response:** ```json @@ -557,16 +559,16 @@ List tokens = instance.Customers.fetchTokens(CustomerId) ### Fetch card ```java -String CardId = "card_F0zoXUp4IPPGoI"; +String cardId = "card_F0zoXUp4IPPGoI"; -Card card=instance.Cards.fetch(CardId); +Card card=instance.cards.fetch(cardId); ``` **Parameters:** | Name | Type | Description | |---------|---------|------------------------------------------------------------------------------| -| CardId* | string | card id to be fetched | +| cardId* | string | card id to be fetched | **Response** ```json @@ -585,18 +587,18 @@ Card card=instance.Cards.fetch(CardId); ## Delete tokens ```java -String CustomerId = "cust_Hwq7Ba6TDXl1ga"; +String customerId = "cust_Hwq7Ba6TDXl1ga"; -String TokenId = "token_1Aa00000000001"; +String tokenId = "token_1Aa00000000001"; -Customer customer = instance.Customers.deleteToken(CustomerId,TokenId) +Customer customer = instance.customers.deleteToken(customerId,tokenId) ``` **Parameters:** | Name | Type | Description | |-------------|---------|------------------------------------------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | -| TokenId* | string | The id of the token to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | **Response:** ```json diff --git a/documents/customers.md b/documents/customers.md index 878d2bb0..53e6e6ac 100644 --- a/documents/customers.md +++ b/documents/customers.md @@ -2,21 +2,21 @@ ### Create customer ```java -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " fail_existing: 0,\n" + - " gstin: \"29XAbbA4369J1PA\",\n" + +String jsonRequest = "{\n" + + "\"name\": \"Gaurav Kumar\",\n" + + "\"contact\": 9123456780,\n" + + "\"email\": \"gaurav.kumar@example.com\",\n" + + "\"fail_existing\": 0,\n" + + "\"gstin: \"29XAbbA4369J1PA\",\n" + " notes: {\n" + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(request); ``` **Parameters:** @@ -49,17 +49,17 @@ Customer customer = instance.Customers.create(request); ### Edit customer ```java -String CustomerId = "cust_1Aa00000000003"; +String customerId = "cust_1Aa00000000003"; -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"Gaurav.Kumar@example.com\",\n" + - " contact: 9000000000\n" + +String jsonRequest = "{\n" + + "\"name\": \"Gaurav Kumar\",\n" + + "\"email\": \"Gaurav.Kumar@example.com\",\n" + + "\"contact\": 9000000000\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(requestJson); -Customer customer = instance.Customers.edit(CustomerId,request); +Customer customer = instance.customers.edit(customerId,request); ``` **Parameters:** @@ -91,13 +91,13 @@ Customer customer = instance.Customers.edit(CustomerId,request); ### Fetch all customer ```java -String json = "{\n" + - "\"count\" : 1\n" + - "}"; +String jsonRequest = "{\n" + + "\"count\" : 1\n" + + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List customer = instance.Customers.fetchAll(options); +List customer = instance.customers.fetchAll(requestJson); ``` **Parameters:** @@ -134,16 +134,16 @@ List customer = instance.Customers.fetchAll(options); ### Fetch a customer ```java -String CustomerId = "cust_1Aa00000000001"; +String customerId = "cust_1Aa00000000001"; -Customer customer = instance.Customers.fetch(CustomerId); +Customer customer = instance.customers.fetch(customerId); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | +| customerId* | string | The id of the customer to be fetched | **Response:** ```json diff --git a/documents/emandate.md b/documents/emandate.md index 275ef914..f0b9d3eb 100644 --- a/documents/emandate.md +++ b/documents/emandate.md @@ -3,20 +3,20 @@ ### Create customer ```java String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " fail_existing: 0,\n" + - " gstin: \"29XAbbA4369J1PA\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + "\"name\": \"Gaurav Kumar\",\n" + + "\"contact\": 9123456780,\n" + + "\"email\": \"gaurav.kumar@example.com\",\n" + + "\"fail_existing\": 0,\n" + + "\"gstin\": \"29XAbbA4369J1PA\",\n" + + "\"notes\": {\n" + + "\"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + "\"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + " }\n" + "}"; JSONObject request = new JSONObject(json); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(request); ``` **Parameters:** @@ -49,36 +49,36 @@ Customer customer = instance.Customers.create(request); ### Create order ```java -String json = "{\n" + - " amount: 0,\n" + - " currency: \"INR\",\n" + - " method: \"emandate\",\n" + - " customer_id: \"cust_1Aa00000000001\",\n" + - " receipt: \"Receipt No. 1\",\n" + - " notes: {\n" + - " notes_key_1: \"Beam me up Scotty\",\n" + - " notes_key_2: \"Engage\"\n" + - " },\n" + - " token: {\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 9999900,\n" + - " expire_at: 4102444799,\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " },\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 1121431121541121,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0000001\"\n" + - " }\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"method\": \"emandate\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"token\": {\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"max_amount\": 9999900,\n" + + " \"expire_at\": 4102444799,\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 1121431121541121,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0000001\"\n" + + " }\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -93,6 +93,7 @@ Order order = instance.Orders.create(request); | token | object | A key-value pair | **Response:** + Create order response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/#112-create-an-order) ------------------------------------------------------------------------------------------------------- @@ -105,40 +106,40 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/emandat ### Create registration link ```java -String json = "{\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9123456780\n" + - " },\n" + - " type: \"link\",\n" + - " amount: 0,\n" + - " currency: \"INR\",\n" + - " description: \"12 p.m. Meals\",\n" + - " subscription_registration: {\n" + - " method: \"emandate\",\n" + - " auth_type: \"netbanking\",\n" + - " expire_at: 1580480689,\n" + - " max_amount: 50000,\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 11214311215411,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0001233\"\n" + - " }\n" + - " },\n" + - " receipt: \"Receipt no. 1\",\n" + - " expire_by: 1880480689,\n" + - " sms_notify: 1,\n" + - " email_notify: 1,\n" + - " notes: {\n" + - " \"note_key 1\": \"Beam me up Scotty\",\n" + - " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + - " }\n" + - "}"; -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9123456780\n" + + " },\n" + + " \"type\": \"link\",\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"description\": \"12 p.m. Meals\",\n" + + " \"subscription_registration\": {\n" + + " \"method\": \"emandate\",\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"expire_at\": 1580480689,\n" + + " \"max_amount\": 50000,\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " \"receipt\": \"Receipt no. 1\",\n" + + " \"expire_by\": 1880480689,\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; +JSONObject requestJson = new JSONObject(jsonRequest); -Invoice invoice = instance.Invoices.createRegistrationLink(request); +Invoice invoice = instance.invoices.createRegistrationLink(requestJson); ``` **Parameters:** @@ -154,24 +155,25 @@ Invoice invoice = instance.Invoices.createRegistrationLink(request); | notes | object | A key-value pair | **Response:** + Create registration link response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/authorization-transaction/#121-create-a-registration-link) ------------------------------------------------------------------------------------------------------- ### Send/Resend notifications ```java -String InvoiceId = "inv_FHrfRupD2ouKIt"; +String invoiceId = "inv_FHrfRupD2ouKIt"; String medium = "sms"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId, medium); +Invoice invoice = instance.invoices.notifyBy(invoiceId, medium); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be notified | +| invoiceId* | string | The id of the invoice to be notified | | medium* | string | `sms`/`email`, Medium through which notification should be sent. | **Response:** @@ -185,16 +187,16 @@ Invoice invoice = instance.Invoices.notifyBy(InvoiceId, medium); ### Cancel a registration link ```java -String InvoiceId = "inv_FHrfRupD2ouKIt"; +String invoiceId = "inv_FHrfRupD2ouKIt"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be cancelled | +| invoiceId* | string | The id of the invoice to be cancelled | **Response:** ```json @@ -259,16 +261,16 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ### Fetch token by payment ID ```java -String PaymentId = "pay_FHf9a7AO0iXM9I"; +String paymentId = "pay_FHf9a7AO0iXM9I"; -Payment payment = instance.Payments.fetch(PaymentId); +Payment payment = instance.payments.fetch(paymentId); ``` **Parameters:** | Name | Type | Description | |------------|--------|-----------------------------------| -| PaymentId* | string | Id of the payment to be retrieved | +| paymentId* | string | Id of the payment to be retrieved | **Response:** ```json @@ -314,16 +316,16 @@ Payment payment = instance.Payments.fetch(PaymentId); ### Fetch tokens by customer ID ```java -String CustomerId = "cust_DtHaBuooGHTuyZ"; +String customerId = "cust_DtHaBuooGHTuyZ"; -Customer customer = instance.Customers.fetchTokens(CustomerId); +Customer customer = instance.customers.fetchTokens(customerId); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | +| customerId* | string | The id of the customer to be fetched | **Response:** ```json @@ -366,19 +368,19 @@ Customer customer = instance.Customers.fetchTokens(CustomerId); ### Delete token ```java -String CustomerId = "cust_DtHaBuooGHTuyZ"; +String customerId = "cust_DtHaBuooGHTuyZ"; -String TokenId = "token_FHf94Uym9tdYFJ"; +String tokenId = "token_FHf94Uym9tdYFJ"; -Customer customer = instance.Customers.deleteToken(customerId, tokenId); +Customer customer = instance.customers.deleteToken(customerId, tokenId); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | -| TokenId* | string | The id of the token to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | **Response:** ```json @@ -392,7 +394,7 @@ Customer customer = instance.Customers.deleteToken(customerId, tokenId); ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\":1000,\n" + " \"currency\":\"INR\",\n" + " \"receipt\":\"Receipt No. 1\",\n" + @@ -402,9 +404,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -441,7 +443,7 @@ Order order = instance.Orders.create(request); ### Create a Recurring Payment ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + @@ -457,9 +459,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.createRecurringPayment(request); +Payment payment = instance.Payments.createRecurringPayment(requestJson); ``` **Parameters:** diff --git a/documents/fund.md b/documents/fund.md index 21bb7c21..7152089e 100644 --- a/documents/fund.md +++ b/documents/fund.md @@ -2,7 +2,7 @@ ### Create a fund account ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"customer_id\":\"cust_Aa000000000001\",\n" + " \"account_type\":\"bank_account\",\n" + " \"bank_account\":{\n" + @@ -12,9 +12,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -FundAccount fundaccount = instance.FundAccount.create(request); +FundAccount fundaccount = instance.fundAccount.create(requestJson); ``` **Parameters:** @@ -47,9 +47,9 @@ FundAccount fundaccount = instance.FundAccount.create(request); ### Fetch all fund accounts ```java -String CustomerId = "cust_Aa000000000001"; +String customerId = "cust_Aa000000000001"; -FundAccount fundaccount = instance.FundAccount.fetch(CustomerId); +FundAccount fundaccount = instance.fundAccount.fetch(customerId); ``` **Parameters:** diff --git a/documents/invoice.md b/documents/invoice.md index 6fc27886..88a2119d 100644 --- a/documents/invoice.md +++ b/documents/invoice.md @@ -5,68 +5,68 @@ Request #1 In this example, an invoice is created using the customer and item details. Here, the customer and item are created while creating the invoice. ```java -String json = "{\n" + - " type: \"invoice\",\n" + - " description: \"Invoice for the month of January 2020\",\n" + - " partial_payment: true,\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9999999999,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " billing_address: {\n" + - " line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + - " line2: \"Hosur Road\",\n" + - " zipcode: 560068,\n" + - " city: \"Bengaluru\",\n" + - " state: \"Karnataka\",\n" + - " country: \"in\"\n" + +String jsonRequest = "{\n" + + " \"type\": \"invoice\",\n" + + " \"description\": \"Invoice for the month of January 2020\",\n" + + " \"partial_payment\": 1,\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": 9999999999,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"billing_address\": {\n" + + " \"line1\": \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + + " \"line2\": \"Hosur Road\",\n" + + " \"zipcode\": 560068,\n" + + " \"city\": \"Bengaluru\",\n" + + " \"state\": \"Karnataka\",\n" + + " \"country\": \"in\"\n" + " },\n" + - " shipping_address: {\n" + - " line1: \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + - " line2: \"Hosur Road\",\n" + - " zipcode: 560068,\n" + - " city: \"Bengaluru\",\n" + - " state: \"Karnataka\",\n" + - " country: \"in\"\n" + + " \"shipping_address\": {\n" + + " \"line1\": \"Ground & 1st Floor, SJR Cyber Laskar\",\n" + + " \"line2\": \"Hosur Road\",\n" + + " \"zipcode\": 560068,\n" + + " \"city\": \"Bengaluru\",\n" + + " \"state\": \"Karnataka\",\n" + + " \"country\": \"in\"\n" + " }\n" + " },\n" + - " line_items: [\n" + + " \"line_items\": [\n" + " {\n" + - " name: \"Master Cloud Computing in 30 Days\",\n" + - " description: \"Book by Ravena Ravenclaw\",\n" + - " amount: 399,\n" + - " currency: \"USD\",\n" + - " quantity: 1\n" + + " \"name\": \"Master Cloud Computing in 30 Days\",\n" + + " \"description\": \"Book by Ravena Ravenclaw\",\n" + + " \"amount\": 399,\n" + + " \"currency\": \"USD\",\n" + + " \"quantity\": 1\n" + " }\n" + " ],\n" + - " sms_notify: 1,\n" + - " email_notify: 1,\n" + - " currency: \"USD\",\n" + - " expire_by: 1589765167\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"currency\": \"USD\",\n" + + " \"expire_by\": 1589765167\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Order order = instance.Invoices.create(request); +Order order = instance.invoices.create(requestRequest); ``` Request #2 In this example, an invoice is created using existing `customer_id` and `item_id` ```java -String json = "{\n" + - " type: \"invoice\",\n" + - " date: 1589994898,\n" + - " customer_id: \"cust_E7q0trFqXgExmT\",\n" + - " line_items: [\n" + +String jsonRequest = "{\n" + + " \"type:\": \"invoice\",\n" + + " \"date\": 1589994898,\n" + + " \"customer_id\": \"cust_E7q0trFqXgExmT\",\n" + + " \"line_items\": [\n" + " {\n" + " \"item_id\": \"item_DRt61i2NnL8oy6\"\n" + " }\n" + " ]\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Invoice invoice = instance.Invoices.create(request); +Invoice invoice = instance.invoices.create(requestRequest); ``` **Parameters:** @@ -79,6 +79,7 @@ Invoice invoice = instance.Invoices.create(request); |customer | object | customer details in a object format | **Response:** + For create invoice response please click [here](https://razorpay.com/docs/api/invoices/#create-an-invoice) ------------------------------------------------------------------------------------------------------- @@ -86,7 +87,7 @@ For create invoice response please click [here](https://razorpay.com/docs/api/in ### Fetch all invoices ```java -List invoice = instance.Invoices.fetchAll(); +List invoice = instance.invoices.fetchAll(); ``` **Parameters:** @@ -99,6 +100,7 @@ List invoice = instance.Invoices.fetchAll(); |receipt | string | The unique receipt number that you entered for internal purposes. | **Response:** + For fetch all invoice response please click [here](https://razorpay.com/docs/api/invoices/#fetch-multiple-invoices) ------------------------------------------------------------------------------------------------------- @@ -106,16 +108,16 @@ For fetch all invoice response please click [here](https://razorpay.com/docs/api ### Fetch invoice ```java -String InvoiceId = "inv_E7q0tqkxBRzdau"; +String invoiceId = "inv_E7q0tqkxBRzdau"; -Invoice invoice = instance.Invoices.fetch(InvoiceId); +Invoice invoice = instance.invoices.fetch(invoiceId); ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be fetched | +| Name | Type | Description | +|------------|---------|------------------------------------------------------------------------------| +| invoiceId* | string | The id of the invoice to be fetched | **Response:** ```json @@ -220,28 +222,22 @@ Invoice invoice = instance.Invoices.fetch(InvoiceId); ### Update invoice ```java -String json = "{\n" + - " line_items: [\n" + - " {\n" + - " id: \"li_DAweOizsysoJU6\",\n" + - " name: \"Book / English August - Updated name and quantity\",\n" + - " quantity: 1\n" + - " },\n" + +String invoiceId = "inv_DAweOiQ7amIUVd"; + +String jsonRequest = "{\n" + + " \"type:\": \"invoice\",\n" + + " \"date\": 1589994898,\n" + + " \"customer_id\": \"cust_E7q0trFqXgExmT\",\n" + + " \"line_items\": [\n" + " {\n" + - " name: \"Book / A Wild Sheep Chase\",\n" + - " amount: 200,\n" + - " currency: \"INR\",\n" + - " quantity: 1\n" + + " \"item_id\": \"item_DRt61i2NnL8oy6\"\n" + " }\n" + - " ],\n" + - " notes: {\n" + - " \"updated-key\": \"An updated note.\"\n" + - " }\n" + + " ]\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Invoice invoice = instance.Invoices.edit(invoiceId,request); +Invoice invoice = instance.invoices.edit(invoiceId,requestJson); ``` **Parameters:** @@ -258,16 +254,16 @@ For update invoice response please click [here](https://razorpay.com/docs/api/in ### Issue an invoice ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -Invoice invoice = instance.Invoices.issue(invoiceId); +Invoice invoice = instance.invoices.issue(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be issued | +| invoiceId* | string | The id of the invoice to be issued | **Response:** ```json @@ -384,16 +380,16 @@ Invoice invoice = instance.Invoices.issue(invoiceId); ### Delete an invoice ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -instance.Invoices.delete(InvoiceId); +instance.invoices.delete(InvoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be deleted | +| invoiceId* | string | The id of the invoice to be deleted | **Response:** ``` @@ -404,16 +400,16 @@ instance.Invoices.delete(InvoiceId); ### Cancel an invoice ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be cancelled | +| invoiceId* | string | The id of the invoice to be cancelled | **Response:** ```json @@ -519,11 +515,11 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ### Send notification ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; String medium = "sms"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +Invoice invoice = instance.invoices.notifyBy(invoiceId,medium); ``` **Parameters:** diff --git a/documents/item.md b/documents/item.md index 0a292fd0..647144bd 100644 --- a/documents/item.md +++ b/documents/item.md @@ -3,16 +3,16 @@ ### Create item ```java -String json = "{\n" + - " \"name\": \"Book / English August\",\n" + - " \"description\": \"An indian story, Booker prize winner.\",\n" + - " \"amount\": 20000,\n" + - " \"currency\": \"INR\"\n" + +String jsonRequest = "{\n" + + "\"name\": \"Book / English August\",\n" + + "\"description\": \"An indian story, Booker prize winner.\",\n" + + "\"amount\": 20000,\n" + + "\"currency\": \"INR\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Item item = instance.Items.create(request); +Item item = instance.items.create(requestJson); ``` **Parameters:** @@ -41,13 +41,13 @@ Item item = instance.Items.create(request); ### Fetch all items ```java -String json = "{\n" + - "\"count\" : 1\n" + - "}"; +String jsonRequest = "{\n" + + "\"count\" : 1\n" + + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List item = instance.Items.fetchAll(options); +List item = instance.items.fetchAll(requestJson); ``` **Parameters:** @@ -100,15 +100,15 @@ List item = instance.Items.fetchAll(options); ### Fetch particular item ```java -String ItemId = "item_7Oxp4hmm6T4SCn"; +String itemId = "item_7Oxp4hmm6T4SCn"; -Item item = instance.Items.fetch(ItemId) +Item item = instance.items.fetch(itemId) ``` **Parameters** | Name | Type | Description | |---------|--------|-------------------------------------| -| ItemId* | string | The id of the item to be fetched | +| itemId* | string | The id of the item to be fetched | **Response:** ```json @@ -127,9 +127,9 @@ Item item = instance.Items.fetch(ItemId) ### Update item ```java -String ItemId = "item_7Oy8OMV6BdEAac"; +String itemId = "item_7Oy8OMV6BdEAac"; -String json = "{\n" + +String jsonRequest = "{\n" + " \"name\": \"Book / Ignited Minds - Updated name!\",\n" + " \"description\": \"New descirption too. :).\",\n" + " \"amount\": 20000,\n" + @@ -137,9 +137,9 @@ String json = "{\n" + " \"active\": true\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Item item = instance.Items.edit(ItemId, request); +Item item = instance.items.edit(itemId, requestJson); ``` **Parameters** @@ -153,6 +153,7 @@ Item item = instance.Items.edit(ItemId, request); | active | boolean | Possible values is `0` or `1` | **Response:** + ```json { "id": "item_7Oy8OMV6BdEAac", @@ -166,8 +167,10 @@ Item item = instance.Items.edit(ItemId, request); ------------------------------------------------------------------------------------------------------- ### Delete item -```js -instance.Items.delete(itemId) +```java +String itemId = "item_7Oy8OMV6BdEAac"; + +instance.items.delete(itemId) ``` **Parameters** @@ -176,6 +179,7 @@ instance.Items.delete(itemId) | itemId* | string | The id of the item to be fetched | **Response:** + ```json [] ``` diff --git a/documents/order.md b/documents/order.md index 4c26a51c..d1d0437c 100644 --- a/documents/order.md +++ b/documents/order.md @@ -3,19 +3,19 @@ ### Create order ```java -String json = "{\n" + - " amount: 50000,\n" + - " currency: \"INR\",\n" + - " receipt: \"receipt#1\",\n" + - " notes: {\n" + - " key1: \"value3\",\n" + - " key2: \"value2\"\n" + - " }\n" + - "}"; - -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"amount\": 50000,\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"receipt#1\",\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -Order order = instance.Orders.create(json) +Order order = instance.orders.create(requestRequest); ``` **Parameters:** @@ -51,13 +51,13 @@ Order order = instance.Orders.create(json) ### Fetch all orders ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -List order = instance.Orders.fetchAll(options); +List order = instance.orders.fetchAll(requestRequest); ``` **Parameters** @@ -99,16 +99,16 @@ List order = instance.Orders.fetchAll(options); ### Fetch particular order -```js -String OrderId = "order_DaaS6LOUAASb7Y"; +```java +String orderId = "order_DaaS6LOUAASb7Y"; -Order order = instance.Orders.fetch(OrderId); +Order order = instance.orders.fetch(orderId); ``` **Parameters** | Name | Type | Description | |----------|--------|-------------------------------------| -| OrderId* | string | The id of the order to be fetched | +| orderId* | string | The id of the order to be fetched | **Response:** @@ -132,15 +132,15 @@ Order order = instance.Orders.fetch(OrderId); ### Fetch payments for an order ```java -String OrderId = "order_DaaS6LOUAASb7Y"; +String orderId = "order_DaaS6LOUAASb7Y"; -Order order = instance.Orders.fetchPayments(OrderId); +Order order = instance.orders.fetchPayments(orderId); ``` **Parameters** | Name | Type | Description | |----------|--------|-------------------------------------| -| OrderId* | string | The id of the order to be retrieve payment info | +| orderId* | string | The id of the order to be retrieve payment info | **Response:** ```json @@ -183,18 +183,18 @@ Order order = instance.Orders.fetchPayments(OrderId); ### Update order ```java -String OrderId = "order_DaaS6LOUAASb7Y"; +String orderId = "order_DaaS6LOUAASb7Y"; -String json = {\n" + +String jsonRequest = {\n" + " \"notes\": {\n" + " \"key1\": \"value3\",\n" + " \"key2\": \"value2\"\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.edit(OrderId,request); +Order order = instance.orders.edit(OrderId,requestJson); ``` **Parameters** diff --git a/documents/papernach.md b/documents/papernach.md index 3160af6c..0c72199f 100644 --- a/documents/papernach.md +++ b/documents/papernach.md @@ -2,21 +2,21 @@ ### Create customer ```java -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " fail_existing: 0,\n" + - " gstin: \"29XAbbA4369J1PA\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": 9123456780,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"fail_existing\": 0,\n" + + " \"gstin\": \"29XAbbA4369J1PA\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -instance.Customers.create(request); +instance.customers.create(requestRequest); ``` **Parameters:** @@ -49,36 +49,36 @@ instance.Customers.create(request); ### Create order ```java -String json = "{\n" + - " amount: 0,\n" + - " currency: \"INR\",\n" + - " method: \"emandate\",\n" + - " customer_id: \"cust_1Aa00000000001\",\n" + - " receipt: \"Receipt No. 1\",\n" + - " notes: {\n" + - " notes_key_1: \"Beam me up Scotty\",\n" + - " notes_key_2: \"Engage\"\n" + - " },\n" + - " token: {\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 9999900,\n" + - " expire_at: 4102444799,\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " },\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 1121431121541121,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0000001\"\n" + - " }\n" + - " }\n" + - "}"; - -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"method\": \"emandate\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"token\": {\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"max_amount\": 9999900,\n" + + " \"expire_at\": 4102444799,\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 1121431121541121,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0000001\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestRequest); ``` **Parameters:** @@ -163,48 +163,49 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/paper-n ### Create registration link ```java -String json = "{\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9123456780\n" + +String jsonRequest = "{\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9123456780\n" + " },\n" + - " amount: 0,\n" + - " currency: \"INR\",\n" + - " type: \"link\",\n" + - " description: \"12 p.m. Meals\",\n" + - " subscription_registration: {\n" + - " method: \"nach\",\n" + - " auth_type: \"physical\",\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 11214311215411,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0001233\"\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"type\": \"link\",\n" + + " \"description\": \"12 p.m. Meals\",\n" + + " \"subscription_registration\": {\n" + + " \"method\": \"nach\",\n" + + " \"auth_type\": \"physical\",\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + " },\n" + - " nach: {\n" + - " form_reference1: \"Recurring Payment for Gaurav Kumar\",\n" + - " form_reference2: \"Method Paper NACH\"\n" + + " \"nach\": {\n" + + " \"form_reference1\": \"Recurring Payment for Gaurav Kumar\",\n" + + " \"form_reference2\": \"Method Paper NACH\"\n" + " },\n" + - " expire_at: 1947483647,\n" + - " max_amount: 50000\n" + + " \"expire_at\": 1947483647,\n" + + " \"max_amount\": 50000\n" + " },\n" + - " receipt: \"Receipt No. 1\",\n" + - " sms_notify: 1,\n" + - " email_notify: 1,\n" + - " expire_by: 1647483647,\n" + - " notes: {\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"expire_by\": 1647483647,\n" + + " \"notes\": {\n" + " \"note_key 1\": \"Beam me up Scotty\",\n" + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Invoices.createRegistrationLink(request); +Payment payment = instance.invoices.createRegistrationLink(requestRequest); ``` **Parameters:** + All parameters listed [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/authorization-transaction/#121-create-a-registration-link) are supported **Response:** @@ -302,7 +303,7 @@ All parameters listed [here](https://razorpay.com/docs/api/recurring-payments/pa ### Send/Resend notifications ```java -String InvoiceId = "inv_FHrZiAubEzDdaq"; +String invoiceId = "inv_FHrZiAubEzDdaq"; String medium = "sms"; @@ -313,7 +314,7 @@ Invoice invoice = instance.Invoices.notifyBy(invoiceId, medium); | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be notified | +| invoiceId* | string | The id of the invoice to be notified | | medium* | string | `sms`/`email`, Medium through which notification should be sent. | **Response:** @@ -327,16 +328,16 @@ Invoice invoice = instance.Invoices.notifyBy(invoiceId, medium); ### Cancel a registration link ```java -String InvoiceId = "inv_FHrZiAubEzDdaq"; +String invoiceId = "inv_FHrZiAubEzDdaq"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be cancelled | +| invoiceId* | string | The id of the invoice to be cancelled | **Response:** ```json @@ -433,9 +434,9 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ### Fetch Payment ID using Order ID ```java -String OrderId = "order_FHrZiBOkWHZPOp"; +String orderId = "order_FHrZiBOkWHZPOp"; -Order order = instance.Orders.fetchPayments(orderId); +Order order = instance.orders.fetchPayments(orderId); ``` **Parameters:** @@ -490,9 +491,9 @@ Order order = instance.Orders.fetchPayments(orderId); ### Fetch token by payment ID ```java -String PaymentId = "pay_1Aa00000000003"; +String paymentId = "pay_1Aa00000000003"; -instance.Payments.fetch(PaymentId); +instance.payments.fetch(paymentId); ``` **Parameters:** @@ -545,9 +546,9 @@ instance.Payments.fetch(PaymentId); ### Fetch tokens by customer ID ```java -String CustomerId = "inv_EnLLfgCzRfcMuh"; +String customerId = "inv_EnLLfgCzRfcMuh"; -Customer customer = instance.Customers.fetchTokens(CustomerId); +Customer customer = instance.customers.fetchTokens(customerId); ``` **Parameters:** @@ -589,11 +590,11 @@ Customer customer = instance.Customers.fetchTokens(CustomerId); ### Delete token ```java -String CustomerId = "cust_DtHaBuooGHTuyZ"; +String customerId = "cust_DtHaBuooGHTuyZ"; -String TokenId = "token_EhYgIE3pOyMQpD"; +String tokenId = "token_EhYgIE3pOyMQpD"; -instance.Customers.deleteToken(customerId, tokenId); +instance.customers.deleteToken(customerId, tokenId); ``` **Parameters:** @@ -614,19 +615,19 @@ instance.Customers.deleteToken(customerId, tokenId); ### Create an order to charge the customer ```java -String json = "{\n" + - " amount: 1000,\n" + - " currency: \"INR\",\n" + - " receipt: \"Receipt No. 1\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\":1000,\n" + + " \"currency\":\"INR\",\n" + + " \"receipt\":\"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestRequest); ``` **Parameters:** @@ -637,7 +638,9 @@ Order order = instance.Orders.create(request); | currency* | string | Currency of the order. Currently only `INR` is supported. | | receipt | string | Your system order reference id. | | notes | object | A key-value pair | + **Response:** + ```json { "id":"order_1Aa00000000002", @@ -662,7 +665,7 @@ Order order = instance.Orders.create(request); ### Create a Recurring Payment ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + @@ -678,25 +681,25 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Payments.createRecurringPayment(request); +Payment payment = instance.Payments.createRecurringPayment(requestRequest); ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------------------------------------------------| -| email* | string | The customer's email address. | -| contact* | string | The customer's phone number. | -| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | -| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | -| order_id* | string | The unique identifier of the order created. | -| customer_id* | string | The `customer_id` for the customer you want to charge. | -| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| -| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| -| description* | string | A user-entered description for the payment.| -| notes* | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | +| Name | Type | Description | +|----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address. | +| contact* | string | The customer's phone number. | +| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| order_id* | string | The unique identifier of the order created. | +| customer_id* | string | The `customer_id` for the customer you want to charge. | +| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| +| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| +| description | string | A user-entered description for the payment.| +| notes | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | **Response:** ```json diff --git a/documents/payment.md b/documents/payment.md index db2b825b..62004af2 100644 --- a/documents/payment.md +++ b/documents/payment.md @@ -3,22 +3,22 @@ ### Capture payment ```java -String PaymentId = "pay_G8VQzjPLoAvm6D"; -String json = "{\n" + +String paymentId = "pay_G8VQzjPLoAvm6D"; +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Payments.capture(PaymentId, request); +Payment payment = instance.payments.capture(paymentId, requestRequest); ``` **Parameters:** | Name | Type | Description | |------------|---------|--------------------------------------------------------------------------------| -| PaymentId* | string | Id of the payment to capture | +| paymentId* | string | Id of the payment to capture | | amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | currency | string | The currency of the payment (defaults to INR) | @@ -64,13 +64,13 @@ Payment payment = instance.Payments.capture(PaymentId, request); ### Fetch all payments ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List payment = instance.Payments.fetchAll(options); +List payment = instance.payments.fetchAll(requestJson); ``` **Parameters:** @@ -130,9 +130,9 @@ List payment = instance.Payments.fetchAll(options); ### Fetch a payment ```java -String PaymentId = "pay_G8VQzjPLoAvm6D"; +String paymentId = "pay_G8VQzjPLoAvm6D"; -Payment payment = instance.Payments.fetch(PaymentId); +Payment payment = instance.payments.fetch(paymentId); ``` **Parameters:** @@ -183,15 +183,15 @@ Payment payment = instance.Payments.fetch(PaymentId); ### Fetch payments for an order ```java -String OrderId = "order_DovFx48wjYEr2I"; +String orderId = "order_DovFx48wjYEr2I"; -Order order = instance.Orders.fetchPayments(OrderId) +Order order = instance.orders.fetchPayments(orderId) ``` **Parameters** | Name | Type | Description | |----------|--------|-------------------------------------| -| OrderId* | string | The id of the order to be retrieve payment info | +| orderId* | string | The id of the order to be retrieve payment info | **Response:** ```json @@ -238,17 +238,18 @@ Order order = instance.Orders.fetchPayments(OrderId) ### Update a payment ```java -String PaymentId = "pay_CBYy6tLmJTzn3Q"; -String json = "{\n" + +String paymentId = "pay_CBYy6tLmJTzn3Q"; + +String jsonRequest = "{\n" + " \"notes\": {\n" + " \"key1\": \"value1\",\n" + " \"key2\": \"value2\"\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Payments.edit(PaymentId,request); +Payment payment = instance.payments.edit(PaymentId,requestRequest); ``` **Parameters:** @@ -303,20 +304,25 @@ Payment payment = instance.Payments.edit(PaymentId,request); Request #1: Card ```java -JSONObject request = new JSONObject({'expand[]':'card'}); +String jsonRequest = "{\"expand[]\":\"card\"}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -List payment = instance.Payments.fetchAll(request); +List payment = instance.payments.fetchAll(requestRequest); ``` Request #2: EMI ```java -JSONObject request = new JSONObject({'expand[]':'emi'}); +String jsonRequest = "{\"expand[]\":\"emi\"}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -List payment = instance.payments.fetchAll(request); +List payment = instance.Payments.fetchAll(requestRequest); ``` -**Response:**
+**Response:** + For expanded card or emi details for payments response please click [here](https://razorpay.com/docs/api/payments/#fetch-expanded-card-or-emi-details-for-payments) ------------------------------------------------------------------------------------------------------- @@ -324,16 +330,16 @@ For expanded card or emi details for payments response please click [here](https ### Fetch card details with paymentId ```java -String PaymentId = "pay_CBYy6tLmJTzn3Q"; +String paymentId = "pay_CBYy6tLmJTzn3Q"; -Card card = instance.Cards.fetchCardDetails(PaymentId); +Card card = instance.cards.fetchCardDetails(paymentId); ``` **Parameters:** | Name | Type | Description | |------------|---------|--------------------------------------| -| PaymentId* | string | Id of the payment to update | +| paymentId* | string | Id of the payment to update | **Response:** ```json @@ -354,20 +360,21 @@ Card card = instance.Cards.fetchCardDetails(PaymentId); ### Fetch Payment Downtime Details -```js +```java List payment = instance.Payments.fetchPaymentDowntime(); ``` -**Response:**
+**Response:** + For payment downtime response please click [here](https://razorpay.com/docs/api/payments/downtime/#fetch-payment-downtime-details) ------------------------------------------------------------------------------------------------------- -### Fetch Payment Downtime +### Fetch Payment Downtime Details By Downtime Id ```java String DowntimeId = "down_F7LroRQAAFuswd"; -instance.Payments.fetchPaymentDowntimeById(DowntimeId); +instance.payments.fetchPaymentDowntimeById(DowntimeId); ``` **Parameters:** @@ -383,22 +390,23 @@ For payment downtime by id response please click [here](https://razorpay.com/doc ### Payment capture settings API ```java -String json = "{\n" + - " amount:50000,\n" + - " currency: 'INR',\n" + - " receipt: 'rcptid_11',\n" + - " payment: {\n" + - " capture : 'automatic',\n" + - " capture_options : {\n" + - " automatic_expiry_period : 12,\n" + - " manual_expiry_period : 7200,\n" + - " refund_speed : 'optimum'\n" + - " } \n" + - " }\n" + - "}"; -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"amount\":50000,\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"rcptid_11\",\n" + + " \"payment\": {\n" + + " \"capture\": \"automatic\",\n" + + " \"capture_options\": {\n" + + " \"automatic_expiry_period\": 12,\n" + + " \"manual_expiry_period\": 7200,\n" + + " \"refund_speed\": \"optimum\"\n" + + " } \n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -instance.Orders.create(request); +instance.orders.create(requestRequest); ``` **Parameters:** @@ -410,7 +418,7 @@ instance.Orders.create(request); | receipt | string | Your system order reference id. | | payment | object | please refer this [doc](https://razorpay.com/docs/payments/payments/capture-settings/api/) for params | -**Response:**
+**Response:** ```json { "id": "order_DBJOWzybf0sJbb", @@ -430,29 +438,30 @@ instance.Orders.create(request); ### Create Payment Json -```js -String json = "{\n" + - " amount: 100,\n" + - " currency: \"INR\",\n" + - " order_id: \"order_EAkbvXiCJlwhHR\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9090909090,\n" + - " method: \"card\",\n" + - " card:{\n" + - " number: 4111111111111111,\n" + - " name: \"Gaurav\",\n" + - " expiry_month: 11,\n" + - " expiry_year: 23,\n" + - " cvv: 100\n" + - " }\n" + - "}"; +```java +String jsonRequest = "{\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"order_id\": \"order_EAkbvXiCJlwhHR\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9090909090,\n" + + " \"method\": \"card\",\n" + + " \"card\":{\n" + + " \"number\": 4111111111111111,\n" + + " \"name\": \"Gaurav\",\n" + + " \"expiry_month\": 11,\n" + + " \"expiry_year\": 23,\n" + + " \"cvv\": 100\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -instance.Payments.createJsonPayment(request); +instance.payments.createJsonPayment(requestRequest); ``` **Parameters:** + please refer this [doc](https://razorpay.com/docs/payment-gateway/s2s-integration/payment-methods/) for params **Response:**
diff --git a/documents/paymentLink.md b/documents/paymentLink.md index ebbad1db..e4e5db8a 100644 --- a/documents/paymentLink.md +++ b/documents/paymentLink.md @@ -6,7 +6,7 @@ Request #1 Standard Payment Link ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 500,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -29,16 +29,16 @@ String json = "{\n" + " \"callback_method\": \"get\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestRequest); ``` Request #2 UPI Payment Link ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"upi_link\": true,\n" + " \"amount\": 500,\n" + " \"currency\": \"INR\",\n" + @@ -60,9 +60,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestRequest); ``` @@ -81,6 +81,7 @@ PaymentLink payment = instance.PaymentLink.create(request); |notes | json object | 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, "note_key": "Beam me up Scotty” | **Response:** + For create payment link response please click [here](https://razorpay.com/docs/api/payment-links/#create-payment-link) ------------------------------------------------------------------------------------------------------- @@ -88,7 +89,13 @@ For create payment link response please click [here](https://razorpay.com/docs/a ### Fetch all payment link ```java -List paymentlink = instance.PaymentLink.fetchAll(); +String jsonRequest = "{\n" + + "\"reference_id\" : TS1989\n" + + "}"; + +JSONObject requestJson = new JSONObject(jsonRequest); + +List paymentlink = instance.paymentLink.fetchAll(requestJson); ``` **Parameters:** @@ -106,9 +113,9 @@ For fetch all payment link response please click [here](https://razorpay.com/doc ### Fetch specific payment link ```java -String PaymentLinkId = "plink_FMbhpT6nqDjDei"; +String paymentLinkId = "plink_FMbhpT6nqDjDei"; -instance.PaymentLink.fetch(PaymentLinkId); +instance.paymentLink.fetch(paymentLinkId); ``` **Parameters:** @@ -118,6 +125,7 @@ instance.PaymentLink.fetch(PaymentLinkId); | paymentLinkId* | string | Unique identifier of the Payment Link. | **Response:** + For fetch specific payment link response please click [here](https://razorpay.com/docs/api/payment-links/#specific-payment-links-by-id) ------------------------------------------------------------------------------------------------------- @@ -125,9 +133,9 @@ For fetch specific payment link response please click [here](https://razorpay.co ### Update payment link ```java -String PaymentLinkId = "plink_FMbhpT6nqDjDei"; +String paymentLinkId = "plink_FMbhpT6nqDjDei"; -String json = "{\n" + +String jsonRequest = "{\n" + " \"reference_id\": \"TS35\",\n" + " \"expire_by\": 1653347540,\n" + " \"reminder_enable\":false,\n" + @@ -136,9 +144,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -PaymentLink paymentlink = instance.PaymentLink.edit(PaymentId,request); +PaymentLink paymentlink = instance.paymentLink.edit(PaymentId,requestRequest); ``` **Parameters:** @@ -152,6 +160,7 @@ PaymentLink paymentlink = instance.PaymentLink.edit(PaymentId,request); | notes | string | object 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, "note_key": "Beam me up Scotty”. | **Response:** + For updating payment link response please click [here](https://razorpay.com/docs/api/payment-links/#update-payment-link) ------------------------------------------------------------------------------------------------------- @@ -161,7 +170,7 @@ For updating payment link response please click [here](https://razorpay.com/docs ```java String PaymentLinkId = "plink_FMbhpT6nqDjDei"; -PaymentLink paymentlink = instance.PaymentLink.cancel(PaymentLinkId,medium); +PaymentLink paymentlink = instance.PaymentLink.cancel(paymentLinkId); ``` **Parameters:** @@ -171,17 +180,18 @@ PaymentLink paymentlink = instance.PaymentLink.cancel(PaymentLinkId,medium); | paymentLinkId* | string | Unique identifier of the Payment Link. | **Response:** + For canceling payment link response please click [here](https://razorpay.com/docs/api/payment-links/#cancel-payment-link) ------------------------------------------------------------------------------------------------------- ### Send notification ```java -String PaymentLinkId = "plink_FMbhpT6nqDjDei"; +String paymentLinkId = "plink_FMbhpT6nqDjDei"; String medium = "email"; -PaymentLink paymentlink = instance.PaymentLink.notifyBy(PaymentLinkId,medium); +PaymentLink paymentlink = instance.paymentLink.notifyBy(paymentLinkId,medium); ``` **Parameters:** @@ -202,7 +212,7 @@ PaymentLink paymentlink = instance.PaymentLink.notifyBy(PaymentLinkId,medium); ### Transfer payments received using payment links ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 20000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": false,\n" + @@ -235,9 +245,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestRequest); ``` @@ -292,7 +302,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Offers on payment links ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 3400,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": false,\n" + @@ -318,9 +328,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` @@ -375,7 +385,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Managing reminders for payment links ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -394,9 +404,9 @@ String json = "{\n" + " \"reminder_enable\": false\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` @@ -475,37 +485,37 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Rename labels in checkout section ```java -String json = "{\n" + - " \"amount\": 500,\n" + - " \"currency\": \"INR\",\n" + - " \"accept_partial\": true,\n" + - " \"first_min_partial_amount\": 100,\n" + - " \"description\": \"For XYZ purpose\",\n" + - " \"customer\": {\n" + - " \"name\": \"Gaurav Kumar\",\n" + - " \"email\": \"gaurav.kumar@example.com\",\n" + - " \"contact\": \"+919999999999\"\n" + - " },\n" + - " \"notify\": {\n" + - " \"sms\": true,\n" + - " \"email\": true\n" + - " },\n" + - " \"reminder_enable\": true,\n" + - " \"options\": {\n" + - " \"checkout\": {\n" + - " \"partial_payment\": {\n" + - " \"min_amount_label\": \"Minimum Money to be paid\",\n" + - " \"partial_amount_label\": \"Pay in parts\",\n" + - " \"partial_amount_description\": \"Pay at least ₹100\",\n" + - " \"full_amount_label\": \"Pay the entire amount\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": 500,\n" + + " \"currency\": \"INR\",\n" + + " \"accept_partial\": true,\n" + + " \"first_min_partial_amount\": 100,\n" + + " \"description\": \"For XYZ purpose\",\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": \"+919999999999\"\n" + + " },\n" + + " \"notify\": {\n" + + " \"sms\": true,\n" + + " \"email\": true\n" + + " },\n" + + " \"reminder_enable\": true,\n" + + " \"options\": {\n" + + " \"checkout\": {\n" + + " \"partial_payment\": {\n" + + " \"min_amount_label\": \"Minimum Money to be paid\",\n" + + " \"partial_amount_label\": \"Pay in parts\",\n" + + " \"partial_amount_description\": \"Pay at least ₹100\",\n" + + " \"full_amount_label\": \"Pay the entire amount\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` **Parameters:** @@ -566,7 +576,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Change Business name ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -590,9 +600,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` **Parameters:** @@ -652,7 +662,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Prefill checkout fields ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -682,9 +692,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` @@ -709,8 +719,8 @@ For prefill checkout fields response please click [here](https://razorpay.com/do ### Customize payment methods -```java -String json = "{\n" + +```java +String jsonRequest = "{\n" + " \"amount\": 500,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -738,9 +748,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` **Parameters:** @@ -801,7 +811,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Set checkout fields as read-only ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -828,9 +838,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` **Parameters:** @@ -891,7 +901,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Implement thematic changes in payment links checkout section ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -917,9 +927,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.paymentLink.create(requestJson); ``` **Parameters:** @@ -979,7 +989,7 @@ PaymentLink payment = instance.PaymentLink.create(request); ### Rename labels in payment details section ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"accept_partial\": true,\n" + @@ -1008,9 +1018,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -PaymentLink payment = instance.PaymentLink.create(request); +PaymentLink payment = instance.PaymentLink.create(requestRequest); ``` **Parameters:** @@ -1028,6 +1038,7 @@ PaymentLink payment = instance.PaymentLink.create(request); |options* | object | Parent parameter under which the hosted_page and label child parameters must be passed.| **Response:** + For rename labels in payment details section response please click [here](https://razorpay.com/docs/payment-links/api/new/advanced-options/customize/rename-payment-details-labels/) ------------------------------------------------------------------------------------------------------- diff --git a/documents/plan.md b/documents/plan.md index 386c3bec..6dad3d81 100644 --- a/documents/plan.md +++ b/documents/plan.md @@ -3,24 +3,24 @@ ### Create plan ```java -String json = "{\n" + - " period: \"weekly\",\n" + - " interval: 1,\n" + - " item: {\n" + - " name: \"Test plan - Weekly\",\n" + - " amount: 69900,\n" + - " currency: \"INR\",\n" + - " description: \"Description for the test plan\"\n" + - " },\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"period\": \"weekly\",\n" + + " \"interval\": 1,\n" + + " \"item\": {\n" + + " \"name\": \"Test plan - Weekly\",\n" + + " \"amount\": 69900,\n" + + " \"currency\": \"INR\",\n" + + " \"description\": \"Description for the test plan\"\n" + + " },\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Plan plan = razorpayclient.Plans.create(request); +Plan plan = razorpayclient.plans.create(requestRequest); ``` **Parameters:** @@ -70,13 +70,13 @@ Plan plan = razorpayclient.Plans.create(request); ### Fetch all plans ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -instance.Plans.fetchAll(options); +instance.plans.fetchAll(requestJson); ``` **Parameters:** @@ -132,16 +132,16 @@ instance.Plans.fetchAll(options); ### Fetch particular plan ```java -String PlanId = "plan_00000000000001"; +String planId = "plan_00000000000001"; -instance.Plans.fetch(PlanId) +instance.plans.fetch(planId); ``` **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| PlanId | string | The id of the plan to be fetched | +| Name | Type | Description | +|--------|-----------|--------------------------------------------------| +| planId | string | The id of the plan to be fetched | **Response:** ```json diff --git a/documents/qrcode.md b/documents/qrcode.md index 156e43ac..f35613ae 100644 --- a/documents/qrcode.md +++ b/documents/qrcode.md @@ -3,23 +3,23 @@ ### Create Qr code ```java -String json = "{\n" + - " type: \"upi_qr\",\n" + - " name: \"Store_1\",\n" + - " usage: \"single_use\",\n" + - " fixed_amount: true,\n" + - " payment_amount: 300,\n" + - " description: \"For Store 1\",\n" + - " customer_id: \"cust_HKsR5se84c5LTO\",\n" + - " close_by: 1681615838,\n" + - " notes: {\n" + - " purpose: \"Test UPI QR code notes\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"type\": \"upi_qr\",\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"fixed_amount\": true,\n" + + " \"payment_amount\": 300,\n" + + " \"description\": \"For Store 1\",\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -QrCode qrcode = instance.qrCode.create(request); +QrCode qrcode = instance.qrCode.create(requestJson); ``` **Parameters:** @@ -64,32 +64,32 @@ QrCode qrcode = instance.qrCode.create(request); ### Create Qr code with GST ```java -String json = "{\n" + - " type: \"upi_qr\",\n" + - " name: \"Store_1\",\n" + - " usage: \"single_use\",\n" + - " fixed_amount: true,\n" + - " payment_amount: 300,\n" + - " description: \"For Store 1\",\n" + - " customer_id: \"cust_HKsR5se84c5LTO\",\n" + - " close_by: 1681615838,\n" + - " notes: {\n" + - " purpose: \"Test UPI QR code notes\"\n" + - " },\n" + - " tax_invoice: {\n" + - " number: \"INV001\",\n" + - " date: 1589994898,\n" + - " customer_name: \"Gaurav Kumar\",\n" + - " business_gstin: \"06AABCU9605R1ZR\",\n" + - " gst_amount: 4000,\n" + - " cess_amount: 0,\n" + - " supply_type: \"interstate\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"type\": \"upi_qr\",\n" + + " \"name\": \"Store_1\",\n" + + " \"usage\": \"single_use\",\n" + + " \"fixed_amount\": true,\n" + + " \"payment_amount\": 300,\n" + + " \"description\": \"For Store 1\",\n" + + " \"customer_id\": \"cust_HKsR5se84c5LTO\",\n" + + " \"close_by\": 1681615838,\n" + + " \"notes\": {\n" + + " \"purpose\": \"Test UPI QR code notes\"\n" + + " },\n" + + " \"tax_invoice\": {\n" + + " \"number\": \"INV001\",\n" + + " \"date\": 1589994898,\n" + + " \"customer_name\": \"Gaurav Kumar\",\n" + + " \"business_gstin\": \"06AABCU9605R1ZR\",\n" + + " \"gst_amount\": 4000,\n" + + " \"cess_amount\": 0,\n" + + " \"supply_type\": \"interstate\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -QrCode qrcode = instance.qrCode.create(request); +QrCode qrcode = instance.qrCode.create(requestJson); ``` **Parameters:** @@ -144,13 +144,13 @@ QrCode qrcode = instance.qrCode.create(request); ### Fetch all Qr code ```java -String json = "{\n" + - "\"count\" : 1\n" + - "}"; +String jsonRequest = "{\n" + + "\"count\" : 1\n" + + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson= new JSONObject(jsonRequest); -List qrcode = instance.QrCode.fetchAll(options); +List qrcode = instance.qrCode.fetchAll(requestJson); ``` **Parameters:** @@ -199,16 +199,16 @@ List qrcode = instance.QrCode.fetchAll(options); ### Fetch a Qr code ```java -String QrCodeId = "qr_HO2r1MDprYtWRT"; +String qrCodeId = "qr_HO2r1MDprYtWRT"; -QrCode qrcode = instance.qrCode.fetch(QrCodeId); +QrCode qrcode = instance.qrCode.fetch(qrCodeId); ``` **Parameters:** | Name | Type | Description | |----------|---------|------------------------------------------------------------------------------| -| QrCodeId | string | The id of the qr code to be fetched | +| qrCodeId | string | The id of the qr code to be fetched | **Response:** ```json @@ -240,11 +240,11 @@ QrCode qrcode = instance.qrCode.fetch(QrCodeId); ### Fetch a Qr code for customer id ```java -String CustomerId = "cust_HKsR5se84c5LTO"; +String jsonRequest = "{\"customer_id\":\"cust_HKsR5se84c5LTO\"}"; -JSONObject request = new JSONObject("{\"customer_id\":"+CustomerId+"}"); +JSONObject requestRequest = new JSONObject(jsonRequest); -List qrcode = instance.QrCode.fetchAll(request) +List qrcode = instance.qrCode.fetchAll(request); ``` **Parameters:** @@ -287,18 +287,18 @@ List qrcode = instance.QrCode.fetchAll(request) ### Fetch a Qr code for payment id ```java - String PaymentId = "pay_FVmAstJWfsD3SO"; +String jsonRequest = "{\"payment_id\":\"pay_FVmAstJWfsD3SO\"}"; - JSONObject request = new JSONObject("{\"payment_id\":"+PaymentId+"}"); +JSONObject requestRequest = new JSONObject(jsonRequest); -List qrcode = instance.QrCode.fetchAll(request); +List qrcode = instance.qrCode.fetchAll(requestRequest); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| PaymentId* | string | The id of the payment to which qr code need to be fetched | +| payment_id* | string | The id of the payment to which qr code need to be fetched | **Response:** ```json @@ -333,14 +333,15 @@ List qrcode = instance.QrCode.fetchAll(request); ### Fetch Payments for a QR Code ```java -String QrCodeId = "qr_HMsVL8HOpbMcjU"; +String qrCodeId = "qr_HMsVL8HOpbMcjU"; -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); + +JSONObject requestJson = new JSONObject(jsonRequest); -List qrcode = instance.qrCode.fetchAllPayments(QrCodeId, options) +List qrcode = instance.qrCode.fetchAllPayments(qrCodeId, requestJson); ``` **Parameters:** @@ -400,17 +401,17 @@ List qrcode = instance.qrCode.fetchAllPayments(QrCodeId, options) ### Close a QR Code -```js -String QrCodeId = "qr_HMsVL8HOpbMcjU"; +```java +String qrCodeId = "qr_HMsVL8HOpbMcjU"; -QrCode qrcode = instance.QrCode.close(QrCodeId); +QrCode qrcode = instance.qrCode.close(qrCodeId); ``` **Parameters:** | Name | Type | Description | |-----------|---------|------------------------------------------------------------------------------| -| QrCodeId* | string | The id of the qr code to be closed | +| qrCodeId* | string | The id of the qr code to be closed | **Response:** ```json diff --git a/documents/refund.md b/documents/refund.md index 537e8db8..1db0b8fa 100644 --- a/documents/refund.md +++ b/documents/refund.md @@ -3,28 +3,28 @@ ### Create a normal refund ```java -String PaymentId = "pay_FCXKPFtYfPXJPy"; - -String json = "{\n" + - " \"amount\": \"100\",\n" + - " \"speed\": \"normal\",\n" + - " \"notes\": {\n" + - " \"notes_key_1\": \"Beam me up Scotty.\",\n" + - " \"notes_key_2\": \"Engage\"\n" + - " },\n" + - " \"receipt\": \"Receipt No. 31\"\n" + +String paymentId = "pay_FCXKPFtYfPXJPy"; + +String jsonRequest = "{\n" + + "\"amount\": \"100\",\n" + + "\"speed\": \"normal\",\n" + + "\"notes\": {\n" + + "\"notes_key_1\": \"Beam me up Scotty.\",\n" + + "\"notes_key_2\": \"Engage\"\n" + + "},\n" + + "\"receipt\": \"Receipt No. 31\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Payments.refund(PaymentId,request); +Payment payment = instance.payments.refund(paymentId,requestRequest); ``` **Parameters:** | Name | Type | Description | |------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment | +| paymentId* | string | The id of the payment | | amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | | speed | string | Here, it must be normal | | notes | array | A key-value pair | @@ -55,24 +55,24 @@ Payment payment = instance.Payments.refund(PaymentId,request); ```java -String PaymentId = "pay_FCXKPFtYfPXJPy"; +String paymentId = "pay_FCXKPFtYfPXJPy"; -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": \"100\",\n" + " \"speed\": \"optimum\",\n" + " \"receipt\": \"Receipt No. 31\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.refund(PaymentId,request); +Payment payment = instance.payments.refund(paymentId,requestJson); ``` **Parameters:** | Name | Type | Description | |------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment | +| paymentId* | string | The id of the payment | | amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | speed* | string | Here, it must be optimum | | receipt | string | A unique identifier provided by you for your internal reference. | @@ -104,22 +104,22 @@ Payment payment = instance.Payments.refund(PaymentId,request); ### Fetch multiple refunds for a payment ```java -String PaymentId = "pay_FIKOnlyii5QGNx"; +String paymentId = "pay_FIKOnlyii5QGNx"; -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -List payment = instance.Payments.fetchAllRefunds(paymentId,option); +List payment = instance.payments.fetchAllRefunds(paymentId,requestRequest); ``` **Parameters:** | Name | Type | Description | |------------|-----------|--------------------------------------------------| -| PaymentId* | string | The id of the payment | +| paymentId* | string | The id of the payment | | from | timestamp | timestamp after which the payments were created | | to | timestamp | timestamp before which the payments were created | | count | integer | number of payments to fetch (default: 10) | @@ -157,19 +157,19 @@ List payment = instance.Payments.fetchAllRefunds(paymentId,option); ### Fetch a specific refund for a payment ```java -String PaymentId = "pay_FIKOnlyii5QGNx"; +String paymentId = "pay_FIKOnlyii5QGNx"; -String RefundId = "rfnd_FP8DDKxqJif6ca"; +String refundId = "rfnd_FP8DDKxqJif6ca"; -Payment payment = instance.Payments.fetchRefund(paymentId,refundId); +Payment payment = instance.payments.fetchRefund(paymentId,refundId); ``` **Parameters:** | Name | Type | Description | |------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | -| RefundId* | string | The id of the refund to be fetched | +| paymentId* | string | The id of the payment to be fetched | +| refundId* | string | The id of the refund to be fetched | **Response:** ```json @@ -197,7 +197,13 @@ Payment payment = instance.Payments.fetchRefund(paymentId,refundId); ### Fetch all refunds ```java -List refund = instance.Refunds.fetchAll(); +String jsonRequest = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject requestJson = new JSONObject(jsonRequest); + +List refund = instance.refunds.fetchAll(requestJson); ``` **Parameters:** @@ -239,9 +245,9 @@ List refund = instance.Refunds.fetchAll(); ### Fetch particular refund ```java -String RefundId = "rfnd_EqWThTE7dd7utf"; +String refundId = "rfnd_EqWThTE7dd7utf"; -List refund = instance.Refunds.fetch(RefundId); +List refund = instance.refunds.fetch(refundId); ``` **Parameters:** @@ -276,18 +282,18 @@ List refund = instance.Refunds.fetch(RefundId); ### Update the refund ```java -String RefundId = "rfnd_EqWThTE7dd7utf"; +String refundId = "rfnd_EqWThTE7dd7utf"; -String json "{\n" + +String jsonRequest "{\n" + " \"notes\": {\n" + " \"notes_key_1\": \"Beam me up Scotty.\",\n" + " \"notes_key_2\": \"Engage\"\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Refund refund = instance.Refunds.edit(RefundId,request); +Refund refund = instance.Refunds.edit(refundId,requestJson); ``` diff --git a/documents/registerEmandate.md b/documents/registerEmandate.md index 6c66e348..942211ea 100644 --- a/documents/registerEmandate.md +++ b/documents/registerEmandate.md @@ -2,21 +2,21 @@ ### Create customer ```java -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " fail_existing: 0,\n" + - " gstin: \"29XAbbA4369J1PA\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": 9123456780,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"fail_existing\": 0,\n" + + " \"gstin\": \"29XAbbA4369J1PA\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(requestJson); ``` **Parameters:** @@ -49,36 +49,36 @@ Customer customer = instance.Customers.create(request); ### Create order ```java -String json = "{\n" + - " amount: 100,\n" + - " currency: \"INR\",\n" + - " method: \"emandate\",\n" + - " receipt: \"Receipt No. 5\",\n" + - " notes: {\n" + - " \"note_key 1\": \"Beam me up Scotty\",\n" + - " \"note_key 2\": \"Engage\"\n" + - " },\n" + - " token: {\n" + - " first_payment_amount: 10000,\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 9999900,\n" + - " expire_at: 4102444799,\n" + - " notes: {\n" + - " \"note_key 1\": \"Tea, Earl Grey… decaf.\",\n" + - " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + - " },\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 11214311215411,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0001233\"\n" + - " }\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"method\": \"emandate\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"token\": {\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"max_amount\": 9999900,\n" + + " \"expire_at\": 4102444799,\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 1121431121541121,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0000001\"\n" + + " }\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -87,13 +87,13 @@ Order order = instance.Orders.create(request); |-----------------|---------|------------------------------------------------------------------------------| | amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | currency* | string | The currency of the payment (defaults to INR) | -| customerId* | string | The id of the customer to be fetched | | method* | string | Payment method used to make the registration transaction. Possible value is `emandate`. | | receipt | string | Your system order reference id. | | token | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#112-create-an-order) are supported | | notes | object | A key-value pair | **Response:** + For create order response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#112-create-an-order) ------------------------------------------------------------------------------------------------------- @@ -107,42 +107,41 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/emandat ### Create registration link ```java -String json = "{\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9123456780\n" + - " },\n" + - " type: \"link\",\n" + - " amount: 100,\n" + - " currency: \"INR\",\n" + - " description: \"Registration Link for Gaurav Kumar\",\n" + - " subscription_registration: {\n" + - " first_payment_amount: 100,\n" + - " method: \"emandate\",\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 50000,\n" + - " expire_at: 1634215992,\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 11214311215411,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0001233\"\n" + - " }\n" + - " },\n" + - " receipt: \"Receipt No. 5\",\n" + - " email_notify: 1,\n" + - " sms_notify: 1,\n" + - " expire_by: 1634215992,\n" + - " notes: {\n" + - " \"note_key 1\": \"Beam me up Scotty\",\n" + - " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9123456780\n" + + " },\n" + + " \"type\": \"link\",\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"description\": \"12 p.m. Meals\",\n" + + " \"subscription_registration\": {\n" + + " \"method\": \"emandate\",\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"expire_at\": 1580480689,\n" + + " \"max_amount\": 50000,\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " \"receipt\": \"Receipt no. 1\",\n" + + " \"expire_by\": 1880480689,\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Invoice invoice = instance.Invoices.createRegistrationLink(request); +Invoice invoice = instance.invoices.createRegistrationLink(requestJson); ``` **Parameters:** @@ -168,19 +167,19 @@ For create registration link response please click [here](https://razorpay.com/d ## Create an order to charge the customer ```java -String json = "{\n" + - " \"amount\": \"100\",\n" + - " \"currency\": \"INR\",\n" + - " \"receipt\": \"Receipt No. 1\",\n" + - " \"notes\": {\n" + - " \"key1\": \"value3\",\n" + - " \"key2\": \"value2\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": \"100\",\n" + + " \"currency\": \"INR\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -216,7 +215,7 @@ Order order = instance.Orders.create(request); ## Create a recurring payment ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + @@ -232,9 +231,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.createRecurringPayment(request); +Payment payment = instance.payments.createRecurringPayment(requestJson); ``` **Parameters:** @@ -264,17 +263,17 @@ Payment payment = instance.Payments.createRecurringPayment(request); ## Send/Resend notifications ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; String medium = "sms"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +Invoice invoice = instance.invoices.notifyBy(invoiceId,medium); ``` **Parameters:** | Name | Type |Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be fetched | +| invoiceId* | string | The id of the invoice to be fetched | | medium* | string | Possible values are `sms` or `email` | **Response:** @@ -288,9 +287,9 @@ Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); ## Cancel registration link ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** @@ -361,15 +360,15 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ## Fetch token by payment id ```java -String PaymentId = "pay_1Aa00000000001"; +String paymentId = "pay_1Aa00000000001"; -Payment payment = instance.Payments.fetch(PaymentId) +Payment payment = instance.payments.fetch(paymentId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | +| paymentId* | string | The id of the payment to be fetched | **Response:** For fetch token by payment id response please click [here](https://razorpay.com/docs/api/recurring-payments/emandate/auto-debit/#21-fetch-token-by-payment-id) @@ -379,15 +378,15 @@ For fetch token by payment id response please click [here](https://razorpay.com/ ## Fetch tokens by customer id ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -List token = instance.Customers.fetchTokens(CustomerId); +List token = instance.customers.fetchTokens(customerId); ``` **Parameters:** | Name | Type | Description | |-------------|---------|------------------------------------------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | +| customerId* | string | The id of the customer to be fetched | **Response:** ```json @@ -430,18 +429,18 @@ List token = instance.Customers.fetchTokens(CustomerId); ## Delete tokens ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -String TokenId = "token_FHf94Uym9tdYFJ"; +String tokenId = "token_FHf94Uym9tdYFJ"; -instance.Customers.deleteToken(CustomerId, TokenId); +instance.Customers.deleteToken(customerId, tokenId); ``` **Parameters:** | Name | Type | Description | |-------------|---------|------------------------------------------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | -| TokenId* | string | The id of the token to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | **Response:** ```json diff --git a/documents/registerNach.md b/documents/registerNach.md index 65f3d2b0..d22d9701 100644 --- a/documents/registerNach.md +++ b/documents/registerNach.md @@ -2,21 +2,21 @@ ### Create customer ```java -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " fail_existing: 0,\n" + - " gstin: \"29XAbbA4369J1PA\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": 9123456780,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"fail_existing\": 0,\n" + + " \"gstin\": \"29XAbbA4369J1PA\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(requestJson); ``` **Parameters:** @@ -50,36 +50,41 @@ Customer customer = instance.Customers.create(request); ### Create Order ```java -String json = "{\n" + -" amount: 100,\n" + -" currency: \"INR\",\n" + -" method: \"emandate\",\n" + -" receipt: \"Receipt No. 5\",\n" + -" notes: {\n" + -" \"note_key 1\": \"Beam me up Scotty\",\n" + -" \"note_key 2\": \"Engage\"\n" + -" },\n" + -" token: {\n" + -" first_payment_amount: 10000,\n" + -" auth_type: \"netbanking\",\n" + -" max_amount: 9999900,\n" + -" expire_at: 4102444799,\n" + -" notes: {\n" + -" \"note_key 1\": \"Tea, Earl Grey… decaf.\",\n" + -" \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + -" },\n" + -" bank_account: {\n" + -" beneficiary_name: \"Gaurav Kumar\",\n" + -" account_number: 11214311215411,\n" + -" account_type: \"savings\",\n" + -" ifsc_code: \"HDFC0001233\"\n" + -" }\n" + -" }\n" + -"}"; - -JSONObject request = new JSONObject(json); - -Order order = instance.Orders.create(request); +String jsonRequest = "{\n" + + " \"amount\": 100,\n" + + " \"currency\": \"INR\",\n" + + " \"method\": \"nach\",\n" + + " \"receipt\": \"Receipt No. 5\",\n" + + " \"notes\": {\n" + + " \"note_key 1\"\": \"Beam me up Scotty\",\n" + + " \"note_key 2\"\": \"Tea. Earl Gray. Hot.\"\n" + + " },\n" + + " \"token\": {\n" + + " \"first_payment_amount\": 10000,\n" + + " \"auth_type\": \"physical\",\n" + + " \"max_amount\": 50000,\n" + + " \"expire_at\": 1634215992,\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Tea, Earl Grey… decaf.\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " },\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + + " },\n" + + " \"nach\": {\n" + + " \"form_reference1\": \"Recurring Payment for Gaurav Kumar\",\n" + + " \"form_reference2\": \"Method Paper NACH\",\n" + + " \"description\": \"Paper NACH Gaurav Kumar\"\n" + + " }\n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); + +Order order = instance.orders.create(requestRequest); ``` **Parameters:** @@ -88,7 +93,6 @@ Order order = instance.Orders.create(request); |-----------------|---------|------------------------------------------------------------------------------| | amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | | currency* | string | The currency of the payment (defaults to INR) | -| customerId* | string | The id of the customer to be fetched | | method* | string | Payment method used to make the registration transaction. Possible value is `nach`. | | receipt | string | Your system order reference id. | | token | object | All keys listed [here](https://razorpay.com/docs/api/recurring-payments/paper-nach/auto-debit/#112-create-an-order) are supported | @@ -161,42 +165,45 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/paper-n ### Create registration link ```java -String json = "{\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9123456780\n" + - " },\n" + - " type: \"link\",\n" + - " amount: 100,\n" + - " currency: \"INR\",\n" + - " description: \"Registration Link for Gaurav Kumar\",\n" + - " subscription_registration: {\n" + - " first_payment_amount: 100,\n" + - " method: \"emandate\",\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 50000,\n" + - " expire_at: 1634215992,\n" + - " bank_account: {\n" + - " beneficiary_name: \"Gaurav Kumar\",\n" + - " account_number: 11214311215411,\n" + - " account_type: \"savings\",\n" + - " ifsc_code: \"HDFC0001233\"\n" + - " }\n" + - " },\n" + - " receipt: \"Receipt No. 5\",\n" + - " email_notify: 1,\n" + - " sms_notify: 1,\n" + - " expire_by: 1634215992,\n" + - " notes: {\n" + - " \"note_key 1\": \"Beam me up Scotty\",\n" + - " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + - " }\n" + - "}"; - -JSONObject request = new JSONObject(json); - -Invoice invoice = instance.Invoices.createRegistrationLink(request); +String jsonRequest = "{\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9123456780\n" + + " },\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"type\": \"link\",\n" + + " \"description\": \"12 p.m. Meals\",\n" + + " \"subscription_registration\": {\n" + + " \"method\": \"nach\",\n" + + " \"auth_type\": \"physical\",\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + + " },\n" + + " \"nach\": {\n" + + " \"form_reference1\": \"Recurring Payment for Gaurav Kumar\",\n" + + " \"form_reference2\": \"Method Paper NACH\"\n" + + " },\n" + + " \"expire_at\": 1947483647,\n" + + " \"max_amount\": 50000\n" + + " },\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"expire_by\": 1647483647,\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + + JSONObject requestRequest = new JSONObject(jsonRequest); + + Payment payment = instance.invoices.createRegistrationLink(requestRequest); ``` **Parameters:** @@ -310,7 +317,7 @@ Invoice invoice = instance.Invoices.createRegistrationLink(request); ## Create an order to charge the customer ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": \"100\",\n" + " \"currency\": \"INR\",\n" + " \"receipt\": \"Receipt No. 1\",\n" + @@ -320,9 +327,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestRequest); ``` **Parameters:** @@ -358,14 +365,14 @@ Order order = instance.Orders.create(request); ## Create a recurring payment ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + " \"currency\": \"INR\",\n" + " \"order_id\": \"order_1Aa00000000002\",\n" + " \"customer_id\": \"cust_1Aa00000000001\",\n" + - " \"token\": \"token_1Aa00000000001\",\n" + + " \"token_id\": \"token_1Aa00000000001\",\n" + " \"recurring\": \"1\",\n" + " \"description\": \"Creating recurring payment for Gaurav Kumar\",\n" + " \"notes\": {\n" + @@ -374,9 +381,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.createRecurringPayment(request); +Payment payment = instance.payments.createRecurringPayment(requestJson); ``` **Parameters:** @@ -406,17 +413,17 @@ Payment payment = instance.Payments.createRecurringPayment(request); ## Send/Resend notifications ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; String medium = "sms"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +Invoice invoice = instance.invoices.notifyBy(invoiceId,medium); ``` **Parameters:** | Name | Type |Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be fetched | +| invoiceId* | string | The id of the invoice to be fetched | | medium* | string | Possible values are `sms` or `email` | **Response:** @@ -431,15 +438,15 @@ Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); ## Cancel registration link ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be fetched | +| invoiceId* | string | The id of the invoice to be fetched | **Response:** ```json @@ -536,15 +543,15 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ## Fetch token by payment id ```java -String PaymentId = "pay_1Aa00000000001"; +String paymentId = "pay_1Aa00000000001"; -Payment payment = instance.Payments.fetch(PaymentId) +Payment payment = instance.payments.fetch(paymentId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | +| paymentId* | string | The id of the payment to be fetched | **Response:** ```json @@ -590,9 +597,9 @@ Payment payment = instance.Payments.fetch(PaymentId) ## Fetch tokens by customer id ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -List token = instance.Customers.fetchTokens(CustomerId); +List token = instance.customers.fetchTokens(customerId); ``` **Parameters:** @@ -633,11 +640,11 @@ List token = instance.Customers.fetchTokens(CustomerId); ## Delete tokens ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -String TokenId = "token_FHf94Uym9tdYFJ"; +String tokenId = "token_FHf94Uym9tdYFJ"; -instance.Customers.deleteToken(CustomerId, TokenId); +instance.customers.deleteToken(customerId, tokenId); ``` **Parameters:** diff --git a/documents/settlement.md b/documents/settlement.md index 6b6290fc..752d49d0 100644 --- a/documents/settlement.md +++ b/documents/settlement.md @@ -3,7 +3,7 @@ ### Fetch all settlements ```java -List settlement = razorpayclient.Settlement.fetchAll(); +List settlement = razorpayclient.settlement.fetchAll(); ``` **Parameters:** @@ -41,16 +41,16 @@ List settlement = razorpayclient.Settlement.fetchAll(); ### Fetch a settlement ```java -String SettlementId = "setl_DGlQ1Rj8os78Ec"; +String settlementId = "setl_DGlQ1Rj8os78Ec"; -Settlement settlement = razorpayclient.Settlement.fetch(SettlementId); +Settlement settlement = razorpayclient.settlement.fetch(settlementId); ``` **Parameters:** | Name | Type | Description | |---------------|-------------|---------------------------------------------| -| SettlementId* | string | The id of the settlement to be fetched | +| settlementId* | string | The id of the settlement to be fetched | **Response:** ```json @@ -70,14 +70,14 @@ Settlement settlement = razorpayclient.Settlement.fetch(SettlementId); ### Settlement report for a month ```java -String json = "{\n" + +String jsonRequest = "{\n" + "year: 2020,\n" + "month: 9\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List settlement = instance.Settlement.reports(request); +List settlement = instance.settlement.reports(requestJson); ``` **Parameters:** @@ -216,15 +216,15 @@ List settlement = instance.Settlement.reports(request); ```java -String json = "{\n" + +String jsonRequest = "{\n" + " year: 2020,\n" + " month: 9,\n" + " day:11\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List settlement = instance.Settlement.reports(request); +List settlement = instance.Settlement.reports(requestJson); ``` **Parameters:** @@ -359,7 +359,7 @@ List settlement = instance.Settlement.reports(request); ### Create on-demand settlement ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": 1221,\n" + " \"settle_full_balance\": false,\n" + " \"description\": \"Testing\",\n" + @@ -369,9 +369,9 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Settlement settlement = instance.Settlement.create(request); +Settlement settlement = instance.settlement.create(requestJson); ``` **Parameters:** @@ -430,7 +430,7 @@ Settlement settlement = instance.Settlement.create(request); ### Fetch all on-demand settlements ```java -List settlement = instance.Settlement.fetchAllDemand(options) +List settlement = instance.settlement.fetchAllDemand(options) ``` **Parameters:** @@ -449,16 +449,16 @@ For all on-demand settlements response please click [here](https://razorpay.com/ ### Fetch on-demand settlement by ID ```java -String SettlementId = "setlodp_FNj7g2cbvw8ueO"; +String settlementId = "setlodp_FNj7g2cbvw8ueO"; -instance.Settlement.fetchDemandSettlement(SettlementId); +instance.settlement.fetchDemandSettlement(settlementId); ``` **Parameters:** | Name | Type | Description | |---------------|--------|-----------------------------------| -| SettlementId* | string | Settlement Id of the On-demand settlement| +| settlementId* | string | Settlement Id of the On-demand settlement| **Response:** For on-demand settlement by ID response please click [here](https://razorpay.com/docs/api/settlements/#fetch-on-demand-settlements-by-id) diff --git a/documents/subscription.md b/documents/subscription.md index 4d772af7..7a7d8c75 100644 --- a/documents/subscription.md +++ b/documents/subscription.md @@ -3,30 +3,30 @@ ### Create subscription ```java -String json = "{\n" + - " plan_id: \"plan_7wAosPWtrkhqZw\",\n" + - " customer_notify: 1,\n" + - " quantity: 5,\n" + - " total_count: 6,\n" + - " start_at: 1495995837,\n" + - " addons: [\n" + - " {\n" + - " item: {\n" + - " name: \"Delivery charges\",\n" + - " amount: 30000,\n" + - " currency: \"INR\"\n" + - " }\n" + - " }\n" + - " ],\n" + - " notes: {\n" + - " key1: \"value3\",\n" + - " key2: \"value2\"\n" + - " }\n" + - "}"; - -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"plan_id\": \"plan_7wAosPWtrkhqZw\",\n" + + " \"customer_notify\": 1,\n" + + " \"quantity\": 5,\n" + + " \"total_count\": 6,\n" + + " \"start_at\": 1495995837,\n" + + " \"addons\": [\n" + + " {\n" + + " \"item\": {\n" + + " \"name\": \"Delivery charges\",\n" + + " \"amount\": 30000,\n" + + " \"currency\": \"INR\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"notes\": {\n" + + " \"key1\": \"value3\",\n" + + " \"key2\": \"value2\"\n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscriptions.create(request); +Subscription subscription = instance.subscriptions.create(requestRequest); ``` **Parameters:** @@ -79,34 +79,34 @@ Subscription subscription = instance.Subscriptions.create(request); ### Create subscription link ```java -String json = "{\n" + - " plan_id: \"plan_HoYg68p5kmuvzD\",\n" + - " total_count: 12,\n" + - " quantity: 1,\n" + - " expire_by: 1633237807,\n" + - " customer_notify: 1,\n" + - " addons: [\n" + - " {\n" + - " item: {\n" + - " name: \"Delivery charges\",\n" + - " amount: 30000,\n" + - " currency: \"INR\"\n" + - " }\n" + - " }\n" + - " ],\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " },\n" + - " notify_info: {\n" + - " notify_phone: 9123456789,\n" + - " notify_email: \"gaurav.kumar@example.com\"\n" + - " }\n" + - "}"; - -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"plan_id\": \"plan_HoYg68p5kmuvzD\",\n" + + " \"total_count\": 12,\n" + + " \"quantity\": 1,\n" + + " \"expire_by\": 1633237807,\n" + + " \"customer_notify\": 1,\n" + + " \"addons\": [\n" + + " {\n" + + " \"item\": {\n" + + " \"name\": \"Delivery charges\",\n" + + " \"amount\": 30000,\n" + + " \"currency\": \"INR\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " },\n" + + " \"notify_info\": {\n" + + " \"notify_phone\": 9123456789,\n" + + " \"notify_email\": \"gaurav.kumar@example.com\"\n" + + " }\n" + + "}"; + +JSONObject requestRequest = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscriptions.create(request); +Subscription subscription = instance.subscriptions.create(requestRequest); ``` **Parameters:** @@ -159,14 +159,14 @@ Subscription subscription = instance.Subscriptions.create(request); ### Fetch all subscriptions -```js -String json = "{\n" + +```java +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List subscription = instance.Subscriptions.fetchAll(options); +List subscription = instance.subscriptions.fetchAll(requestJson); ``` **Parameters:** @@ -223,9 +223,9 @@ List subscription = instance.Subscriptions.fetchAll(options); ### Fetch particular subscription ```java -String SubscriptionId = "sub_00000000000001"; +String subscriptionId = "sub_00000000000001"; -Subscription subscription = instance.Subscriptions.fetch(SubscriptionId); +Subscription subscription = instance.subscriptions.fetch(subscriptionId); ``` **Parameters:** @@ -273,13 +273,13 @@ Subscription subscription = instance.Subscriptions.fetch(SubscriptionId); ### Cancel particular subscription ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"cancel_at_cycle_end\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscription.cancel(subscriptionId,options) +Subscription subscription = instance.subscription.cancel(subscriptionId,requestJson) ``` **Parameters:** @@ -328,17 +328,17 @@ Subscription subscription = instance.Subscription.cancel(subscriptionId,options) ```java -String SubscriptionId = "sub_00000000000002"; +String subscriptionId = "sub_00000000000002"; -Subscription subscription = instance.Subscription.update(SubscriptionId); +Subscription subscription = instance.subscription.update(subscriptionId); ``` **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| SubscriptionId* | string | The id of the subscription to be updated | -| options | object | All parameters listed [here](https://razorpay.com/docs/api/subscriptions/#update-a-subscription) for update | +| Name | Type | Description | +|-----------------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be updated | +| options | object | All parameters listed [here](https://razorpay.com/docs/api/subscriptions/#update-a-subscription) for update | **Response:** ```json @@ -379,16 +379,16 @@ Subscription subscription = instance.Subscription.update(SubscriptionId); ### Fetch details of pending update ```java -String SubscriptionId = "sub_00000000000001"; +String subscriptionId = "sub_00000000000001"; -Subscription subscription = instance.Subscription.fetchPendingUpdate(SubscriptionId); +Subscription subscription = instance.subscription.fetchPendingUpdate(subscriptionId); ``` **Parameters:** | Name | Type | Description | |-----------------|-----------|--------------------------------------------------| -| SubscriptionId* | string | The id of the subscription to fetch pending update | +| subscriptionId* | string | The id of the subscription to fetch pending update | **Response:** ```json @@ -428,16 +428,16 @@ Subscription subscription = instance.Subscription.fetchPendingUpdate(Subscriptio ### Cancel a update ```java -String SubscriptionId = "sub_00000000000001"; +String subscriptionId = "sub_00000000000001"; -Subscription subscription = instance.Subscription.cancelPendingUpdate(SubscriptionId); +Subscription subscription = instance.subscription.cancelPendingUpdate(subscriptionId); ``` **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| SubscriptionId* | string | The id of the subscription to be cancel an update | +| Name | Type | Description | +|-----------------|-----------|--------------------------------------------------| +| subscriptionId* | string | The id of the subscription to be cancel an update | **Response:** ```json @@ -476,16 +476,16 @@ Subscription subscription = instance.Subscription.cancelPendingUpdate(Subscripti ### Pause a subscription -```js -String SubscriptionId = "sub_00000000000001"; +```java +String subscriptionId = "sub_00000000000001"; -String json = "{\n" + +String jsonRequest = "{\n" + "pause_at : 'now'\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscription.pause(SubscriptionId,request); +Subscription subscription = instance.subscription.pause(SubscriptionId,requestJson); ``` @@ -537,13 +537,13 @@ Subscription subscription = instance.Subscription.pause(SubscriptionId,request); ```java String SubscriptionId = "sub_00000000000001"; -String json = "{\n" + - "resume_at : 'now'\n" + - "}"; +String jsonRequest = "{\n" + + "resume_at : 'now'\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Subscription subscription = instance.Subscription.resume(SubscriptionId,request); +Subscription subscription = instance.subscription.resume(SubscriptionId,requestJson); ``` **Parameters:** @@ -592,13 +592,13 @@ Subscription subscription = instance.Subscription.resume(SubscriptionId,request) ### Fetch all invoices for a subscription ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"subscription_id\":subscriptionId\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List invoice = instance.Invoices.fetchAll(request); +List invoice = instance.invoices.fetchAll(requestJson); ``` **Parameters:** @@ -698,11 +698,11 @@ List invoice = instance.Invoices.fetchAll(request); ### Delete offer linked to a subscription ```java -String SubscriptionId = "sub_I3GGEs7Xgmnozy"; +String subscriptionId = "sub_I3GGEs7Xgmnozy"; -String OfferId = "offer_JHD834hjbxzhd38d"; +String offerId = "offer_JHD834hjbxzhd38d"; -instance.Subscription.deleteSubscriptionOffer(SubscriptionId, OfferId); +instance.subscription.deleteSubscriptionOffer(subscriptionId, offerId); ``` **Parameters:** diff --git a/documents/token.md b/documents/token.md index 20e5dd18..e34d67c1 100644 --- a/documents/token.md +++ b/documents/token.md @@ -5,7 +5,7 @@ ```java String Paymentid = "pay_FHfqtkRzWvxky4"; -Payment payment = instance.Payments.fetch(Paymentids); +Payment payment = instance.payments.fetch(paymentids); ``` **Parameters:** @@ -60,10 +60,10 @@ Payment payment = instance.Payments.fetch(Paymentids); ### Fetch tokens by customer id -```js -String CustomerId = "cust_DtHaBuooGHTuyZ"; +```java +String customerId = "cust_DtHaBuooGHTuyZ"; -List customer = instance.Customers.fetchTokens(CustomerId); +List customer = instance.customers.fetchTokens(customerId); ``` **Parameters:** @@ -121,20 +121,20 @@ List customer = instance.Customers.fetchTokens(CustomerId); ------------------------------------------------------------------------------------------------------- ### Fetch particular token -```js -String CustomerId = "cust_DtHaBuooGHTuyZ"; +```java +String customerId = "cust_DtHaBuooGHTuyZ"; -String TokenId = "token_HouA2OQR5Z2jTL"; +String tokenId = "token_HouA2OQR5Z2jTL"; -Customer customer = instance.Customers.fetchToken(CustomerId, TokenId) +Customer customer = instance.Customers.fetchToken(customerId, tokenId) ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | -| TokenId* | string | The id of the token to be fetched | +| customerId* | string | The id of the customer to be fetched | +| tokenId* | string | The id of the token to be fetched | **Response:** ```json @@ -175,11 +175,11 @@ Customer customer = instance.Customers.fetchToken(CustomerId, TokenId) ### Delete token ```js -String CustomerId = "cust_DtHaBuooGHTuyZ"; +String customerId = "cust_DtHaBuooGHTuyZ"; -String TokenId = "token_HouA2OQR5Z2jTL"; +String tokenId = "token_HouA2OQR5Z2jTL"; -Customer customer = instance.Customers.deleteToken(CustomerId, TokenId) +Customer customer = instance.customers.deleteToken(customerId, tokenId); ``` **Parameters:** diff --git a/documents/transfer.md b/documents/transfer.md index df9f112b..09cb7e26 100644 --- a/documents/transfer.md +++ b/documents/transfer.md @@ -3,7 +3,7 @@ ### Create transfers from payment ```java -String PaymentId = "pay_E8JR8E0XyjUSZd"; +String paymentId = "pay_E8JR8E0XyjUSZd"; String json = "{\n" + " \"transfers\": [\n" + " {\n" + @@ -25,7 +25,7 @@ String json = "{\n" + JSONObject request = new JSONObject(json); -instance.Payments.transfer(PaymentId,request); +instance.payments.transfer(paymentId,request); ``` **Parameters:** @@ -70,43 +70,43 @@ instance.Payments.transfer(PaymentId,request); ### Create transfers from order ```java -String json = "{\n" + - " amount: 2000,\n" + - " currency: \"INR\",\n" + - " transfers: [\n" + - " {\n" + - " account: \"acc_CPRsN1LkFccllA\",\n" + - " amount: 1000,\n" + - " currency: \"INR\",\n" + - " notes: {\n" + - " branch: \"Acme Corp Bangalore North\",\n" + - " name: \"Gaurav Kumar\"\n" + - " },\n" + - " linked_account_notes: [\n" + - " \"branch\"\n" + - " ],\n" + - " on_hold: 1,\n" + - " on_hold_until: 1671222870\n" + - " },\n" + - " {\n" + - " account: \"acc_CNo3jSI8OkFJJJ\",\n" + - " amount: 1000,\n" + - " currency: \"INR\",\n" + - " notes: {\n" + - " branch: \"Acme Corp Bangalore South\",\n" + - " name: \"Saurav Kumar\"\n" + - " },\n" + - " linked_account_notes: [\n" + - " \"branch\"\n" + - " ],\n" + - " on_hold: 0\n" + - " }\n" + - " ]\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": 2000,\n" + + " \"currency\": \"INR\",\n" + + " \"transfers\": [\n" + + " {\n" + + " \"account\": \"acc_CPRsN1LkFccllA\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"notes\": {\n" + + " \"branch\": \"Acme Corp Bangalore North\",\n" + + " \"name\": \"Gaurav Kumar\"\n" + + " },\n" + + " \"linked_account_notes\": [\n" + + " \"branch\"\n" + + " ],\n" + + " \"on_hold\": 1,\n" + + " \"on_hold_until\": 1671222870\n" + + " },\n" + + " {\n" + + " \"account\": \"acc_CNo3jSI8OkFJJJ\",\n" + + " \"amount\": 1000,\n" + + " \"currency\": \"INR\",\n" + + " \"notes\": {\n" + + " \"branch\": \"Acme Corp Bangalore South\",\n" + + " \"name\": \"Saurav Kumar\"\n" + + " },\n" + + " \"linked_account_notes\": [\n" + + " \"branch\"\n" + + " ],\n" + + " \"on_hold\": 0\n" + + " }\n" + + " ]\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -170,15 +170,15 @@ Order order = instance.Orders.create(request); ### Direct transfers ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\account\": \"acc_CPRsN1LkFccllA\",\n + "\"amount\": 500,\n" + "\"currency\": \"INR\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Transfer transfer = instance.Transfers.create(request); +Transfer transfer = instance.transfers.create(requestJson); ``` **Parameters:** @@ -215,9 +215,9 @@ Transfer transfer = instance.Transfers.create(request); ### Fetch transfer for a payment ```java -String PaymentId = "pay_E9up5WhIfMYnKW"; +String paymentId = "pay_E9up5WhIfMYnKW"; -List payment = instance.Payments.fetchAllTransfers(PaymentId) +List payment = instance.payments.fetchAllTransfers(paymentId) ``` **Parameters:** @@ -258,9 +258,9 @@ List payment = instance.Payments.fetchAllTransfers(PaymentId) ### Fetch transfer ```java -String TransferId = "trf_E7V62rAxJ3zYMo"; +String transferId = "trf_E7V62rAxJ3zYMo"; -Transfer transfer = instance.Transfers.fetch(TransferId); +Transfer transfer = instance.transfers.fetch(transferId); ``` **Parameters:** @@ -295,18 +295,18 @@ Transfer transfer = instance.Transfers.fetch(TransferId); ### Fetch transfers for a settlement ```java -String RecipientSettlementId = "setl_DHYJ3dRPqQkAgV"; +String jsonRequest = {\"recipient_settlement_id\":\"setl_DHYJ3dRPqQkAgV\"}"; -JSONObject request = new JSONObject("{\"recipient_settlement_id\":"+RecipientSettlementId+"}"); +JSONObject requestRequest = new JSONObject(jsonRequest); -List transfer = instance.Transfers.fetchAll(request); +List transfer = instance.transfers.fetchAll(requestRequest); ``` **Parameters:** | Name | Type | Description | |---------------|-------------|---------------------------------------------| -| recipientSettlementId* | string | The recipient settlement id obtained from the settlement.processed webhook payload. | +| recipient_settlement_id* | string | The recipient settlement id obtained from the settlement.processed webhook payload. | **Response:** ```json @@ -340,12 +340,13 @@ List transfer = instance.Transfers.fetchAll(request); ### Fetch settlement details ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"expand[]\" : \"recipient_settlement\" \n" + "}"; -JSONObject request = new JSONObject(json); + +JSONObject requestJson = new JSONObject(jsonRequest); -List transfer = instance.Transfers.fetchAll(request); +List transfer = instance.transfers.fetchAll(requestJson); ``` **Parameters:** @@ -396,25 +397,25 @@ List transfer = instance.Transfers.fetchAll(request); ### Refund payments and reverse transfer from a linked account ```java -String PaymentId = "pay_EAdwQDe4JrhOFX"; +String paymentId = "pay_EAdwQDe4JrhOFX"; -String json = "{\n" + - " amount : 100,\n" + - " reverse_all : 1\n" + - "}"; +String jsonRequest = "{\n" + + "\"amount\" : 100,\n" + + "\"reverse_all\" : 1\n" + + "})"; -JSONObject request = new JSONObject(json); +JSONObject requestRequest = new JSONObject(jsonRequest); -Payment payment = instance.Payments.refund(PaymentId,request); +Payment payment = instance.payments.refund(paymentId,requestJson); ``` **Parameters:** -| Name | Type | Description | -|---------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | -| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | -| reverse_all | boolean | 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.| +| Name | Type | Description | +|-------------|-------------|---------------------------------------------| +| paymentId* | string | The id of the payment to be fetched | +| amount* | integer | The amount to be captured (should be equal to the authorized amount, in paise) | +| reverse_all | boolean | 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.| **Response:** ```json @@ -437,11 +438,11 @@ Payment payment = instance.Payments.refund(PaymentId,request); ### Fetch payments of a linked account ```java -String LinkedAccountId = "acc_CPRsN1LkFccllA"; +String jsonRequest = "{\"X-Razorpay-Account\":\"acc_CPRsN1LkFccllA\"}" -JSONObject request = new JSONObject("{\"X-Razorpay-Account\":"+LinkedAccountId+"}"); +JSONObject requestJson = new JSONObject(jsonRequest); -List payment = instance.Payments.fetchAll(request); +List payment = instance.payments.fetchAll(requestJson); ``` **Parameters:** @@ -491,22 +492,22 @@ List payment = instance.Payments.fetchAll(request); ### Reverse transfers from all linked accounts ```java -String TransferId = "trf_EAznuJ9cDLnF7Y"; +String transferId = "trf_EAznuJ9cDLnF7Y"; -String json = "{\n" + - "amount:100\n" + - "}"; +String jsonRequest = "{\n" + + "\"amount\":100\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Transfer transfer = instance.Transfers.reversal(TransferId,request); +Transfer transfer = instance.Transfers.reversal(transferId,requestJson); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| TransferId* | string | The id of the transfer to be fetched | +| transferId* | string | The id of the transfer to be fetched | | amount | integer | The amount to be captured (should be equal to the authorized amount, in paise) | **Response:** @@ -529,24 +530,29 @@ Transfer transfer = instance.Transfers.reversal(TransferId,request); ### Hold settlements for transfers ```java -String PaymentId = "pay_EB1R2s8D4vOAKG"; - -String json = "{\n" + - " \"amount\": 500,\n" + - " \"currency\": \"INR\",\n" + - " \"on_hold\": \"1\"\n" + - "}"; +String paymentId = "pay_EB1R2s8D4vOAKG"; + +String jsonRequest = "{\n" + + " \"transfers\": [\n" + + " {\n" + + " \"amount\": 100,\n" + + " \"account\": \"acc_CMaomTz4o0FOFz\",\n" + + " \"currency\": \"INR\",\n" + + " \"on_hold\": 1\n" + + " }\n" + + " ]\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.transfer(PaymentId,request); +Payment payment = instance.payments.transfer(paymentId,requestJson); ``` **Parameters:** | Name | Type | Description | |------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | +| paymentId* | string | The id of the payment to be fetched | | transfers | array | All parameters listed here https://razorpay.com/docs/api/route/#hold-settlements-for-transfers are supported | **Response:** @@ -580,24 +586,25 @@ Payment payment = instance.Payments.transfer(PaymentId,request); ### Modify settlement hold for transfers ```java -String PaymentId = "pay_EAeSM2Xul8xYRo"; +String paymentId = "pay_EAeSM2Xul8xYRo"; -String json = "{\n" + +String jsonRequest = "{\n" + "\"on_hold\": \"1\",\n" + "\"on_hold_until\": \"1679691505\"\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Transfer transfer = instance.Transfers.edit(PaymentId,request); +Transfer transfer = instance.Transfers.edit(paymentId,requestJson); ``` **Parameters:** -| Name | Type | Description | -|------------|-------------|---------------------------------------------| -| PaymentId* | string | The id of the payment to be fetched | -| transfers | array | All parameters listed here https://razorpay.com/docs/api/route/#hold-settlements-for-transfers are supported | +| Name | Type | Description | +|---------------|---------|---------------------------------------------| +| paymentId* | string | The id of the payment to be fetched | +| on_hold | boolean | Possible value is `0` or `1` | +| on_hold_until | integer | | **Response:** ```json diff --git a/documents/upi.md b/documents/upi.md index 1f0459d9..b005a18a 100644 --- a/documents/upi.md +++ b/documents/upi.md @@ -2,19 +2,19 @@ ### Create customer ```java -String json = "{\n" + - " name: \"Gaurav Kumar\",\n" + - " contact: 9123456780,\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"contact\": 9123456780,\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Customer customer = instance.Customers.create(request); +Customer customer = instance.customers.create(requestJson); ``` **Parameters:** @@ -48,30 +48,30 @@ Customer customer = instance.Customers.create(request); ### Create order ```java -String json = "{\n" + - " amount: 0,\n" + - " currency: \"INR\",\n" + - " method: \"upi\",\n" + - " customer_id: \"cust_1Aa00000000001\",\n" + - " receipt: \"Receipt No. 1\",\n" + - " notes: {\n" + - " notes_key_1: \"Beam me up Scotty\",\n" + - " notes_key_2: \"Engage\"\n" + - " },\n" + - " token: {\n" + - " auth_type: \"netbanking\",\n" + - " max_amount: 9999900,\n" + - " expire_at: 4102444799,\n" + - " notes: {\n" + - " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + - " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + - " }\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"method\": \"upi\",\n" + + " \"customer_id\": \"cust_1Aa00000000001\",\n" + + " \"receipt\": \"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Beam me up Scotty\",\n" + + " \"notes_key_2\": \"Engage\"\n" + + " },\n" + + " \"token\": {\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"max_amount\": 9999900,\n" + + " \"expire_at\": 4102444799,\n" + + " \"notes\": {\n" + + " \"notes_key_1\": \"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\": \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` @@ -117,33 +117,41 @@ Please refer this [doc](https://razorpay.com/docs/api/recurring-payments/upi/aut ### Create registration link ```java -String json = "{\n" + - " customer: {\n" + - " name: \"Gaurav Kumar\",\n" + - " email: \"gaurav.kumar@example.com\",\n" + - " contact: 9123456780\n" + - " },\n" + - " type: \"link\",\n" + - " amount: 100,\n" + - " currency: \"INR\",\n" + - " description: \"Registration Link for Gaurav Kumar\",\n" + - " subscription_registration: {\n" + - " method: \"upi\",\n" + - " max_amount: 500,\n" + - " expire_at: 1634215992\n" + - " },\n" + - " receipt: \"Receipt No. 5\",\n" + - " email_notify: 1,\n" + - " sms_notify: 1,\n" + - " expire_by: 1634215992,\n" + - " notes: {\n" + - " \"note_key 1\": \"Beam me up Scotty\",\n" + - " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + - " }\n" + - "}"; -JSONObject request = new JSONObject(json); - -Invoice invoice = instance.Invoices.createRegistrationLink(request); +String jsonRequest = "{\n" + + " \"customer\": {\n" + + " \"name\": \"Gaurav Kumar\",\n" + + " \"email\": \"gaurav.kumar@example.com\",\n" + + " \"contact\": 9123456780\n" + + " },\n" + + " \"type\": \"link\",\n" + + " \"amount\": 0,\n" + + " \"currency\": \"INR\",\n" + + " \"description\": \"12 p.m. Meals\",\n" + + " \"subscription_registration\": {\n" + + " \"method\": \"emandate\",\n" + + " \"auth_type\": \"netbanking\",\n" + + " \"expire_at\": 1580480689,\n" + + " \"max_amount\": 50000,\n" + + " \"bank_account\": {\n" + + " \"beneficiary_name\": \"Gaurav Kumar\",\n" + + " \"account_number\": 11214311215411,\n" + + " \"account_type\": \"savings\",\n" + + " \"ifsc_code\": \"HDFC0001233\"\n" + + " }\n" + + " },\n" + + " \"receipt\": \"Receipt no. 1\",\n" + + " \"expire_by\": 1880480689,\n" + + " \"sms_notify\": 1,\n" + + " \"email_notify\": 1,\n" + + " \"notes\": {\n" + + " \"note_key 1\": \"Beam me up Scotty\",\n" + + " \"note_key 2\": \"Tea. Earl Gray. Hot.\"\n" + + " }\n" + + "}"; + + JSONObject requestJson = new JSONObject(jsonRequest); + + Invoice invoice = instance.invoices.createRegistrationLink(requestJson); ``` **Parameters:** @@ -221,18 +229,18 @@ Invoice invoice = instance.Invoices.createRegistrationLink(request); ### Send/Resend notifications ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; String medium = "sms"; -Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); +Invoice invoice = instance.invoices.notifyBy(invoiceId,medium); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be notified | +| invoiceId* | string | The id of the invoice to be notified | | medium* | string | `sms`/`email`, Medium through which notification should be sent. | **Response:** @@ -246,16 +254,16 @@ Invoice invoice = instance.Invoices.notifyBy(InvoiceId,medium); ### Cancel a registration link ```java -String InvoiceId = "inv_DAweOiQ7amIUVd"; +String invoiceId = "inv_DAweOiQ7amIUVd"; -Invoice invoice = instance.Invoices.cancel(InvoiceId); +Invoice invoice = instance.invoices.cancel(invoiceId); ``` **Parameters:** | Name | Type | Description | |------------|---------|------------------------------------------------------------------------------| -| InvoiceId* | string | The id of the invoice to be cancelled | +| invoiceId* | string | The id of the invoice to be cancelled | **Response:** ```json @@ -320,16 +328,16 @@ Invoice invoice = instance.Invoices.cancel(InvoiceId); ### Fetch token by payment ID ```java -String PaymentId = "pay_1Aa00000000001"; +String paymentId = "pay_1Aa00000000001"; -Payment payment = instance.Payments.fetch(PaymentId) +Payment payment = instance.payments.fetch(paymentId) ``` **Parameters:** | Name | Type | Description | |------------|--------|-----------------------------------| -| PaymentId* | string | Id of the payment to be retrieved | +| paymentId* | string | Id of the payment to be retrieved | **Response:** ```json @@ -378,16 +386,16 @@ Payment payment = instance.Payments.fetch(PaymentId) ### Fetch tokens by customer ID ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -List token = instance.Customers.fetchTokens(CustomerId); +List token = instance.customers.fetchTokens(customerId); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | +| customerId* | string | The id of the customer to be fetched | **Response:** ```json @@ -427,19 +435,19 @@ List token = instance.Customers.fetchTokens(CustomerId); ### Delete token ```java -String CustomerId = "cust_BMB3EwbqnqZ2EI"; +String customerId = "cust_BMB3EwbqnqZ2EI"; -String TokenId = "token_FHf94Uym9tdYFJ"; +String tokenId = "token_FHf94Uym9tdYFJ"; -instance.Customers.deleteToken(CustomerId, TokenId); +instance.customers.deleteToken(customerId, tokenId); ``` **Parameters:** | Name | Type | Description | |-------------|-------------|---------------------------------------------| -| CustomerId* | string | The id of the customer to be fetched | -| TokenId* | string | The id of the token to be fetched | +| customerId* | string | customer id for which token to deleted | +| tokenId* | string | The id of the token to be fetched | **Response:** ```json @@ -452,19 +460,19 @@ instance.Customers.deleteToken(CustomerId, TokenId); ### Create an order to charge the customer ```java -String json = "{\n" + - " \"amount\": \"100\",\n" + - " \"currency\": \"INR\",\n" + - " \"receipt\": \"Receipt No. 1\",\n" + - " \"notes\": {\n" + - " \"key1\": \"value3\",\n" + - " \"key2\": \"value2\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"amount\":1000,\n" + + " \"currency\":\"INR\",\n" + + " \"receipt\":\"Receipt No. 1\",\n" + + " \"notes\": {\n" + + " \"notes_key_1\":\"Tea, Earl Grey, Hot\",\n" + + " \"notes_key_2\":\"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Order order = instance.Orders.create(request); +Order order = instance.orders.create(requestJson); ``` **Parameters:** @@ -501,7 +509,7 @@ Order order = instance.Orders.create(request); ### Create a recurring payment ```java -String json = "{\n" + +String jsonRequest = "{\n" + " \"email\": \"gaurav.kumar@example.com\",\n" + " \"contact\": \"9123456789\",\n" + " \"amount\": 1000,\n" + @@ -517,25 +525,25 @@ String json = "{\n" + " }\n" + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.createRecurringPayment(request); +Payment payment = instance.payments.createRecurringPayment(requestJson); ``` **Parameters:** -| Name | Type | Description | -|-----------------|---------|------------------------------------------------------------------------------| -| email* | string | The customer's email address. | -| contact* | string | The customer's phone number. | -| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | -| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | -| order_id* | string | The unique identifier of the order created. | -| customer_id* | string | The `customer_id` for the customer you want to charge. | -| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| -| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| -| description* | string | A user-entered description for the payment.| -| notes* | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | +| Name | Type | Description | +|----------------|---------|------------------------------------------------------------------------------| +| email* | string | The customer's email address. | +| contact* | string | The customer's phone number. | +| amount* | integer | The amount you want to charge your customer. This should be the same as the amount in the order. | +| currency* | string | The 3-letter ISO currency code for the payment. Currently, only `INR` is supported. | +| order_id* | string | The unique identifier of the order created. | +| customer_id* | string | The `customer_id` for the customer you want to charge. | +| token* | string | The `token_id` generated when the customer successfully completes the authorization payment. Different payment instruments for the same customer have different `token_id`.| +| recurring* | string | Determines if recurring payment is enabled or not. Possible values:
* `1` - Recurring is enabled.* `0` - Recurring is not enabled.| +| description | string | A user-entered description for the payment.| +| notes | object | Key-value pair that can be used to store additional information about the entity. Maximum 15 key-value pairs, 256 characters (maximum) each. | **Response:** ```json diff --git a/documents/virtualAccount.md b/documents/virtualAccount.md index c77869be..98cb04c2 100644 --- a/documents/virtualAccount.md +++ b/documents/virtualAccount.md @@ -2,23 +2,23 @@ ### Create a virtual account ```java -String json = "{\n" + - " receivers: {\n" + - " types: [\n" + - " \"bank_account\"\n" + - " ]\n" + - " },\n" + - " description: \"Virtual Account created for Raftar Soft\",\n" + - " customer_id: \"cust_CaVDm8eDRSXYME\",\n" + - " close_by: 1681615838,\n" + - " notes: {\n" + - " project_name: \"Banking Software\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"receivers\": {\n" + + " \"types\": [\n" + + " \"bank_account\"\n" + + " ]\n" + + " },\n" + + " \"description\": \"Virtual Account created for Raftar Soft\",\n" + + " \"customer_id\": \"cust_CaVDm8eDRSXYME\",\n" + + " \"close_by\": 1681615838,\n" + + " \"notes\": {\n" + + " \"project_name\": \"Banking Software\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); +VirtualAccount virtualaccount = instance.virtualAccounts.create(requestJson); ``` **Parameters:** @@ -68,31 +68,31 @@ VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); ```java -String json = "{\n" + - " receivers: {\n" + - " types: [\n" + - " \"bank_account\"\n" + - " ]\n" + - " },\n" + - " allowed_payers: [\n" + - " {\n" + - " type: \"bank_account\",\n" + - " bank_account: {\n" + - " ifsc: \"RATN0VAAPIS\",\n" + - " account_number: 2223330027558515\n" + - " }\n" + - " }\n" + - " ],\n" + - " description: \"Virtual Account created for Raftar Soft\",\n" + - " customer_id: \"cust_HssUOFiOd2b1TJ\",\n" + - " notes: {\n" + - " project_name: \"Banking Software\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " \"receivers\": {\n" + + " \"types\": [\n" + + " \"bank_account\"\n" + + " ]\n" + + " },\n" + + " \"allowed_payers\": [\n" + + " {\n" + + " \"type\": \"bank_account\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"RATN0VAAPIS\",\n" + + " \"account_number\": 2223330027558515\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"description\": \"Virtual Account created for Raftar Soft\",\n" + + " \"customer_id\": \"cust_HssUOFiOd2b1TJ\",\n" + + " \"notes\": {\n" + + " \"project_name\": \"Banking Software\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); +VirtualAccount virtualaccount = instance.virtualAccounts.create(requestJson); ``` @@ -160,22 +160,22 @@ VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); ### Create static/dynamic qr ```java -String json = "{\n" + - " receivers: {\n" + - " types: [\n" + - " \"qr_code\"\n" + - " ]\n" + - " },\n" + - " description: \"First QR code\",\n" + - " amount_expected: 100,\n" + - " notes: {\n" + - " receiver_key: \"receiver_value\"\n" + - " }\n" + - "}"; +String jsonRequest = "{\n" + + " receivers: {\n" + + " types: [\n" + + " \"qr_code\"\n" + + " ]\n" + + " },\n" + + " description: \"First QR code\",\n" + + " amount_expected: 100,\n" + + " notes: {\n" + + " receiver_key: \"receiver_value\"\n" + + " }\n" + + "}"; -JSONObject request = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); +VirtualAccount virtualaccount = instance.virtualAccounts.create(requestJson); ``` @@ -220,30 +220,31 @@ VirtualAccount virtualaccount = instance.VirtualAccounts.create(request); ### Fetch virtual account by id ```java -String VirtualId = "va_4xbQrmEoA5WJ0G"; +String virtualId = "va_4xbQrmEoA5WJ0G"; -VirtualAccount virtualaccount = instance.VirtualAccounts.fetch(virtualId); +VirtualAccount virtualaccount = instance.virtualAccounts.fetch(virtualId); ``` **Parameters:** | Name | Type | Description | |------------|-------------|---------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | +| virtualId* | string | The id of the virtual to be updated | **Response:** + For fetch virtual account by id response please click [here](https://razorpay.com/docs/api/smart-collect/#fetch-a-virtual-account-by-id) ------------------------------------------------------------------------------------------------------- ### Fetch all virtual account ```java -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List virtualaccount = instance.VirtualAccounts.fetchAll(options); +List virtualaccount = instance.virtualAccounts.fetchAll(requestJson); ``` **Parameters:** @@ -295,22 +296,22 @@ List virtualaccount = instance.VirtualAccounts.fetchAll(options) ### Fetch payments for a virtual account ```java -String VirtualId = "va_DlGmm7jInLudH9"; +String virtualId = "va_DlGmm7jInLudH9"; -String json = "{\n" + +String jsonRequest = "{\n" + "\"count\" : 1\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -List virtualaccount = instance.VirtualAccounts.fetchPayments(VirtualId,options); +List virtualaccount = instance.virtualAccounts.fetchPayments(virtualId,requestJson); ``` **Parameters:** | Name | Type | Description | |------------|-----------|--------------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | +| virtualId* | string | The id of the virtual to be updated | | from | timestamp | timestamp after which the payments were created | | to | timestamp | timestamp before which the payments were created | | count | integer | number of payments to fetch (default: 10) | @@ -358,16 +359,16 @@ List virtualaccount = instance.VirtualAccounts.fetchPayments(Vir ### Fetch payment details using id and transfer method ```java -String PaymentId = "pay_CmiztqmYJPtDAu"; +String paymentId = "pay_CmiztqmYJPtDAu"; -Payment payment = instance.Payments.fetchBankTransfers(paymentId) +Payment payment = instance.payments.fetchBankTransfers(paymentId) ``` **Parameters:** -| Name | Type | Description | -|-------|-----------|--------------------------------------------------| -| virtualId* | string | The id of the virtual to be updated | +| Name | Type | Description | +|------------|-----------|-------------------------------------| +| paymentId* | string | The id of the payment to be updated | **Response:** ```json @@ -421,9 +422,9 @@ Payment payment = instance.Payments.fetchBankTransfers(paymentId) ### Refund payments made to a virtual account ```java -String PaymentId = "pay_E54n391WnEAV9H"; +String paymentId = "pay_E54n391WnEAV9H"; -String json = "{\n" + +String jsonRequest = "{\n" + " \"amount\": \"100\",\n" + " \"speed\": \"normal\",\n" + " \"notes\": {\n" + @@ -433,9 +434,9 @@ String json = "{\n" + " \"receipt\": \"Receipt No. 31\"\n" + "}"; -JSONObject options = new JSONObject(json); +JSONObject requestJson = new JSONObject(jsonRequest); -Payment payment = instance.Payments.refund(PaymentId,request); +Payment payment = instance.payments.refund(paymentId,requestJson); ``` **Parameters:** @@ -471,56 +472,58 @@ Payment payment = instance.Payments.refund(PaymentId,request); ### Add receiver to an existing virtual account ```java -String VirtualId = "va_Di5gbNptcWV8fQ"; - -String json = "{\n" + - " types: [\n" + - " \"vpa\"\n" + - " ],\n" + - " vpa: {\n" + - " descriptor: \"gauravkumar\"\n" + - " }\n" + - "}"; +String virtualId = "va_Di5gbNptcWV8fQ"; -JSONObject request = new JSONObject(json); +String jsonRequest = "{\n" + + " \"type\": [\n" + + " \"vpa\"\n" + + " ],\n" + + " \"vpa\": {\n" + + " \"descriptor\": \"gauravkumar\"\n" + + " }\n" + + "}"; -VirtualAccount virtualaccount = instance.VirtualAccounts.addReceiver(VirtualId,request); +JSONObject requestRequest = new JSONObject(jsonRequest); + +VirtualAccount virtualaccount = instance.virtualAccounts.addReceiver(virtualId,requestRequest); ``` **Parameters:** | Name | Type | Description | |------------|-----------|--------------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | +| virtualId* | string | The id of the virtual to be updated | | types* | object | The receiver type to be added to the virtual account. Possible values are `vpa` or `bank_account` | | vpa | object | This is to be passed only when `vpa` is passed as the receiver types. | **Response:** + For add receiver to an existing virtual account response please click [here](https://razorpay.com/docs/api/smart-collect/#add-receiver-to-an-existing-virtual-account) ------------------------------------------------------------------------------------------------------- ### Add an Allowed Payer Account ```java -String VirtualId = "va_Di5gbNptcWV8fQ"; - -String json = "{\n" + -" types: \"bank_account\",\n" + -" bank_account: {\n" + -" ifsc: \"UTIB0000013\",\n" + -" account_number: 914010012345679\n" + -" }\n" + -"}"; - -JSONObject request = new JSONObject(json); -VirtualAccount virtualaccount = instance.VirtualAccounts.addAllowedPayers(VirtualId,request); +String virtualId = "va_Di5gbNptcWV8fQ"; + +String jsonRequest = "{\n" + + " \"types\": \"bank_account\",\n" + + " \"bank_account\": {\n" + + " \"ifsc\": \"UTIB0000013\",\n" + + " \"account_number\": 914010012345679\n" + + " }\n" + + "}"; + +JSONObject requestJson = new JSONObject(jsonRequest); + +VirtualAccount virtualaccount = instance.virtualAccounts.addAllowedPayers(virtualId,requestJson); ``` **Parameters:** | Name | Type | Description | |---------------|-----------|--------------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | +| virtualId* | string | The id of the virtual to be updated | | types* | object | The receiver type to be added to the virtual account. Possible values are `vpa` or `bank_account` | | bank_account* | object | Indicates the bank account details such as `ifsc` and `account_number` | @@ -568,19 +571,19 @@ VirtualAccount virtualaccount = instance.VirtualAccounts.addAllowedPayers(Virtua ### Delete an Allowed Payer Account ```java -String VirtualId = "va_Di5gbNptcWV8fQ"; +String virtualId = "va_Di5gbNptcWV8fQ"; -String AllowedPlayer = "ba_DlGmm9mSj8fjRM"; +String allowedPlayer = "ba_DlGmm9mSj8fjRM"; -instance.VirtualAccounts.deleteAllowedPayer(VirtualId,AllowedPayersId) +instance.VirtualAccounts.deleteAllowedPayer(virtualId,allowedPayersId) ``` **Parameters:** | Name | Type | Description | |------------------|-----------|--------------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | -| AllowedPayersId* | string | The id of the allowed payers to be updated | +| virtualId* | string | The id of the virtual to be updated | +| allowedPayersId* | string | The id of the allowed payers to be updated | **Response:** ```json @@ -589,18 +592,19 @@ instance.VirtualAccounts.deleteAllowedPayer(VirtualId,AllowedPayersId) ------------------------------------------------------------------------------------------------------- ### Close virtual account ```java -String VirtualId = "va_Di5gbNptcWV8fQ"; +String virtualId = "va_Di5gbNptcWV8fQ"; -instance.VirtualAccounts.close(VirtualId) +instance.virtualAccounts.close(virtualId) ``` **Parameters:** | Name | Type | Description | |------------|-----------|--------------------------------------------------| -| VirtualId* | string | The id of the virtual to be updated | +| virtualId* | string | The id of the virtual to be updated | **Response:** + For close virtual account response please click [here](https://razorpay.com/docs/api/smart-collect/#close-a-virtual-account) ------------------------------------------------------------------------------------------------------- diff --git a/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 9303949a..0e0fcd61 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -23,6 +23,7 @@ public class Constants { static final String PAYMENT_TRANSFER_GET = "payments/%s/transfers"; static final String PAYMENT_BANK_TRANSFER_GET = "payments/%s/bank_transfer"; static final String PAYMENT_EDIT = "payments/%s"; + static final String FETCH_CARD_DETAILS = "payments/%s/card"; static final String FETCH_DOWNTIME_LIST = "payments/downtimes"; static final String FETCH_DOWNTIME_GET = "payments/downtimes"; static final String PAYMENT_JSON_CREATE = "payments/create/json";