Skip to content

Commit 7706588

Browse files
committed
integrate ach payments
1 parent c52e521 commit 7706588

File tree

14 files changed

+630
-5
lines changed

14 files changed

+630
-5
lines changed

app/src/main/java/com/flutterwave/rave_android/MainActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class MainActivity extends AppCompatActivity {
4646
SwitchCompat ghMobileMoneySwitch;
4747
SwitchCompat isLiveSwitch;
4848
SwitchCompat isMpesaSwitch;
49+
SwitchCompat accountAchSwitch;
4950
SwitchCompat addSubAccountsSwitch;
5051
SwitchCompat isPreAuthSwitch;
5152
List<Meta> meta = new ArrayList<>();
@@ -71,6 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
7172
startPayBtn = findViewById(R.id.startPaymentBtn);
7273
cardSwitch = findViewById(R.id.cardPaymentSwitch);
7374
accountSwitch = findViewById(R.id.accountPaymentSwitch);
75+
accountAchSwitch = findViewById(R.id.accountAchSwitch);
7476
isMpesaSwitch = findViewById(R.id.accountMpesaSwitch);
7577
isPreAuthSwitch = findViewById(R.id.isPreAuthSwitch);
7678
ghMobileMoneySwitch = findViewById(R.id.accountGHMobileMoneySwitch);
@@ -192,6 +194,7 @@ private void validateEntries() {
192194
.acceptMpesaPayments(isMpesaSwitch.isChecked())
193195
.acceptAccountPayments(accountSwitch.isChecked())
194196
.acceptCardPayments(cardSwitch.isChecked())
197+
.acceptAchPayments(accountAchSwitch.isChecked())
195198
.acceptGHMobileMoneyPayments(ghMobileMoneySwitch.isChecked())
196199
.onStagingEnv(!isLiveSwitch.isChecked())
197200
.setSubAccounts(subAccounts)

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
android:id="@+id/accountMpesaSwitch"
4949
/>
5050

51+
<android.support.v7.widget.SwitchCompat
52+
android:layout_width="match_parent"
53+
android:layout_height="wrap_content"
54+
android:layout_marginBottom="10dp"
55+
android:text="Accept ACH payments"
56+
android:checked="false"
57+
android:id="@+id/accountAchSwitch"
58+
/>
59+
5160
<android.support.v7.widget.SwitchCompat
5261
android:layout_width="match_parent"
5362
android:layout_height="wrap_content"

raveandroid/src/main/java/com/flutterwave/raveandroid/Payload.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public String getCardBIN() {
1818

1919
private String cardBIN;
2020

21+
private boolean is_us_bank_charge;
22+
2123
private String remember_device_mobile_key;
2224

2325
private String remember_device_email;
@@ -224,7 +226,7 @@ public Payload(String phonenumber,
224226

225227
public Payload(List<Meta> meta, List<SubAccount> subaccounts, String narration, String IP, String accountnumber, String accountbank,
226228
String lastname, String firstname, String currency, String country, String amount,
227-
String email, String device_fingerprint, String txRef, String PBFPubKey,String bvn) {
229+
String email, String device_fingerprint, String txRef, String PBFPubKey, String bvn, boolean is_us_bank_charge) {
228230
this.meta = meta;
229231
this.subaccounts = subaccounts;
230232
this.narration = narration;
@@ -241,6 +243,7 @@ public Payload(List<Meta> meta, List<SubAccount> subaccounts, String narration,
241243
this.txRef = txRef;
242244
this.PBFPubKey = PBFPubKey;
243245
this.bvn = bvn;
246+
this.is_us_bank_charge = is_us_bank_charge;
244247

245248
if (meta == null) {
246249
meta = new ArrayList<>();
@@ -591,5 +594,13 @@ public void setVoucher(String voucher) {
591594
public void setIs_mobile_money_gh(String is_mobile_money_gh) {
592595
this.is_mobile_money_gh = is_mobile_money_gh;
593596
}
597+
598+
public boolean isIs_us_bank_charge() {
599+
return is_us_bank_charge;
600+
}
601+
602+
public void setIs_us_bank_charge(boolean is_us_bank_charge) {
603+
this.is_us_bank_charge = is_us_bank_charge;
604+
}
594605
}
595606

raveandroid/src/main/java/com/flutterwave/raveandroid/PayloadBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class PayloadBuilder {
2323
private String bvn;
2424
private String voucher;
2525
private boolean isPreAuth = false;
26+
private boolean is_us_bank_charge = false;
2627

2728
public PayloadBuilder setIs_mobile_money_gh(String is_mobile_money_gh) {
2829
this.is_mobile_money_gh = is_mobile_money_gh;
@@ -103,6 +104,11 @@ public PayloadBuilder setIsPreAuth(boolean isPreAuth){
103104
return this;
104105
}
105106

107+
public PayloadBuilder setIsUsBankCharge(boolean is_us_bank_charge){
108+
this.is_us_bank_charge = is_us_bank_charge;
109+
return this;
110+
}
111+
106112
public PayloadBuilder setCurrency(String currency) {
107113
this.currency = currency;
108114
return this;
@@ -184,7 +190,7 @@ public Payload createBankPayload() {
184190
List<Meta> metaObj = Utils.pojofyMetaString(meta);
185191
List<SubAccount> subaccountsObj = Utils.pojofySubaccountString(subAccounts);
186192
Payload payload = new Payload(metaObj, subaccountsObj,narration, ip, accountnumber, accountbank, lastname,
187-
firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey,bvn);
193+
firstname, currency, country, amount, email, device_fingerprint, txRef, pbfPubKey,bvn, is_us_bank_charge);
188194
payload.setPayment_type("account");
189195

190196
return payload;

raveandroid/src/main/java/com/flutterwave/raveandroid/RavePayActivity.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.widget.RelativeLayout;
2121

2222
import com.flutterwave.raveandroid.account.AccountFragment;
23+
import com.flutterwave.raveandroid.ach.AchFragment;
2324
import com.flutterwave.raveandroid.card.CardFragment;
2425
import com.flutterwave.raveandroid.ghmobilemoney.GhMobileMoneyFragment;
2526
import com.flutterwave.raveandroid.mpesa.MpesaFragment;
@@ -96,7 +97,12 @@ protected void onCreate(Bundle savedInstanceState) {
9697
}
9798

9899
if (ravePayInitializer.isWithAccount()) {
99-
raveFragments.add(new RaveFragment(new AccountFragment(), "Account"));
100+
if (ravePayInitializer.getCountry().equalsIgnoreCase("us") && ravePayInitializer.getCurrency().equalsIgnoreCase("usd")) {
101+
raveFragments.add(new RaveFragment(new AchFragment(), "ACH"));
102+
}
103+
else if (ravePayInitializer.getCountry().equalsIgnoreCase("ng") && ravePayInitializer.getCurrency().equalsIgnoreCase("ngn")){
104+
raveFragments.add(new RaveFragment(new AccountFragment(), "Account"));
105+
}
100106
}
101107

102108
if (ravePayInitializer.isWithMpesa()) {

raveandroid/src/main/java/com/flutterwave/raveandroid/RavePayInitializer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class RavePayInitializer {
2323
String meta;
2424
String subAccounts;
2525
String payment_plan;
26+
boolean withAch = false;
2627
boolean withMpesa = false;
2728
boolean withCard = true;
2829
boolean withAccount = true;
@@ -35,7 +36,7 @@ public RavePayInitializer(String email, double amount, String publicKey,
3536
String encryptionKey, String txRef, String narration,
3637
String currency, String country, String fName,
3738
String lName, boolean withCard,
38-
boolean withAccount, boolean withMpesa, boolean withGHMobileMoney, int theme,
39+
boolean withAccount, boolean withMpesa, boolean withGHMobileMoney, boolean withAch, int theme,
3940
boolean staging, String meta, String subAccounts, String payment_plan, boolean isPreAuth) {
4041
this.email = email;
4142
this.amount = amount;
@@ -51,6 +52,7 @@ public RavePayInitializer(String email, double amount, String publicKey,
5152
this.withGHMobileMoney = withGHMobileMoney;
5253
this.withMpesa = withMpesa;
5354
this.withCard = withCard;
55+
this.withAch = withAch;
5456
this.theme = theme;
5557
this.staging = staging;
5658
this.meta = meta;
@@ -118,6 +120,12 @@ public boolean isWithCard() {
118120
return withCard;
119121
}
120122

123+
public boolean isWithAch() { return withAch; }
124+
125+
public void setWithAch(boolean withAch) {
126+
this.withAch = withAch;
127+
}
128+
121129
public void setWithCard(boolean withCard) {
122130
this.withCard = withCard;
123131
}

raveandroid/src/main/java/com/flutterwave/raveandroid/RavePayManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class RavePayManager {
3131
private Activity activity;
3232
boolean withCard = true;
3333
boolean withAccount = true;
34+
boolean withAch = false;
3435
boolean withMpesa = false;
3536
boolean withGHMobileMoney = false;
3637
private int theme = R.style.DefaultTheme;
@@ -57,6 +58,11 @@ public RavePayManager(Activity activity) {
5758
this.activity = activity;
5859
}
5960

61+
public RavePayManager acceptAchPayments(boolean withAch) {
62+
this.withAch = withAch;
63+
return this;
64+
}
65+
6066
public RavePayManager acceptCardPayments(boolean withCard) {
6167
this.withCard = withCard;
6268
return this;
@@ -163,6 +169,6 @@ public void initialize() {
163169
}
164170

165171
public RavePayInitializer createRavePayInitializer() {
166-
return new RavePayInitializer(email, amount, publicKey, encryptionKey, txRef, narration, currency, country, fName, lName, withCard, withAccount, withMpesa, withGHMobileMoney, theme, staging, meta, subAccounts, payment_plan, isPreAuth);
172+
return new RavePayInitializer(email, amount, publicKey, encryptionKey, txRef, narration, currency, country, fName, lName, withCard, withAccount, withMpesa, withGHMobileMoney, withAch, theme, staging, meta, subAccounts, payment_plan, isPreAuth);
167173
}
168174
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.flutterwave.raveandroid.ach;
2+
3+
import com.flutterwave.raveandroid.Payload;
4+
import com.flutterwave.raveandroid.RavePayInitializer;
5+
import com.flutterwave.raveandroid.responses.RequeryResponse;
6+
7+
public interface AchContract {
8+
9+
interface View {
10+
void showProgressIndicator(boolean active);
11+
12+
void showAmountField(boolean active);
13+
14+
void showRedirectMessage(boolean b);
15+
16+
void onPaymentError(String message);
17+
18+
void showWebView(String authUrl, String flwRef);
19+
20+
void onRequerySuccessful(RequeryResponse response, String responseAsJSONString, String flwRef);
21+
22+
void onPaymentFailed(String message, String responseAsJSONString);
23+
24+
void onPaymentSuccessful(String status, String flwRef, String responseAsJSONString);
25+
26+
void showAmountError(String msg);
27+
28+
void showFee(String authUrl, String flwRef, String chargedAmount, String currency);
29+
}
30+
31+
interface UserActionsListener {
32+
void onStartAchPayment(RavePayInitializer ravePayInitializer);
33+
34+
void onPayButtonClicked(RavePayInitializer ravePayInitializer, String amount);
35+
36+
void chargeAccount(Payload payload, String encryptionKey);
37+
38+
void verifyRequeryResponse(RequeryResponse response, String responseAsJSONString, RavePayInitializer ravePayInitializer, String flwRef);
39+
40+
void onFeeConfirmed(String authUrl, String flwRef);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)