Skip to content

Commit

Permalink
Merge pull request #541 from SwedbankPay/feature/native-payments
Browse files Browse the repository at this point in the history
Native Payment support
  • Loading branch information
alleus authored Nov 27, 2024
2 parents 9c5b21f + 12bb064 commit c546885
Show file tree
Hide file tree
Showing 86 changed files with 5,295 additions and 163 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- uses: ./.github/actions/generate-docs-action
2 changes: 1 addition & 1 deletion .github/workflows/run-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- name: Run Checks with Gradle
run: ./gradlew check
- name: Check generating docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-connected-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Run Connected Checks
id: testing
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'
- name: Build with Gradle
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
env:
Expand Down
9 changes: 0 additions & 9 deletions .idea/codeStyles/Project.xml

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

2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

7 changes: 5 additions & 2 deletions .idea/misc.xml

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

3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Dependencies(map: Map<String, String>) {
val `play-services-basement` by map
val gson by map

val googlepay by map

val junit by map

val `joda-time` by map
Expand All @@ -46,6 +48,7 @@ class Dependencies(map: Map<String, String>) {
val mockwebserver by map

val robolectric by map

//val `mockito-inline` by map
val `mockito-kotlin` by map
val `dexmaker-mockito-inline` by map
Expand Down
7 changes: 0 additions & 7 deletions buildSrc/src/main/kotlin/Publish.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fun Project.publishToMaven(description: String) {
private fun Project.createReleasePublication(description: String): MavenPublication {
return the<PublishingExtension>().publications.create<MavenPublication>("release") {
from(components["release"])
artifact(sourcesJar())
artifact(javadocJar())

pom {
Expand All @@ -36,12 +35,6 @@ private fun Project.createReleasePublication(description: String): MavenPublicat
organization.set("Swedbank Pay")
organizationUrl.set("https://www.swedbankpay.com/")
}
developer {
name.set("Pertti Kröger")
email.set("[email protected]")
organization.set("Qvik")
organizationUrl.set("https://qvik.com/")
}
}

scm {
Expand Down
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/ReleaseArtifacts.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.task
import org.gradle.kotlin.dsl.the

fun Project.sourcesJar() = task<Jar>("sourcesJar") {
from(project.the<LibraryExtension>().sourceSets["main"].java.srcDirs)
archiveClassifier.set("sources")
}

fun Project.javadocJar() = task<Jar>("javadocJar") {
from(tasks["dokkaJavadoc"])
Expand Down
6 changes: 4 additions & 2 deletions dependencies/dependencies.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
extra["kotlin_version"] = "1.8.10"

extra["libs"] = mapOf(
"android-gradle-plugin" to "com.android.tools.build:gradle:7.4.2", //7.1.3
"android-gradle-plugin" to "com.android.tools.build:gradle:8.5.0",

"jgit" to "org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r",

Expand Down Expand Up @@ -35,10 +35,12 @@ extra["libs"] = mapOf(
"play-services-basement" to "com.google.android.gms:play-services-basement:18.2.0",
"gson" to "com.google.code.gson:gson:2.10.1",

"googlepay" to "com.google.android.gms:play-services-wallet:19.4.0",

"junit" to "junit:junit:4.13.2",

"joda-time" to "joda-time:joda-time:2.12.5",
"threetenbp" to "org.threeten:threetenbp:1.6.8",
"threetenbp" to "org.threeten:threetenbp:1.7.0",

"okhttp" to "com.squareup.okhttp3:okhttp:4.10.0",
"mockwebserver" to "com.squareup.okhttp3:mockwebserver:4.10.0",
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue May 10 11:11:12 CEST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
9 changes: 5 additions & 4 deletions mobilesdk-merchantbackend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply(from = "../dependencies/dependencies.gradle.kts")
val kotlin_version: String by extra

plugins {
id("com.android.library")
kotlin("android")
Expand All @@ -13,13 +13,14 @@ apply {
plugin("kotlin-android")
}

val javaVersion = JavaVersion.VERSION_11
val javaVersion = JavaVersion.VERSION_17
android {
compileSdk = 33
compileSdk = 34

defaultConfig {
minSdk = 21
targetSdk = 33

namespace = "com.swedbankpay.mobilesdk.merchantbackend"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion mobilesdk-merchantbackend/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.swedbankpay.mobilesdk.merchantbackend">
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.swedbankpay.mobilesdk.merchantbackend

import android.content.Context
import com.swedbankpay.mobilesdk.*
import com.swedbankpay.mobilesdk.Configuration
import com.swedbankpay.mobilesdk.Consumer
import com.swedbankpay.mobilesdk.PaymentOrder
import com.swedbankpay.mobilesdk.PaymentOrderPayer
import com.swedbankpay.mobilesdk.Problem
import com.swedbankpay.mobilesdk.ViewConsumerIdentificationInfo
import com.swedbankpay.mobilesdk.ViewPaymentOrderInfo
import com.swedbankpay.mobilesdk.find
import com.swedbankpay.mobilesdk.merchantbackend.MerchantBackendConfiguration.Builder
import com.swedbankpay.mobilesdk.merchantbackend.internal.remote.CacheableResult
import com.swedbankpay.mobilesdk.merchantbackend.internal.remote.WhitelistedDomain
Expand Down Expand Up @@ -112,8 +119,8 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
val currentInstrument = paymentOrder.instrument
if (currentInstrument != null && availableInstruments != null) { //why was this part of the clause? && availableInstruments.contains(currentInstrument)
instrument = currentInstrument
}
}

} else {
setInstrument = paymentOrderIn.mobileSDK?.setInstrument
availableInstruments = setInstrument?.let { _ ->
Expand All @@ -123,7 +130,7 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
paymentOrderIn.paymentOrder?.instrument
}
}

return ViewPaymentOrderInfo(
id = paymentId,
webViewBaseUrl = backendUrl,
Expand Down Expand Up @@ -160,7 +167,7 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
val instrument = requireNotNull(updateInfo as? String) {
"Unexpected updateInfo $updateInfo (expected String)"
}

if (!viewPaymentOrderInfo.isV3) {
return updateInstrumentV2(context, viewPaymentOrderInfo, instrument)
}
Expand Down Expand Up @@ -188,11 +195,12 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi

return viewPaymentOrderInfo.copy(
viewPaymentLink = viewPaymentLink ?: viewPaymentOrderInfo.viewPaymentLink,
availableInstruments = availableInstruments ?: viewPaymentOrderInfo.availableInstruments,
availableInstruments = availableInstruments
?: viewPaymentOrderInfo.availableInstruments,
instrument = instrumentIn ?: instrument
)
}

private suspend fun updateInstrumentV2(
context: Context,
viewPaymentOrderInfo: ViewPaymentOrderInfo,
Expand All @@ -204,7 +212,7 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
"Payment order is not in instrument mode"
}
val link = Link.PaymentOrderSetInstrument(linkHref.toHttpUrl())

val paymentOrderIn = try {
link.patch(context, this, instrument)
} catch (e: RequestProblemException) {
Expand All @@ -214,14 +222,15 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
}
}

val viewPaymentLink = paymentOrderIn.operations.find("view-paymentorder")?.href
val viewPaymentLink = paymentOrderIn.operations.find("view-paymentorder")?.href
val setInstrument = paymentOrderIn.mobileSDK?.setInstrument
val availableInstruments = paymentOrderIn.paymentOrder?.availableInstruments
val instrumentIn = paymentOrderIn.paymentOrder?.instrument

return viewPaymentOrderInfo.copy(
viewPaymentLink = viewPaymentLink ?: viewPaymentOrderInfo.viewPaymentLink,
availableInstruments = availableInstruments ?: viewPaymentOrderInfo.availableInstruments,
availableInstruments = availableInstruments
?: viewPaymentOrderInfo.availableInstruments,
instrument = instrumentIn ?: instrument,
userData = setInstrument?.href?.toString() ?: linkHref
)
Expand All @@ -236,7 +245,13 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi
): T? {

return BackendOperation.ExpandOperation(this)
.post(context = context, paymentId = paymentId, expand = expand, endpoint = endpoint, entityType = entityType)
.post(
context = context,
paymentId = paymentId,
expand = expand,
endpoint = endpoint,
entityType = entityType
)
}

private suspend fun getTopLevelResources(context: Context): TopLevelResources {
Expand Down Expand Up @@ -333,23 +348,24 @@ class MerchantBackendConfiguration private constructor(builder: Builder) : Confi

private fun Context.getProblemErrorMessage(problem: Problem) = when (problem) {
is MerchantBackendProblem -> getFriendlyDescription(problem)
else -> problem.title ?: problem.detail ?: getString(R.string.swedbankpaysdk_problem_unknown)
else -> problem.title ?: problem.detail
?: getString(com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_unknown)
}

private fun Context.getFriendlyDescription(merchantBackendProblem: MerchantBackendProblem): String {
val resId = when (merchantBackendProblem) {
is MerchantBackendProblem.Client.MobileSDK.Unauthorized -> R.string.swedbankpaysdk_problem_unauthorized
is MerchantBackendProblem.Client.MobileSDK.InvalidRequest -> R.string.swedbankpaysdk_problem_invalid_request
is MerchantBackendProblem.Client.SwedbankPay.InputError -> R.string.swedbankpaysdk_problem_input_error
is MerchantBackendProblem.Client.SwedbankPay.Forbidden -> R.string.swedbankpaysdk_problem_forbidden
is MerchantBackendProblem.Client.SwedbankPay.NotFound -> R.string.swedbankpaysdk_problem_not_found
is MerchantBackendProblem.Client.Unknown -> R.string.swedbankpaysdk_problem_unknown
is MerchantBackendProblem.Server.MobileSDK.BackendConnectionTimeout -> R.string.swedbankpaysdk_problem_backend_connection_timeout
is MerchantBackendProblem.Server.MobileSDK.BackendConnectionFailure -> R.string.swedbankpaysdk_problem_backend_connection_failure
is MerchantBackendProblem.Server.MobileSDK.InvalidBackendResponse -> R.string.swedbankpaysdk_problem_invalid_backend_response
is MerchantBackendProblem.Server.SwedbankPay.SystemError -> R.string.swedbankpaysdk_problem_system_error
is MerchantBackendProblem.Server.SwedbankPay.ConfigurationError -> R.string.swedbankpaysdk_problem_configuration_error
is MerchantBackendProblem.Server.Unknown -> R.string.swedbankpaysdk_problem_unknown
is MerchantBackendProblem.Client.MobileSDK.Unauthorized -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_unauthorized
is MerchantBackendProblem.Client.MobileSDK.InvalidRequest -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_invalid_request
is MerchantBackendProblem.Client.SwedbankPay.InputError -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_input_error
is MerchantBackendProblem.Client.SwedbankPay.Forbidden -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_forbidden
is MerchantBackendProblem.Client.SwedbankPay.NotFound -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_not_found
is MerchantBackendProblem.Client.Unknown -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_unknown
is MerchantBackendProblem.Server.MobileSDK.BackendConnectionTimeout -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_backend_connection_timeout
is MerchantBackendProblem.Server.MobileSDK.BackendConnectionFailure -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_backend_connection_failure
is MerchantBackendProblem.Server.MobileSDK.InvalidBackendResponse -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_invalid_backend_response
is MerchantBackendProblem.Server.SwedbankPay.SystemError -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_system_error
is MerchantBackendProblem.Server.SwedbankPay.ConfigurationError -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_configuration_error
is MerchantBackendProblem.Server.Unknown -> com.swedbankpay.mobilesdk.R.string.swedbankpaysdk_problem_unknown
}
return getString(resId)
}
22 changes: 19 additions & 3 deletions mobilesdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ apply {
plugin("kotlin-android")
}

val javaVersion = JavaVersion.VERSION_11
val javaVersion = JavaVersion.VERSION_17
android {
compileSdk = 33
compileSdk = 34

defaultConfig {
minSdk = 21 // Required by okhttp (from version 3.13 onwards)
targetSdk = 33
namespace = "com.swedbankpay.mobilesdk"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-rules.pro")
buildConfigField("String", "SDK_VERSION", "\"$version\"")

unitTestVariants.configureEach {
mergedFlavor.manifestPlaceholders["swedbankPaymentUrlScheme"] = ""
}

testVariants.configureEach {
mergedFlavor.manifestPlaceholders["swedbankPaymentUrlScheme"] = ""
}
}

testOptions {
Expand All @@ -33,9 +41,15 @@ android {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

kotlinOptions {
jvmTarget = javaVersion.toString()
}

buildFeatures {
buildConfig = true
}

}

dependencies {
Expand Down Expand Up @@ -66,6 +80,8 @@ dependencies {

implementation(libs.gson)

implementation(libs.googlepay)

compileOnly(libs.`joda-time`)
compileOnly(libs.threetenbp)

Expand Down
Loading

0 comments on commit c546885

Please sign in to comment.