|
3 | 3 | import com.flutterwave.bean.BeneficiaryRequest; |
4 | 4 | import com.flutterwave.bean.ListResponse; |
5 | 5 | import com.flutterwave.bean.Response; |
| 6 | +import org.apache.http.NameValuePair; |
| 7 | +import org.apache.http.message.BasicNameValuePair; |
6 | 8 |
|
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
7 | 11 | import java.util.Optional; |
8 | 12 |
|
9 | 13 | import static com.flutterwave.bean.ChargeTypes.BENEFICIARY; |
10 | 14 | import static com.flutterwave.client.Utility.*; |
11 | 15 | import static com.flutterwave.utility.Properties.getProperty; |
12 | 16 |
|
13 | 17 | /** |
| 18 | + * Manage Transfer Beneficiaries. |
14 | 19 | * @author Cleopatra Douglas |
15 | 20 | */ |
16 | 21 | public class Beneficiaries { |
17 | 22 |
|
18 | 23 | private String ERROR = "Error processing request, please check logs"; |
19 | 24 |
|
| 25 | + /** |
| 26 | + * Create beneficiaries for Transfers. |
| 27 | + * @param beneficiaryRequest bean |
| 28 | + * @return Response |
| 29 | + */ |
20 | 30 | public Response runCreateBeneficiary(BeneficiaryRequest beneficiaryRequest){ |
21 | 31 | return Optional.of(post(getProperty("BENEFICIARY_BASE"), beneficiaryRequest.toString(), |
22 | 32 | BENEFICIARY, null)) |
23 | 33 | .map(Response::toResponse).orElseThrow(() -> new RuntimeException(ERROR)); |
24 | 34 | } |
25 | 35 |
|
26 | | - public ListResponse runGetAllBeneficiaries(Optional<Integer> id){ |
27 | | - return Optional.of(get(getProperty("BENEFICIARY_BASE"), BENEFICIARY, null)) |
| 36 | + /** |
| 37 | + * Get all beneficiaries saves for Transfers. |
| 38 | + * @param page This is the page number to retrieve e.g. setting 1 retrieves the first page |
| 39 | + * @return ListResponse |
| 40 | + */ |
| 41 | + public ListResponse runGetAllBeneficiaries(Optional<Integer> page){ |
| 42 | + List<NameValuePair> nameValuePairs = new ArrayList<>(); |
| 43 | + page.ifPresent(s -> nameValuePairs.add(new BasicNameValuePair("page", s.toString()))); |
| 44 | + return Optional.of(get(getProperty("BENEFICIARY_BASE"), BENEFICIARY, nameValuePairs)) |
28 | 45 | .map(ListResponse::toListResponse).orElseThrow(() -> new RuntimeException(ERROR)); |
29 | 46 | } |
30 | 47 |
|
| 48 | + /** |
| 49 | + * Get all details for a particular beneficiary. |
| 50 | + * @param id int This is the unique identifier for the beneficiary you intend to fetch. |
| 51 | + * It is returned in the call to create a beneficiary as data.id |
| 52 | + * @return Response |
| 53 | + */ |
31 | 54 | public Response runGetBeneficiary(int id){ |
32 | 55 | return Optional.of(get(getProperty("BENEFICIARY_BASE") +"/" + id, BENEFICIARY, null)) |
33 | 56 | .map(Response::toResponse).orElseThrow(() -> new RuntimeException(ERROR)); |
34 | 57 | } |
35 | 58 |
|
| 59 | + /** |
| 60 | + * Remove a beneficiary from your beneficiary list. |
| 61 | + * @param id int This is the unique identifier for the beneficiary you intend to fetch. |
| 62 | + * It is returned in the call to create a beneficiary as data.id |
| 63 | + * @return Response |
| 64 | + */ |
36 | 65 | public Response runDeleteBeneficiary(int id){ |
37 | 66 | return Optional.of(delete(getProperty("BENEFICIARY_BASE") +"/" + id, BENEFICIARY, null)) |
38 | 67 | .map(Response::toResponse).orElseThrow(() -> new RuntimeException(ERROR)); |
|
0 commit comments