diff --git a/documents/contacts.md b/documents/contacts.md new file mode 100644 index 00000000..4393a9a9 --- /dev/null +++ b/documents/contacts.md @@ -0,0 +1,180 @@ +## Contact + +### Create Contact +```java +String jsonRequest = "{\n" + + "\"name\": \"Gaurav Kumar\",\n" + + "\"contact\": 9123456780,\n" + + "\"email\": \"gaurav.kumar@example.com\",\n" + + "\"type\": \"employee\",\n" + + "\"reference_id\": Acme Contact ID 12345,\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject requestJson = new JSONObject(jsonRequest); + +Contact contact = instance.contacts.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": "cont_00000000000001", + "entity": "contact", + "name": "Gaurav Kumar", + "contact": "9123456789", + "email": "gaurav.kumar@example.com", + "type": "self", + "reference_id": "Acme Contact ID 12345", + "batch_id": null, + "active": true, + "notes": { + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at": 1545320320 +} +``` + +------------------------------------------------------------------------------------------------------- + +### Update a contact +```java +String contactId = "cont_00000000000001"; + +String jsonRequest = "{\n" + + "\"name\": \"Gaurav Kumar\",\n" + + "\"email\": \"Gaurav.Kumar@example.com\",\n" + + "\"contact\": 9123456789\n" + + "\"type\": \"self\"\n" + + "\"reference_id\": \"Acme Contact ID 12345\"\n" + + " notes: {\n" + + " notes_key_1: \"Tea, Earl Grey, Hot\",\n" + + " notes_key_2: \"Tea, Earl Grey… decaf.\"\n" + + " }\n" + + "}"; + +JSONObject requestJson = new JSONObject(requestJson); + +Contact contact = instance.contacts.edit(contact_Id,request); +``` + +**Parameters:** + +| Name | Type | Description | +|------------|-------------|-------------------------------------| +| ContactId* | string | The id of the contact to be updated | +| email | string | Email of the contact | +| name | string | Name of the contact | +| contact | string | Contact number of the contact | + +**Response:** +```json +{ + "id": "cont_00000000000001", + "entity": "contact", + "name": "Gaurav Kumar", + "contact": "9123456789", + "email": "gaurav.kumar@example.com", + "type": "self", + "reference_id": "Acme Contact ID 12345", + "batch_id": null, + "active": true, + "notes": { + "notes_key_1":"Tea, Earl Grey, Hot", + "notes_key_2":"Tea, Earl Grey… decaf." + }, + "created_at": 1545320320 +} + +``` +------------------------------------------------------------------------------------------------------- + +### Fetch all customer +```java +String jsonRequest = "{\n" + + "\"count\" : 1\n" + + "}"; + +JSONObject requestJson = new JSONObject(jsonRequest); + +List customer = instance.customers.fetchAll(requestJson); +``` + +**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/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index 4aaf3fe7..88083ca3 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -61,6 +61,8 @@ public class Constants { static final String FUND_ACCOUNT_CREATE = "fund_accounts"; static final String FUND_ACCOUNT_FETCH = "fund_accounts/%s"; + static final String FUND_ACCOUNT_UPDATE = "fund_accounts/%s"; + static final String FUND_ACCOUNT_FETCH_ALL = "fund_accounts"; static final String ORDER_CREATE = "orders"; static final String ORDER_GET = "orders/%s"; @@ -125,4 +127,10 @@ public class Constants { 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"; + + static final String CONTACT_CREATE = "contacts"; + static final String CONTACT_FETCH = "contacts/%s"; + static final String CONTACT_EDIT = "contacts/%s"; + static final String CONTACT_FETCH_ALL = "contacts"; + static final String CONTACT_UPDATE = "contacts/%s"; } diff --git a/src/main/java/com/razorpay/Contact.java b/src/main/java/com/razorpay/Contact.java new file mode 100644 index 00000000..786d6b01 --- /dev/null +++ b/src/main/java/com/razorpay/Contact.java @@ -0,0 +1,10 @@ +package com.razorpay; + +import org.json.JSONObject; + +public class Contact extends Entity { + + public Contact(JSONObject jsonObject) { + super(jsonObject); + } +} diff --git a/src/main/java/com/razorpay/ContactClient.java b/src/main/java/com/razorpay/ContactClient.java new file mode 100644 index 00000000..2b35774e --- /dev/null +++ b/src/main/java/com/razorpay/ContactClient.java @@ -0,0 +1,44 @@ +package com.razorpay; + +import java.util.List; + +import org.json.JSONObject; + +public class ContactClient extends ApiClient { + + ContactClient(String auth) { + super(auth); + } + + public Contact create(JSONObject request) throws RazorpayException { + return post(Constants.CONTACT_CREATE, request); + } + + public Contact fetch(String id) throws RazorpayException { + return get(String.format(Constants.CONTACT_FETCH, id), null); + } + + public Contact edit(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants. CONTACT_EDIT, id), request); + } + public Contact update(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants. CONTACT_UPDATE, 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 contacts filtered by parameters @request + * @throws RazorpayException + */ + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.CONTACT_FETCH_ALL, request); + } +} diff --git a/src/main/java/com/razorpay/FundAccountClient.java b/src/main/java/com/razorpay/FundAccountClient.java index e7133314..cfb4ed5f 100644 --- a/src/main/java/com/razorpay/FundAccountClient.java +++ b/src/main/java/com/razorpay/FundAccountClient.java @@ -2,6 +2,8 @@ import org.json.JSONObject; +import java.util.List; + public class FundAccountClient extends ApiClient{ FundAccountClient(String auth) { @@ -15,4 +17,25 @@ public FundAccount create(JSONObject request) throws RazorpayException { public FundAccount fetch(String id) throws RazorpayException { return get(String.format(Constants.FUND_ACCOUNT_FETCH, id), null); } + + public FundAccount update(String id, JSONObject request) throws RazorpayException { + return patch(String.format(Constants. FUND_ACCOUNT_UPDATE, 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 fund account filtered by parameters @request + * @throws RazorpayException + */ + public List fetchAll(JSONObject request) throws RazorpayException { + return getCollection(Constants.FUND_ACCOUNT_FETCH_ALL, request); + } } \ 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 a42bbcdd..c74ce04a 100755 --- a/src/main/java/com/razorpay/RazorpayClient.java +++ b/src/main/java/com/razorpay/RazorpayClient.java @@ -22,6 +22,7 @@ public class RazorpayClient { public ItemClient items; public FundAccountClient fundAccount; public VirtualAccountClient virtualAccounts; + public ContactClient contact; public RazorpayClient(String key, String secret) throws RazorpayException { this(key, secret, false); @@ -46,6 +47,8 @@ public RazorpayClient(String key, String secret, Boolean enableLogging) throws R items = new ItemClient(auth); fundAccount = new FundAccountClient(auth); virtualAccounts = new VirtualAccountClient(auth); + contact = new ContactClient(auth); + } public RazorpayClient addHeaders(Map headers) {