Skip to content
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

Add paymentMethodTypes to CustomerAdapter. #8015

Merged
merged 6 commits into from Feb 29, 2024

Conversation

jaynewstrom-stripe
Copy link
Collaborator

@jaynewstrom-stripe jaynewstrom-stripe commented Feb 28, 2024

Summary

Supplying payment method types will filter available payment methods (new and saved) to the list provided.

Motivation

https://jira.corp.stripe.com/browse/MOBILESDK-1401

Copy link
Contributor

github-actions bot commented Feb 28, 2024

Diffuse output:

OLD: identity-example-release-base.apk (signature: V1, V2)
NEW: identity-example-release-pr.apk (signature: V1, V2)

          │          compressed          │         uncompressed         
          ├───────────┬───────────┬──────┼───────────┬───────────┬──────
 APK      │ old       │ new       │ diff │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
      dex │     2 MiB │     2 MiB │  0 B │   4.1 MiB │   4.1 MiB │  0 B 
     arsc │   1.4 MiB │   1.4 MiB │  0 B │   1.4 MiB │   1.4 MiB │  0 B 
 manifest │   2.3 KiB │   2.3 KiB │  0 B │   8.1 KiB │   8.1 KiB │  0 B 
      res │ 363.2 KiB │ 363.2 KiB │  0 B │ 490.6 KiB │ 490.6 KiB │  0 B 
   native │   6.2 MiB │   6.2 MiB │  0 B │  15.8 MiB │  15.8 MiB │  0 B 
    asset │  67.8 KiB │  67.8 KiB │  0 B │  87.7 KiB │  87.7 KiB │  0 B 
    other │ 114.7 KiB │ 114.7 KiB │  0 B │ 270.3 KiB │ 270.3 KiB │  0 B 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
    total │  10.2 MiB │  10.2 MiB │  0 B │  22.2 MiB │  22.2 MiB │  0 B 

 DEX     │ old   │ new   │ diff      
─────────┼───────┼───────┼───────────
   files │     1 │     1 │ 0         
 strings │ 20963 │ 20963 │ 0 (+0 -0) 
   types │  6509 │  6509 │ 0 (+0 -0) 
 classes │  5298 │  5298 │ 0 (+0 -0) 
 methods │ 30646 │ 30646 │ 0 (+0 -0) 
  fields │ 17817 │ 17817 │ 0 (+0 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  262 │  262 │  0   
 entries │ 5504 │ 5504 │  0

@jaynewstrom-stripe
Copy link
Collaborator Author

Still need to filter retrievePaymentMethods by the supplied paymentMethodTypes

Comment on lines +46 to +57
paymentMethodTypes?.filter { PaymentMethod.Type.fromCode(it) == null }?.takeIf { it.isNotEmpty() }?.run {
val cause = IllegalStateException("Invalid payment method types provided (${joinToString()}).")
return CustomerAdapter.Result.failure(cause, null)
}

val supportedPaymentMethodCodes = supportedPaymentMethodTypes.map { it.code }.toSet()
val unsupportedPaymentMethods = paymentMethodTypes?.minus(supportedPaymentMethodCodes) ?: emptyList()
if (unsupportedPaymentMethods.isNotEmpty()) {
val unsupportedCodes = unsupportedPaymentMethods.joinToString()
val cause = IllegalStateException("Unsupported payment method types provided ($unsupportedCodes).")
return CustomerAdapter.Result.failure(cause, null)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Two differences between iOS and Android in the impl:

  1. On iOS we have CustomerSheetError with specific types. If i read this correctly, everything is of type IllegalStateException, so there's no specific type
  2. On iOS, if a payment method deserializes to unknown, we effectively throw the same error -- unsupported.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't have error types (and it doesn't look like we expose exceptions of this nature for CustomerSheet or PaymentSheet).

I think I'm ok with both of those differences between platforms, but happy to discuss a change if you feel strongly.

): Result<ElementsSessionWithMetadata> {
val initializationMode = PaymentSheet.InitializationMode.DeferredIntent(
PaymentSheet.IntentConfiguration(
mode = PaymentSheet.IntentConfiguration.Mode.Setup(),
paymentMethodTypes = customerAdapter.paymentMethodTypes ?: emptyList()
Copy link
Contributor

Choose a reason for hiding this comment

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

If a user passes in ["card", "klarna"] where does klarna get filtered out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jaynewstrom-stripe jaynewstrom-stripe merged commit 0a2d20e into master Feb 29, 2024
12 checks passed
@jaynewstrom-stripe jaynewstrom-stripe deleted the jaynewstrom/cs-paymentMethodTypes branch February 29, 2024 17:15
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.

None yet

3 participants