Skip to content

Commit 00aa365

Browse files
authored
Add customer info for gpay payment provider (APPS-1820) (#221)
1 parent 9ee1597 commit 00aa365

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
## UNRELEASED
55
### Added
6+
* core: Add customer info needed for a Google Pay payment provider
67
### Changed
78
### Removed
89
### Fixed

core/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,6 @@ dependencies {
9393
testImplementation(libs.squareup.okhttp3.mockwebserver)
9494
testImplementation(libs.koltin.reflect)
9595
testImplementation(libs.androidx.coreTesting)
96+
97+
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
9698
}

core/src/main/java/io/snabble/sdk/checkout/Checkout.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,8 @@ class Checkout @JvmOverloads constructor(
399399
/**
400400
* Authorize a for one-time use payment requests, e.g. sending tokenized payment data of google pay.
401401
*/
402-
fun authorizePayment(encryptedOrigin: String?) {
403-
val authorizePaymentRequest = AuthorizePaymentRequest(
404-
encryptedOrigin = encryptedOrigin
405-
)
402+
fun authorizePayment(authPayRequest: AuthorizePaymentRequest?) {
403+
val authorizePaymentRequest = authPayRequest ?: AuthorizePaymentRequest()
406404
storedAuthorizePaymentRequest = authorizePaymentRequest
407405
checkoutProcess?.let { checkoutProcess ->
408406
checkoutApi.authorizePayment(checkoutProcess,
@@ -545,11 +543,11 @@ class Checkout @JvmOverloads constructor(
545543
if (authorizePaymentUrl != null) {
546544
if (authorizePaymentRequestFailed) {
547545
authorizePaymentRequestFailed = false
548-
authorizePayment(storedAuthorizePaymentRequest?.encryptedOrigin)
546+
authorizePayment(storedAuthorizePaymentRequest)
549547
} else {
550548
val storedAuthorizePaymentRequest = storedAuthorizePaymentRequest
551549
if (storedAuthorizePaymentRequest != null) {
552-
authorizePayment(storedAuthorizePaymentRequest.encryptedOrigin)
550+
authorizePayment(storedAuthorizePaymentRequest)
553551
} else {
554552
notifyStateChanged(CheckoutState.REQUEST_PAYMENT_AUTHORIZATION_TOKEN)
555553
}

core/src/main/java/io/snabble/sdk/checkout/CheckoutApi.kt

+3
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ data class PaymentResult(
310310

311311
data class AuthorizePaymentRequest(
312312
val encryptedOrigin: String? = null,
313+
val name: String? = null,
314+
val countryCode: String? = null,
315+
val state: String? = null
313316
)
314317

315318
data class Check(

core/src/main/java/io/snabble/sdk/checkout/DefaultCheckoutApi.kt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit
2121
class DefaultCheckoutApi(private val project: Project,
2222
private val shoppingCart: ShoppingCart
2323
) : CheckoutApi {
24+
2425
private val okHttpClient: OkHttpClient = project.okHttpClient
2526
private var call: Call? = null
2627

core/src/main/java/io/snabble/sdk/googlepay/GooglePayHelper.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.google.gson.JsonObject
2020
import io.snabble.sdk.PaymentMethod
2121
import io.snabble.sdk.Project
2222
import io.snabble.sdk.Snabble
23+
import io.snabble.sdk.checkout.AuthorizePaymentRequest
2324
import io.snabble.sdk.utils.GsonHolder
2425
import io.snabble.sdk.utils.Logger
2526

@@ -219,7 +220,18 @@ class GooglePayHelper(
219220
project.checkout.abortError()
220221
} else {
221222
val base64Token = String(Base64.encode(token.toByteArray(), Base64.NO_WRAP))
222-
project.checkout.authorizePayment(base64Token)
223+
val address: BillingAddress? = jsonPaymentData.get("paymentMethodData")
224+
?.asJsonObject?.get("info")
225+
?.asJsonObject?.get("billingAddress")
226+
?.let { GsonHolder.get().fromJson(it, BillingAddress::class.java) }
227+
project.checkout.authorizePayment(
228+
AuthorizePaymentRequest(
229+
encryptedOrigin = base64Token,
230+
name = address?.name,
231+
countryCode = address?.countryCode,
232+
state = address?.administrativeArea
233+
)
234+
)
223235
}
224236
} catch (e: Exception) {
225237
project.checkout.abortError()
@@ -240,6 +252,8 @@ class GooglePayHelper(
240252
}
241253
}
242254

255+
private data class BillingAddress(val name: String?, val countryCode: String?, val administrativeArea: String?)
256+
243257
interface IsReadyToPayListener {
244258
fun isReadyToPay(isReadyToPay: Boolean)
245259
}

0 commit comments

Comments
 (0)