diff --git a/app/src/main/java/com/flutterwave/rave_android/MainActivity.java b/app/src/main/java/com/flutterwave/rave_android/MainActivity.java index fad0f7f9..13cd46d8 100644 --- a/app/src/main/java/com/flutterwave/rave_android/MainActivity.java +++ b/app/src/main/java/com/flutterwave/rave_android/MainActivity.java @@ -22,6 +22,7 @@ import com.flutterwave.raveandroid.RaveUiManager; import com.flutterwave.raveandroid.data.Utils; import com.flutterwave.raveandroid.rave_core.models.SavedCard; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Meta; import com.flutterwave.raveandroid.rave_java_commons.RaveConstants; import com.flutterwave.raveandroid.rave_java_commons.SubAccount; @@ -32,7 +33,6 @@ import com.flutterwave.raveandroid.rave_presentation.card.CardPaymentCallback; import com.flutterwave.raveandroid.rave_presentation.card.CardPaymentManager; import com.flutterwave.raveandroid.rave_presentation.card.SavedCardsListener; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveutils.verification.AVSVBVFragment; import com.flutterwave.raveutils.verification.OTPFragment; import com.flutterwave.raveutils.verification.PinFragment; @@ -58,8 +58,7 @@ public class MainActivity EditText narrationEt; EditText currencyEt; EditText countryEt; - EditText fNameEt; - EditText lNameEt; + EditText fullNameEt; EditText durationEt; EditText frequencyEt; EditText phoneNumberEt; @@ -112,8 +111,7 @@ protected void onCreate(Bundle savedInstanceState) { narrationEt = findViewById(R.id.narrationTV); currencyEt = findViewById(R.id.currencyEt); countryEt = findViewById(R.id.countryEt); - fNameEt = findViewById(R.id.fNameEt); - lNameEt = findViewById(R.id.lnameEt); + fullNameEt = findViewById(R.id.fullNameEt); phoneNumberEt = findViewById(R.id.phoneNumberEt); durationEt = findViewById(R.id.expiryDaysEt); frequencyEt = findViewById(R.id.frequencyEt); @@ -162,6 +160,17 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { } }); + francMobileMoneySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + if (b) { + countryEt.setVisibility(View.VISIBLE); + } else { + countryEt.setVisibility(View.GONE); + } + } + }); + cardSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { @@ -254,8 +263,7 @@ private void validateEntries() { String txRef = txRefEt.getText().toString(); String narration = narrationEt.getText().toString(); String currency = currencyEt.getText().toString(); - String fName = fNameEt.getText().toString(); - String lName = lNameEt.getText().toString(); + String fullName = fullNameEt.getText().toString(); String phoneNumber = phoneNumberEt.getText().toString(); String accountDuration = durationEt.getText().toString(); String accountPaymentFrequency = frequencyEt.getText().toString(); @@ -321,7 +329,7 @@ private void validateEntries() { .acceptRwfMobileMoneyPayments(rwfMobileMoneySwitch.isChecked()) .acceptUkPayments(ukbankSwitch.isChecked()) .acceptSaBankPayments(saBankSwitch.isChecked()) - .acceptFrancMobileMoneyPayments(francMobileMoneySwitch.isChecked()) + .acceptFrancMobileMoneyPayments(francMobileMoneySwitch.isChecked(), countryEt.getText().toString()) .acceptBankTransferPayments(bankTransferSwitch.isChecked()) .acceptUssdPayments(ussdSwitch.isChecked()) .acceptBarterPayments(barterSwitch.isChecked()) @@ -330,8 +338,7 @@ private void validateEntries() { .setAmount(Double.parseDouble(amount)) .setCurrency(currency) .setEmail(email) - .setfName(fName) - .setlName(lName) + .setFullName(fullName) .setPhoneNumber(phoneNumber, false) .setNarration(narration) .setPublicKey(publicKey) @@ -365,8 +372,7 @@ private void validateEntries() { raveManager = new RaveNonUIManager().setAmount(Double.parseDouble(amount)) .setCurrency(currency) .setEmail(email) - .setfName(fName) - .setlName(lName) + .setFullName(fullName) .setPhoneNumber(phoneNumber) .setNarration(narration) .setPublicKey(publicKey) @@ -459,8 +465,7 @@ private void clearErrors() { narrationEt.setError(null); currencyEt.setError(null); countryEt.setError(null); - fNameEt.setError(null); - lNameEt.setError(null); + fullNameEt.setError(null); durationEt.setError(null); frequencyEt.setError(null); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index bd13fab1..8a65beaf 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -149,6 +149,15 @@ android:checked="false" android:text="@string/francophone" /> + + - - - - orderedPaymentTypesList = new ArrayList<>(); - private boolean isPhoneEditable = true; String phoneNumber = ""; - private boolean saveCardFeatureAllowed = true; - private boolean usePhoneAndEmailSuppliedToSaveCards = true; String email; double amount; String publicKey; @@ -26,7 +23,6 @@ public class RavePayInitializer { String currency; String country; String fName; - String lName; String meta; String subAccounts; String payment_plan; @@ -38,11 +34,13 @@ public class RavePayInitializer { boolean isPermanent; int frequency; int duration; + private boolean isPhoneEditable = true; + private boolean saveCardFeatureAllowed = true; + private boolean usePhoneAndEmailSuppliedToSaveCards = true; public RavePayInitializer(String email, double amount, String publicKey, String encryptionKey, String txRef, String narration, - String currency, String country, String fName, - String lName, int theme, String phoneNumber, + String currency, String country, String fullName, int theme, String phoneNumber, boolean isPhoneEditable, boolean saveCardFeatureAllowed, boolean usePhoneAndEmailSuppliedToSaveCards, boolean isPermanent, int duration, int frequency, boolean staging, String meta, String subAccounts, String payment_plan, boolean isPreAuth, @@ -56,7 +54,6 @@ public RavePayInitializer(String email, double amount, String publicKey, this.currency = currency; this.country = country; this.fName = fName; - this.lName = lName; this.isPermanent = isPermanent; this.duration = duration; this.frequency = frequency; @@ -96,22 +93,26 @@ public void setMeta(String meta) { this.meta = meta; } - public String getSubAccount(){return subAccounts;} + public String getSubAccount() { + return subAccounts; + } - public void setSubAccount(String subAccounts){this.subAccounts=subAccounts;} + public void setSubAccount(String subAccounts) { + this.subAccounts = subAccounts; + } public boolean isStaging() { return staging; } - public ArrayList getOrderedPaymentTypesList() { - return orderedPaymentTypesList; - } - public void setStaging(boolean staging) { this.staging = staging; } + public ArrayList getOrderedPaymentTypesList() { + return orderedPaymentTypesList; + } + public int getTheme() { return theme; } @@ -201,15 +202,6 @@ public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } - - public String getlName() { - return lName; - } - - public void setlName(String lName) { - this.lName = lName; - } - public String getPayment_plan() { return payment_plan; } @@ -222,20 +214,22 @@ public void setPreAuth(boolean isPreAuth) { this.isPreAuth = isPreAuth; } - public boolean getIsPreAuth() { return isPreAuth; } + public boolean getIsPreAuth() { + return isPreAuth; + } public boolean getIsDisplayFee() { return displayFee; } - public boolean getIsPhoneEditable() { - return isPhoneEditable; - } - public void setIsDisplayFee(boolean displayFee) { this.displayFee = displayFee; } + public boolean getIsPhoneEditable() { + return isPhoneEditable; + } + public boolean getIsPermanent() { return isPermanent; } diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/RaveUiManager.java b/rave_android/src/main/java/com/flutterwave/raveandroid/RaveUiManager.java index c0a25e44..82c03456 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/RaveUiManager.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/RaveUiManager.java @@ -122,7 +122,6 @@ public RaveUiManager setCurrency(String currency) { country = "TZ"; break; default: - country = "NG"; break; } return this; @@ -134,16 +133,23 @@ public RaveUiManager setCountry(String country) { return this; } + @Deprecated public RaveUiManager setfName(String fName) { this.fName = fName; return this; } + @Deprecated public RaveUiManager setlName(String lName) { this.lName = lName; return this; } + public RaveUiManager setFullName(String fullName) { + this.fullName = fullName; + return this; + } + public RaveUiManager setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; return this; @@ -256,9 +262,10 @@ public RaveUiManager acceptSaBankPayments(boolean withSaBankAccount) { return this; } - public RaveUiManager acceptFrancMobileMoneyPayments(boolean withFrancMobileMoney) { + public RaveUiManager acceptFrancMobileMoneyPayments(boolean withFrancMobileMoney, String country) { if (!orderedPaymentTypesList.contains(PAYMENT_TYPE_FRANCO_MOBILE_MONEY) && withFrancMobileMoney) orderedPaymentTypesList.add(PAYMENT_TYPE_FRANCO_MOBILE_MONEY); + this.country = country; return this; } @@ -348,8 +355,7 @@ private RavePayInitializer createRavePayInitializer() { getNarration(), getCurrency(), getCountry(), - getfName(), - getlName(), + getFullName(), theme, getPhoneNumber(), allowEditPhone, diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/account/AccountUiPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/account/AccountUiPresenter.java index c4cc6793..c9952101 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/account/AccountUiPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/account/AccountUiPresenter.java @@ -202,15 +202,13 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(NG) .setCurrency(NGN) .setPBFPubKey(ravePayInitializer.getPublicKey()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setDevice_fingerprint(deviceIdGetter.getDeviceId()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setAccountbank(dataHashMap.get(fieldBankCode).getData()) .setMeta(ravePayInitializer.getMeta()) .setSubAccount(ravePayInitializer.getSubAccount()) - .setBVN(dataHashMap.get(fieldBVN).getData()) .setIsPreAuth(ravePayInitializer.getIsPreAuth()); @@ -218,9 +216,13 @@ public void processTransaction(HashMap dataHashMap, RavePayI builder.setAccountnumber(dataHashMap.get(fieldAccount).getData()); } + if (dataHashMap.get(fieldBVN).getData() != null && !dataHashMap.get(fieldBVN).getData().isEmpty()) + builder.setBVN(dataHashMap.get(fieldBVN).getData()); + Payload body = builder.createBankPayload(); - body.setPasscode(dataHashMap.get(fieldDOB).getData()); - body.setPhonenumber(dataHashMap.get(fieldPhone).getData()); + String dob = dataHashMap.get(fieldDOB).getData(); + if (dob != null && !dob.isEmpty()) body.setPasscode(dob); + body.setPhone_number(dataHashMap.get(fieldPhone).getData()); boolean isInternetBanking = dataHashMap.get(fieldAccount) == null; diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/ach/AchPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/ach/AchPresenter.java index 3fac8838..a58fe859 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/ach/AchPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/ach/AchPresenter.java @@ -20,7 +20,6 @@ import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; @@ -28,6 +27,8 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_ACH; + public class AchPresenter extends AchHandler implements AchUiContract.UserActionsListener { @@ -103,13 +104,11 @@ public void processTransaction(String amount, final RavePayInitializer ravePayIn .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) .setPBFPubKey(ravePayInitializer.getPublicKey()) - .setIsUsBankCharge(ravePayInitializer.getOrderedPaymentTypesList().contains(RaveConstants.PAYMENT_TYPE_ACH)) .setDevice_fingerprint(deviceIdGetter.getDeviceId()); if (ravePayInitializer.getPayment_plan() != null) { @@ -125,19 +124,11 @@ public void processTransaction(String amount, final RavePayInitializer ravePayIn public void chargeAccount(Payload payload, String encryptionKey, final boolean isDisplayFee) { - String requestBodyAsString = payloadToJsonConverter.convertChargeRequestPayloadToJson(payload); - String accountRequestBody = payloadEncryptor.getEncryptedData(requestBodyAsString, encryptionKey); - - final ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(accountRequestBody); - mView.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("ACH").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_ACH, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { @@ -186,7 +177,6 @@ public void onFeeConfirmed(String authUrl, String flwRef) { public void requeryTx(String publicKey) { final String flwRef = sharedMgr.fetchFlwRef(); - //todo call requery RequeryRequestBody body = new RequeryRequestBody(); body.setFlw_ref(flwRef); @@ -196,7 +186,7 @@ public void requeryTx(String publicKey) { logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { mView.showProgressIndicator(false); diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferPresenter.java index 7f6cb0ed..15e24f9d 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/banktransfer/BankTransferPresenter.java @@ -138,8 +138,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/barter/BarterPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/barter/BarterPresenter.java index 3620644d..cdee8ca4 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/barter/BarterPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/barter/BarterPresenter.java @@ -99,8 +99,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardFragment.java b/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardFragment.java index df1776ca..41fe6782 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardFragment.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardFragment.java @@ -37,16 +37,15 @@ import com.flutterwave.raveandroid.SwipeToDeleteCallback; import com.flutterwave.raveandroid.ViewObject; import com.flutterwave.raveandroid.card.savedcards.SavedCardRecyclerAdapter; -import com.flutterwave.raveandroid.card.savedcards.SavedCardsActivity; import com.flutterwave.raveandroid.card.savedcards.SavedCardsFragment; import com.flutterwave.raveandroid.data.EmailObfuscator; import com.flutterwave.raveandroid.data.PhoneNumberObfuscator; import com.flutterwave.raveandroid.data.events.FeeDisplayResponseEvent; import com.flutterwave.raveandroid.di.modules.CardUiModule; import com.flutterwave.raveandroid.rave_core.models.SavedCard; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_logger.events.StartTypingEvent; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveandroid.rave_presentation.data.events.ErrorEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.responses.SaveCardResponse; @@ -443,7 +442,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { String country = data.getStringExtra(AVSVBVFragment.EXTRA_COUNTRY); AddressDetails address = new AddressDetails(streetAddress, city, state, zipCode, country); - presenter.chargeCardWithAddressDetails(payLoad, address, ravePayInitializer.getEncryptionKey(), authModel); + presenter.chargeCardWithAddressDetails(payLoad, address, ravePayInitializer.getEncryptionKey()); break; case WEB_VERIFICATION_REQUEST_CODE: presenter.requeryTx(flwRef, ravePayInitializer.getPublicKey()); @@ -596,7 +595,7 @@ public void showCardSavingOption(boolean shouldShow) { public void collectOtpForSaveCardCharge(Payload payload) { String authInstruction = "Enter the one time password (OTP) sent to " + phoneNumberObfuscator.obfuscatePhoneNumber(payload - .getPhonenumber()) + " or " + emailObfuscator.obfuscateEmail(payload + .getPhone_number()) + " or " + emailObfuscator.obfuscateEmail(payload .getEmail()); showOTPLayoutForSavedCard(payload, authInstruction); } @@ -772,7 +771,7 @@ public void onClick(DialogInterface dialog, int which) { } @Override - public void collectCardAddressDetails(final Payload payload, String authModel) { + public void collectCardAddressDetails(final Payload payload) { this.payLoad = payload; this.authModel = authModel; new RaveVerificationUtils(this, ravePayInitializer.isStaging(), ravePayInitializer.getPublicKey(), ravePayInitializer.getTheme()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardUiPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardUiPresenter.java index c8b8cde5..aa442af7 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardUiPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/card/CardUiPresenter.java @@ -217,8 +217,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCurrency(ravePayInitializer.getCurrency()) .setCvv(dataHashMap.get(fieldCvv).getData()) .setEmail(dataHashMap.get(fieldEmail).getData()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID).setTxRef(ravePayInitializer.getTxRef()) .setExpiryyear(dataHashMap.get(fieldCardExpiry).getData().substring(3, 5)) .setExpirymonth(dataHashMap.get(fieldCardExpiry).getData().substring(0, 2)) @@ -254,8 +253,7 @@ public void processSavedCardTransaction(SavedCard savedCard, RavePayInitializer .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/card/NullUiCardView.java b/rave_android/src/main/java/com/flutterwave/raveandroid/card/NullUiCardView.java index 56de8c27..b0b5c87a 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/card/NullUiCardView.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/card/NullUiCardView.java @@ -132,7 +132,7 @@ public void onFetchFeeError(String errorMessage) { } @Override - public void collectCardAddressDetails(Payload payload, String authModel) { + public void collectCardAddressDetails(Payload payload) { } diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyPresenter.java index 8a824c1b..0dcaeefc 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/francMobileMoney/FrancMobileMoneyPresenter.java @@ -96,8 +96,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyPresenter.java index 47285e2d..b36ac6dd 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/ghmobilemoney/GhMobileMoneyPresenter.java @@ -71,8 +71,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaPresenter.java index 5893cd06..3548f38b 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/mpesa/MpesaPresenter.java @@ -97,8 +97,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/rwfmobilemoney/RwfMobileMoneyPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/rwfmobilemoney/RwfMobileMoneyPresenter.java index 5e350278..aaa3df89 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/rwfmobilemoney/RwfMobileMoneyPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/rwfmobilemoney/RwfMobileMoneyPresenter.java @@ -100,8 +100,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(NG) //Country has to be set to NG for RWF payments (as at 10/12/2018) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountFragment.java b/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountFragment.java index 2c7f8346..6c6876ab 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountFragment.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountFragment.java @@ -167,7 +167,7 @@ public void onTransactionFeeRetrieved(String chargeAmount, final Payload payload if (getActivity() != null) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setMessage(getResources().getString(R.string.charge) + chargeAmount + ravePayInitializer.getCurrency() + getResources().getString(R.string.askToContinue)); + builder.setMessage(getResources().getString(R.string.charge) + " " + chargeAmount + " " + ravePayInitializer.getCurrency() + getResources().getString(R.string.askToContinue)); builder.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenter.java index 6777d5fa..8bb7ddb5 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenter.java @@ -68,8 +68,7 @@ public void processTransaction(RavePayInitializer ravePayInitializer) { .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/ugmobilemoney/UgMobileMoneyPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/ugmobilemoney/UgMobileMoneyPresenter.java index 4f6dccd3..d8ca89a7 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/ugmobilemoney/UgMobileMoneyPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/ugmobilemoney/UgMobileMoneyPresenter.java @@ -101,8 +101,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(NG) //Country has to be set to NG for UGX payments (as at 10/12/2018) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/NullUkView.java b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/NullUkView.java index 5b005733..c6b9b803 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/NullUkView.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/NullUkView.java @@ -59,7 +59,7 @@ public void onPaymentSuccessful(String status, String flwRef, String responseAsS } @Override - public void showTransactionPage(String amount, String paymentCode, String flwRef, String txRef) { + public void showTransactionPage(String amount, String paymentCode, final String flwRef, final String txRef) { } diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkFragment.java b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkFragment.java index a28aefc4..5db3b987 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkFragment.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkFragment.java @@ -239,7 +239,6 @@ public void onClick(View view) { }); dialog.show(); } - } @Override diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkPresenter.java index 76894752..8cf4f96f 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/uk/UkPresenter.java @@ -85,8 +85,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceID) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/ussd/UssdPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/ussd/UssdPresenter.java index 7133e003..ead0e169 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/ussd/UssdPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/ussd/UssdPresenter.java @@ -62,8 +62,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/java/com/flutterwave/raveandroid/zmmobilemoney/ZmMobileMoneyPresenter.java b/rave_android/src/main/java/com/flutterwave/raveandroid/zmmobilemoney/ZmMobileMoneyPresenter.java index 8d4972c2..5bcf39a4 100644 --- a/rave_android/src/main/java/com/flutterwave/raveandroid/zmmobilemoney/ZmMobileMoneyPresenter.java +++ b/rave_android/src/main/java/com/flutterwave/raveandroid/zmmobilemoney/ZmMobileMoneyPresenter.java @@ -67,8 +67,7 @@ public void processTransaction(HashMap dataHashMap, RavePayI .setCountry(ravePayInitializer.getCountry()) .setCurrency(ravePayInitializer.getCurrency()) .setEmail(ravePayInitializer.getEmail()) - .setFirstname(ravePayInitializer.getfName()) - .setLastname(ravePayInitializer.getlName()) + .setFullname(ravePayInitializer.getfName()) .setIP(deviceIdGetter.getDeviceId()) .setTxRef(ravePayInitializer.getTxRef()) .setMeta(ravePayInitializer.getMeta()) diff --git a/rave_android/src/main/res/values/strings.xml b/rave_android/src/main/res/values/strings.xml index a41b4eef..11257970 100644 --- a/rave_android/src/main/res/values/strings.xml +++ b/rave_android/src/main/res/values/strings.xml @@ -151,7 +151,7 @@ I have completed this payment → 4327122 04-00-53 - Barter Funnding + Barter Funding Reference Code 4990 @@ -164,6 +164,7 @@ You are currently on staging mode Choose another payment method SECURED BY FLUTTERWAVE + Please select a card Select network @@ -188,9 +189,4 @@ MTN - - Hello blank fragment - Please select a card - Barter Funding - diff --git a/rave_android/src/test/java/com/flutterwave/raveandroid/account/AccountPresenterTest.java b/rave_android/src/test/java/com/flutterwave/raveandroid/account/AccountPresenterTest.java index 01b4e8b1..8f791557 100644 --- a/rave_android/src/test/java/com/flutterwave/raveandroid/account/AccountPresenterTest.java +++ b/rave_android/src/test/java/com/flutterwave/raveandroid/account/AccountPresenterTest.java @@ -1,6 +1,5 @@ package com.flutterwave.raveandroid.account; -import com.google.android.material.textfield.TextInputLayout; import android.view.View; import com.flutterwave.raveandroid.RavePayInitializer; @@ -29,6 +28,7 @@ import com.flutterwave.raveandroid.validators.DateOfBirthValidator; import com.flutterwave.raveandroid.validators.EmailValidator; import com.flutterwave.raveandroid.validators.PhoneValidator; +import com.google.android.material.textfield.TextInputLayout; import com.google.gson.Gson; import org.junit.Before; @@ -318,8 +318,8 @@ public void processTransaction_isDisplayFeeFalse_chargeAccountCalledWithCorrectP assertEquals(country, capturedPayload.getCountry()); assertEquals(currency, capturedPayload.getCurrency()); assertEquals(email, capturedPayload.getEmail()); - assertEquals(fingerPrint, capturedPayload.getIP()); - assertEquals(txRef, capturedPayload.getTxRef()); + assertEquals(fingerPrint, capturedPayload.getClient_ip()); + assertEquals(txRef, capturedPayload.getTx_ref()); assertEquals(pubKey, capturedPayload.getPBFPubKey()); assertEquals(deviceId, capturedPayload.getDevice_fingerprint()); @@ -383,8 +383,8 @@ public void processTransaction_isDisplayFeeTrue_fetchFeCalledWithCorrectParams() assertEquals(country, capturedPayload.getCountry()); assertEquals(currency, capturedPayload.getCurrency()); assertEquals(email, capturedPayload.getEmail()); - assertEquals(fingerPrint, capturedPayload.getIP()); - assertEquals(txRef, capturedPayload.getTxRef()); + assertEquals(fingerPrint, capturedPayload.getClient_ip()); + assertEquals(txRef, capturedPayload.getTx_ref()); assertEquals(pubKey, capturedPayload.getPBFPubKey()); assertEquals(deviceId, capturedPayload.getDevice_fingerprint()); diff --git a/rave_android/src/test/java/com/flutterwave/raveandroid/ach/AchPresenterTest.java b/rave_android/src/test/java/com/flutterwave/raveandroid/ach/AchPresenterTest.java index 6c555ae6..0be6022d 100644 --- a/rave_android/src/test/java/com/flutterwave/raveandroid/ach/AchPresenterTest.java +++ b/rave_android/src/test/java/com/flutterwave/raveandroid/ach/AchPresenterTest.java @@ -168,8 +168,8 @@ public void processTransaction_chargeAccountCalledWithCorrectParams() { assertEquals(email, capturedPayload.getEmail()); assertEquals(firstName, capturedPayload.getFirstname()); assertEquals(lastName, capturedPayload.getLastname()); - assertEquals(fingerPrint, capturedPayload.getIP()); - assertEquals(txRef, capturedPayload.getTxRef()); + assertEquals(fingerPrint, capturedPayload.getClient_ip()); + assertEquals(txRef, capturedPayload.getTx_ref()); assertEquals(pubKey, capturedPayload.getPBFPubKey()); assertEquals(isAch, capturedPayload.isIs_us_bank_charge()); assertEquals(deviceId, capturedPayload.getDevice_fingerprint()); diff --git a/rave_android/src/test/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenterTest.java b/rave_android/src/test/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenterTest.java index 0ecd3973..21676e2b 100644 --- a/rave_android/src/test/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenterTest.java +++ b/rave_android/src/test/java/com/flutterwave/raveandroid/sabankaccount/SaBankAccountPresenterTest.java @@ -133,8 +133,8 @@ public void processTransaction_chargeSaBankAccountCalledWithCorrectParams() { assertEquals(email, capturedPayload.getEmail()); assertEquals(firstName, capturedPayload.getFirstname()); assertEquals(lastName, capturedPayload.getLastname()); - assertEquals(fingerPrint, capturedPayload.getIP()); - assertEquals(txRef, capturedPayload.getTxRef()); + assertEquals(fingerPrint, capturedPayload.getClient_ip()); + assertEquals(txRef, capturedPayload.getTx_ref()); assertEquals(pubKey, capturedPayload.getPBFPubKey()); assertEquals(deviceId, capturedPayload.getDevice_fingerprint()); diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/AddressDetails.java b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/AddressDetails.java similarity index 93% rename from rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/AddressDetails.java rename to rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/AddressDetails.java index 7195adca..e53eefe1 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/AddressDetails.java +++ b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/AddressDetails.java @@ -1,4 +1,4 @@ -package com.flutterwave.raveandroid.rave_presentation.data; +package com.flutterwave.raveandroid.rave_java_commons; public class AddressDetails { private final String streetAddress; diff --git a/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/Payload.java b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/Payload.java index d08a28ae..9d5b7eab 100644 --- a/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/Payload.java +++ b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/Payload.java @@ -1,336 +1,179 @@ package com.flutterwave.raveandroid.rave_java_commons; import com.flutterwave.raveandroid.rave_core.models.SavedCard; -import com.google.gson.annotations.SerializedName; +import com.google.gson.Gson; +import com.google.gson.JsonElement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.AVS_NOAUTH; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PIN; + /** * Created by hamzafetuga on 05/07/2017. */ -public class Payload -{ +public class Payload { + public String network; + public String voucher; + public String bvn; private Boolean is_permanent; private Integer duration; private Integer frequency; - - private boolean is_ussd; private String orderRef; + private String order_id; private String is_barter; private String card_hash; - - public String getCardBIN() { - return cardBIN; - } - private String cardBIN; - - private boolean is_us_bank_charge; - private boolean is_saved_card_charge; - - private boolean is_uk_bank_charge2; - - private String remember_device_mobile_key; - + private Boolean is_saved_card_charge; + private Boolean preauthorize;//Todo: test preauth compatibility private String device_key; private String otp; + private String expiry_month; + private String PBFPubKey; + private String client_ip; + private String account_number; + private String account_name; + private String phone_number; + private String narration; + private String account_bank; + private String fullname; + private String currency; + private String country; + private String amount; + private String email; + private String expiry_year; + private String cvv; + private String device_fingerprint; + private String card_number; + private String tx_ref; + private String txRef;// Required for v2 charges + private String payment_type; + private String payment_plan; + private String passcode; + private String redirect_url = RaveConstants.RAVE_3DS_CALLBACK; + private JsonElement meta; + private List subaccounts; + private Authorization authorization; // Constructor for saved card charge - public Payload(List meta, - List subaccounts, String narration, String PBFPubKey, String IP, - String lastname, String firstname, String currency, String country, String amount, - String email, String device_fingerprint, String txRef, Boolean - is_saved_card_charge, String phonenumber) { + public Payload(List subaccounts, String narration, String PBFPubKey, String IP, + String fullname, String currency, String country, String amount, + String email, String device_fingerprint, String tx_ref, Boolean + is_saved_card_charge, String phone_number) { this.narration = narration; this.PBFPubKey = PBFPubKey; - this.IP = IP; + this.client_ip = IP; this.subaccounts = subaccounts; - this.lastname = lastname; - this.firstname = firstname; + this.fullname = fullname; this.currency = currency; this.country = country; this.amount = amount; this.email = email; this.device_fingerprint = device_fingerprint; - this.txRef = txRef; + this.tx_ref = tx_ref; + this.txRef = tx_ref; this.is_saved_card_charge = is_saved_card_charge; - this.phonenumber = phonenumber; - - if (meta == null) { - meta = new ArrayList<>(); - } - - meta.add(new Meta("sdk", "android")); - this.meta = meta; - } - - public String getOtp() { - return otp; - } - - private String remember_device_email; - - private String charge_type; - - public String getRemember_device_mobile_key() { - return remember_device_mobile_key; - } - - private String bvn; - - public void setRemember_device_mobile_key(String remember_device_mobile_key) { - this.remember_device_mobile_key = remember_device_mobile_key; - } - - public void setOtp(String otp) { - this.otp = otp; - } - - public String getDevice_key() { - return device_key; - } - - - public String getRemember_device_email() { - return remember_device_email; - } - - public void setRemember_device_email(String remember_device_email) { - this.remember_device_email = remember_device_email; - } - - public String getIs_remembered() { - return is_remembered; - } - - public void setIs_remembered(String is_remembered) { - this.is_remembered = is_remembered; - } - - private String is_remembered; - - private String payment_plan; - - public String getIs_mpesa() { - return is_mpesa; - } - - public void setIs_mpesa(String is_mpesa) { - this.is_mpesa = is_mpesa; - } - - public String getIs_mpesa_lipa() { - return is_mpesa_lipa; - } - - public void setIs_mpesa_lipa(String is_mpesa_lipa) { - this.is_mpesa_lipa = is_mpesa_lipa; + this.phone_number = phone_number; } - private String is_mpesa; - private String is_mpesa_lipa; - - public void setDevice_key(String device_key) { - this.device_key = device_key; - } - - public Payload(List meta, List subaccounts, String narration, - String expirymonth, String PBFPubKey, String IP, String lastname, - String firstname, String currency, String country, String amount, - String email, String expiryyear, String cvv, String device_fingerprint, - String cardno, String txRef) { + public Payload(List subaccounts, String narration, + String expiry_month, String PBFPubKey, String IP, + String fullname, String currency, String country, String amount, + String email, String expiry_year, String cvv, String device_fingerprint, + String card_number, String tx_ref) { this.narration = narration; - this.expirymonth = expirymonth; + this.expiry_month = expiry_month; this.PBFPubKey = PBFPubKey; - this.IP = IP; + this.client_ip = IP; this.subaccounts = subaccounts; - this.lastname = lastname; - this.firstname = firstname; + this.fullname = fullname; this.currency = currency; this.country = country; this.amount = amount; this.email = email; - this.expiryyear = expiryyear; + this.expiry_year = expiry_year; this.cvv = cvv; this.device_fingerprint = device_fingerprint; - this.cardno = cardno; - this.txRef = txRef; - - if (meta == null) { - meta = new ArrayList<>(); - } - - meta.add(new Meta("sdk", "android")); - this.meta = meta; - - } - - - public String getBillingcity() { - return billingcity; - } - - public void setBillingcity(String billingcity) { - this.billingcity = billingcity; - } - - public String getBillingaddress() { - return billingaddress; - } - - public void setBillingaddress(String billingaddress) { - this.billingaddress = billingaddress; - } - - public String getBVN() { - return bvn; - } - - public void setBVN(String bvn){ - this.bvn = bvn; - } - - public String getBillingstate() { - return billingstate; - } - - public void setBillingstate(String billingstate) { - this.billingstate = billingstate; - } - - public String getBillingcountry() { - return billingcountry; - } - - public void setBillingcountry(String billingcountry) { - this.billingcountry = billingcountry; + this.card_number = card_number; + this.tx_ref = tx_ref; + this.txRef = tx_ref; } - private String billingcity; - private String billingaddress; - private String billingstate; - private String billingcountry; - - public Payload(List meta, List subaccounts, String narration, String IP, String accountnumber, String accountbank, - String lastname, String firstname, String currency, String country, String amount, - String email, String device_fingerprint, String txRef, String PBFPubKey, - String billingaddress, String billingcity, String billingstate, String billingzip, String billingcountry) { - this.narration = narration; - this.IP = IP; - this.accountnumber = accountnumber; - this.accountbank = accountbank; - this.lastname = lastname; - this.firstname = firstname; - this.currency = currency; - this.country = country; - this.amount = amount; - this.email = email; - this.device_fingerprint = device_fingerprint; - this.txRef = txRef; - this.PBFPubKey = PBFPubKey; - this.billingaddress = billingaddress; - this.billingstate = billingstate; - this.billingcity = billingcity; - this.billingcountry = billingcountry; - this.billingzip = billingzip; - this.subaccounts = subaccounts; - - if (meta == null) { - meta = new ArrayList<>(); - } - - meta.add(new Meta("sdk", "android")); - this.meta = meta; - - } - - public Payload(String phonenumber, - List meta, - List subaccounts, + public Payload(String phone_number, List subaccounts, String narration, String IP, - String lastname, - String firstname, + String fullname, String currency, String country, String amount, String email, String device_fingerprint, - String txRef, + String tx_ref, String PBFPubKey) { - this.meta = meta; this.subaccounts = subaccounts; this.narration = narration; - this.IP = IP; - this.phonenumber = phonenumber; - this.lastname = lastname; - this.firstname = firstname; + this.client_ip = IP; + this.phone_number = phone_number; + this.fullname = fullname; this.currency = currency; this.country = country; this.amount = amount; this.email = email; this.device_fingerprint = device_fingerprint; - this.txRef = txRef; + this.tx_ref = tx_ref; + this.txRef = tx_ref; this.PBFPubKey = PBFPubKey; - - if (meta == null) { - meta = new ArrayList<>(); - } - - meta.add(new Meta("sdk", "android")); - this.meta = meta; - } - public Payload(List meta, List subaccounts, String narration, String IP, String accountnumber, String accountbank, - String lastname, String firstname, String currency, String country, String amount, - String email, String device_fingerprint, String txRef, String PBFPubKey, String bvn, boolean is_us_bank_charge) { + public Payload(List subaccounts, String narration, String IP, String accountnumber, String accountbank, + String fullname, String currency, String country, String amount, + String email, String device_fingerprint, String tx_ref, String PBFPubKey, String bvn) { this.meta = meta; this.subaccounts = subaccounts; this.narration = narration; - this.IP = IP; - this.accountnumber = accountnumber; - this.accountbank = accountbank; - this.lastname = lastname; - this.firstname = firstname; + this.client_ip = IP; + this.account_number = accountnumber; + this.account_bank = accountbank; + this.fullname = fullname; this.currency = currency; this.country = country; this.amount = amount; this.email = email; this.device_fingerprint = device_fingerprint; - this.txRef = txRef; + this.tx_ref = tx_ref; + this.txRef = tx_ref; this.PBFPubKey = PBFPubKey; this.bvn = bvn; - this.is_us_bank_charge = is_us_bank_charge; - - if (meta == null) { - meta = new ArrayList<>(); - } - - meta.add(new Meta("sdk", "android")); - this.meta = meta; + } + public String getCardBIN() { + return cardBIN; } + public void setCardBIN(String cardBIN) { + this.cardBIN = cardBIN; + } + public String getOtp() { + return otp; + } - public String getToken() { - return token; + public void setOtp(String otp) { + this.otp = otp; } - public String getPasscode() { - return passcode; + public void setDevice_key(String device_key) { + this.device_key = device_key; } public void setPasscode(String passcode) { this.passcode = passcode; } - private String passcode; - public String getPayment_plan() { return payment_plan; } @@ -339,363 +182,132 @@ public void setPayment_plan(String payment_plan) { this.payment_plan = payment_plan; } - public String getCharge_type() { - return charge_type; - } - - public void setCharge_type(String charge_type){ - this.charge_type = charge_type; - } - - public void setToken(String token) { - this.token = token; - } - - String token; - - public List getMeta() { - return meta; - } - - public void setMeta(List meta) { - this.meta = meta; - } - - public String getNarration() { - return narration; - } - - public void setNarration(String narration) { - this.narration = narration; - } - - public void setPin(String pin) { - this.pin = pin; - } - - private String pin; - - private String redirect_url = RaveConstants.RAVE_3DS_CALLBACK; - - public String getPBFSecKey() { - return PBFSecKey; - } - - public void setPBFSecKey(String PBFSecKey) { - this.PBFSecKey = PBFSecKey; - } + /** + * @param meta + * @deprecated This is deprecated way to set meta values. Only left because of charge methods that use v2 API + */ + public void setMetaForV2(List meta) { + if (meta == null) { + meta = new ArrayList<>(); + } - public void setSECKEY(String SECKEY) { - this.SECKEY = SECKEY; + meta.add(new Meta("sdk", "android")); + this.meta = new Gson().toJsonTree(meta); } - String SECKEY; - - private String PBFSecKey; - - @SerializedName("suggested_auth") - private String suggestedAuth; - private List meta; - - private List subaccounts; + public void setMeta(HashMap meta) { + if (meta == null) { + meta = new HashMap<>(); + } - public String getBillingzip() { - return billingzip; - } + meta.put("sdk", "android"); + this.meta = new Gson().toJsonTree(meta); - public void setBillingzip(String billingzip) { - this.billingzip = billingzip; } - private String billingzip; - - public String getPayment_type() { - return payment_type; - } public void setPayment_type(String payment_type) { this.payment_type = payment_type; } - private boolean is_mobile_money_franco; - - private String payment_type; - - public boolean getIs_mobile_money_franco() { - return is_mobile_money_franco; + public String getPhone_number() { + return phone_number; } - public void setIs_mobile_money_franco(boolean is_mobile_money_franco) { - this.is_mobile_money_franco = is_mobile_money_franco; + public void setPhone_number(String phone_number) { + this.phone_number = phone_number; } - private String is_sa_call_pay; - - public void setIs_sa_call_pay(String is_sa_call_pay){ - this.is_sa_call_pay = is_sa_call_pay; - } - - private String getIs_sa_call_pay(){ - return is_sa_call_pay; - } - - public String getPhonenumber() { - return phonenumber; - } - - public void setPhonenumber(String phonenumber) { - this.phonenumber = phonenumber; - } - - private String phonenumber; - - private String narration; - - public void setIs_internet_banking(String is_internet_banking) { - this.is_internet_banking = is_internet_banking; - } - - private String is_internet_banking; - - private String expirymonth; - - private String PBFPubKey; - - private String IP; - - private String accountnumber; - - private String accountname; - public String getAccountnumber() { - return accountnumber; + return account_number; } public void setAccountnumber(String accountnumber) { - this.accountnumber = accountnumber; - } - - public String getAccountbank() { - return accountbank; - } - - public void setAccountbank(String accountbank) { - this.accountbank = accountbank; - } - - private String accountbank; - - private String lastname; - - private String firstname; - - private String currency; - - private String country; - - private String amount; - - private String email; - - private String expiryyear; - - private String cvv; - - private String device_fingerprint; - - private String cardno; - - private String txRef; - - public String getExpirymonth () - { - return expirymonth; + this.account_number = accountnumber; } - public void setExpirymonth (String expirymonth) - { - this.expirymonth = expirymonth; + public void setAccount_bank(String account_bank) { + this.account_bank = account_bank; } - public String getPBFPubKey () - { + public String getPBFPubKey() { return PBFPubKey; } - public void setPBFPubKey (String PBFPubKey) - { + public void setPBFPubKey(String PBFPubKey) { this.PBFPubKey = PBFPubKey; } - public String getIP () - { - return IP; - } - - public void setIP (String IP) - { - this.IP = IP; - } - - public String getLastname () - { - return lastname; - } - - public void setLastname (String lastname) - { - this.lastname = lastname; + public String getClient_ip() { + return client_ip; } - public String getFirstname () - { - return firstname; + public void setFullname(String fullname) { + this.fullname = fullname; } - public void setFirstname (String firstname) - { - this.firstname = firstname; - } - - public String getCurrency () - { + public String getCurrency() { return currency; } - public void setCurrency (String currency) - { + public void setCurrency(String currency) { this.currency = currency; } - public String getCountry () - { + public String getCountry() { return country; } - public void setCountry (String country) - { + public void setCountry(String country) { this.country = country; } - public String getAmount () - { + public String getAmount() { return amount; } - public void setAmount (String amount) - { + public void setAmount(String amount) { this.amount = amount; } - public String getEmail () - { + public String getEmail() { return email; } - public void setEmail (String email) - { + public void setEmail(String email) { this.email = email; } - public String getExpiryyear () - { - return expiryyear; - } - - public void setExpiryyear (String expiryyear) - { - this.expiryyear = expiryyear; - } - - public String getCvv () - { - return cvv; - } - - public void setCvv (String cvv) - { - this.cvv = cvv; - } - - public String getDevice_fingerprint () - { + public String getDevice_fingerprint() { return device_fingerprint; } - public void setDevice_fingerprint (String device_fingerprint) - { + public void setDevice_fingerprint(String device_fingerprint) { this.device_fingerprint = device_fingerprint; } - public String getCardno () - { - return cardno; - } - - public void setCardno (String cardno) - { - this.cardno = cardno; - } - - public String getTxRef () - { - return txRef; + public String getCard_number() { + return card_number; } - public void setTxRef (String txRef) - { - this.txRef = txRef; - } - - public void setSuggestedAuth(String suggestedAuth) { - this.suggestedAuth = suggestedAuth; + public String getTx_ref() { + return tx_ref; } @Override - public String toString() - { - return "ClassPojo [expirymonth = "+expirymonth+", PBFPubKey = "+PBFPubKey+", IP = "+IP+", lastname = "+lastname+", firstname = "+firstname+", currency = "+currency+", country = "+country+", amount = "+amount+", email = "+email+", expiryyear = "+expiryyear+", cvv = "+cvv+", device_fingerprint = "+device_fingerprint+", cardno = "+cardno+", txRef = "+txRef+"]"; - } - - public void setCardBIN(String cardBIN) { - this.cardBIN = cardBIN; + public String toString() { + return "ClassPojo [expirymonth = " + expiry_month + ", PBFPubKey = " + PBFPubKey + ", IP = " + client_ip + ", fullname = " + fullname + ", currency = " + currency + ", country = " + country + ", amount = " + amount + ", email = " + email + ", expiryyear = " + expiry_year + ", cvv = " + cvv + ", device_fingerprint = " + device_fingerprint + ", cardno = " + card_number + ", txRef = " + tx_ref + "]"; } - public String is_mobile_money_gh; - - public String is_mobile_money_ug; - public void setNetwork(String network) { this.network = network; } - public String network; - - public String voucher; - public void setVoucher(String voucher) { this.voucher = voucher; } - public void setIs_mobile_money_gh(String is_mobile_money_gh) { - this.is_mobile_money_gh = is_mobile_money_gh; - } - - public void setIs_mobile_money_ug(String is_mobile_money_ug) { - this.is_mobile_money_ug = is_mobile_money_ug; - } - - public boolean isIs_us_bank_charge() { - return is_us_bank_charge; - } - - public void setIs_us_bank_charge(boolean is_us_bank_charge) { - this.is_us_bank_charge = is_us_bank_charge; - } - - public boolean is_bank_transfer; - public String getCard_hash() { return card_hash; } @@ -704,80 +316,74 @@ public void setCard_hash(String card_hash) { this.card_hash = card_hash; } - public void setIs_bank_transfer(boolean is_bank_transfer) { - this.is_bank_transfer = is_bank_transfer; - } - - public boolean getIs_permanent() { - return is_permanent; - } - - public void setIs_permanent(boolean is_permanent) { + public void setIs_permanent(Boolean is_permanent) { this.is_permanent = is_permanent; } - public int getDuration() { - return duration; - } - public void setDuration(int duration) { this.duration = duration; } - public int getFrequency() { - return frequency; - } - public void setFrequency(int frequency) { this.frequency = frequency; } - public boolean getIs_ussd() { - return is_ussd; - } - - public void setIs_ussd(boolean is_ussd) { - this.is_ussd = is_ussd; - } - - public String getOrderRef() { - return orderRef; - } - public void setOrderRef(String orderRef) { this.orderRef = orderRef; } - public boolean getIs_uk_bank_charge() { - return is_uk_bank_charge2; + public void setAccountname(String accountname) { + this.account_name = accountname; } - public void setIs_uk_bank_charge2(boolean is_uk_bank_charge2) { - this.is_uk_bank_charge2 = is_uk_bank_charge2; + public void setIs_barter(String is_barter) { + this.is_barter = is_barter; } - public String getAccountname() { - return accountname; + public void setSavedCardDetails(SavedCard savedCard) { + is_saved_card_charge = true; + this.setCardBIN(savedCard.getMasked_pan().substring(0, 6)); + this.setCard_hash(savedCard.getCardHash()); + this.setDevice_key(phone_number); } - public void setAccountname(String accountname) { - this.accountname = accountname; + public void setPreauthorize(Boolean preauthorize) { + this.preauthorize = preauthorize; } - public String getIs_barter() { - return is_barter; + public void setPin(String pin) { + this.authorization = new Authorization(PIN, pin); } - public void setIs_barter(String is_barter) { - this.is_barter = is_barter; + public void setAddressDetails(AddressDetails address) { + this.authorization = new Authorization(AVS_NOAUTH, address); } - public void setSavedCardDetails(SavedCard savedCard) { - is_saved_card_charge = true; - this.setCardBIN(savedCard.getMasked_pan().substring(0, 6)); - this.setCard_hash(savedCard.getCardHash()); - this.setDevice_key(phonenumber); + private class Authorization { + String mode; + String pin; + String address; + String city; + String state; + String zipcode; + String country; + + Authorization(String mode, String pin) { + this.mode = mode; + this.pin = pin; + } + + Authorization(String mode, AddressDetails addressDetails) { + this.mode = mode; + if (addressDetails != null) { + address = addressDetails.getStreetAddress(); + city = addressDetails.getCity(); + state = addressDetails.getState(); + zipcode = addressDetails.getZipCode(); + country = addressDetails.getCountry(); + } + } } } diff --git a/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/RaveConstants.java b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/RaveConstants.java index 89b72d39..803b465b 100644 --- a/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/RaveConstants.java +++ b/rave_java_commons/src/main/java/com/flutterwave/raveandroid/rave_java_commons/RaveConstants.java @@ -25,8 +25,8 @@ public class RaveConstants { public static final int ADDRESS_DETAILS_REQUEST_CODE = 5343; public static final int MANUAL_CARD_CHARGE = 403; - public static String PUBLIC_KEY = "FLWPUBK-e634d14d9ded04eaf05d5b63a0a06d2f-X"; //test - public static String ENCRYPTION_KEY = "bb9714020722eb4cf7a169f2";//test + public static String PUBLIC_KEY = "FLWPUBK_TEST-7ddb1c9cb4571aa27d588f468fb8c052-X"; //test + public static String ENCRYPTION_KEY = "FLWSECK_TEST24a907495c60";//test // public static String STAGING_URL = "https://ravesandbox.azurewebsites.net"; // public static String LIVE_URL = "https://raveapi.azurewebsites.net"; public static String STAGING_URL = "https://ravesandboxapi.flutterwave.com"; @@ -36,7 +36,30 @@ public class RaveConstants { public static String FLUTTERWAVE_UK_SORT_CODE = "04-00-53"; public static String FLUTTERWAVE_UK_BENEFICIARY_NAME = "Barter Funding"; + public static String CHARGE_TYPE_CARD = "card"; + public static String CHARGE_TYPE_ACH = "ach_payment"; + public static String CHARGE_TYPE_ACCOUNT = "debit_ng_account"; + public static String CHARGE_TYPE_UK_ACCOUNT = "debit_uk_account"; + public static String CHARGE_TYPE_BANK_TRANSFER = "bank_transfer"; + public static String CHARGE_TYPE_SA_BANK = "ach_payment"; + public static String CHARGE_TYPE_USSD = "ussd"; + public static String CHARGE_TYPE_GH_MOMO = "mobile_money_ghana"; + public static String CHARGE_TYPE_RW_MOMO = "mobile_money_rwanda"; + public static String CHARGE_TYPE_UG_MOMO = "mobile_money_uganda"; + public static String CHARGE_TYPE_ZM_MOMO = "mobile_money_zambia"; + public static String CHARGE_TYPE_MPESA = "mpesa"; + public static String CHARGE_TYPE_FRANC_MOMO = "mobile_money_franco"; + + // Authentication methods + public static final String PIN = "pin"; + public static final String OTP = "otp"; + public static final String REDIRECT = "redirect"; + public static final String BANK_TRANSFER = "banktransfer"; + public static final String CALLBACK = "callback"; + public static final String AVS_NOAUTH = "avs_noauth"; + + public static String AVS_VBVSECURECODE = "AVS_VBVSECURECODE"; public static String VBV = "VBVSECURECODE"; public static String GTB_OTP = "GTB_OTP"; public static String ACCESS_OTP = "ACCESS_OTP"; @@ -46,9 +69,7 @@ public class RaveConstants { public static String RWF = "RWF"; public static String NOAUTH = "NOAUTH"; public static String NOAUTH_SAVED_CARD = "noauth-saved-card"; - public static String PIN = "PIN"; public static String selectNetwork = "Select network"; - public static String AVS_VBVSECURECODE = "AVS_VBVSECURECODE"; public static String enterOTP = "Enter your one time password (OTP)"; public static String NOAUTH_INTERNATIONAL = "NOAUTH_INTERNATIONAL"; public static String RAVEPAY = "ravepay"; diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RaveNonUIManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RaveNonUIManager.java index 8176b5af..4b02de94 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RaveNonUIManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RaveNonUIManager.java @@ -85,7 +85,6 @@ public RaveNonUIManager setCurrency(String currency) { country = "TZ"; break; default: - country = "NG"; break; } return this; @@ -97,16 +96,23 @@ public RaveNonUIManager setCountry(String country) { return this; } + @Deprecated public RaveNonUIManager setfName(String fName) { this.fName = fName; return this; } + @Deprecated public RaveNonUIManager setlName(String lName) { this.lName = lName; return this; } + public RaveNonUIManager setFullName(String fullName) { + this.fullName = fullName; + return this; + } + public RaveNonUIManager setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; return this; diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RavePayManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RavePayManager.java index c2e839b5..06b17dff 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RavePayManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/RavePayManager.java @@ -11,6 +11,7 @@ abstract public class RavePayManager { protected String country = "NG"; protected String fName = ""; protected String lName = ""; + protected String fullName = null; protected String meta = ""; protected String subAccounts = ""; protected String payment_plan; @@ -57,12 +58,8 @@ public String getCountry() { return country; } - public String getfName() { - return fName; - } - - public String getlName() { - return lName; + public String getFullName() { + return fullName != null ? fullName : fName + " " + lName; } public String getMeta() { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandler.java index dcb689b6..822ab329 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandler.java @@ -17,7 +17,6 @@ import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.ValidateChargeBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; @@ -28,10 +27,16 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_ACCOUNT; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.OTP; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.enterOTP; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.invalidCharge; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.success; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.unknownAuthmsg; /** * Created by hamzafetuga on 20/07/2017. @@ -82,38 +87,34 @@ public void onError(String message) { @Override public void chargeAccount(final Payload payload, String encryptionKey) { - String cardRequestBodyAsString = payloadToJsonConverter.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); - mAccountInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("Account").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_ACCOUNT, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mAccountInteractor.showProgressIndicator(false); if (response.getData() != null) { - String authUrlCrude = response.getData().getAuthurl(); - String flwRef = response.getData().getFlwRef(); - boolean isValidUrl = urlValidator.isUrlValid(authUrlCrude); - if (authUrlCrude != null && isValidUrl) { - mAccountInteractor.displayInternetBankingPage(authUrlCrude, flwRef); - } else { - if (response.getData().getValidateInstruction() != null) { - mAccountInteractor.collectOtp(payload.getPBFPubKey(), flwRef, response.getData().getValidateInstruction()); - } else if (response.getData().getValidateInstructions() != null && - response.getData().getValidateInstructions().getInstruction() != null) { - mAccountInteractor.collectOtp(payload.getPBFPubKey(), flwRef, response.getData().getValidateInstructions().getInstruction()); - } else { - mAccountInteractor.collectOtp(payload.getPBFPubKey(), flwRef, null); + String authMode = response.getAuthMode(); + String flwRef = response.getFlwRef(); + if (authMode != null) { + switch (authMode) { + case OTP: + String instructions = response.getValidateInstructions(); + instructions = (instructions == null || instructions.length() == 0) ? enterOTP : instructions; + mAccountInteractor.collectOtp(payload.getPBFPubKey(), flwRef, instructions); + break; + case REDIRECT: + mAccountInteractor.displayInternetBankingPage(response.getAuthUrl(), flwRef); + break; + default: + mAccountInteractor.onPaymentError(unknownAuthmsg); } + + } else { + mAccountInteractor.onPaymentError(noResponse); } } @@ -128,18 +129,15 @@ public void onError(String message) { } @Override - public void authenticateAccountCharge(final String flwRef, String otp, final String PBFPubKey) { + public void authenticateAccountCharge(final String flwRef, String otp, final String publicKey) { - ValidateChargeBody body = new ValidateChargeBody(); - body.setPBFPubKey(PBFPubKey); - body.setOtp(otp); - body.setTransactionreference(flwRef); + ValidateChargeBody body = new ValidateChargeBody(flwRef, otp, "account"); mAccountInteractor.showProgressIndicator(true); - logEvent(new ValidationAttemptEvent("Account").getEvent(), PBFPubKey); + logEvent(new ValidationAttemptEvent("Account").getEvent(), publicKey); - networkRequest.validateAccountCharge(body, new ResultCallback() { + networkRequest.validateCharge(publicKey, body, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mAccountInteractor.showProgressIndicator(false); @@ -149,7 +147,7 @@ public void onSuccess(ChargeResponse response) { String message = response.getMessage(); if (status.equalsIgnoreCase(success)) { - requeryTx(flwRef, PBFPubKey); + requeryTx(flwRef, publicKey); } else { mAccountInteractor.onPaymentError(status); } @@ -211,7 +209,7 @@ public void requeryTx(String flwRef, String publicKey) { logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { mAccountInteractor.showProgressIndicator(false); diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountPaymentManager.java index 38db1e7a..76638c50 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/account/AccountPaymentManager.java @@ -52,7 +52,7 @@ private Payload createPayload(BankAccount account) { Payload body = builder.createBankPayload(); body.setPasscode(account.getDateOfBirth()); - body.setPhonenumber(manager.getPhoneNumber()); + body.setPhone_number(manager.getPhoneNumber()); return body; } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandler.java index 7920dc87..1f124533 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandler.java @@ -15,7 +15,6 @@ import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; @@ -23,6 +22,7 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_ACH; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; @@ -48,19 +48,11 @@ public AchHandler(AchContract.Interactor interactor) { public void chargeAccount(Payload payload, String encryptionKey) { - String requestBodyAsString = payloadToJsonConverter.convertChargeRequestPayloadToJson(payload); - String accountRequestBody = payloadEncryptor.getEncryptedData(requestBodyAsString, encryptionKey); - - final ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(accountRequestBody); - interactor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("ACH").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_ACH, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { @@ -97,8 +89,6 @@ public void onError(String message) { } public void requeryTx(String flwRef, String publicKey) { - //todo call requery - RequeryRequestBody body = new RequeryRequestBody(); body.setFlw_ref(flwRef); body.setPBFPubKey(publicKey); @@ -107,7 +97,7 @@ public void requeryTx(String flwRef, String publicKey) { logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { interactor.showProgressIndicator(false); diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchPaymentManager.java index 20466774..62a0a4a5 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ach/AchPaymentManager.java @@ -36,13 +36,11 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) .setPBFPubKey(manager.getPublicKey()) - .setIsUsBankCharge(true) .setDevice_fingerprint(manager.getUniqueDeviceID()); if (manager.getPayment_plan() != null) { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandler.java index ebdb3adc..af52ef10 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandler.java @@ -14,7 +14,6 @@ import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; @@ -22,6 +21,9 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.BANK_TRANSFER; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_BANK_TRANSFER; + /** * Created by hfetuga on 27/06/2018. */ @@ -85,40 +87,30 @@ public void onError(String message) { @Override public void payWithBankTransfer(final Payload payload, final String encryptionKey) { - String cardRequestBodyAsString = payloadToJson.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey); - encryptedCardRequestBody = encryptedCardRequestBody.trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); + txRef = payload.getTx_ref(); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("Bank Transfer").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_BANK_TRANSFER, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - if (response.getData() != null) { + if (response.getAuthMode() != null && response.getAuthMode().equalsIgnoreCase(BANK_TRANSFER)) { hasTransferDetails = true; - flwRef = response.getData().getFlw_reference(); - txRef = response.getData().getTx_ref(); - orderRef = response.getData().getOrderRef(); + flwRef = response.getFlwRef(); publicKey = payload.getPBFPubKey(); - if (response.getData().getNote() != null && response.getData().getNote().contains("to ")) { - beneficiaryName = response.getData().getNote().substring( - response.getData().getNote().indexOf("to ") + 3 - ); + String note = response.getTransferNote(); + if (note != null && note.contains("to ")) { + beneficiaryName = note.substring(note.indexOf("to ") + 3); } - amount = response.getData().getAmount(); - accountNumber = response.getData().getAccountnumber(); - bankName = response.getData().getBankname(); + amount = response.getTransferAmount(); + accountNumber = response.getTransferAccountNumber(); + bankName = response.getTransferBankName(); mInteractor.onTransferDetailsReceived( amount, accountNumber, @@ -155,17 +147,18 @@ public void requeryTx(final String flwRef, final String txRef, final String publ RequeryRequestBody body = new RequeryRequestBody(); body.setFlw_ref(flwRef); + body.setTx_ref(txRef); body.setPBFPubKey(publicKey); logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryPayWithBankTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryPayWithBankTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + if (response.getStatus() == null) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("01")) { + } else if (response.getStatus().equalsIgnoreCase("pending")) { if (pollingCancelled) { mInteractor.showPollingIndicator(false); mInteractor.onPollingCanceled(flwRef, txRef, responseAsJSONString); @@ -177,7 +170,7 @@ public void onSuccess(RequeryResponse response, String responseAsJSONString) { mInteractor.onPollingTimeout(flwRef, txRef, responseAsJSONString); } } - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferPaymentManager.java index 95eec566..958523e9 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferPaymentManager.java @@ -37,8 +37,7 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterHandler.java index 726d7c49..bc566408 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterHandler.java @@ -55,7 +55,7 @@ public void chargeBarter(final Payload payload, final String encryptionKey) { mInteractor.showProgressIndicator(true); - networkRequest.charge(body, new ResultCallback() { + networkRequest.chargeV2(body, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { @@ -74,7 +74,7 @@ public void onSuccess(ChargeResponse response) { } String authUrlCrude = authUrlBuilder.build().toString(); - String flwRef = response.getData().getFlw_reference(); + String flwRef = response.getData().getFlwRef(); if (flwRef == null) flwRef = response.getData().getFlwRef(); mInteractor.loadBarterCheckout(authUrlCrude, flwRef); @@ -105,17 +105,17 @@ public void requeryTx(final String flwRef, final String publicKey) { mInteractor.showPollingIndicator(true); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { if (response.getData() == null) { mInteractor.onPaymentFailed(flwRef, responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + } else if ("02".equals(response.getData().getChargeResponseCode()) || "pending".equalsIgnoreCase(response.getData().getStatus())) { if (pollingCancelled) { mInteractor.showPollingIndicator(false); mInteractor.onPollingCanceled(flwRef, responseAsJSONString); } else requeryTx(flwRef, publicKey); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if ("00".equals(response.getData().getChargeResponseCode()) || "successful".equalsIgnoreCase(response.getData().getStatus())) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, responseAsJSONString); } else { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterPaymentManager.java index 425e02eb..713f7420 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/barter/BarterPaymentManager.java @@ -40,8 +40,7 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardContract.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardContract.java index 40fd00d4..3923c7ed 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardContract.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardContract.java @@ -5,9 +5,9 @@ import android.webkit.WebView; import com.flutterwave.raveandroid.rave_core.models.SavedCard; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_logger.Event; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveandroid.rave_remote.responses.SaveCardResponse; import java.util.List; @@ -97,12 +97,11 @@ interface CardInteractor { /** * Called when the card used requires Address Verification. - * Collect the {@link AddressDetails} from the user and then continue the charge by calling {@link CardPaymentHandler#chargeCardWithAddressDetails(Payload, AddressDetails, String, String)} with that address. + * Collect the {@link AddressDetails} from the user and then continue the charge by calling {@link CardPaymentHandler#chargeCardWithAddressDetails(Payload, AddressDetails, String)} with that address. * - * @param payload Payload with the charge details - * @param authModel Authentication Model to be passed to the {@link CardPaymentHandler#chargeCardWithAddressDetails(Payload, AddressDetails, String, String)} function. + * @param payload Payload with the charge details */ - void collectCardAddressDetails(Payload payload, String authModel); + void collectCardAddressDetails(Payload payload); /** * Called to display a {@link android.webkit.WebView} for charges that require webpage authentication. @@ -175,7 +174,7 @@ interface CardPaymentHandler { void logEvent(Event event, String publicKey); - void chargeCardWithAddressDetails(Payload payLoad, AddressDetails address, String encryptionKey, String authModel); + void chargeCardWithAddressDetails(Payload payload, AddressDetails address, String encryptionKey); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardInteractorImpl.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardInteractorImpl.java index 71b1785c..c5379b64 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardInteractorImpl.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardInteractorImpl.java @@ -16,7 +16,6 @@ class CardInteractorImpl implements CardContract.CardInteractor { private CardPaymentCallback callback; private String flwRef; - private String authModel; private Payload payload; private SavedCardsListener savedCardsListener; private FeeCheckListener feeCheckListener; @@ -52,9 +51,8 @@ public void collectOtp(String flwRef, String message) { } @Override - public void collectCardAddressDetails(Payload payload, String authModel) { + public void collectCardAddressDetails(Payload payload) { this.payload = payload; - this.authModel = authModel; callback.collectAddress(); } @@ -143,10 +141,6 @@ public Payload getPayload() { return payload; } - String getAuthModel() { - return authModel; - } - public void setSavedCardsListener(SavedCardsListener savedCardsListener) { this.savedCardsListener = (savedCardsListener != null) ? savedCardsListener : new NullSavedCardsListener(); } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentCallback.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentCallback.java index db7c93cd..080d77a2 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentCallback.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentCallback.java @@ -5,7 +5,7 @@ import androidx.annotation.Nullable; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; public interface CardPaymentCallback { /** diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandler.java index 78a9c1f9..08564cff 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandler.java @@ -4,10 +4,10 @@ import com.flutterwave.raveandroid.rave_core.models.DeviceIdGetter; import com.flutterwave.raveandroid.rave_core.models.SavedCard; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; import com.flutterwave.raveandroid.rave_presentation.data.PayloadToJsonConverter; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; @@ -40,13 +40,17 @@ import javax.inject.Inject; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.ACCESS_OTP; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.AVS_NOAUTH; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.AVS_VBVSECURECODE; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_CARD; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.GTB_OTP; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.NOAUTH; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.NOAUTH_INTERNATIONAL; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.NOAUTH_SAVED_CARD; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.OTP; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.PIN; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.VBV; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.enterOTP; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; @@ -119,12 +123,125 @@ public void chargeCard(final Payload payload, final String encryptionKey) { logEvent(new ChargeAttemptEvent("Card").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_CARD, body, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mCardInteractor.showProgressIndicator(false); + String authMode = response.getAuthMode(); + String flwRef = response.getFlwRef(); + if (authMode != null) { + switch (authMode) { + case PIN: + mCardInteractor.collectCardPin(payload); + break; + case OTP: + String processorResponse = response.getData().getProcessorResponse(); + processorResponse = (processorResponse == null || processorResponse.length() == 0) ? enterOTP : processorResponse; + mCardInteractor.collectOtp(flwRef, processorResponse); + break; + case REDIRECT: + mCardInteractor.showWebPage(response.getAuthUrl(), flwRef); + break; + case AVS_NOAUTH: + mCardInteractor.collectCardAddressDetails(payload); + } + + } else { + mCardInteractor.onPaymentError(noResponse); + } + +// if (response.getData() != null) { +// +// if (response.getData().getSuggested_auth() != null) { +// String suggested_auth = response.getData().getSuggested_auth(); +// +// if (suggested_auth.equals(PIN)) { +// mCardInteractor.collectCardPin(payload); +// } else if (suggested_auth.equals(AVS_VBVSECURECODE)) { //address verification then verification by visa +// mCardInteractor.collectCardAddressDetails(payload, AVS_VBVSECURECODE); +// } else if (suggested_auth.equalsIgnoreCase(NOAUTH_INTERNATIONAL)) { +// mCardInteractor.collectCardAddressDetails(payload, NOAUTH_INTERNATIONAL); +// } else { +// mCardInteractor.onPaymentError(unknownAuthmsg); +// } +// } else { +// // Check if transaction is already successful +// if (response.getData().getChargeResponseCode() != null && response.getData().getChargeResponseCode().equalsIgnoreCase("00")) { +// String flwRef = response.getData().getFlwRef(); +// +// requeryTx(flwRef, payload.getPBFPubKey()); +// +// } else { +// +// String authModelUsed = response.getData().getAuthModelUsed(); +// +// if (authModelUsed != null) { +// String flwRef = response.getData().getFlwRef(); +// +// if (authModelUsed.equalsIgnoreCase(VBV) || authModelUsed.equalsIgnoreCase(AVS_VBVSECURECODE) || authModelUsed.equalsIgnoreCase(NOAUTH_SAVED_CARD)) { +// String authUrlCrude = response.getData().getAuthurl(); +// mCardInteractor.showWebPage(authUrlCrude, flwRef); +// } else if (authModelUsed.equalsIgnoreCase(GTB_OTP) +// || authModelUsed.equalsIgnoreCase(ACCESS_OTP) +// || authModelUsed.toLowerCase().contains("otp") +// || authModelUsed.equalsIgnoreCase(PIN)) { +// String chargeResponseMessage = response.getData().getChargeResponseMessage(); +// chargeResponseMessage = (chargeResponseMessage == null || chargeResponseMessage.length() == 0) ? enterOTP : chargeResponseMessage; +// mCardInteractor.collectOtp(flwRef, chargeResponseMessage); +// } else if (authModelUsed.equalsIgnoreCase(NOAUTH)) { +// requeryTx(flwRef, payload.getPBFPubKey()); +// } else { +// mCardInteractor.onPaymentError(unknownAuthmsg); +// } +// } else { +// mCardInteractor.onPaymentError(unknownAuthmsg); +// } +// } +// } +// } else { +// mCardInteractor.onPaymentError(noResponse); +// } + } + + @Override + public void onError(String message) { + mCardInteractor.showProgressIndicator(false); + mCardInteractor.onPaymentError(message); + } + }); + } + + /** + * Makes a generic call to the v2 charge endpoint with the payload provided. Handles both conditions + * for initial charge request and when the suggested auth has been added. + * + * @param payload {@link Payload} object to be sent. + * @param encryptionKey Rave encryption key gotten from dashboard + * @deprecated This has been deprecated in favor of the {@link CardPaymentHandler#chargeCard(Payload, String) v3 charge}. + * It's only left for use for saved card charge (with Webpage authentication) which has not yet been migrated. + * Other auth models might not work well with this route. + */ + @Deprecated + private void chargeCardV2(final Payload payload, final String encryptionKey) { + String cardRequestBodyAsString = payloadToJsonConverter.convertChargeRequestPayloadToJson(payload); + String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey); + + final ChargeRequestBody body = new ChargeRequestBody(); + body.setAlg("3DES-24"); + body.setPBFPubKey(payload.getPBFPubKey()); + body.setClient(encryptedCardRequestBody); + + mCardInteractor.showProgressIndicator(true); + logEvent(new ChargeAttemptEvent("Card").getEvent(), payload.getPBFPubKey()); + + + networkRequest.chargeV2(body, new ResultCallback() { + @Override + public void onSuccess(ChargeResponse response) { + + mCardInteractor.showProgressIndicator(false); if (response.getData() != null) { if (response.getData().getSuggested_auth() != null) { @@ -133,9 +250,13 @@ public void onSuccess(ChargeResponse response) { if (suggested_auth.equals(PIN)) { mCardInteractor.collectCardPin(payload); } else if (suggested_auth.equals(AVS_VBVSECURECODE)) { //address verification then verification by visa - mCardInteractor.collectCardAddressDetails(payload, AVS_VBVSECURECODE); + mCardInteractor.collectCardAddressDetails(payload +// , AVS_VBVSECURECODE + ); } else if (suggested_auth.equalsIgnoreCase(NOAUTH_INTERNATIONAL)) { - mCardInteractor.collectCardAddressDetails(payload, NOAUTH_INTERNATIONAL); + mCardInteractor.collectCardAddressDetails(payload +// , NOAUTH_INTERNATIONAL + ); } else { mCardInteractor.onPaymentError(unknownAuthmsg); } @@ -190,12 +311,12 @@ public void onError(String message) { public void chargeSavedCard(Payload payload, String encryptionKey) { if (payload.getOtp() == null || payload.getOtp() == "") { sendRaveOTP(payload); - } else chargeCard(payload, encryptionKey); + } else chargeCardV2(payload, encryptionKey); } public void sendRaveOTP(final Payload payload) { SendOtpRequestBody body = new SendOtpRequestBody(); - body.setDevice_key(payload.getPhonenumber()); + body.setDevice_key(payload.getPhone_number()); body.setPublic_key(payload.getPBFPubKey()); body.setCard_hash(payload.getCard_hash()); @@ -217,16 +338,10 @@ public void onError(String message) { } @Override - public void chargeCardWithAddressDetails(Payload payload, AddressDetails address, String encryptionKey, String authModel) { - payload.setSuggestedAuth(authModel); - payload.setBillingaddress(address.getStreetAddress()); - payload.setBillingcity(address.getCity()); - payload.setBillingzip(address.getZipCode()); - payload.setBillingcountry(address.getCountry()); - payload.setBillingstate(address.getState()); + public void chargeCardWithAddressDetails(Payload payload, AddressDetails address, String encryptionKey) { + payload.setAddressDetails(address); logEvent(new ChargeAttemptEvent("AVS Card").getEvent(), payload.getPBFPubKey()); - chargeCard(payload, encryptionKey); } @@ -234,25 +349,20 @@ public void chargeCardWithAddressDetails(Payload payload, AddressDetails address @Override public void chargeCardWithPinAuthModel(final Payload payload, String pin, String encryptionKey) { payload.setPin(pin); - payload.setSuggestedAuth(PIN); chargeCard(payload, encryptionKey); - } @Override public void validateCardCharge(final String flwRef, String otp, final String publicKey) { - ValidateChargeBody body = new ValidateChargeBody(); - body.setPBFPubKey(publicKey); - body.setOtp(otp); - body.setTransaction_reference(flwRef); + ValidateChargeBody body = new ValidateChargeBody(flwRef, otp, CHARGE_TYPE_CARD); mCardInteractor.showProgressIndicator(true); logEvent(new ValidationAttemptEvent("Card").getEvent(), publicKey); - networkRequest.validateCardCharge(body, new ResultCallback() { + networkRequest.validateCharge(publicKey, body, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mCardInteractor.showProgressIndicator(false); @@ -291,7 +401,7 @@ public void requeryTx(final String flwRef, final String publicKey) { logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { mCardInteractor.showProgressIndicator(false); @@ -344,7 +454,7 @@ public void onError(String message) { } @Override - public void deleteASavedCard(String cardHash, String phoneNumber, String publicKey){ + public void deleteASavedCard(String cardHash, String phoneNumber, String publicKey) { mCardInteractor.showProgressIndicator(true); RemoveSavedCardRequestBody body = new RemoveSavedCardRequestBody(cardHash, phoneNumber, publicKey); networkRequest.deleteASavedCard(body, new ResultCallback() { @@ -371,7 +481,7 @@ public void lookupSavedCards(String publicKey, body.setDevice_key(phoneNumber); body.setPublic_key(publicKey); - if(showLoader) + if (showLoader) mCardInteractor.showProgressIndicator(true); @@ -406,7 +516,7 @@ public void onError(String message) { @Override public void fetchFee(final Payload payload) { - boolean isCardnoValid = cardNoValidator.isCardNoStrippedValid(payload.getCardno()); + boolean isCardnoValid = cardNoValidator.isCardNoStrippedValid(payload.getCard_number()); FeeCheckRequestBody body = new FeeCheckRequestBody(); body.setAmount(payload.getAmount()); @@ -414,7 +524,7 @@ public void fetchFee(final Payload payload) { body.setPBFPubKey(payload.getPBFPubKey()); if (isCardnoValid) { - body.setCard6(payload.getCardno().substring(0, 6)); + body.setCard6(payload.getCard_number().substring(0, 6)); } else { body.setCard6(payload.getCardBIN()); } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentManager.java index a25dfeb7..93c13a62 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentManager.java @@ -1,10 +1,10 @@ package com.flutterwave.raveandroid.rave_presentation.card; import com.flutterwave.raveandroid.rave_core.models.SavedCard; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_presentation.FeeCheckListener; import com.flutterwave.raveandroid.rave_presentation.RaveNonUIManager; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveandroid.rave_presentation.data.PayloadBuilder; import com.flutterwave.raveandroid.rave_presentation.di.RaveComponent; import com.flutterwave.raveandroid.rave_presentation.di.card.CardModule; @@ -21,6 +21,7 @@ public class CardPaymentManager { public CardPaymentHandler paymentHandler; CardInteractorImpl interactor; private int chargeType; + //Todo: Look into making UI layer depend on payment managers public CardPaymentManager(RaveNonUIManager manager, CardPaymentCallback callback) { this.manager = manager; @@ -52,8 +53,7 @@ private Payload createPayload(Card card) { .setCurrency(manager.getCurrency()) .setCvv(card.getCvv()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getfName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setExpiryyear(card.getExpiryYear()) @@ -88,8 +88,7 @@ public void submitAddress(AddressDetails addressDetails) { paymentHandler.chargeCardWithAddressDetails( interactor.getPayload(), addressDetails, - manager.getEncryptionKey(), - interactor.getAuthModel() + manager.getEncryptionKey() ); } @@ -142,8 +141,7 @@ private Payload createPayload(SavedCard card) { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/PayloadBuilder.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/PayloadBuilder.java index 0ae33350..99c98fcf 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/PayloadBuilder.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/PayloadBuilder.java @@ -1,7 +1,6 @@ package com.flutterwave.raveandroid.rave_presentation.data; import com.flutterwave.raveandroid.rave_core.models.SavedCard; -import com.flutterwave.raveandroid.rave_java_commons.Meta; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_java_commons.SubAccount; @@ -12,8 +11,7 @@ public class PayloadBuilder { private String expirymonth; private String pbfPubKey; private String ip; - private String lastname; - private String firstname; + private String fullname; private String currency = "NGN"; private String country = "NG"; private String amount; @@ -27,83 +25,19 @@ public class PayloadBuilder { private String bvn; private String voucher; private String otp; - private boolean isPreAuth = false; - private boolean is_us_bank_charge = false; - private boolean is_bank_transfer = false; - private boolean is_saved_card_charge = false; + private Boolean isPreAuth = null; + private Boolean is_saved_card_charge = null; private SavedCard savedCard; - private boolean isPermanent; + private Boolean isPermanent; private int frequency; private int duration; - - public PayloadBuilder setIs_mobile_money_gh(String is_mobile_money_gh) { - this.is_mobile_money_gh = is_mobile_money_gh; - return this; - } - - public PayloadBuilder setIs_mobile_money_ug(String is_mobile_money_ug) { - this.is_mobile_money_ug = is_mobile_money_ug; - return this; - } - - private String is_mobile_money_rwf; - - public PayloadBuilder setIs_bank_transfer(boolean is_bank_transfer) { - this.is_bank_transfer = is_bank_transfer; - return this; - } - - - private String is_mobile_money_gh; - private String is_mobile_money_ug; - - public PayloadBuilder setIs_mobile_money_rwf(String is_mobile_money_rwf) { - this.is_mobile_money_rwf = is_mobile_money_rwf; - return this; - } - private String phonenumber; - private String txRef; - private String meta = ""; - private String subAccounts = ""; - - public PayloadBuilder setCustomer_phone(String customer_phone) { - this.customer_phone = customer_phone; - return this; - } - - private String customer_phone; + private String meta = null; + private String subAccounts = null; private String narration; - private String pin; private String accountbank; private String accountnumber; - private String accountname; - - public PayloadBuilder setAccountnumber(String accountnumber) { - this.accountnumber = accountnumber; - return this; - } - - public PayloadBuilder setAccountbank(String accountbank) { - this.accountbank = accountbank; - return this; - } - - public PayloadBuilder setPin(String pin) { - this.pin = pin; - return this; - } - - public PayloadBuilder setExpirymonth(String expirymonth) { - this.expirymonth = expirymonth; - return this; - } - - public PayloadBuilder setVoucher(String voucher) { - this.voucher = voucher; - return this; - } public PayloadBuilder setPBFPubKey(String pbfPubKey) { this.pbfPubKey = pbfPubKey; @@ -120,97 +54,22 @@ public PayloadBuilder setBVN(String bvn) { return this; } - public PayloadBuilder setLastname(String lastname) { - this.lastname = lastname; - return this; - } - - public PayloadBuilder setFirstname(String firstname) { - this.firstname = firstname; - return this; - } - public PayloadBuilder setIsPreAuth(boolean isPreAuth) { this.isPreAuth = isPreAuth; return this; } - public PayloadBuilder setIsUsBankCharge(boolean is_us_bank_charge) { - this.is_us_bank_charge = is_us_bank_charge; - return this; - } - - public PayloadBuilder setCurrency(String currency) { - this.currency = currency; - return this; - } - - public PayloadBuilder setPhonenumber(String phonenumber) { - this.phonenumber = phonenumber; - return this; - } - - public PayloadBuilder setCountry(String country) { - this.country = country; - return this; - } - - public PayloadBuilder setAmount(String amount) { - this.amount = amount; - return this; - } - - public PayloadBuilder setEmail(String email) { - this.email = email; - return this; - } - - public PayloadBuilder setExpiryyear(String expiryyear) { - this.expiryyear = expiryyear; - return this; - } - - public PayloadBuilder setCvv(String cvv) { - this.cvv = cvv; - return this; - } - public PayloadBuilder setPaymentPlan(String payment_plan) { this.payment_plan = payment_plan; return this; } - public PayloadBuilder setDevice_fingerprint(String device_fingerprint) { - this.device_fingerprint = device_fingerprint; - return this; - } - - public PayloadBuilder setCardno(String cardno) { - this.cardno = cardno; - return this; - } - - public PayloadBuilder setTxRef(String txRef) { - this.txRef = txRef; - return this; - } - - public String getAccountname() { - return accountname; - } - - public PayloadBuilder setAccountname(String accountname) { - this.accountname = accountname; - return this; - } - public Payload createPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(metaObj, subaccountsObj, narration, expirymonth, - pbfPubKey, ip, lastname, - firstname, currency, country, + Payload payload = new Payload(subaccountsObj, narration, expirymonth, + pbfPubKey, ip, + fullname, currency, country, amount, email, expiryyear, cvv, device_fingerprint, cardno, txRef); @@ -219,31 +78,26 @@ public Payload createPayload() { payload.setPayment_plan(payment_plan); } - if (isPreAuth) { - payload.setCharge_type("preauth"); - } + payload.setPreauthorize(isPreAuth); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createBankPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(metaObj, subaccountsObj, narration, ip, accountnumber, accountbank, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey, bvn, is_us_bank_charge); + Payload payload = new Payload(subaccountsObj, narration, ip, accountnumber, accountbank, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey, bvn); payload.setPayment_type("account"); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createBankTransferPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setIs_bank_transfer(true); - payload.setPayment_type("banktransfer"); - payload.setNetwork(network); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); // Setup account expiry details if (isPermanent) { @@ -252,132 +106,114 @@ public Payload createBankTransferPayload() { if (duration > 0) payload.setDuration(duration); if (frequency > 0) payload.setFrequency(frequency); } + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } - public Payload createUssdPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setAccountbank(accountbank); - payload.setIs_ussd(true); - payload.setPayment_type("USSD"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + payload.setAccount_bank(accountbank); payload.setOrderRef(txRef); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createMpesaPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setPayment_type("mpesa"); - payload.setIs_mpesa("1"); - payload.setIs_mpesa_lipa("1"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createFrancPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setPayment_type("mobilemoneyfranco"); - payload.setIs_mobile_money_franco(true); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createUKPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setPayment_type("account"); payload.setAccountnumber("00000"); payload.setAccountname("account rave mobile"); - payload.setAccountbank("093"); - payload.setIs_uk_bank_charge2(true); + payload.setAccount_bank("093"); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } - public Payload createSaBankAccountPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setPayment_type("account"); - payload.setIs_sa_call_pay("1"); payload.setAccountnumber("00000"); - payload.setAccountbank("093"); + payload.setAccount_bank("093"); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createBarterPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setPayment_type("barter"); payload.setIs_barter("1"); + payload.setMetaForV2(Utils.pojofyMetaStringForV2(meta)); return payload; } public Payload createGhMobileMoneyPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setIs_mobile_money_gh("1"); - payload.setPayment_type("mobilemoneygh"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setVoucher(voucher); payload.setNetwork(network); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createZmMobileMoneyPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setIs_mobile_money_ug("1"); - payload.setPayment_type("mobilemoneyzambia"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setVoucher(voucher); payload.setNetwork(network); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createUgMobileMoneyPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setIs_mobile_money_ug("1"); - payload.setPayment_type("mobilemoneyuganda"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setNetwork(network); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createRwfMobileMoneyPayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(phonenumber, metaObj, subaccountsObj, narration, ip, lastname, - firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); - payload.setIs_mobile_money_gh("1"); - payload.setPayment_type("mobilemoneygh"); + Payload payload = new Payload(phonenumber, subaccountsObj, narration, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey); payload.setNetwork(network); + payload.setMeta(Utils.pojofyMetaString(meta)); return payload; } public Payload createSavedCardChargePayload() { - List metaObj = Utils.pojofyMetaString(meta); List subaccountsObj = Utils.pojofySubaccountString(subAccounts); - Payload payload = new Payload(metaObj, subaccountsObj, narration, - pbfPubKey, ip, lastname, - firstname, currency, country, + Payload payload = new Payload(subaccountsObj, narration, + pbfPubKey, ip, + fullname, currency, country, amount, email, device_fingerprint, txRef, is_saved_card_charge, phonenumber); @@ -385,37 +221,21 @@ public Payload createSavedCardChargePayload() { payload.setPayment_plan(payment_plan); } - if (isPreAuth) { - payload.setCharge_type("preauth"); - } + payload.setPreauthorize(isPreAuth); payload.setCardBIN(savedCard.getMasked_pan().substring(0, 6)); payload.setCard_hash(savedCard.getCardHash()); payload.setDevice_key(phonenumber); + payload.setMetaForV2(Utils.pojofyMetaStringForV2(meta)); return payload; } - public PayloadBuilder setMeta(String meta) { - this.meta = meta; - return this; - } - public PayloadBuilder setSubAccount(String subAccounts) { this.subAccounts = subAccounts; return this; } - public PayloadBuilder setNarration(String narration) { - this.narration = narration; - return this; - } - - public PayloadBuilder setNetwork(String network) { - this.network = network; - return this; - } - public String getOtp() { return otp; } @@ -425,69 +245,80 @@ public PayloadBuilder setOtp(String otp) { return this; } - public boolean isIs_saved_card_charge() { - return is_saved_card_charge; - } - public PayloadBuilder setIs_saved_card_charge(boolean is_saved_card_charge) { this.is_saved_card_charge = is_saved_card_charge; return this; } - public SavedCard getSavedCard() { - return savedCard; - } - - public String getExpirymonth() { - return expirymonth; - } - - public String getPbfPubKey() { - return pbfPubKey; - } - - public String getIp() { - return ip; + public PayloadBuilder setSavedCard(SavedCard savedCard) { + this.savedCard = savedCard; + return this; } - public String getLastname() { - return lastname; + public PayloadBuilder setExpirymonth(String expirymonth) { + this.expirymonth = expirymonth; + return this; } - public String getFirstname() { - return firstname; + public PayloadBuilder setFullname(String fullname) { + this.fullname = fullname; + return this; } public String getCurrency() { return currency; } + public PayloadBuilder setCurrency(String currency) { + this.currency = currency; + return this; + } + public String getCountry() { return country; } + public PayloadBuilder setCountry(String country) { + this.country = country; + return this; + } + public String getAmount() { return amount; } + public PayloadBuilder setAmount(String amount) { + this.amount = amount; + return this; + } + public String getEmail() { return email; } - public String getExpiryyear() { - return expiryyear; + public PayloadBuilder setEmail(String email) { + this.email = email; + return this; + } + + public PayloadBuilder setExpiryyear(String expiryyear) { + this.expiryyear = expiryyear; + return this; } - public String getCvv() { - return cvv; + public PayloadBuilder setCvv(String cvv) { + this.cvv = cvv; + return this; } - public String getDevice_fingerprint() { - return device_fingerprint; + public PayloadBuilder setDevice_fingerprint(String device_fingerprint) { + this.device_fingerprint = device_fingerprint; + return this; } - public String getCardno() { - return cardno; + public PayloadBuilder setCardno(String cardno) { + this.cardno = cardno; + return this; } public String getPayment_plan() { @@ -498,82 +329,73 @@ public String getNetwork() { return network; } - public String getBvn() { - return bvn; + public PayloadBuilder setNetwork(String network) { + this.network = network; + return this; } - public String getVoucher() { - return voucher; + public PayloadBuilder setVoucher(String voucher) { + this.voucher = voucher; + return this; } public boolean isPreAuth() { return isPreAuth; } - public boolean isIs_us_bank_charge() { - return is_us_bank_charge; - } - - public boolean isIs_bank_transfer() { - return is_bank_transfer; - } - - public String getIs_mobile_money_gh() { - return is_mobile_money_gh; - } - - public String getIs_mobile_money_ug() { - return is_mobile_money_ug; - } - public String getPhonenumber() { return phonenumber; } + public PayloadBuilder setPhonenumber(String phonenumber) { + this.phonenumber = phonenumber; + return this; + } + public String getTxRef() { return txRef; } - public String getMeta() { - return meta; + public PayloadBuilder setTxRef(String txRef) { + this.txRef = txRef; + return this; } - public String getSubAccounts() { - return subAccounts; + public String getMeta() { + return meta; } - public String getCustomer_phone() { - return customer_phone; + public PayloadBuilder setMeta(String meta) { + this.meta = meta; + return this; } - public String getNarration() { - return narration; + public String getSubAccounts() { + return subAccounts;// TOdo: Test subaccount functionality } - public String getPin() { - return pin; + public PayloadBuilder setNarration(String narration) { + this.narration = narration; + return this; } - public String getAccountbank() { - return accountbank; + public PayloadBuilder setAccountbank(String accountbank) { + this.accountbank = accountbank; + return this; } public String getAccountnumber() { return accountnumber; } - public PayloadBuilder setIsPermanent(boolean permanent) { - this.isPermanent = permanent; + public PayloadBuilder setAccountnumber(String accountnumber) { + this.accountnumber = accountnumber; return this; } - public boolean getPermanent() { - return isPermanent; - } - - - public int getFrequency() { - return frequency; + public PayloadBuilder setIsPermanent(boolean permanent) { + this.isPermanent = permanent; + return this; } public PayloadBuilder setfrequency(int frequency) { @@ -581,17 +403,8 @@ public PayloadBuilder setfrequency(int frequency) { return this; } - public int getDuration() { - return duration; - } - public PayloadBuilder setDuration(int duration) { this.duration = duration; return this; } - - public PayloadBuilder setSavedCard(SavedCard savedCard) { - this.savedCard = savedCard; - return this; - } } \ No newline at end of file diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/Utils.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/Utils.java index 8dd9dc4e..4e8e9b9b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/Utils.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/Utils.java @@ -21,6 +21,7 @@ import java.security.MessageDigest; import java.security.PublicKey; import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; import java.util.List; import javax.crypto.Cipher; @@ -65,7 +66,7 @@ public static String convertChargeRequestPayloadToJson(Payload body) { return gson.toJson(body, type); } - public static List pojofyMetaString(String meta) { + public static List pojofyMetaStringForV2(String meta) { try { Gson gson = new Gson(); Type type = new TypeToken>() { @@ -77,6 +78,23 @@ public static List pojofyMetaString(String meta) { } } + public static HashMap pojofyMetaString(String metas) { + try { + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + List meta1 = gson.fromJson(metas, type); + + HashMap metaMap = new HashMap<>(); + for (Meta meta : meta1) metaMap.put(meta.getMetaname(), meta.getMetavalue()); + + return metaMap; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static List pojofySubaccountString(String subaccount) { try { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/TransactionStatusChecker.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/TransactionStatusChecker.java index 52a97e9d..b9e58a67 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/TransactionStatusChecker.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/TransactionStatusChecker.java @@ -18,9 +18,9 @@ public Boolean getTransactionStatus(String responseAsJSONString) { try { JsonObject jsonObject = gson.fromJson(responseAsJSONString, JsonObject.class); JsonObject jsonData = jsonObject.getAsJsonObject("data"); - String chargeResponse = jsonData.get("chargeResponseCode").getAsString(); + String status = jsonData.get("status").getAsString(); - if (chargeResponse.equalsIgnoreCase("00")) { + if (status.equalsIgnoreCase("successful")) { return true; } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/UrlValidator.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/UrlValidator.java index 7f5f908b..a0ed3885 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/UrlValidator.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/data/validators/UrlValidator.java @@ -12,6 +12,6 @@ public UrlValidator() { } public boolean isUrlValid(String url) { - return Pattern.matches("^(https?|ftp|file|http)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", url); + return url != null && Pattern.matches("^(https?|ftp|file|http)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", url); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandler.java index 98c52d5b..c8db29ea 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandler.java @@ -6,14 +6,12 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; @@ -21,6 +19,7 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_FRANC_MOMO; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; @@ -79,27 +78,20 @@ public void onError(String message) { @Override public void chargeFranc(final Payload payload, final String encryptionKey) { - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("Francophone Mobile Money").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_FRANC_MOMO, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); if (response.getData() != null) { - String flwRef = response.getData().getData().getFlw_reference(); - String txRef = response.getData().getData().getTransaction_reference(); + String flwRef = response.getFlwRef(); + String txRef = response.getTxRef(); requeryTx(flwRef, txRef, payload.getPBFPubKey()); } else { mInteractor.onPaymentError(noResponse); @@ -127,21 +119,22 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { requeryTx(flwRef, txRef, publicKey); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancophoneMobileMoneyPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancophoneMobileMoneyPaymentManager.java index 4b0212eb..f9bc436b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancophoneMobileMoneyPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancophoneMobileMoneyPaymentManager.java @@ -12,12 +12,14 @@ public class FrancophoneMobileMoneyPaymentManager { private final RaveNonUIManager manager; + private final String country; @Inject public FrancMobileMoneyHandler paymentHandler; FrancMobileMoneyInteractorImpl interactor; - public FrancophoneMobileMoneyPaymentManager(RaveNonUIManager manager, FrancophoneMobileMoneyPaymentCallback callback) { + public FrancophoneMobileMoneyPaymentManager(RaveNonUIManager manager, String country, FrancophoneMobileMoneyPaymentCallback callback) { this.manager = manager; + this.country = country; injectFields(manager.getRaveComponent(), callback); @@ -32,11 +34,10 @@ public void charge() { private Payload createPayload() { PayloadBuilder builder = new PayloadBuilder(); builder.setAmount(String.valueOf(manager.getAmount())) - .setCountry(manager.getCountry()) + .setCountry(country) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandler.java index ebbaafec..ad71c9de 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandler.java @@ -6,23 +6,22 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; +import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; -import com.flutterwave.raveandroid.rave_remote.responses.MobileMoneyChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_GH_MOMO; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; -import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; /** @@ -39,6 +38,7 @@ public class GhMobileMoneyHandler implements GhMobileMoneyContract.Handler { private GhMobileMoneyContract.Interactor mInteractor; private boolean pollingCancelled = false; private String txRef = null; + private String flwRef = null; @Inject public GhMobileMoneyHandler(GhMobileMoneyContract.Interactor mInteractor) { @@ -79,37 +79,25 @@ public void onError(String message) { @Override public void chargeGhMobileMoney(final Payload payload, final String encryptionKey) { - txRef = payload.getTxRef(); - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); + txRef = payload.getTx_ref(); + // Todo: merge code redundancies in different payment methods mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("GH Mobile Money").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeMobileMoneyWallet(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_GH_MOMO, payload, new ResultCallback() { @Override - public void onSuccess(MobileMoneyChargeResponse response) { + public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - MobileMoneyChargeResponse.Data data = response.getData(); - if (data != null) { - if (data.getCode() != null && data.getCode().equals("02") - && data.getCaptchaLink() != null) { - mInteractor.showWebPage(data.getCaptchaLink()); - } else { - String flwRef = data.getFlwRef(); - String txRef = data.getTx_ref(); - requeryTx(flwRef, txRef, payload.getPBFPubKey()); - } - } else { - mInteractor.onPaymentError(noResponse); + + if (response.getAuthMode() != null && response.getAuthMode().equalsIgnoreCase(REDIRECT) && response.getAuthUrl() != null) + mInteractor.showWebPage(response.getAuthUrl()); + else { + flwRef = response.getFlwRef(); + requeryTx(flwRef, txRef, payload.getPBFPubKey()); } } @@ -124,7 +112,7 @@ public void onError(String message) { @Override public void requeryTx(final String publicKey) { - requeryTx(null, txRef, publicKey); + requeryTx(flwRef, txRef, publicKey); } @Override @@ -139,21 +127,21 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { if (!pollingCancelled) { requeryTx(flwRef, txRef, publicKey); } else mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhanaMobileMoneyPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhanaMobileMoneyPaymentManager.java index a4225f86..878bd135 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhanaMobileMoneyPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhanaMobileMoneyPaymentManager.java @@ -55,8 +55,7 @@ private Payload createPayload(String network, String voucher) { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandler.java index 572af1ea..f8790fc1 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandler.java @@ -6,14 +6,13 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; +import com.flutterwave.raveandroid.rave_presentation.data.validators.TransactionStatusChecker; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; @@ -21,6 +20,7 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_MPESA; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; @@ -38,6 +38,8 @@ public class MpesaHandler implements MpesaContract.Handler { RemoteRepository networkRequest; @Inject PayloadEncryptor payloadEncryptor; + @Inject + TransactionStatusChecker transactionStatusChecker; private MpesaContract.Interactor mInteractor; private boolean pollingCancelled = false; @@ -80,23 +82,13 @@ public void onError(String message) { @Override public void chargeMpesa(final Payload payload, final String encryptionKey) { - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey) - .trim().replaceAll("\\n", ""); - -// Log.d("encrypted", encryptedCardRequestBody); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("MPesa").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_MPESA, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { @@ -131,21 +123,21 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { if (!pollingCancelled) { requeryTx(flwRef, txRef, publicKey); } else mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaPaymentManager.java index 5a812974..3f6a043e 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaPaymentManager.java @@ -35,8 +35,7 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandler.java index 3b2684db..8bea2076 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandler.java @@ -6,23 +6,22 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; +import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; -import com.flutterwave.raveandroid.rave_remote.responses.MobileMoneyChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_RW_MOMO; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; -import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; /** @@ -41,6 +40,7 @@ public class RwfMobileMoneyHandler implements RwfMobileMoneyContract.Handler { private RwfMobileMoneyContract.Interactor mInteractor; private boolean pollingCancelled = false; private String txRef = null; + private String flwRef = null; @Inject public RwfMobileMoneyHandler(RwfMobileMoneyContract.Interactor mInteractor) { @@ -81,37 +81,25 @@ public void onError(String message) { @Override public void chargeRwfMobileMoney(final Payload payload, final String encryptionKey) { - txRef = payload.getTxRef(); - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); + txRef = payload.getTx_ref(); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("Rwanda Mobile Money").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeMobileMoneyWallet(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_RW_MOMO, payload, new ResultCallback() { @Override - public void onSuccess(MobileMoneyChargeResponse response) { + public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - MobileMoneyChargeResponse.Data data = response.getData(); - if (data != null) { - if (data.getCode() != null && data.getCode().equals("02") - && data.getCaptchaLink() != null) { - mInteractor.showWebPage(data.getCaptchaLink()); - } else { - String flwRef = data.getFlwRef(); - String txRef = data.getTx_ref(); - requeryTx(flwRef, txRef, payload.getPBFPubKey()); - } - } else mInteractor.onPaymentError(noResponse); + if (response.getAuthMode() != null && response.getAuthMode().equalsIgnoreCase(REDIRECT) && response.getAuthUrl() != null) + mInteractor.showWebPage(response.getAuthUrl()); + else { + flwRef = response.getFlwRef(); + requeryTx(flwRef, txRef, payload.getPBFPubKey()); + } } @@ -126,7 +114,7 @@ public void onError(String message) { @Override public void requeryTx(final String publicKey) { - requeryTx(null, txRef, publicKey); + requeryTx(flwRef, txRef, publicKey); } @Override @@ -141,21 +129,21 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { if (!pollingCancelled) { requeryTx(flwRef, txRef, publicKey); } else mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyPaymentManager.java index d2424fde..0ac0760b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyPaymentManager.java @@ -39,8 +39,7 @@ private Payload createPayload() { .setCountry(NG) //Country has to be set to NG for RWF payments (as at 10/12/2018) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandler.java index 4e2e5433..c9b0bcc1 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandler.java @@ -6,7 +6,6 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_presentation.data.validators.TransactionStatusChecker; @@ -14,7 +13,6 @@ import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; @@ -108,7 +106,7 @@ public void requeryTx(String publicKey, String flwRef) { logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { mView.showProgressIndicator(false); @@ -124,28 +122,20 @@ public void onError(String message, String responseAsJSONString) { @Override public void chargeSaBankAccount(final Payload payload, String encryptionKey) { - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); mView.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("SA Bank Account").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeSaBankAccount(body, new ResultCallback() { + networkRequest.chargeSaBankAccount(payload.getPBFPubKey(), payload, new ResultCallback() { @Override public void onSuccess(SaBankAccountResponse response) { mView.showProgressIndicator(false); - - if (response.getData().getData().getRedirectUrl() != null) { - String authUrl = response.getData().getData().getRedirectUrl(); - String flwRef = response.getData().getData().getFlwReference(); + String authUrl = response.getAuthUrl(); + if (authUrl != null) { + String flwRef = response.getData().getFlwRef(); mView.showWebView(authUrl, flwRef); } else { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountPaymentManager.java index d37b9f2b..8ad6947b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountPaymentManager.java @@ -36,8 +36,7 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandler.java index c0252f6d..3c3b86d9 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandler.java @@ -6,23 +6,22 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; +import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; -import com.flutterwave.raveandroid.rave_remote.responses.MobileMoneyChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_UG_MOMO; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; -import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; @@ -37,6 +36,7 @@ public class UgMobileMoneyHandler implements UgMobileMoneyContract.Handler { private UgMobileMoneyContract.Interactor mInteractor; private boolean pollingCancelled = false; private String txRef = null; + private String flwRef = null; @Inject public UgMobileMoneyHandler(UgMobileMoneyContract.Interactor mInteractor) { @@ -77,38 +77,24 @@ public void onError(String message) { @Override public void chargeUgMobileMoney(final Payload payload, final String encryptionKey) { - txRef = payload.getTxRef(); - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); + txRef = payload.getTx_ref(); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("UG Mobile Money").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeMobileMoneyWallet(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_UG_MOMO, payload, new ResultCallback() { @Override - public void onSuccess(MobileMoneyChargeResponse response) { + public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - MobileMoneyChargeResponse.Data data = response.getData(); - if (data != null) { - if (data.getCode() != null && data.getCode().equals("02") - && data.getCaptchaLink() != null) { - mInteractor.showWebPage(data.getCaptchaLink()); - } else { - String flwRef = data.getFlwRef(); - String txRef = data.getTx_ref(); - requeryTx(flwRef, txRef, payload.getPBFPubKey()); - } - } else { - mInteractor.onPaymentError(noResponse); + if (response.getAuthMode() != null && response.getAuthMode().equalsIgnoreCase(REDIRECT) && response.getAuthUrl() != null) + mInteractor.showWebPage(response.getAuthUrl()); + else { + flwRef = response.getFlwRef(); + requeryTx(flwRef, txRef, payload.getPBFPubKey()); } } @@ -138,25 +124,21 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { -// Log.d("Requery response",responseAsJSONString); - if (pollingCancelled) { - mInteractor.showPollingIndicator(false); - mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } - else requeryTx(flwRef, txRef, publicKey); - - } else if (response.getData().getChargeResponseCode().equals("00")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { + if (!pollingCancelled) { + requeryTx(flwRef, txRef, publicKey); + } else mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgandaMobileMoneyPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgandaMobileMoneyPaymentManager.java index ff6b17d0..1eb9d6c9 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgandaMobileMoneyPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgandaMobileMoneyPaymentManager.java @@ -39,8 +39,7 @@ private Payload createPayload() { .setCountry(NG) //Country has to be set to NG for UGX payments (as at 10/12/2018) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkBankPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkBankPaymentManager.java index 40bf2f86..c85cb22b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkBankPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkBankPaymentManager.java @@ -36,8 +36,7 @@ private Payload createPayload() { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandler.java index f972e981..1750218b 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandler.java @@ -6,22 +6,20 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; -import com.flutterwave.raveandroid.rave_remote.responses.PollingResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_UK_ACCOUNT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; @@ -82,73 +80,22 @@ public void onError(String message) { @Override public void chargeUk(final Payload payload, final String encryptionKey) { - txRef = payload.getTxRef(); - - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey); - encryptedCardRequestBody = encryptedCardRequestBody.trim(); - encryptedCardRequestBody = encryptedCardRequestBody.replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); - + txRef = payload.getTx_ref(); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("UK").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeWithPolling(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_UK_ACCOUNT, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { - + mInteractor.showProgressIndicator(false); if (response.getData() != null) { String amount = response.getAmount(); String paymentCode = response.getPaymentCode(); String flwRef = response.getFlwRef(); - if (amount != null && paymentCode != null) { - mInteractor.showProgressIndicator(false); - mInteractor.showTransactionPage(amount, paymentCode, flwRef, txRef); - } else if (response.getPingUrl() != null) { - callPingUrl(response.getPingUrl()); - } else { - mInteractor.showProgressIndicator(false); - mInteractor.onPaymentError(noResponse); - } - } else { - mInteractor.showProgressIndicator(false); - mInteractor.onPaymentError(noResponse); - } - - } - - @Override - public void onError(String message) { - mInteractor.showProgressIndicator(false); - mInteractor.onPaymentError(message); - } - }); - } - - void callPingUrl(final String pingUrl) { - - networkRequest.pollUrl(pingUrl, new ResultCallback() { - @Override - public void onSuccess(PollingResponse response) { - - if (response.data != null) { - if (response.getResponse() != null) { - - mInteractor.showProgressIndicator(false); - String amount = response.getAmount(); - String paymentCode = response.getPaymentCode(); - String flwRef = response.getFlwRef(); - if (amount != null && paymentCode != null) - mInteractor.showTransactionPage(amount, paymentCode, flwRef, txRef); - else mInteractor.onPaymentError(noResponse); - } else callPingUrl(pingUrl); + mInteractor.showTransactionPage(amount, paymentCode, flwRef, txRef); } else { mInteractor.onPaymentError(noResponse); } @@ -176,17 +123,17 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { if (response.getData() == null) { mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + } else if (response.getStatus().equalsIgnoreCase("pending")) { if (pollingCancelled) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } else requeryTx(flwRef, txRef, publicKey); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandler.java index ba8a3fe8..a7374362 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandler.java @@ -15,7 +15,6 @@ import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; @@ -23,6 +22,7 @@ import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_USSD; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; public class UssdHandler implements UssdContract.Handler { @@ -80,41 +80,29 @@ public void onError(String message) { @Override public void payWithUssd(final Payload payload, final String encryptionKey) { - String cardRequestBodyAsString = payloadToJson.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey); - encryptedCardRequestBody = encryptedCardRequestBody.trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("USSD").getEvent(), payload.getPBFPubKey()); - networkRequest.charge(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_USSD, payload, new ResultCallback() { @Override public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - if (response.getData() != null) { - flwRef = response.getData().getUssdData().getFlw_reference(); + String code = response.getUssdCode(); + + if (code != null) { + flwRef = response.getFlwRef(); publicKey = payload.getPBFPubKey(); - String note = null; - if (response.getData().getNote() != null) note = response.getData().getNote(); - else if (response.getData().getUssdData().getNote() != null) - note = response.getData().getUssdData().getNote(); - else mInteractor.onPaymentError("No response data was returned"); - if (note != null) { - if (note.contains("|")) { - ussdCode = note.substring(0, note.indexOf("|")); - } else ussdCode = note; - referenceCode = response.getData().getUssdData().getReference_code(); - mInteractor.onUssdDetailsReceived(ussdCode, referenceCode); - } + if (code.contains("|")) { + ussdCode = code.substring(0, code.indexOf("|")); + if (code.length() > code.indexOf("|") + 1) + referenceCode = code.substring(code.indexOf("|") + 1); + } else ussdCode = code; + mInteractor.onUssdDetailsReceived(ussdCode, referenceCode); } else { mInteractor.onPaymentError("No response data was returned"); } @@ -144,15 +132,13 @@ public void requeryTx(final String flwRef, final String publicKey, final long re logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - - if (response.getData() == null) { - mInteractor.showPollingIndicator(false); + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { if (pollingCancelled) { mInteractor.showPollingIndicator(false); mInteractor.onPollingCanceled(flwRef, responseAsJSONString); @@ -164,12 +150,13 @@ public void onSuccess(RequeryResponse response, String responseAsJSONString) { mInteractor.onPollingTimeout(flwRef, responseAsJSONString); } } - } else if (response.getData().getChargeResponseCode().equals("00")) { + + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdPaymentManager.java index efab8c19..10340149 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdPaymentManager.java @@ -39,8 +39,7 @@ private Payload createPayload(Bank bank) { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZambiaMobileMoneyPaymentManager.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZambiaMobileMoneyPaymentManager.java index f4e7bb1f..2906f818 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZambiaMobileMoneyPaymentManager.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZambiaMobileMoneyPaymentManager.java @@ -41,8 +41,7 @@ private Payload createPayload(String network) { .setCountry(manager.getCountry()) .setCurrency(manager.getCurrency()) .setEmail(manager.getEmail()) - .setFirstname(manager.getfName()) - .setLastname(manager.getlName()) + .setFullname(manager.getFullName()) .setIP(manager.getUniqueDeviceID()) .setTxRef(manager.getTxRef()) .setMeta(manager.getMeta()) diff --git a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandler.java b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandler.java index 2c9acbd8..d9b65654 100644 --- a/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandler.java +++ b/rave_presentation/src/main/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandler.java @@ -6,23 +6,22 @@ import com.flutterwave.raveandroid.rave_logger.Event; import com.flutterwave.raveandroid.rave_logger.EventLogger; import com.flutterwave.raveandroid.rave_presentation.data.PayloadEncryptor; -import com.flutterwave.raveandroid.rave_presentation.data.Utils; import com.flutterwave.raveandroid.rave_presentation.data.events.ChargeAttemptEvent; import com.flutterwave.raveandroid.rave_presentation.data.events.RequeryEvent; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; import com.flutterwave.raveandroid.rave_remote.RemoteRepository; import com.flutterwave.raveandroid.rave_remote.ResultCallback; -import com.flutterwave.raveandroid.rave_remote.requests.ChargeRequestBody; import com.flutterwave.raveandroid.rave_remote.requests.RequeryRequestBody; +import com.flutterwave.raveandroid.rave_remote.responses.ChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.FeeCheckResponse; -import com.flutterwave.raveandroid.rave_remote.responses.MobileMoneyChargeResponse; import com.flutterwave.raveandroid.rave_remote.responses.RequeryResponse; import javax.inject.Inject; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_ZM_MOMO; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.RAVEPAY; -import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.noResponse; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.REDIRECT; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.transactionError; /** @@ -39,6 +38,7 @@ public class ZmMobileMoneyHandler implements ZmMobileMoneyContract.Handler { private ZmMobileMoneyContract.Interactor mInteractor; private boolean pollingCancelled = false; private String txRef = null; + private String flwRef = null; @Inject public ZmMobileMoneyHandler(ZmMobileMoneyContract.Interactor mInteractor) { @@ -79,37 +79,25 @@ public void onError(String message) { @Override public void chargeZmMobileMoney(final Payload payload, final String encryptionKey) { - txRef = payload.getTxRef(); - String cardRequestBodyAsString = Utils.convertChargeRequestPayloadToJson(payload); - String encryptedCardRequestBody = payloadEncryptor.getEncryptedData(cardRequestBodyAsString, encryptionKey).trim().replaceAll("\\n", ""); - - ChargeRequestBody body = new ChargeRequestBody(); - body.setAlg("3DES-24"); - body.setPBFPubKey(payload.getPBFPubKey()); - body.setClient(encryptedCardRequestBody); + txRef = payload.getTx_ref(); mInteractor.showProgressIndicator(true); logEvent(new ChargeAttemptEvent("Zambia Mobile Money").getEvent(), payload.getPBFPubKey()); - networkRequest.chargeMobileMoneyWallet(body, new ResultCallback() { + networkRequest.charge(payload.getPBFPubKey(), CHARGE_TYPE_ZM_MOMO, payload, new ResultCallback() { @Override - public void onSuccess(MobileMoneyChargeResponse response) { + public void onSuccess(ChargeResponse response) { mInteractor.showProgressIndicator(false); - MobileMoneyChargeResponse.Data data = response.getData(); - if (data != null) { - if (data.getCode() != null && data.getCode().equals("02") - && data.getCaptchaLink() != null) { - mInteractor.showWebPage(data.getCaptchaLink()); - } else { - String flwRef = data.getFlwRef(); - String txRef = data.getTx_ref(); - requeryTx(flwRef, txRef, payload.getPBFPubKey()); - } - } else mInteractor.onPaymentError(noResponse); + if (response.getAuthMode() != null && response.getAuthMode().equalsIgnoreCase(REDIRECT) && response.getAuthUrl() != null) + mInteractor.showWebPage(response.getAuthUrl()); + else { + flwRef = response.getFlwRef(); + requeryTx(flwRef, txRef, payload.getPBFPubKey()); + } } @@ -123,7 +111,7 @@ public void onError(String message) { @Override public void requeryTx(final String publicKey) { - requeryTx(null, txRef, publicKey); + requeryTx(flwRef, txRef, publicKey); } @Override @@ -138,22 +126,22 @@ public void requeryTx(final String flwRef, final String txRef, final String publ logEvent(new RequeryEvent().getEvent(), publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { - if (response.getData() == null) { + + if (response.getStatus() == null) mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { - if (pollingCancelled) { - mInteractor.showPollingIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); - } else requeryTx(flwRef, txRef, publicKey); - } else if (response.getData().getChargeResponseCode().equals("00")) { + else if (response.getStatus().equalsIgnoreCase("pending")) { + if (!pollingCancelled) { + requeryTx(flwRef, txRef, publicKey); + } else mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); + } else if (response.getStatus().equalsIgnoreCase("successful")) { mInteractor.showPollingIndicator(false); mInteractor.onPaymentSuccessful(flwRef, txRef, responseAsJSONString); } else { mInteractor.showProgressIndicator(false); - mInteractor.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); + mInteractor.onPaymentFailed(response.getStatus(), responseAsJSONString); } } diff --git a/rave_presentation/src/main/res/values/strings.xml b/rave_presentation/src/main/res/values/strings.xml index c32e8958..f11f7450 100644 --- a/rave_presentation/src/main/res/values/strings.xml +++ b/rave_presentation/src/main/res/values/strings.xml @@ -1,6 +1,3 @@ - - Hello blank fragment - diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandlerTest.java index 310f74af..851849a7 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/account/AccountHandlerTest.java @@ -380,7 +380,7 @@ public void requeryTx_onError_onPaymentFailedCalledWithCorrectParams() { paymentHandler.requeryTx(generateRandomString(), generateRandomString()); verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message, responseJsonAsString); //assert diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandlerTest.java index 0b829542..5daaf98b 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ach/AchHandlerTest.java @@ -177,7 +177,7 @@ public void requeryTx_onError_onPaymentFailedCalledWithCorrectParams() { paymentHandler.requeryTx(generateRandomString(), generateRandomString()); verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message, jsonResponse); verify(interactor).onPaymentFailed(jsonResponse); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandlerTest.java index c5f3d800..f029b02c 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/banktransfer/BankTransferHandlerTest.java @@ -204,7 +204,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_00_Calle String responseJson = generateRandomString(); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("00"), responseJson); verify(interactor).showPollingIndicator(false); @@ -225,7 +225,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_01_onPol ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("01"), responseJson); verify(interactor).showPollingIndicator(false); @@ -257,7 +257,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_01_reque ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("01"), responseJson); verify(paymentHandlerMock, times(2)) @@ -280,7 +280,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_01_Polli ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("01"), responseJson); verify(interactor).showPollingIndicator(false); @@ -298,7 +298,7 @@ public void requeryTx_onSuccess_nullResponse_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString(), true, time, time); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); verify(interactor).onPaymentFailed(requeryResponse.getStatus(), jsonResponse); @@ -314,7 +314,7 @@ public void requeryTx_onSuccess_chargeResponseCodeNeither00Nor01_onPaymentFailed paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString(), true, time, time); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("099"), jsonResponse); verify(interactor).showProgressIndicator(false); @@ -330,7 +330,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString(), true, time, time); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryPayWithBankTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryPayWithBankTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(generateRandomString(), generateRandomString()); verify(interactor).onPaymentFailed(anyString(), anyString()); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandlerTest.java index 501bda49..8af1b511 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/card/CardPaymentHandlerTest.java @@ -1,5 +1,6 @@ package com.flutterwave.raveandroid.rave_presentation.card; +import com.flutterwave.raveandroid.rave_java_commons.AddressDetails; import com.flutterwave.raveandroid.rave_java_commons.Meta; import com.flutterwave.raveandroid.rave_java_commons.Payload; import com.flutterwave.raveandroid.rave_java_commons.SubAccount; @@ -7,7 +8,6 @@ import com.flutterwave.raveandroid.rave_presentation.TestNetworkModule; import com.flutterwave.raveandroid.rave_presentation.TestRaveComponent; import com.flutterwave.raveandroid.rave_presentation.TestUtilsModule; -import com.flutterwave.raveandroid.rave_presentation.data.AddressDetails; import com.flutterwave.raveandroid.rave_presentation.data.validators.TransactionStatusChecker; import com.flutterwave.raveandroid.rave_remote.Callbacks; import com.flutterwave.raveandroid.rave_remote.FeeCheckRequestBody; @@ -137,7 +137,7 @@ public void chargeCard_onSuccessWithAVS_VBVSECURECODE_onAVS_VBVSECURECODEModelSu //assert verify(interactor).showProgressIndicator(false); - verify(interactor).collectCardAddressDetails(eq(payload), anyString()); + verify(interactor).collectCardAddressDetails(eq(payload)); } @@ -155,7 +155,7 @@ public void chargeCard_onSuccess_onNOAUTH_INTERNATIONALSuggested_onNoAuthInterna captor.getAllValues().get(0).onSuccess(chargeResponse); verify(interactor).showProgressIndicator(false); - verify(interactor).collectCardAddressDetails(payload, NOAUTH_INTERNATIONAL); + verify(interactor).collectCardAddressDetails(payload); } @@ -379,7 +379,7 @@ public void validateCardCharge_onSuccess_isNotSuccess_onPaymentErrorCalled() { ArgumentCaptor captor = ArgumentCaptor.forClass(ResultCallback.class); - verify(networkRequest).validateCardCharge(any(ValidateChargeBody.class), captor.capture()); + verify(networkRequest).validateCharge(publicKey, any(ValidateChargeBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(chargeResponse); verify(interactor).onPaymentError(message); @@ -403,7 +403,7 @@ public void validateCardCharge_onError_isNotSuccess_onPaymentErrorCalled() { ArgumentCaptor captor = ArgumentCaptor.forClass(ResultCallback.class); - verify(networkRequest).validateCardCharge(any(ValidateChargeBody.class), captor.capture()); + verify(networkRequest).validateCharge(publicKey, any(ValidateChargeBody.class), captor.capture()); captor.getAllValues().get(0).onError(message); verify(interactor).onPaymentError(message); @@ -523,7 +523,7 @@ public void requeryTx_onError_onPaymentFailedCalledWithCorrectParams() { paymentHandler.requeryTx(generateRandomString(), generateRandomString()); verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message, responseAsString); //assert diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandlerTest.java index 5de484d4..9f127ec2 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/francmobilemoney/FrancMobileMoneyHandlerTest.java @@ -155,7 +155,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -175,7 +175,7 @@ public void requeryTx_onSuccessWithChargeResponseCode00_onPaymentSuccessfulCalle paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -196,14 +196,14 @@ public void requeryTx_onSuccessWithChargeResponseCode02_RequeryTxCalled() { paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -213,7 +213,7 @@ public void requeryTx_onSuccessWithChargeResponseCodeNot00or02_onPaymentFailedCa paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -231,7 +231,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandlerTest.java index 1df6ad99..1b91ec0f 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ghmobilemoney/GhMobileMoneyHandlerTest.java @@ -153,7 +153,7 @@ public void requeryTx_onSuccessWithNullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -173,7 +173,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode00_onPaymentSuc paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful("00"); String jsonResponse = generateRandomString(); @@ -194,14 +194,14 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_requeryTxCal paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful("02"); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -211,7 +211,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCodeNot00or02_onPay paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful("03"); String jsonResponse = generateRandomString(); @@ -229,7 +229,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandlerTest.java index 67ea5fab..839eb1dc 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/mpesa/MpesaHandlerTest.java @@ -154,7 +154,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -174,7 +174,7 @@ public void requeryTx_onSuccessWithChargeResponseCode00_onPaymentSuccessfulCalle paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -195,14 +195,14 @@ public void requeryTx_onSuccessWithChargeResponseCode02_onPollingRoundComplete() paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -212,7 +212,7 @@ public void requeryTx_onSuccessWithChargeResponseCodeNot00or02_onPaymentFailedCa paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -230,7 +230,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandlerTest.java index 5d1386c0..0ecffd2d 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/rwfmobilemoney/RwfMobileMoneyHandlerTest.java @@ -154,7 +154,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -174,7 +174,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode00_onPaymentSuc paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -195,14 +195,14 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_onPollingRou paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -212,7 +212,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCodeNot00or02_onPay paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -230,7 +230,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandlerTest.java index 4e3b7e24..ce14a749 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/sabankaccount/SaBankAccountHandlerTest.java @@ -125,7 +125,7 @@ public void chargeSaBankAccount_noDisplayFee_onSuccess_validResponseReturned_sho ArgumentCaptor captor = ArgumentCaptor.forClass(ResultCallback.class); - verify(networkRequest).chargeSaBankAccount(any(ChargeRequestBody.class), captor.capture()); + verify(networkRequest).chargeSaBankAccount(, any(ChargeRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateValidChargeResponse()); // verify(sharedPrefsRequest).saveFlwRef(any(String.class)); @@ -150,7 +150,7 @@ public void chargeSaBankAccount_onSuccess_noRedirectUrlReturned_onPaymentErrorCa verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(ResultCallback.class); - verify(networkRequest).chargeSaBankAccount(any(ChargeRequestBody.class), captor.capture()); + verify(networkRequest).chargeSaBankAccount(, any(ChargeRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateChargeResponseWithNoRedirectUrl()); verify(interactor).showProgressIndicator(false); @@ -175,7 +175,7 @@ public void chargeSaBankAccount_onError_onPaymentErrorCalled_messageReturned() { verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(ResultCallback.class); - verify(networkRequest).chargeSaBankAccount(any(ChargeRequestBody.class), captor.capture()); + verify(networkRequest).chargeSaBankAccount(, any(ChargeRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message); @@ -193,7 +193,7 @@ public void requeryTx_onError_onPaymentFailedCalledWithCorrectParams() { paymentHandler.requeryTx(generateRandomString(), generateRandomString()); verify(interactor).showProgressIndicator(true); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message, jsonResponse); verify(interactor).onPaymentFailed(message, jsonResponse); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandlerTest.java index eb6923cd..4098db64 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ugmobilemoney/UgMobileMoneyHandlerTest.java @@ -154,7 +154,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -174,7 +174,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode00_onPaymentSuc paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -195,14 +195,14 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_onPollingRou paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -212,7 +212,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCodeNot00or02_onPay paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -230,7 +230,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandlerTest.java index b48a3479..157b430a 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/uk/UkHandlerTest.java @@ -221,7 +221,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -244,7 +244,7 @@ public void requeryTx_onSuccessWithChargeResponseCode00_onPaymentSuccessfulCalle paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -268,7 +268,7 @@ public void requeryTx_onSuccessWithChargeResponseCode02_onPollingRoundComplete() paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); @@ -276,7 +276,7 @@ public void requeryTx_onSuccessWithChargeResponseCode02_onPollingRoundComplete() captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); //assert - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -293,7 +293,7 @@ public void requeryTx_onSuccessWithChargeResponseCodeNot00or02_onPaymentFailedCa paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -320,7 +320,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(message, jsonResponse); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandlerTest.java index a43adb2e..e72ac202 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/ussd/UssdHandlerTest.java @@ -199,7 +199,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_00_Calle String responseJson = generateRandomString(); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("00"), responseJson); verify(interactor).showPollingIndicator(false); @@ -220,7 +220,7 @@ public void requeryTx_onSuccess_onRequerySuccessful_onPaymentSuccessful_02_onPol ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("02"), responseJson); verify(interactor).showPollingIndicator(false); @@ -239,14 +239,14 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_requeryTxCal paymentHandler.requeryTx(flwRef, encryptionKey, System.currentTimeMillis(), 300000); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful("02"); String jsonResponse = generateRandomString(); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -259,7 +259,7 @@ public void requeryTx_onSuccess_nullResponse_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), time, 300); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); verify(interactor).onPaymentFailed(requeryResponse.getStatus(), jsonResponse); @@ -275,7 +275,7 @@ public void requeryTx_onSuccess_chargeResponseCodeNeither00Nor02_onPaymentFailed paymentHandler.requeryTx(generateRandomString(), generateRandomString(), time, 300); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onSuccess(generateRequerySuccessful("099"), jsonResponse); verify(interactor).showProgressIndicator(false); @@ -291,7 +291,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), time, 300); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); captor.getAllValues().get(0).onError(generateRandomString(), generateRandomString()); verify(interactor).onPaymentFailed(anyString(), anyString()); diff --git a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandlerTest.java b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandlerTest.java index 765f4e67..155ae330 100644 --- a/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandlerTest.java +++ b/rave_presentation/src/test/java/com/flutterwave/raveandroid/rave_presentation/zmmobilemoney/ZmMobileMoneyHandlerTest.java @@ -170,7 +170,7 @@ public void requeryTx_onSuccess_nullData_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateNullQuery(); String jsonResponse = generateRandomString(); @@ -190,7 +190,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode00_onPaymentSuc paymentHandler.requeryTx(flwRef, txRef, generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_00(); String jsonResponse = generateRandomString(); @@ -211,7 +211,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_onPollingRou paymentHandler.requeryTx(flwRef, txRef, encryptionKey); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRequerySuccessful_02(); String jsonResponse = generateRandomString(); @@ -219,7 +219,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCode02_onPollingRou captor.getAllValues().get(0).onSuccess(requeryResponse, jsonResponse); - verify(networkRequest, times(2)).requeryTx(any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); + verify(networkRequest, times(2)).requeryTx(publicKey, any(RequeryRequestBody.class), any(Callbacks.OnRequeryRequestComplete.class)); } @@ -229,7 +229,7 @@ public void requeryTx_onSuccessWithValidDataAndChargeResponseCodeNot00or02_onPay paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); RequeryResponse requeryResponse = generateRandomRequerySuccessful(); String jsonResponse = generateRandomString(); @@ -247,7 +247,7 @@ public void requeryTx_onError_onPaymentFailedCalled() { paymentHandler.requeryTx(generateRandomString(), generateRandomString(), generateRandomString()); ArgumentCaptor captor = ArgumentCaptor.forClass(Callbacks.OnRequeryRequestComplete.class); - verify(networkRequest).requeryTx(any(RequeryRequestBody.class), captor.capture()); + verify(networkRequest).requeryTx(publicKey, any(RequeryRequestBody.class), captor.capture()); String message = generateRandomString(); String jsonResponse = generateRandomString(); diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/ApiService.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/ApiService.java index 61aef4b6..7bd114bd 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/ApiService.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/ApiService.java @@ -14,7 +14,9 @@ import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; +import retrofit2.http.Header; import retrofit2.http.POST; +import retrofit2.http.Query; import retrofit2.http.Url; /** @@ -23,32 +25,34 @@ public interface ApiService { + @POST("v3/sdkcheckout/charges") +// @POST("/flwv3-pug/getpaidx/api/charge") + Call encryptedCharge(@Query("type") String chargeType, @Header("Authorization") String authorizationHeader, @Body ChargeRequestBody body); + @POST("/flwv3-pug/getpaidx/api/charge") -// Call charge(@Body ChargeRequestBody body); - Call charge(@Body ChargeRequestBody body); + Call chargeV2(@Body ChargeRequestBody body); - @POST("/flwv3-pug/getpaidx/api/charge?use_polling=1") -// Call charge(@Body ChargeRequestBody body); - Call chargeWithPolling(@Body ChargeRequestBody body); + @POST("v3/sdkcheckout/charges") +// @POST("/flwv3-pug/getpaidx/api/charge") + Call charge(@Query("type") String chargeType, @Header("Authorization") String authorizationHeader, @Body Payload body); + + @POST("/v3/sdkcheckout/validate-charge") +// @POST("/flwv3-pug/getpaidx/api/validatecharge") + Call validateCharge(@Header("Authorization") String authorizationHeader, @Body ValidateChargeBody body); @GET() // Call charge(@Body ChargeRequestBody body); Call pollUrl(@Url String url); - @POST("/flwv3-pug/getpaidx/api/validatecharge") - Call validateCardCharge(@Body ValidateChargeBody body); // Call validateCardCharge(@Body ValidateChargeBody body); + // Todo: code optimization, remove unused methods and fields. - @POST("/flwv3-pug/getpaidx/api/validate") - Call validateAccountCharge(@Body ValidateChargeBody body); -// Call validateAccountCharge(@Body ValidateChargeBody body); - - @POST("/flwv3-pug/getpaidx/api/verify/mpesa") - Call requeryTx(@Body RequeryRequestBody body); + @POST("v3/sdkcheckout/mpesa-verify") + Call requeryTx(@Header("Authorization") String authorizationHeader, @Body RequeryRequestBody body); // Call requeryTx(@Body RequeryRequestBody body); - @POST("/flwv3-pug/getpaidx/api/verify/pwbt") - Call requeryPayWithBankTx(@Body RequeryRequestBody body); + @POST("/v3/sdkcheckout/pwbt-verify") + Call requeryPayWithBankTx(@Header("Authorization") String authorizationHeader, @Body RequeryRequestBody body); // Call requeryTx(@Body RequeryRequestBody body); @POST("/flwv3-pug/getpaidx/api/v2/verify") diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/RemoteRepository.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/RemoteRepository.java index d70f808a..3ce12a2f 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/RemoteRepository.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/RemoteRepository.java @@ -38,6 +38,7 @@ import retrofit2.Call; import retrofit2.Retrofit; +import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.CHARGE_TYPE_SA_BANK; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.expired; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.tokenExpired; import static com.flutterwave.raveandroid.rave_java_commons.RaveConstants.tokenNotFound; @@ -65,54 +66,53 @@ public RemoteRepository(@Named("mainRetrofit") Retrofit mainRetrofit, this.executor = executor; } - public void charge(ChargeRequestBody body, final ResultCallback callback) { + public void charge(String publicKey, String chargeType, ChargeRequestBody body, final ResultCallback callback) { executor.execute( - service.charge(body), + service.encryptedCharge(chargeType, "Bearer " + publicKey, body), new TypeToken() { }.getType(), new GenericNetworkCallback(callback) ); } - public void chargeWithPolling(ChargeRequestBody body, final ResultCallback callback) { - - Call call = service.chargeWithPolling(body); - + public void charge(String publicKey, String chargeType, Payload body, final ResultCallback callback) { executor.execute( - call, + service.charge(chargeType, "Bearer " + publicKey, body), new TypeToken() { }.getType(), new GenericNetworkCallback(callback) ); } - public void pollUrl(String url, final ResultCallback callback) { - - Call call = service.pollUrl(url); - + /** + * @deprecated This has been deprecated in favor of the {@link RemoteRepository#charge(String, String, ChargeRequestBody, ResultCallback)} v3 charge}. + * It's only left for use for saved card charge and barter charges which have not yet been migrated to v3. + * Other charge types might not work well with this route. + */ + public void chargeV2(ChargeRequestBody body, final ResultCallback callback) { executor.execute( - call, - new TypeToken() { + service.chargeV2(body), + new TypeToken() { }.getType(), - new GenericNetworkCallback(callback) + new GenericNetworkCallback(callback) ); } - public void chargeMobileMoneyWallet(ChargeRequestBody body, final ResultCallback callback) { + public void pollUrl(String url, final ResultCallback callback) { - Call call = service.charge(body); + Call call = service.pollUrl(url); executor.execute( call, - new TypeToken() { + new TypeToken() { }.getType(), - new GenericNetworkCallback(callback) + new GenericNetworkCallback(callback) ); } - public void chargeSaBankAccount(ChargeRequestBody requestBody, final ResultCallback callback) { - Call call = service.charge(requestBody); + public void chargeSaBankAccount(String publicKey, Payload payload, final ResultCallback callback) { + Call call = service.charge(CHARGE_TYPE_SA_BANK, "Bearer " + publicKey, payload); executor.execute( call, @@ -123,9 +123,9 @@ public void chargeSaBankAccount(ChargeRequestBody requestBody, final ResultCallb } - public void validateCardCharge(ValidateChargeBody body, final ResultCallback callback) { + public void validateCharge(String publicKey, ValidateChargeBody body, final ResultCallback callback) { - Call call = service.validateCardCharge(body); + Call call = service.validateCharge("Bearer " + publicKey, body); executor.execute( call, @@ -136,22 +136,9 @@ public void validateCardCharge(ValidateChargeBody body, final ResultCallback cal } + public void requeryTx(String publicKey, RequeryRequestBody requeryRequestBody, final Callbacks.OnRequeryRequestComplete callback) { - public void validateAccountCharge(ValidateChargeBody body, final ResultCallback callback) { - - Call call = service.validateAccountCharge(body); - - executor.execute( - call, - new TypeToken() { - }.getType(), - new GenericNetworkCallback(callback) - ); - } - - public void requeryTx(RequeryRequestBody requeryRequestBody, final Callbacks.OnRequeryRequestComplete callback) { - - Call call = service.requeryTx(requeryRequestBody); + Call call = service.requeryTx("Bearer " + publicKey, requeryRequestBody); executor.execute( call, @@ -161,9 +148,9 @@ public void requeryTx(RequeryRequestBody requeryRequestBody, final Callbacks.OnR ); } - public void requeryPayWithBankTx(RequeryRequestBody requeryRequestBody, final Callbacks.OnRequeryRequestComplete callback) { + public void requeryPayWithBankTx(String publicKey, RequeryRequestBody requeryRequestBody, final Callbacks.OnRequeryRequestComplete callback) { - Call call = service.requeryPayWithBankTx(requeryRequestBody); + Call call = service.requeryPayWithBankTx("Bearer " + publicKey, requeryRequestBody); executor.execute( call, diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/RequeryRequestBody.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/RequeryRequestBody.java index 5126f55c..21d9ff89 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/RequeryRequestBody.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/RequeryRequestBody.java @@ -6,38 +6,23 @@ public class RequeryRequestBody { + String PBFPubKey; + String flw_ref; private String order_ref; - private String tx_ref; public void setTx_ref(String tx_ref) { this.tx_ref = tx_ref; } - public String getPBFPubKey() { - return PBFPubKey; - } - public void setPBFPubKey(String PBFPubKey) { this.PBFPubKey = PBFPubKey; } - String PBFPubKey; - - public String getFlw_ref() { - return flw_ref; - } - public void setFlw_ref(String flw_ref) { this.flw_ref = flw_ref; } - String flw_ref; - - public String getOrder_ref() { - return order_ref; - } - public void setOrder_ref(String order_ref) { this.order_ref = order_ref; } diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/ValidateChargeBody.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/ValidateChargeBody.java index 6d49418c..7dcca9f7 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/ValidateChargeBody.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/requests/ValidateChargeBody.java @@ -5,42 +5,16 @@ */ public class ValidateChargeBody { - String transaction_reference; - - public String getTransactionreference() { - return transactionreference; - } - - public void setTransactionreference(String transactionreference) { - this.transactionreference = transactionreference; - } - - String transactionreference; - String PBFPubKey; + String flw_ref; String otp; + String type; - public String getTransaction_reference() { - return transaction_reference; - } - - public void setTransaction_reference(String transaction_reference) { - this.transaction_reference = transaction_reference; - } + public ValidateChargeBody(String flw_ref, + String otp, + String type) { - public String getPBFPubKey() { - return PBFPubKey; - } - - public void setPBFPubKey(String PBFPubKey) { - this.PBFPubKey = PBFPubKey; - } - - public String getOtp() { - return otp; - } - - public void setOtp(String otp) { + this.flw_ref = flw_ref; this.otp = otp; + this.type = type; } - } diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java index 689f1abc..3a6e6e4f 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/ChargeResponse.java @@ -1,5 +1,7 @@ package com.flutterwave.raveandroid.rave_remote.responses; +import com.google.gson.annotations.SerializedName; + /** * Created by hamzafetuga on 18/07/2017. */ @@ -9,6 +11,7 @@ public class ChargeResponse { String status; String message; Data data; + ChargeMeta meta; public String getStatus() { return status; @@ -42,39 +45,89 @@ public String getPaymentCode() { return data == null ? null : data.payment_code; } - public String getFlwRef() { - return (data == null) ? null : data.getFlwRef(); + public String getAuthMode() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.mode; } - public String getTxRef() { - return (data == null) ? null : data.getTx_ref(); + public ChargeMeta getChargeMeta() { + return (meta != null) ? meta : data.meta; + } + + public String getAuthUrl() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.redirect; } public String getPingUrl() { return (data == null) ? null : data.ping_url; } - public static class AccountValidateInstructions { - public String getInstruction() { - return instruction; - } + public String getUssdCode() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.note; + } - public void setInstruction(String instruction) { - this.instruction = instruction; - } + public String getTransferNote() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.transfer_note; + } - String instruction; + public String getTransferAmount() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.transfer_amount; + } + public String getTransferBankName() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.transfer_bank; + } + + public String getTransferAccountNumber() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.transfer_account; + } + + public String getValidateInstructions() { + ChargeMeta meta = getChargeMeta(); + return (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.validate_instructions; + } + + public String getFlwRef() { + return (data == null) ? null : data.getFlwRef(); + } + + public String getTxRef() { + return (data == null) ? null : data.getTx_ref(); } public static class Data { + ChargeMeta meta;// For account charge + String ping_url; Data data; String suggested_auth; String chargeResponseCode; String authModelUsed; String flwRef; + String flw_ref; // Pay with bank (extra) response fields String flw_reference; @@ -86,6 +139,25 @@ public static class Data { private String requery_url; private String orderRef; + String txRef; + + String appFee; + String currency; + String charged_amount; + String note; + String amount; + String validateInstruction; + String transaction_reference; + String payment_code; + + String chargeResponseMessage; + String processor_response; + String authurl; + String redirectUrl; + @SerializedName("link") + String captchaLink; + String code; + public void setFlw_reference(String flw_reference) { this.flw_reference = flw_reference; @@ -95,6 +167,10 @@ public String getReference_code() { return payment_code; } + public String getProcessorResponse() { + return processor_response; + } + public void setReference_code(String reference_code) { this.payment_code = reference_code; } @@ -147,13 +223,6 @@ public void setRedirectUrl(String redirectUrl) { this.redirectUrl = redirectUrl; } - - String note; - String amount; - String validateInstruction; - String transaction_reference; - String payment_code; - public Data getData() { return data; } @@ -162,10 +231,6 @@ public void setData(Data data) { this.data = data; } - public String getPayment_code() { - return payment_code; - } - public String getTransaction_reference() { return transaction_reference; } @@ -175,10 +240,6 @@ public void setValidateInstruction(String validateInstruction) { this.validateInstruction = validateInstruction; } - public String getFlw_reference() { - return flw_reference; - } - public String getResponse_code() { return response_code; } @@ -203,12 +264,6 @@ public String getAmount() { return amount; } - public AccountValidateInstructions getValidateInstructions() { - return validateInstructions; - } - - AccountValidateInstructions validateInstructions; - public String getValidateInstruction() { return validateInstruction; } @@ -221,29 +276,19 @@ public void setTx_ref(String txRef) { this.txRef = txRef; } - String txRef; - String chargeResponseMessage; - String authurl; - String appFee; - String currency; - String charged_amount; - public String getRedirectUrl() { return redirectUrl; } - String redirectUrl; - public String getAuthurl() { return authurl; } public String getFlwRef() { - return flwRef == null ? flw_reference : flwRef; - } - public void setValidateInstructions(AccountValidateInstructions validateInstructions) { - this.validateInstructions = validateInstructions; + return flwRef != null ? flwRef : + flw_ref != null ? flw_ref : + flw_reference; } public String getChargeResponseMessage() { @@ -323,24 +368,32 @@ public String getRedirect_url() { return redirect_url; } - public void setRedirect_url(String redirect_url) { - this.redirect_url = redirect_url; - } - public String getRequery_url() { return requery_url; } - public void setRequery_url(String requery_url) { - this.requery_url = requery_url; + public String getCode() { + return code; } + } - public String getOrderRef() { - return orderRef; - } + private class ChargeMeta { + Authorization authorization; + + private class Authorization { + String mode; + String redirect; + String note; + String validate_instructions; + + //Pay with bank transfer + String transfer_reference; + String transfer_account; + String transfer_bank; + String account_expiration; + String transfer_note; + String transfer_amount; - public void setOrderRef(String orderRef) { - this.orderRef = orderRef; } } } diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/RequeryResponse.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/RequeryResponse.java index a22cfe55..b8ec6cdc 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/RequeryResponse.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/RequeryResponse.java @@ -9,22 +9,20 @@ public class RequeryResponse { String status; + Data data; public Data getData() { return data; } - Data data; - - public String getStatus() { - return status; - } - - public void setData(Data data) { this.data = data; } + public String getStatus() { + return data == null ? null : data.status; + } + public void setStatus(String status) { this.status = status; } @@ -32,6 +30,9 @@ public void setStatus(String status) { public static class Data { Data data; + String chargeResponseCode; + CardDets card; + String status; public Data getData() { return data; @@ -41,18 +42,18 @@ public void setData(Data data) { this.data = data; } - String chargeResponseCode; + public String getChargeResponseCode() { + return chargeResponseCode; + } - public String getChargeResponseCode() { return chargeResponseCode; } + public void setChargeResponseCode(String chargeResponseCode) { + this.chargeResponseCode = chargeResponseCode; + } public CardDets getCard() { return card; } - CardDets card; - - String status; - public String getStatus() { return status; } @@ -60,10 +61,6 @@ public String getStatus() { public void setStatus(String status) { this.status = status; } - - public void setChargeResponseCode(String chargeResponseCode) { - this.chargeResponseCode = chargeResponseCode; - } } public static class Card_tokens diff --git a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/SaBankAccountResponse.java b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/SaBankAccountResponse.java index ff88b56d..9a7369b5 100644 --- a/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/SaBankAccountResponse.java +++ b/rave_remote/src/main/java/com/flutterwave/raveandroid/rave_remote/responses/SaBankAccountResponse.java @@ -6,6 +6,7 @@ public class SaBankAccountResponse { private String status; private String message; private Data data; + ChargeMeta meta; public String getStatus() { return status; @@ -125,14 +126,35 @@ public void setTypeData(String typeData) { } } + public ChargeMeta getChargeMeta() { + return (meta != null) ? meta : data.meta; + } + + public String getAuthUrl() { + ChargeMeta meta = getChargeMeta(); + return (data == null) ? null + : (data.authUrl != null) ? data.authUrl + : (meta == null) ? null + : (meta.authorization == null) ? null + : meta.authorization.redirect; + } - public static class Data{ + public static class Data { + ChargeMeta meta; + @SerializedName("auth_url") + String authUrl; + @SerializedName("flw_ref") + String flwRef; private Data_ data; @SerializedName("response_code") private String responseCode; @SerializedName("response_message") private String responseMessage; + public String getFlwRef() { + return flwRef; + } + public Data_ getData() { return data; } @@ -158,6 +180,25 @@ public void setResponseMessage(String responseMessage) { } } + private class ChargeMeta { + Authorization authorization; + + private class Authorization { + String mode; + String redirect; + String note; + String validate_instructions; + + //Pay with bank transfer + String transfer_reference; + String transfer_account; + String transfer_bank; + String account_expiration; + String transfer_note; + String transfer_amount; + + } + } } diff --git a/rave_utils/src/main/java/com/flutterwave/raveutils/verification/web/WebPresenter.java b/rave_utils/src/main/java/com/flutterwave/raveutils/verification/web/WebPresenter.java index 464dbe1b..f76f15bc 100644 --- a/rave_utils/src/main/java/com/flutterwave/raveutils/verification/web/WebPresenter.java +++ b/rave_utils/src/main/java/com/flutterwave/raveutils/verification/web/WebPresenter.java @@ -30,14 +30,14 @@ public void requeryTx(final String flwRef, final String publicKey) { body.setOrder_ref(flwRef); // Uses Order ref instead of flwref body.setPBFPubKey(publicKey); - networkRequest.requeryTx(body, new Callbacks.OnRequeryRequestComplete() { + networkRequest.requeryTx(publicKey, body, new Callbacks.OnRequeryRequestComplete() { @Override public void onSuccess(RequeryResponse response, String responseAsJSONString) { if (response.getData() == null) { mView.onPaymentFailed(response.getStatus(), responseAsJSONString); - } else if (response.getData().getChargeResponseCode().equals("02")) { + } else if ("02".equals(response.getData().getChargeResponseCode()) || "pending".equalsIgnoreCase(response.getData().getStatus())) { mView.onPollingRoundComplete(flwRef, publicKey); - } else if (response.getData().getChargeResponseCode().equals("00")) { + } else if ("00".equals(response.getData().getChargeResponseCode()) || "successful".equalsIgnoreCase(response.getData().getStatus())) { mView.onPaymentSuccessful(responseAsJSONString); } else { mView.onPaymentFailed(response.getData().getStatus(), responseAsJSONString); diff --git a/rave_utils/src/main/res/values/strings.xml b/rave_utils/src/main/res/values/strings.xml index a41b4eef..b8046dec 100644 --- a/rave_utils/src/main/res/values/strings.xml +++ b/rave_utils/src/main/res/values/strings.xml @@ -151,7 +151,7 @@ I have completed this payment → 4327122 04-00-53 - Barter Funnding + Barter Funding Reference Code 4990 @@ -188,9 +188,4 @@ MTN - - Hello blank fragment - Please select a card - Barter Funding -