Skip to content

Add Google Pay Implementation - #438

Open
sshropshire wants to merge 21 commits into
feature/google_payfrom
add_google_pay_implementation
Open

Add Google Pay Implementation#438
sshropshire wants to merge 21 commits into
feature/google_payfrom
add_google_pay_implementation

Conversation

@sshropshire

@sshropshire sshropshire commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

  • Add Google Pay End-to-end implementation
  • Unit tests and documentation will follow in a separate PR

Checklist

  • Added a changelog entry

Authors

List GitHub usernames for everyone who contributed to this pull request.

companion object {
fun createPaymentsClient(context: Context): PaymentsClient {
val walletOptions = Wallet.WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend CoreConfig to contain environment for Google Pay, use it here dynamically

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this more?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can change CoreConfig to include GooglePayEnvironment like below

data CoreConfig(
val clientId: String,
val environment: Environment = Environment.SANDBOX,
val googlePayEnvironment = (WalletConstants.ENVIRONMENT_TEST
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then core would have a dependency on Google Pay. So if someone is using CardPayments, they will need to pull in Google Pay into their project as well even though they aren't using that feature.


@OptIn(InternalSerializationApi::class)
suspend fun start(request: GooglePayCheckoutRequest): GooglePayStartResult {
val merchantId = request.merchantId

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should merchantId be coming from GooglePayCheckoutRequest, merchant passing everytime
this doesn't look like start, it's eligibility check for google pay

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should we put it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be CoreConfig all details which will not change in every transaction stays in 1 place

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google Pay is the only feature that requires a merchantId. I wouldn't feel comfortable doing that unless merchant ID was required for all payment methods.

intent: Intent?
): GooglePayLaunchResult? {
val googlePayResult = googlePayContract.parseResult(resultCode, intent)
val success = googlePayResult.status.statusCode == CommonStatusCodes.SUCCESS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val success = googlePayResult.status.statusCode in listOf(CommonStatusCodes.SUCCESS, CommonStatusCodes.SUCCESS_CACHE)
?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's SUCCESS_CACHE?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUCCESS_CACHE is when it already checked before and didn't performed realtime check and got values from cache, in our situation I think this is valid success case
https://developers.google.com/android/reference/com/google/android/gms/common/api/CommonStatusCodes#SUCCESS_CACHE()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the docs it doesn't seem like SUCCESS_CACHE is a possibility. This is a good callout in general though, I'll look into the other error codes mentioned here.


is GraphQLResult.Failure -> {
val error =
PayPalSDKError(123, "Unable to launch google pay: unable to fetch config.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to define error codes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitely. We also probably don't need error codes. That's a holdover from iOS. That's a separate item though.

clientId = coreConfig.clientId,
merchantId = listOf(merchantId),
// TODO: see if we need this
merchantOrigin = "com.paypal.android.sdk",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be looking for host origin?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like the way JS does it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guessing by the name, not sure if it's expecting appId or host of merchant

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Android the merchant isn't guaranteed to have a host. On JS I think they get this from Window.location–I'm not aware of an equivalent on Android.

@sshropshire
sshropshire force-pushed the add_google_pay_implementation branch from a73f63d to ade31a9 Compare August 20, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants