Skip to content

Commit

Permalink
initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sodiqOladeni committed Mar 20, 2024
1 parent 909e46c commit 71a4253
Show file tree
Hide file tree
Showing 65 changed files with 2,770 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.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
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/misc.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
86 changes: 86 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id("kotlin-kapt")
id("kotlin-parcelize")
alias(libs.plugins.kotlin.serialization)
}

android {
namespace = "com.mangopay.checkout.example"
compileSdk = 34

defaultConfig {
applicationId = "com.mangopay.checkout.example"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
dataBinding = true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.android.material)

implementation(libs.android.lottie)
implementation(libs.bundles.ktor)
implementation(libs.ktor.client.android)
implementation(libs.bundles.play.services.pay.and.wallet)
implementation(libs.insert.koin.android)
implementation(libs.coroutines.android)

implementation(libs.mangopay.android.checkout)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
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,24 @@
package com.mangopay.checkout.example

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

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

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.mangopay.checkout.example", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".MainApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Checkout"
tools:targetApi="31">

<activity
android:name=".shopping.ShoppingMarketActivity"
android:exported="true"
android:label="@string/shufitness_store"
android:theme="@style/Theme.ShuFitness">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
19 changes: 19 additions & 0 deletions app/src/main/java/com/mangopay/checkout/example/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mangopay.checkout.example

import android.app.Application
import com.mangopay.checkout.example.di.demoAppModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin

class MainApplication: Application() {

override fun onCreate() {
super.onCreate()
startKoin {
androidLogger()
androidContext(this@MainApplication)
modules(demoAppModule)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mangopay.checkout.example.client

import android.util.Log
import io.ktor.client.plugins.logging.Logger

class CustomHttpLogger : Logger {
override fun log(message: String) {
Log.d("HTTP_MESSAGE", message)
}
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/mangopay/checkout/example/client/KtorAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mangopay.checkout.example.client

import com.mangopay.android.core.model.request.CreateCardRegRestRequest
import com.mangopay.android.core.model.request.CreatePayInRestRequest
import com.mangopay.android.core.model.response.CardRegistrationResponse
import com.mangopay.checkout.example.model.response.OAuthResponse
import com.mangopay.checkout.example.model.response.PayInPaymentResponse
import com.mangopay.checkout.example.model.request.PaypalPaymentRequest
import com.mangopay.checkout.example.model.response.PaypalPaymentResponse
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.bearerAuth
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.request.url

class KtorAPI(private val client: HttpClient) {
suspend fun createPaypal(passphrase: String, clientId: String, request: PaypalPaymentRequest): PaypalPaymentResponse {
val bearerToken = createOAuthToken(passphrase = passphrase, clientId = clientId)
val response = client.post {
url("https://api.sandbox.mangopay.com/V2.01/$clientId/payins/payment-methods/paypal")
setBody(request)
bearerAuth(bearerToken.accessToken)
}
return response.body()
}
suspend fun createPayin(passphrase: String, clientId: String, request: CreatePayInRestRequest): PayInPaymentResponse {
val bearerToken = createOAuthToken(passphrase = passphrase, clientId = clientId)
val response = client.post {
url("https://api.sandbox.mangopay.com/V2.01/$clientId/payins/card/direct")
setBody(request)
bearerAuth(bearerToken.accessToken)
}
return response.body()
}
suspend fun createCardRegistrations(passphrase: String, clientId: String, request: CreateCardRegRestRequest): CardRegistrationResponse {
val bearerToken = createOAuthToken(passphrase = passphrase, clientId = clientId)
val response = client.post {
url("https://api.sandbox.mangopay.com/V2.01/$clientId/cardregistrations")
setBody(request)
bearerAuth(bearerToken.accessToken)
}
return response.body()
}
private suspend fun createOAuthToken(passphrase: String, clientId: String): OAuthResponse {
return client.post {
url("https://api.sandbox.mangopay.com/V2.01/oauth/token")
basicAuth(username = clientId, password = passphrase)
}.body()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.mangopay.checkout.example.client

import com.mangopay.android.core.exception.MangopayApiException
import com.mangopay.android.core.model.response.MangoErrorResponse
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.android.Android
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.plugins.DefaultRequest
import io.ktor.client.plugins.HttpResponseValidator
import io.ktor.client.plugins.HttpTimeout
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.serialization.kotlinx.json.json
import io.ktor.util.network.UnresolvedAddressException
import kotlinx.serialization.json.Json

object RestApiClient {

fun get(): HttpClient {
return HttpClient(Android) {
expectSuccess = true
install(Logging) {
logger = CustomHttpLogger()
level = LogLevel.ALL
}

install(DefaultRequest) {
headers.append("Content-Type", "application/json")
}

install(HttpTimeout) {
requestTimeoutMillis = 100000
}
HttpResponseValidator {
handleResponseExceptionWithRequest { exception, _ ->
when (exception) {
is UnresolvedAddressException -> throw MangopayApiException("Error connecting to the internet")
is ClientRequestException -> {
val exceptionResponse = exception.response
val errorResponse: MangoErrorResponse? = exceptionResponse.body()
throw MangopayApiException(
errorResponse?.message ?: "Invalid API response"
)
}
else -> {
throw MangopayApiException(exception.message.orEmpty(), exception)
}
}

}
}
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/mangopay/checkout/example/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mangopay.checkout.example.di

import com.mangopay.checkout.example.client.KtorAPI
import com.mangopay.checkout.example.client.RestApiClient
import org.koin.dsl.module

val demoAppModule = module {
single { RestApiClient.get() }
single { KtorAPI(get()) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mangopay.checkout.example.model

import android.os.Parcelable
import com.mangopay.checkout.example.R
import kotlinx.parcelize.Parcelize

@Parcelize
data class DemoProductObject(
val id: Int,
val productName: String,
val productPrice: Int,
val productImage: Int
) : Parcelable {

companion object {
private val shoes = listOf(R.drawable.shoe1, R.drawable.shoe2)
fun getFakeProducts() = List(7) {
val initIndex = it+1
DemoProductObject(it, "SneakShu ${initIndex}00", 10 * initIndex, shoes.random())
}
}
}

Loading

0 comments on commit 71a4253

Please sign in to comment.