From 3ccf89b5c45ad758342e7a9bbf8c3573d3fa65e3 Mon Sep 17 00:00:00 2001 From: jitendra-1217 Date: Tue, 21 Aug 2018 20:53:45 +0530 Subject: [PATCH] invoice: Adds cancel endpoint --- README.md | 19 +++++++++++-------- src/main/java/com/razorpay/Constants.java | 1 + src/main/java/com/razorpay/InvoiceClient.java | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 421bfb9e..4659db3f 100644 --- a/README.md +++ b/README.md @@ -100,14 +100,14 @@ Refund refund = razorpayClient.Payments.fetchRefund("refund_id"); * 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", ); - + transfers.put(transfer); request.put("transfers", transfers); @@ -164,7 +164,7 @@ List payments = razorpayClient.Orders.fetchPayments("order_id"); You can use the Utils class to verify the signature received in response to a payment made using Orders API ```java JSONObject paymentResponse = new JSONObject(); -options.put("razorpay_order_id", ""); +options.put("razorpay_order_id", ""); options.put("razorpay_payment_id", ""); options.put("razorpay_signature", ""); Utils.verifyPaymentSignature(paymentResponse, ""); @@ -189,11 +189,10 @@ 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"); +request.put("sms_notify", "0"); Invoice invoice = razorpayClient.Invoices.create(request); ``` - * Fetch a particular invoice: ```java Invoice invoice = razorpayClient.Invoices.fetch("invoice_id"); @@ -202,6 +201,10 @@ Invoice invoice = razorpayClient.Invoices.fetch("invoice_id"); ```java List invoices = razorpayClient.Invoices.fetchAll(); ``` +* Cancel a particular invoice: +```java +Invoice invoice = razorpayClient.Invoices.cancel("invoice_id"); +``` ### [Cards](https://docs.razorpay.com/v1/page/cards) @@ -256,7 +259,7 @@ 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); ``` @@ -411,8 +414,8 @@ List paymentList = razorpayClient.VirtualAccounts.fetchPayments("virtua * Make custom requests -You can make custom API requests using clients. For example, here is how to make custom request to `/payments/path` endpoint. +You can make custom API requests using clients. For example, here is how to make custom request to `/payments/path` endpoint. ```java Entity response = razorpayClient.Payments.post("path", JSONObject requestBody); -``` \ 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 8ff13c8d..bf2a27ab 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -38,6 +38,7 @@ public class Constants { static final String INVOICE_CREATE = "invoices"; static final String INVOICE_GET = "invoices/%s"; static final String INVOICE_LIST = "invoices"; + static final String INVOICE_CANCEL = "invoices/%s/cancel"; static final String CARD_GET = "cards/%s"; diff --git a/src/main/java/com/razorpay/InvoiceClient.java b/src/main/java/com/razorpay/InvoiceClient.java index bb5f86c4..a08d0385 100644 --- a/src/main/java/com/razorpay/InvoiceClient.java +++ b/src/main/java/com/razorpay/InvoiceClient.java @@ -25,4 +25,8 @@ public List fetchAll(JSONObject request) throws RazorpayException { public Invoice fetch(String id) throws RazorpayException { return get(String.format(Constants.INVOICE_GET, id), null); } + + public Invoice cancel(String id) throws RazorpayException { + return post(String.format(Constants.INVOICE_CANCEL, id), null); + } }