Skip to content

Add customer info for gpay payment provider (APPS-1820) #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

## UNRELEASED
### Added
* core: Add customer info needed for a Google Pay payment provider
### Changed
### Removed
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ dependencies {
testImplementation(libs.squareup.okhttp3.mockwebserver)
testImplementation(libs.koltin.reflect)
testImplementation(libs.androidx.coreTesting)

implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
}
10 changes: 4 additions & 6 deletions core/src/main/java/io/snabble/sdk/checkout/Checkout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,8 @@ class Checkout @JvmOverloads constructor(
/**
* Authorize a for one-time use payment requests, e.g. sending tokenized payment data of google pay.
*/
fun authorizePayment(encryptedOrigin: String?) {
val authorizePaymentRequest = AuthorizePaymentRequest(
encryptedOrigin = encryptedOrigin
)
fun authorizePayment(authPayRequest: AuthorizePaymentRequest?) {
val authorizePaymentRequest = authPayRequest ?: AuthorizePaymentRequest()
storedAuthorizePaymentRequest = authorizePaymentRequest
checkoutProcess?.let { checkoutProcess ->
checkoutApi.authorizePayment(checkoutProcess,
Expand Down Expand Up @@ -545,11 +543,11 @@ class Checkout @JvmOverloads constructor(
if (authorizePaymentUrl != null) {
if (authorizePaymentRequestFailed) {
authorizePaymentRequestFailed = false
authorizePayment(storedAuthorizePaymentRequest?.encryptedOrigin)
authorizePayment(storedAuthorizePaymentRequest)
} else {
val storedAuthorizePaymentRequest = storedAuthorizePaymentRequest
if (storedAuthorizePaymentRequest != null) {
authorizePayment(storedAuthorizePaymentRequest.encryptedOrigin)
authorizePayment(storedAuthorizePaymentRequest)
} else {
notifyStateChanged(CheckoutState.REQUEST_PAYMENT_AUTHORIZATION_TOKEN)
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/io/snabble/sdk/checkout/CheckoutApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ data class PaymentResult(

data class AuthorizePaymentRequest(
val encryptedOrigin: String? = null,
val name: String? = null,
val countryCode: String? = null,
val state: String? = null
)

data class Check(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit
class DefaultCheckoutApi(private val project: Project,
private val shoppingCart: ShoppingCart
) : CheckoutApi {

private val okHttpClient: OkHttpClient = project.okHttpClient
private var call: Call? = null

Expand Down
16 changes: 15 additions & 1 deletion core/src/main/java/io/snabble/sdk/googlepay/GooglePayHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.google.gson.JsonObject
import io.snabble.sdk.PaymentMethod
import io.snabble.sdk.Project
import io.snabble.sdk.Snabble
import io.snabble.sdk.checkout.AuthorizePaymentRequest
import io.snabble.sdk.utils.GsonHolder
import io.snabble.sdk.utils.Logger

Expand Down Expand Up @@ -219,7 +220,18 @@ class GooglePayHelper(
project.checkout.abortError()
} else {
val base64Token = String(Base64.encode(token.toByteArray(), Base64.NO_WRAP))
project.checkout.authorizePayment(base64Token)
val address: BillingAddress? = jsonPaymentData.get("paymentMethodData")
?.asJsonObject?.get("info")
?.asJsonObject?.get("billingAddress")
?.let { GsonHolder.get().fromJson(it, BillingAddress::class.java) }
project.checkout.authorizePayment(
AuthorizePaymentRequest(
encryptedOrigin = base64Token,
name = address?.name,
countryCode = address?.countryCode,
state = address?.administrativeArea
)
)
}
} catch (e: Exception) {
project.checkout.abortError()
Expand All @@ -240,6 +252,8 @@ class GooglePayHelper(
}
}

private data class BillingAddress(val name: String?, val countryCode: String?, val administrativeArea: String?)

interface IsReadyToPayListener {
fun isReadyToPay(isReadyToPay: Boolean)
}