Skip to content

Commit f55309b

Browse files
initial commit
0 parents  commit f55309b

File tree

106 files changed

+6833
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+6833
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.3"
6+
defaultConfig {
7+
applicationId "com.flutterwave.rave_android"
8+
minSdkVersion 15
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.3.1'
28+
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
29+
testCompile 'junit:junit:4.12'
30+
compile project(':raveandroid')
31+
}

app/proguard-rules.pro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/hamzafetuga/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.flutterwave.rave_android;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.flutterwave.rave_android", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.flutterwave.rave_android">
4+
5+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
6+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
7+
<uses-permission android:name="android.permission.INTERNET" />
8+
9+
<application xmlns:tools="http://schemas.android.com/tools"
10+
tools:replace="android:theme"
11+
android:allowBackup="true"
12+
android:icon="@mipmap/ic_launcher"
13+
android:label="@string/app_name"
14+
android:roundIcon="@mipmap/ic_launcher_round"
15+
android:supportsRtl="true"
16+
android:theme="@style/AppTheme.NoActionBar">
17+
<activity android:name=".MainActivity">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
package com.flutterwave.rave_android;
2+
3+
import android.content.Intent;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.os.Bundle;
6+
import android.support.v7.widget.SwitchCompat;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.EditText;
10+
import android.widget.Toast;
11+
import com.flutterwave.raveandroid.RaveConstants;
12+
import com.flutterwave.raveandroid.RavePayActivity;
13+
import com.flutterwave.raveandroid.RavePayManager;
14+
import com.flutterwave.raveandroid.Utils;
15+
16+
17+
public class MainActivity extends AppCompatActivity {
18+
19+
EditText emailEt;
20+
EditText amountEt;
21+
EditText publicKeyEt;
22+
EditText secretKeyEt;
23+
EditText txRefEt;
24+
EditText narrationEt;
25+
EditText currencyEt;
26+
EditText countryEt;
27+
EditText fNameEt;
28+
EditText lNameEt;
29+
Button startPayBtn;
30+
SwitchCompat cardSwitch;
31+
SwitchCompat accountSwitch;
32+
SwitchCompat isLiveSwitch;
33+
34+
@Override
35+
protected void onCreate(Bundle savedInstanceState) {
36+
super.onCreate(savedInstanceState);
37+
setContentView(R.layout.activity_main);
38+
39+
emailEt = (EditText) findViewById(R.id.emailEt);
40+
amountEt = (EditText) findViewById(R.id.amountEt);
41+
publicKeyEt = (EditText) findViewById(R.id.publicKeyEt);
42+
secretKeyEt = (EditText) findViewById(R.id.secretKeyEt);
43+
txRefEt = (EditText) findViewById(R.id.txRefEt);
44+
narrationEt = (EditText) findViewById(R.id.narrationTV);
45+
currencyEt = (EditText) findViewById(R.id.currencyEt);
46+
countryEt = (EditText) findViewById(R.id.countryEt);
47+
fNameEt = (EditText) findViewById(R.id.fNameEt);
48+
lNameEt = (EditText) findViewById(R.id.lnameEt);
49+
startPayBtn = (Button) findViewById(R.id.startPaymentBtn);
50+
cardSwitch = (SwitchCompat) findViewById(R.id.cardPaymentSwitch);
51+
accountSwitch = (SwitchCompat) findViewById(R.id.accountPaymentSwitch);
52+
isLiveSwitch = (SwitchCompat) findViewById(R.id.isLiveSwitch);
53+
54+
publicKeyEt.setText(RaveConstants.PUBLIC_KEY);
55+
secretKeyEt.setText(RaveConstants.PRIVATE_KEY);
56+
57+
startPayBtn.setOnClickListener(new View.OnClickListener() {
58+
@Override
59+
public void onClick(View v) {
60+
validateEntries();
61+
}
62+
});
63+
64+
65+
}
66+
67+
private void validateEntries() {
68+
clearErrors();
69+
String email = emailEt.getText().toString();
70+
String amount = amountEt.getText().toString();
71+
String publicKey = publicKeyEt.getText().toString();
72+
String secretKey = secretKeyEt.getText().toString();
73+
String txRef = txRefEt.getText().toString();
74+
String narration = narrationEt.getText().toString();
75+
String currency = currencyEt.getText().toString();
76+
String country = countryEt.getText().toString();
77+
String fName = fNameEt.getText().toString();
78+
String lName = lNameEt.getText().toString();
79+
80+
boolean valid = true;
81+
82+
if (amount.length() == 0) {
83+
amount = "0";
84+
}
85+
86+
//check for complusory fields
87+
if (!Utils.isEmailValid(email)) {
88+
valid = false;
89+
emailEt.setError("A valid email is required");
90+
}
91+
92+
if (publicKey.length() < 1){
93+
valid = false;
94+
publicKeyEt.setError("A valid public key is required");
95+
}
96+
97+
if (secretKey.length() < 1){
98+
valid = false;
99+
secretKeyEt.setError("A valid secret key is required");
100+
}
101+
102+
if (txRef.length() < 1){
103+
valid = false;
104+
txRefEt.setError("A valid txRef key is required");
105+
}
106+
107+
if (currency.length() < 1){
108+
valid = false;
109+
currencyEt.setError("A valid currency code is required");
110+
}
111+
112+
if (country.length() < 1){
113+
valid = false;
114+
countryEt.setError("A valid country code is required");
115+
}
116+
117+
if (valid) {
118+
new RavePayManager(this).setAmount(Double.parseDouble(amount))
119+
.setCountry(country)
120+
.setCurrency(currency)
121+
.setEmail(email)
122+
.setfName(fName)
123+
.setlName(lName)
124+
.setNarration(narration)
125+
.setPublicKey(publicKey)
126+
.setSecretKey(secretKey)
127+
.setTxRef(txRef)
128+
.acceptAccountPayments(accountSwitch.isChecked())
129+
.acceptCardPayments(cardSwitch.isChecked())
130+
.onStagingEnv(!isLiveSwitch.isChecked())
131+
// .withTheme(R.style.TestNewTheme)
132+
.initialize();
133+
134+
}
135+
}
136+
137+
@Override
138+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
139+
140+
if (requestCode == RaveConstants.RAVE_REQUEST_CODE && data != null) {
141+
142+
String message = data.getStringExtra("response");
143+
144+
if (resultCode == RavePayActivity.RESULT_SUCCESS) {
145+
Toast.makeText(this, "SUCCESS " + message, Toast.LENGTH_SHORT).show();
146+
}
147+
else if (resultCode == RavePayActivity.RESULT_ERROR) {
148+
Toast.makeText(this, "ERROR " + message, Toast.LENGTH_SHORT).show();
149+
}
150+
else if (resultCode == RavePayActivity.RESULT_CANCELLED) {
151+
Toast.makeText(this, "CANCELLED " + message, Toast.LENGTH_SHORT).show();
152+
}
153+
}
154+
else {
155+
super.onActivityResult(requestCode, resultCode, data);
156+
}
157+
}
158+
159+
private void clearErrors() {
160+
emailEt.setError(null);
161+
amountEt.setError(null);
162+
publicKeyEt.setError(null);
163+
secretKeyEt.setError(null);
164+
txRefEt.setError(null);
165+
narrationEt.setError(null);
166+
currencyEt.setError(null);
167+
countryEt.setError(null);
168+
fNameEt.setError(null);
169+
lNameEt.setError(null);
170+
}
171+
172+
}

0 commit comments

Comments
 (0)