Skip to content

Commit

Permalink
[CEPF-1750]: Added fetch payment methods endpoint (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Oct 22, 2024
1 parent e21a963 commit a4aec2a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion documents/payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ please refer this [doc](https://razorpay.com/docs/payments/third-party-validatio
```java
RazorpayClient instance = new RazorpayClient("key",""); // Use only razorpay key

Methods response = instance.payments.get("methods",null);
Methods methods = instance.payments.fetchPaymentMethods();
```

**Response:** <br>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/razorpay/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Constants {
static final String PAYMENT_CREATE_UPI = "payments/create/upi";
static final String VALIDATE_VPA = "payments/validate/vpa";

static final String FETCH_PAYMENT_METHODS = "methods";
static final String METHODS = "methods";

static final String PAYMENTLINK_CREATE = "payment_links";
static final String PAYMENTLINK_LIST = "payment_links";
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/razorpay/PaymentClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ public Payment validateUpi(JSONObject request) throws RazorpayException {
public Payment expandedDetails(String id, JSONObject request) throws RazorpayException {
return get(Constants.VERSION, String.format(Constants.PAYMENT_GET, id), request);
}
public Methods fetchPaymentMethods() throws RazorpayException {
return get(Constants.VERSION, Constants.METHODS, null);
}
}
44 changes: 44 additions & 0 deletions src/test/java/com/razorpay/PaymentClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -999,4 +999,48 @@ public void expandedDetails() throws RazorpayException {
assertTrue(false);
}
}

@Test
public void fetchPaymentMethods() throws RazorpayException {
String mockedResponseJson = "{\n" +
" \"entity\": \"methods\",\n" +
" \"card\": true,\n" +
" \"debit_card\": true,\n" +
" \"credit_card\": true,\n" +
" \"prepaid_card\": true,\n" +
" \"card_networks\": {},\n" +
" \"card_subtype\": {},\n" +
" \"amex\": false,\n" +
" \"netbanking\": {},\n" +
" \"wallet\": [],\n" +
" \"emi\": false,\n" +
" \"upi\": true,\n" +
" \"cardless_emi\": [],\n" +
" \"paylater\": [],\n" +
" \"google_pay_cards\": false,\n" +
" \"app\": {},\n" +
" \"gpay\": false,\n" +
" \"emi_types\": {},\n" +
" \"debit_emi_providers\": {},\n" +
" \"intl_bank_transfer\": [],\n" +
" \"fpx\": [],\n" +
" \"nach\": false,\n" +
" \"cod\": false,\n" +
" \"offline\": false,\n" +
" \"sodexo\": false,\n" +
" \"upi_config\": [],\n" +
" \"recurring\": {},\n" +
" \"upi_intent\": true\n" +
"}";

try {
mockResponseFromExternalClient(mockedResponseJson.toString());
mockResponseHTTPCodeFromExternalClient(200);
Methods fetch = paymentClient.fetchPaymentMethods();
assertNotNull(fetch);
assertEquals("methods", fetch.get("entity"));
} catch (IOException e) {
assertTrue(false);
}
}
}

0 comments on commit a4aec2a

Please sign in to comment.