Skip to content

Commit 15c7892

Browse files
committed
Improve null safety for Uk payments
1 parent 9f98565 commit 15c7892

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

rave_android/src/main/java/com/flutterwave/raveandroid/uk/NullUkView.java

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

33
import com.flutterwave.raveandroid.ViewObject;
44
import com.flutterwave.raveandroid.rave_java_commons.Payload;
5-
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
65

76
import java.util.HashMap;
87

@@ -60,7 +59,8 @@ public void onPaymentSuccessful(String status, String flwRef, String responseAsS
6059
}
6160

6261
@Override
63-
public void showTransactionPage(ChargeResponse response) {
62+
public void showTransactionPage(String amount, String paymentCode, String flwRef, String txRef) {
6463

6564
}
65+
6666
}

rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkFragment.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.flutterwave.raveandroid.rave_java_commons.RaveConstants;
3131
import com.flutterwave.raveandroid.rave_logger.events.StartTypingEvent;
3232
import com.flutterwave.raveandroid.rave_presentation.data.events.ErrorEvent;
33-
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
3433
import com.google.android.material.textfield.TextInputEditText;
3534
import com.google.android.material.textfield.TextInputLayout;
3635

@@ -187,7 +186,7 @@ public void onTransactionFeeFetched(String charge_amount, final Payload payload,
187186
if (getActivity() != null) {
188187

189188
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
190-
builder.setMessage(getResources().getString(R.string.charge) + charge_amount + ravePayInitializer.getCurrency() + getResources().getString(R.string.askToContinue));
189+
builder.setMessage(getResources().getString(R.string.charge) + " " + charge_amount + " " + ravePayInitializer.getCurrency() + getResources().getString(R.string.askToContinue));
191190
builder.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
192191
@Override
193192
public void onClick(DialogInterface dialog, int which) {
@@ -219,23 +218,23 @@ public void showToast(String message) {
219218
}
220219

221220
@Override
222-
public void showTransactionPage(final ChargeResponse response) {
221+
public void showTransactionPage(String amount, String paymentCode, final String flwRef, final String txRef) {
223222

224223
if (getContext() != null) {
225224
final Dialog dialog = new Dialog(getContext());
226225
dialog.setContentView(R.layout.rave_sdk_ukinstruction_layout);
227226
dialog.setTitle("Flutterwave");
228227
presenter.logEvent(new InstructionsDisplayedEvent("UK").getEvent(), ravePayInitializer.getPublicKey());
229228

230-
((TextView) dialog.findViewById(R.id.amount)).setText(String.format("%s %s", "GBP", response.getData().getData().getAmount()));
229+
((TextView) dialog.findViewById(R.id.amount)).setText(String.format("%s %s", "GBP", amount));
231230
((TextView) dialog.findViewById(R.id.accountNumber)).setText(getString(R.string.flutterwave_ukaccount));
232231
((TextView) dialog.findViewById(R.id.sortCode)).setText(getString(R.string.flutterwave_sortcode));
233-
((TextView) dialog.findViewById(R.id.reference)).setText(response.getData().getData().getPayment_code());
232+
((TextView) dialog.findViewById(R.id.reference)).setText(amount);
234233

235234
dialog.findViewById(R.id.ukPaymentButton).setOnClickListener(new View.OnClickListener() {
236235
@Override
237236
public void onClick(View view) {
238-
presenter.requeryTx(response.getData().getData().getFlw_reference(), response.getData().getData().getTransaction_reference(), ravePayInitializer.getPublicKey());
237+
presenter.requeryTx(flwRef, txRef, ravePayInitializer.getPublicKey());
239238
}
240239
});
241240
dialog.show();

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkContract.java

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

33
import com.flutterwave.raveandroid.rave_java_commons.Payload;
44
import com.flutterwave.raveandroid.rave_logger.Event;
5-
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
65

76

87
public interface UkContract {
@@ -22,7 +21,7 @@ interface Interactor {
2221

2322
void onPaymentSuccessful(String status, String flwRef, String responseAsString);
2423

25-
void showTransactionPage(ChargeResponse response);
24+
void showTransactionPage(String amount, String paymentCode, String flwRef, String txRef);
2625
}
2726

2827
interface Handler {

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class UkHandler implements UkContract.Handler {
4040
PayloadEncryptor payloadEncryptor;
4141
private UkContract.Interactor mInteractor;
4242
private boolean pollingCancelled = false;
43+
String txRef = null;
4344

4445
@Inject
4546
public UkHandler(UkContract.Interactor mInteractor) {
@@ -79,6 +80,8 @@ public void onError(String message) {
7980

8081
@Override
8182
public void chargeUk(final Payload payload, final String encryptionKey) {
83+
txRef = payload.getTxRef();
84+
8285
String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload);
8386
String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey);
8487
encryptedCardRequestBody = encryptedCardRequestBody.trim();
@@ -101,7 +104,10 @@ public void onSuccess(ChargeResponse response) {
101104
mInteractor.showProgressIndicator(false);
102105

103106
if (response.getData() != null) {
104-
mInteractor.showTransactionPage(response);
107+
String amount = response.getAmount();
108+
String paymentCode = response.getPaymentCode();
109+
String flwRef = response.getFlwRef();
110+
mInteractor.showTransactionPage(amount, paymentCode, flwRef, txRef);
105111
} else {
106112
mInteractor.onPaymentError(noResponse);
107113
}

rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkInteractorImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.flutterwave.raveandroid.rave_java_commons.Payload;
44
import com.flutterwave.raveandroid.rave_presentation.FeeCheckListener;
55
import com.flutterwave.raveandroid.rave_presentation.NullFeeCheckListener;
6-
import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse;
76
import com.google.gson.Gson;
87
import com.google.gson.JsonObject;
98
import com.google.gson.reflect.TypeToken;
@@ -57,16 +56,16 @@ public void onPaymentSuccessful(String status, String flwRef, String responseAsS
5756
}
5857

5958
@Override
60-
public void showTransactionPage(ChargeResponse response) {
59+
public void showTransactionPage(String amount, String paymentCode, final String flwRef, final String txRef) {
6160
callback.showTransactionDetails(
62-
response.getData().getAmount(),
61+
amount,
6362
FLUTTERWAVE_UK_ACCOUNT,
6463
FLUTTERWAVE_UK_SORT_CODE,
6564
FLUTTERWAVE_UK_BENEFICIARY_NAME,
66-
response.getData().getData().getPayment_code()
65+
paymentCode
6766
);
68-
this.flwRef = response.getData().getData().getFlw_reference();
69-
this.txRef = response.getData().getData().getTransaction_reference();
67+
this.flwRef = flwRef;
68+
this.txRef = txRef;
7069
}
7170

7271
@Override

rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ public void setData(Data data) {
3434
this.data = data;
3535
}
3636

37+
public String getAmount() {
38+
return data == null ? null : data.amount;
39+
}
40+
41+
public String getPaymentCode() {
42+
return data == null ? null : data.payment_code;
43+
}
44+
45+
public String getFlwRef() {
46+
return (data == null) ? null : data.getFlwRef();
47+
}
48+
49+
public String getTxRef() {
50+
return (data == null) ? null : data.getTx_ref();
51+
}
3752

3853
public static class AccountValidateInstructions {
3954
public String getInstruction() {

0 commit comments

Comments
 (0)