Skip to content

Commit

Permalink
Merge pull request #20 from TrustlyInc/DEV-233807-choose_webview_inap…
Browse files Browse the repository at this point in the history
…pbrowser

[DEV-233807] Choose between webview and inappbrowser
  • Loading branch information
andresguedes authored Dec 18, 2024
2 parents 2f49aff + 596a20f commit 958ca6d
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 172 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Java Version](https://badgen.net/badge/java/8/orange?icon=java)](https://www.oracle.com/java/technologies/javase/jdk8-naming.html)
[![Platform](https://badgen.net/badge/Android/34/green?icon=java)](https://developer.android.com/about/versions/14)
[![Gradle Plugin](https://badgen.net/badge/gradle/v8.0/green?icon=groovy)](https://gradle.org/whats-new/gradle-8)
[![Maven Central Version](https://badgen.net/badge/maven/v1.0.0/yellow?icon=java)](https://central.sonatype.com/artifact/net.trustly/android-sdk/3.2.2)
[![Maven Central Version](https://badgen.net/badge/maven/v1.0.0/yellow?icon=java)](https://central.sonatype.com/artifact/net.trustly/android-sdk/3.3.0)

# Trustly Android SDK

Expand All @@ -29,7 +29,7 @@ it, include the dependency below in your `build.gradle` file.

```
dependencies {
implementation 'net.trustly:trustly-android-sdk:3.2.2'
implementation 'net.trustly:trustly-android-sdk:3.3.0'
}
```

Expand All @@ -42,6 +42,7 @@ ___

| VERSION | DESCRIPTION | BRANCH |
| :-------: | :----------- | :----------- |
3.3.0 | Open WebView or Chrome Custom Tabs by remote configuration | *main*
3.2.2 | Update custom environment host mount | *main*
3.2.1 | Removing allow backup flag from Application | *main*
3.2.0 | Support for Android API 19 | *main*
Expand Down
Binary file modified trustly-android-sdk/.DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions trustly-android-sdk/.idea/gradle.xml

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

57 changes: 11 additions & 46 deletions trustly-android-sdk/.idea/sonarlint/issuestore/index.pb

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

57 changes: 11 additions & 46 deletions trustly-android-sdk/.idea/sonarlint/securityhotspotstore/index.pb

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

29 changes: 24 additions & 5 deletions trustly-android-sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
plugins {
id 'maven-publish'
id 'com.android.library' version '8.2.2'
id 'com.android.library' version '8.6.1'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
id 'org.jetbrains.kotlin.android' version '1.8.22'
}

def sdkVersion = "3.2.3"
def sdkVersion = "3.3.1-dev"
def localIP = "10.0.2.2"

android {
publishing {
Expand All @@ -14,10 +16,10 @@ android {
}
namespace 'net.trustly.android.sdk'

compileSdk 34
compileSdk 35

defaultConfig {
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 34
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -33,12 +35,21 @@ android {
testCoverageEnabled true
}
}

buildTypes.configureEach {
buildConfigField "String", "SDK_VERSION", "\"$sdkVersion\""
buildConfigField "String", "LOCAL_IP", "\"$localIP\""
}

testOptions {
unitTests.returnDefaultValues = true
}
buildFeatures {
buildConfig true
}
kotlinOptions {
jvmTarget = '11'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
Expand All @@ -48,14 +59,22 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.browser:browser:1.8.0'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.11.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.12.0'
testImplementation 'com.google.code.gson:gson:2.11.0'
testImplementation 'org.mockito:mockito-core:5.14.0'
testImplementation 'org.mockito:mockito-inline:4.2.0'

androidTestImplementation 'androidx.test:core:1.6.1'
androidTestImplementation 'androidx.test:runner:1.6.2'
androidTestImplementation 'androidx.test:rules:1.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.ext:truth:1.6.0'
androidTestImplementation 'com.google.truth:truth:1.1.3'
}

tasks.register('javadoc', Javadoc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.trustly.android.sdk.data

import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface APIMethod {

@GET("frontend/mobile/setup")
fun getSettings(
@Query("token") token: String
): Call<Settings>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package net.trustly.android.sdk.data

import android.util.Log
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class APIRequest(private val apiInterface: APIMethod, private val settings: (Settings) -> Unit, private val error: (String) -> Unit) {

fun getSettingsData(token: String) {
apiInterface.getSettings(token).enqueue(object : Callback<Settings> {
override fun onResponse(call: Call<Settings>, response: Response<Settings>) {
if (response.isSuccessful && response.body() != null) {
Log.d("APIRequestNew", response.body().toString())
settings.invoke(response.body() as Settings)
}
}

override fun onFailure(call: Call<Settings>, t: Throwable) {
Log.e("APIRequestNew", t.message.toString())
error.invoke(t.message.toString())
}
})
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.trustly.android.sdk.data

import net.trustly.android.sdk.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


object RetrofitInstance {

fun getInstance(baseUrl: String): Retrofit {
val interceptor = HttpLoggingInterceptor()
if (BuildConfig.DEBUG) interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
val okHttpClient = OkHttpClient.Builder().addInterceptor(interceptor).build()
return Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.trustly.android.sdk.data

data class Settings(
val settings: StrategySetting
)

data class StrategySetting(
val integrationStrategy: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ private static void showDisabledBrowserMessage(Context context) {
alertDialog.show();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package net.trustly.android.sdk.util;

import android.net.Uri;
import android.util.Base64;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -73,4 +79,42 @@ private static String urlEncode(String str) {
}
}

public static String getJsonFromParameters(Map<String, String> parameters) {
try {
JSONObject jsonObject = buildJsonObject(parameters);
return jsonObject.toString().replace("\"nameValuePairs\":{", "")
.replace(" }\n},", "}")
.replace("\\/", "/");
} catch (JSONException e) {
return new Gson().toJson(parameters);
}
}

public static JSONObject buildJsonObject(Map<String, String> data) throws JSONException {
JSONObject json = new JSONObject();
for (Map.Entry<String, String> e : data.entrySet()) {
String[] keys = e.getKey().split("\\.");
JSONObject current = json;
for (int i = 0; i < keys.length; ++i) {
String key = keys[i];
try {
current = current.getJSONObject(key);
} catch (JSONException ex) {
if (i == keys.length - 1) {
current.put(key, e.getValue());
} else {
JSONObject tmp = new JSONObject();
current.put(key, tmp);
current = tmp;
}
}
}
}
return json;
}

public static String encodeStringToBase64(String value) {
return Base64.encodeToString(value.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT);
}

}
Loading

0 comments on commit 958ca6d

Please sign in to comment.