Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
liciolentimo committed Aug 6, 2019
0 parents commit fed0d30
Show file tree
Hide file tree
Showing 45 changed files with 1,216 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
60 changes: 60 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.mpesaandroid"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

buildTypes.each {

// CONSUMER_KEY & CONSUMER_SECRET Build Variables are referenced from gradle.properties file
it.buildConfigField 'String', 'CONSUMER_KEY', DARAJA_CONSUMER_KEY
it.buildConfigField 'String', 'CONSUMER_SECRET', DARAJA_CONSUMER_SECRET
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.jakewharton.timber:timber:4.7.1'

implementation 'com.github.jumadeveloper:networkmanager:0.0.2'

implementation 'cn.pedant.sweetalert:library:1.3'

implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'

implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okio:okio:2.1.0'

}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.mpesaandroid;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.example.mpesaandroid", appContext.getPackageName());
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.mpesaandroid">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:icon,android:theme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
88 changes: 88 additions & 0 deletions app/src/main/java/com/example/mpesaandroid/ApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.example.mpesaandroid;

import com.example.mpesaandroid.interceptor.AccessTokenInterceptor;
import com.example.mpesaandroid.interceptor.AuthInterceptor;
import com.example.mpesaandroid.services.STKPushService;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.mpesaandroid.AppConstants.BASE_URL;
import static com.example.mpesaandroid.AppConstants.CONNECT_TIMEOUT;
import static com.example.mpesaandroid.AppConstants.READ_TIMEOUT;
import static com.example.mpesaandroid.AppConstants.WRITE_TIMEOUT;

public class ApiClient {
private Retrofit retrofit;
private boolean isDebug;
private boolean isGetAccessToken;
private String mAuthToken;
private HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();

public ApiClient setIsDebug(boolean isDebug) {
this.isDebug = isDebug;
return this;
}

//Set authentication token
public ApiClient setAuthToken(String authToken) {
mAuthToken = authToken;
return this;
}

// Determine of token endpoint has been called only from the accessToken.
public ApiClient setGetAccessToken(boolean getAccessToken) {
isGetAccessToken = getAccessToken;
return this;
}


//OKHttp Configuration
private OkHttpClient.Builder okHttpClient() {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
okHttpClient
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor);

return okHttpClient;
}


private Retrofit getRestAdapter() {

Retrofit.Builder builder = new Retrofit.Builder();
builder.baseUrl(BASE_URL);
builder.addConverterFactory(GsonConverterFactory.create());

if (isDebug) {
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
}

OkHttpClient.Builder okhttpBuilder = okHttpClient();

if (isGetAccessToken) {
okhttpBuilder.addInterceptor(new AccessTokenInterceptor());
}

if (mAuthToken != null && !mAuthToken.isEmpty()) {
okhttpBuilder.addInterceptor(new AuthInterceptor(mAuthToken));
}

builder.client(okhttpBuilder.build());

retrofit = builder.build();

return retrofit;
}

// Create an instance of STKPushService
public STKPushService mpesaService() {
return getRestAdapter().create(STKPushService.class);
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/example/mpesaandroid/AppConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.mpesaandroid;

public class AppConstants {
public static final int CONNECT_TIMEOUT = 60 * 1000;

public static final int READ_TIMEOUT = 60 * 1000;

public static final int WRITE_TIMEOUT = 60 * 1000;

public static final String BASE_URL = "https://sandbox.safaricom.co.ke/";

//STKPush Properties
public static final String BUSINESS_SHORT_CODE = "174379";
public static final String PASSKEY = "bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919";
public static final String TRANSACTION_TYPE = "CustomerPayBillOnline";
public static final String PARTYB = "174379"; // This is usually the same as the shortcode provided above.
public static final String CALLBACKURL = "http://mpesa-requestbin.herokuapp.com/1fw79g11";

}
Loading

0 comments on commit fed0d30

Please sign in to comment.