|
1 | 1 | package com.flutterwave.raveandroid.banktransfer; |
2 | 2 |
|
3 | 3 | import android.content.Context; |
| 4 | +import android.os.Bundle; |
4 | 5 | import android.util.Log; |
5 | 6 |
|
6 | 7 | import com.flutterwave.raveandroid.FeeCheckRequestBody; |
|
21 | 22 |
|
22 | 23 | import java.util.HashMap; |
23 | 24 |
|
24 | | -/** |
25 | | - * Created by hfetuga on 27/06/2018. |
26 | | - */ |
27 | | - |
28 | 25 | public class BankTransferPresenter implements BankTransferContract.UserActionsListener { |
| 26 | + private static final String ACCOUNT_NUMBER = "account_number"; |
| 27 | + private static final String BANK_NAME = "bank_name"; |
| 28 | + private static final String BENEFICIARY_NAME = "benef_name"; |
| 29 | + private static final String AMOUNT = "amount"; |
| 30 | + private static final String TX_REF = "txref"; |
| 31 | + private static final String FLW_REF = "flwref"; |
| 32 | + private static final String PUBLIC_KEY = "pbfkey"; |
29 | 33 | private Context context; |
30 | 34 | private BankTransferContract.View mView; |
31 | 35 | private AmountValidator amountValidator = new AmountValidator(); |
32 | 36 | private String txRef = null, flwRef = null, publicKey = null; |
33 | 37 | private long requeryCountdownTime = 0; |
34 | 38 | private boolean pollingCancelled = false; |
| 39 | + private String beneficiaryName, accountNumber, amount, bankName; |
| 40 | + private boolean hasTransferDetails = false; |
35 | 41 |
|
36 | 42 | BankTransferPresenter(Context context, BankTransferContract.View mView) { |
37 | 43 | this.context = context; |
@@ -90,17 +96,21 @@ public void onSuccess(ChargeResponse response, String responseAsJSONString) { |
90 | 96 |
|
91 | 97 | if (response.getData() != null) { |
92 | 98 | Log.d("resp", responseAsJSONString); |
| 99 | + hasTransferDetails = true; |
93 | 100 |
|
94 | 101 | flwRef = response.getData().getFlw_reference(); |
95 | 102 | txRef = response.getData().getTx_ref(); |
96 | 103 | publicKey = payload.getPBFPubKey(); |
97 | | - String beneficiaryName = response.getData().getNote().substring( |
| 104 | + beneficiaryName = response.getData().getNote().substring( |
98 | 105 | response.getData().getNote().indexOf("to ") + 3 |
99 | 106 | ); |
| 107 | + amount = response.getData().getAmount(); |
| 108 | + accountNumber = response.getData().getAccountnumber(); |
| 109 | + bankName = response.getData().getBankname(); |
100 | 110 | mView.onTransferDetailsReceived( |
101 | | - response.getData().getAmount(), |
102 | | - response.getData().getAccountnumber(), |
103 | | - response.getData().getBankname(), |
| 111 | + amount, |
| 112 | + accountNumber, |
| 113 | + bankName, |
104 | 114 | beneficiaryName); |
105 | 115 | } else { |
106 | 116 | mView.onPaymentError("No response data was returned"); |
@@ -128,6 +138,38 @@ public void cancelPolling() { |
128 | 138 | pollingCancelled = true; |
129 | 139 | } |
130 | 140 |
|
| 141 | + @Override |
| 142 | + public Bundle getState() { |
| 143 | + if (hasTransferDetails) { |
| 144 | + Bundle state = new Bundle(); |
| 145 | + state.putString(ACCOUNT_NUMBER, accountNumber); |
| 146 | + state.putString(BANK_NAME, bankName); |
| 147 | + state.putString(BENEFICIARY_NAME, beneficiaryName); |
| 148 | + state.putString(AMOUNT, amount); |
| 149 | + state.putString(TX_REF, txRef); |
| 150 | + state.putString(FLW_REF, flwRef); |
| 151 | + state.putString(PUBLIC_KEY, publicKey); |
| 152 | + return state; |
| 153 | + } else return null; |
| 154 | + } |
| 155 | + |
| 156 | + @Override |
| 157 | + public void restoreState(Bundle savedInstanceState) { |
| 158 | + if (savedInstanceState != null) { |
| 159 | + hasTransferDetails = true; |
| 160 | + accountNumber = savedInstanceState.getString(ACCOUNT_NUMBER); |
| 161 | + bankName = savedInstanceState.getString(BANK_NAME); |
| 162 | + beneficiaryName = savedInstanceState.getString(BENEFICIARY_NAME); |
| 163 | + amount = savedInstanceState.getString(AMOUNT); |
| 164 | + txRef = savedInstanceState.getString(TX_REF); |
| 165 | + flwRef = savedInstanceState.getString(FLW_REF); |
| 166 | + publicKey = savedInstanceState.getString(PUBLIC_KEY); |
| 167 | + |
| 168 | + mView.onTransferDetailsReceived(amount, accountNumber, bankName, beneficiaryName); |
| 169 | + } |
| 170 | + |
| 171 | + } |
| 172 | + |
131 | 173 | @Override |
132 | 174 | public void requeryTx() { |
133 | 175 |
|
|
0 commit comments