Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CEPF-1750]: Added fetch payment methods endpoint #329

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
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);
}
}
}
Loading