Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions documents/contacts.md
Original file line number Diff line number Diff line change
@@ -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> 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**
<br>
<br>
**For reference click [here](https://razorpay.com/docs/api/customers/)**
8 changes: 8 additions & 0 deletions src/main/java/com/razorpay/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
}
10 changes: 10 additions & 0 deletions src/main/java/com/razorpay/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.razorpay;

import org.json.JSONObject;

public class Contact extends Entity {

public Contact(JSONObject jsonObject) {
super(jsonObject);
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/razorpay/ContactClient.java
Original file line number Diff line number Diff line change
@@ -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<Contact> fetchAll() throws RazorpayException {
return fetchAll(null);
}

/**
* This method get list of contacts filtered by parameters @request
* @throws RazorpayException
*/
public List<Contact> fetchAll(JSONObject request) throws RazorpayException {
return getCollection(Constants.CONTACT_FETCH_ALL, request);
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/razorpay/FundAccountClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.json.JSONObject;

import java.util.List;

public class FundAccountClient extends ApiClient{

FundAccountClient(String auth) {
Expand All @@ -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<FundAccount> fetchAll() throws RazorpayException {
return fetchAll(null);
}

/**
* This method get list of fund account filtered by parameters @request
* @throws RazorpayException
*/
public List<FundAccount> fetchAll(JSONObject request) throws RazorpayException {
return getCollection(Constants.FUND_ACCOUNT_FETCH_ALL, request);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/razorpay/RazorpayClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<String, String> headers) {
Expand Down