Skip to content

Commit 35453fc

Browse files
committed
Resolve issues With missing response data
1 parent f1848d0 commit 35453fc

File tree

6 files changed

+65
-8
lines changed

6 files changed

+65
-8
lines changed

src/main/java/com/flutterwave/bean/BillRequest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ public class BillRequest extends Shared {
1616
private String recurrence;
1717
private String country;
1818
private String customer;
19+
private String type;
20+
private String reference;
1921

2022

21-
public BillRequest(String country, String customer, BigDecimal amount,
23+
public BillRequest(String country, String customer, BigDecimal amount, String type, String reference,
2224
Optional<Recurrence> recurrence, Optional<GhanaAirtimeBills> ghanaAirtimeBills) {
2325

2426
this.country = country;
27+
this.type = type;
28+
this.reference = reference;
2529
this.customer = customer;
2630
this.setAmount(amount);
2731
recurrence.ifPresent(value -> this.recurrence = String.valueOf(value));

src/main/java/com/flutterwave/bean/Data.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.core.JsonProcessingException;
56
import com.fasterxml.jackson.databind.ObjectMapper;
67
import com.google.gson.Gson;
78
import com.google.gson.GsonBuilder;
@@ -104,6 +105,11 @@ public class Data {
104105
private String response_message;
105106
private String product_code;
106107
private String email;
108+
private String account_number;
109+
private String expiry_date;
110+
private String note;
111+
private String active;
112+
private String frequency;
107113

108114
private Customer getCustomer(){
109115
try {
@@ -139,4 +145,20 @@ public String getCustomerString(){
139145
}
140146
return null;
141147
}
148+
149+
@Override
150+
public String toString() {
151+
152+
String value = null;
153+
ObjectMapper objectMapper = new ObjectMapper();
154+
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
155+
try {
156+
value = objectMapper.writeValueAsString(this);
157+
} catch (JsonProcessingException e) {
158+
e.printStackTrace();
159+
}
160+
161+
return value;
162+
163+
}
142164
}

src/main/java/com/flutterwave/bean/ListResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class ListResponse {
2424
private String code;
2525

2626
public static ListResponse toListResponse(String value){
27-
System.out.println(value);
2827
return new GsonBuilder().create().
2928
fromJson(value, ListResponse.class);
3029
}

src/main/java/com/flutterwave/services/Transactions.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,22 @@ public Response runVerifyTransaction(int id) {
3939
* Query previously initiated transactions. You can do a single or bulk query with the endpoint depending on your use case.
4040
* @return ListResponse
4141
*/
42-
public ListResponse runGetTransactions() {
42+
public ListResponse runGetTransactions(Optional<String> from, Optional<String> to, Optional<String> page,
43+
Optional<String> customer_email,Optional<String> status,Optional<String> tx_ref,
44+
Optional<String> customer_fullname, Optional<String> currency) {
45+
46+
List<NameValuePair> nameValuePairs = new ArrayList<>();
47+
from.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("from", from.get())));
48+
to.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("to", to.get())));
49+
page.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("page", page.get())));
50+
customer_email.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("customer_email", customer_email.get())));
51+
status.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("status", status.get())));
52+
tx_ref.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("tx_ref", tx_ref.get())));
53+
customer_fullname.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("customer_fullname", customer_fullname.get())));
54+
currency.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("currency", currency.get())));
55+
4356
return Optional.of(get(getProperty("VERIFY_TRANSACTION_ENDPOINT"),
44-
GET_TRANSACTION, null))
57+
GET_TRANSACTION, nameValuePairs))
4558
.map(ListResponse::toListResponse).orElseThrow(() -> new RuntimeException(ERROR));
4659
}
4760

@@ -91,9 +104,18 @@ public ListResponse runViewTimeline(int id) {
91104
}
92105

93106
public class Refunds {
94-
public ListResponse runGet() {
107+
public ListResponse runGet(Optional<String> from, Optional<String> to, Optional<String> status,
108+
Optional<String> currency,Optional<String> id) {
109+
110+
List<NameValuePair> nameValuePairs = new ArrayList<>();
111+
from.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("from", from.get())));
112+
to.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("to", to.get())));
113+
currency.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("currency", currency.get())));
114+
id.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("id", id.get())));
115+
status.ifPresent(String -> nameValuePairs.add(new BasicNameValuePair("status", status.get())));
116+
95117
return Optional.of(get(getProperty("REFUND_ENDPOINT"),
96-
REFUND, null))
118+
REFUND, nameValuePairs))
97119
.map(ListResponse::toListResponse).orElseThrow(() -> new RuntimeException(ERROR));
98120
}
99121

src/test/java/com/flutterwave/services/BillsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ void setUp() {
3232
billRequest = new BillRequest("NG",
3333
"+23490803840303",
3434
new BigDecimal("500"),
35+
"AIRTIME",
36+
"14rdxs",
3537
Optional.of(ONCE),
3638
Optional.empty());
3739
}

src/test/java/com/flutterwave/services/TransactionsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ void runVerifyTransaction() {
3030

3131
@Test
3232
void runGetTransactions() {
33-
Assertions.assertEquals("success", new Transactions().runGetTransactions().getStatus());
33+
Assertions.assertEquals("success", new Transactions().runGetTransactions(Optional.empty(),
34+
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
35+
Optional.empty(), Optional.empty()).getStatus());
3436
}
3537

3638
@Test
@@ -52,7 +54,13 @@ void runViewTimeline() {
5254

5355
@Test
5456
void rungetRefunds() {
55-
Assertions.assertEquals("success", new Transactions().new Refunds().runGet().getStatus());
57+
Assertions.assertEquals("success", new Transactions().new Refunds().runGet(
58+
Optional.empty(),
59+
Optional.empty(),
60+
Optional.empty(),
61+
Optional.empty(),
62+
Optional.empty()
63+
).getStatus());
5664
}
5765

5866
@Test

0 commit comments

Comments
 (0)