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

Don't allow PaymentSheet.Configuration to be null. #7625

Merged

Conversation

jaynewstrom-stripe
Copy link
Collaborator

@jaynewstrom-stripe jaynewstrom-stripe commented Nov 13, 2023

Summary

When I was looking at prototyping an LPM refactor, I realized we had a lot of one off defaults for each of the properties of the payment sheet configuration. This change makes it all happen in the configuration class, and not leak to other parts of the codebase.

Motivation

Simplifying logic in PaymentSheet.

Copy link
Contributor

github-actions bot commented Nov 13, 2023

Diffuse output:

OLD: paymentsheet-example-release-master.apk (signature: V1, V2)
NEW: paymentsheet-example-release-pr.apk (signature: V1, V2)

          │           compressed           │           uncompressed           
          ├───────────┬───────────┬────────┼───────────┬───────────┬──────────
 APK      │ old       │ new       │ diff   │ old       │ new       │ diff     
──────────┼───────────┼───────────┼────────┼───────────┼───────────┼──────────
      dex │   3.6 MiB │   3.6 MiB │ -649 B │   7.8 MiB │   7.8 MiB │ -1.4 KiB 
     arsc │   2.3 MiB │   2.3 MiB │    0 B │   2.3 MiB │   2.3 MiB │      0 B 
 manifest │   5.1 KiB │   5.1 KiB │    0 B │  25.4 KiB │  25.4 KiB │      0 B 
      res │ 905.5 KiB │ 905.5 KiB │    0 B │   1.4 MiB │   1.4 MiB │      0 B 
   native │   2.6 MiB │   2.6 MiB │    0 B │     6 MiB │     6 MiB │      0 B 
    asset │     3 MiB │     3 MiB │  -19 B │     3 MiB │     3 MiB │    -19 B 
    other │ 204.5 KiB │ 204.5 KiB │   -7 B │ 460.3 KiB │ 460.3 KiB │      0 B 
──────────┼───────────┼───────────┼────────┼───────────┼───────────┼──────────
    total │  12.5 MiB │  12.5 MiB │ -675 B │  20.8 MiB │  20.8 MiB │ -1.4 KiB 

 DEX     │ old   │ new   │ diff            
─────────┼───────┼───────┼─────────────────
   files │     1 │     1 │   0             
 strings │ 38527 │ 38525 │  -2 (+8 -10)    
   types │ 12669 │ 12668 │  -1 (+6 -7)     
 classes │ 10652 │ 10651 │  -1 (+0 -1)     
 methods │ 55476 │ 55471 │  -5 (+477 -482) 
  fields │ 35667 │ 35655 │ -12 (+164 -176) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  292 │  292 │  0   
 entries │ 6936 │ 6936 │  0
APK
    compressed     │     uncompressed     │                                
──────────┬────────┼───────────┬──────────┤                                
 size     │ diff   │ size      │ diff     │ path                           
──────────┼────────┼───────────┼──────────┼────────────────────────────────
  3.6 MiB │ -649 B │   7.8 MiB │ -1.4 KiB │ ∆ classes.dex                  
  6.4 KiB │  -22 B │   6.2 KiB │    -22 B │ ∆ assets/dexopt/baseline.prof  
 65.6 KiB │   -8 B │ 147.1 KiB │      0 B │ ∆ META-INF/CERT.SF             
    765 B │   +3 B │     633 B │     +3 B │ ∆ assets/dexopt/baseline.profm 
 49.9 KiB │   +3 B │ 147.1 KiB │      0 B │ ∆ META-INF/MANIFEST.MF         
  1.2 KiB │   -2 B │   1.2 KiB │      0 B │ ∆ META-INF/CERT.RSA            
──────────┼────────┼───────────┼──────────┼────────────────────────────────
  3.7 MiB │ -675 B │   8.1 MiB │ -1.4 KiB │ (total)
DEX
STRINGS:

   old   │ new   │ diff        
  ───────┼───────┼─────────────
   38527 │ 38525 │ -2 (+8 -10) 
  + VLLLLLLLLLLLLZLLLLL
  + [Lhf/c1;
  + [Lod/o;
  + [Lod/r;
  + [Lve/d0;
  + [Lve/q;
  + [Lve/u;
  + ~~R8{backend:dex,compilation-mode:release,has-checksums:false,min-api:21,pg-map-id:1aa91e7,r8-mode:full,version:8.1.65}
  
  - Lve/h0;
  - VLLLLLLLLLLLZLLLLL
  - [Lhf/b1;
  - [Lod/l;
  - [Lod/p;
  - [Lve/e0;
  - [Lve/t;
  - [Lve/v;
  - appName
  - ~~R8{backend:dex,compilation-mode:release,has-checksums:false,min-api:21,pg-map-id:3b6a093,r8-mode:full,version:8.1.65}
  

TYPES:

   old   │ new   │ diff       
  ───────┼───────┼────────────
   12669 │ 12668 │ -1 (+6 -7) 
  + [Lhf/c1;
  + [Lod/o;
  + [Lod/r;
  + [Lve/d0;
  + [Lve/q;
  + [Lve/u;
  
  - Lve/h0;
  - [Lhf/b1;
  - [Lod/l;
  - [Lod/p;
  - [Lve/e0;
  - [Lve/t;
  - [Lve/v;
  

METHODS:

   old   │ new   │ diff           
  ───────┼───────┼────────────────
   55476 │ 55471 │ -5 (+477 -482) 
  + com.stripe.android.paymentsheet.addresselement.AddressElementActivity e(AddressElementActivity) → l
  + com.stripe.android.paymentsheet.example.playground.PaymentSheetPlaygroundActivity k(p, y, i, int)
  + com.stripe.android.paymentsheet.example.playground.PaymentSheetPlaygroundActivity m(PaymentSheetPlaygroundActivity, y, t2, c2, p, i, int)
  + com.stripe.android.paymentsheet.paymentdatacollection.polling.x <init>(r, e, j, x, i1)
  + com.stripe.android.stripe3ds2.views.ChallengeProgressFragment <init>(String, c1, Integer)
  + com.stripe.android.stripecardscan.cardimageverification.CardImageVerificationActivity access_getImageConfigs_p(CardImageVerificationActivity) → b
  + ec.g a0(i) → z0
  + ec.h a0(i) → z0
  + ec.i a0(i) → z0
  + ef.f <init>(c1)
  + hf.b1 <init>(int)
  + hf.b1 <init>(int, int)
  + hf.b1 a(a) → x
  + hf.b1 b(JSONObject) → g
  + hf.b1 c() → c
  + hf.b1 d(String, d) → a
  + hf.b1 e(List) → JSONArray
  + hf.c1 <clinit>()
  + hf.c1 <init>(String)
  + hf.c1 <init>(UUID)
  + hf.c1 describeContents() → int
  + hf.c1 equals(Object) → boolean
  + hf.c1 hashCode() → int
  + hf.c1 toString() → String
  + hf.c1 writeToParcel(Parcel, int)
  + hf.c <init>(String, c1, String, String, String, String)
  + hf.h0 <init>(c1, i0, PublicKey, String, String, PublicKey, d)
  + hf.l0 <init>(c1, a1, m0, b, i, j0, h1, h, c, p)
  + hf.l0 a(c1, p) → a
  + hf.n1 <init>(d, String, PublicKey, String, c1, KeyPair, String)
  + i3.s Q(Integer, List) → s2
  + i3.s R(TransformationMethod) → TransformationMethod
  + id.p <init>(a, a, a, a, a, a, a, a, a, int)
  + if.a <init>(String, String, String, c1, String, int, String, List, Boolean, Boolean)
  + if.a <init>(String, String, String, c1, List, int)
  + if.d <init>(String, String, String, String, i, boolean, String, String, String, String, boolean, List, String, String, c, List, String, String, String, String, c, String, c1, String, String, String, String, String)
  + if.g <init>(String, String, String, String, f, String, String, String, String, c1)
  + if.g <init>(String, String, String, String, String, String, String, c1, int)
  + j.g <init>(e, Application, c0)
  + jd.n <init>(c1, s, q5, j5, i, boolean, Integer, String, Set)
  + ke.i <init>(d0, k, w, d)
  + ke.k <init>(b0, e0, a, j, p0, j3, j, Context, b, u, c0, a, boolean, Set, b, q, s, w)
  + ke.k b(String, z1, m)
  + ke.k c()
  + ke.k d(w, d0)
  + ke.k e(a0)
  + ke.k f()
  + ke.k g(j, a, c) → f
  + ke.l <init>(a, a, a, a, a, a, a, e, a, e, a, c, a, a, e, a, a, h)
  + ke.r <init>(s, d0, d)
  + ke.u c() → d0
  + kf.v <init>(String, c1, Integer)
  + kotlinx.coroutines.c0 J1(p, i) → p
  + kotlinx.coroutines.c0 a0(g0, a, a, m, i, int, int)
  + l6.c a() → u
  + l6.c b() → c
  + l6.c c() → z
  + me.b <init>(j, a, int)
  + me.e <init>(p0, p0, j, Context, f)
  + nd.q0 <init>(d0, Integer, boolean, Set)
  + nd.q A0(RSAPublicKey, SecretKey, int, Provider) → byte[]
  + nd.q A1(View, e0)
  + nd.q B0(d1)
  + nd.q B1(ImageView, int)
  + nd.q C0(h)
  + nd.q C1(TextView, int)
  + nd.q D0(c0, s, j, a, d) → Object
  + nd.q E0(Class) → Class
  + nd.q E1(Object) → Set
  + nd.q F0(i) → g
  + nd.q F1(Object[]) → Set
  + nd.q G0(b, d, Object) → b
  + nd.q G1(TextView, int)
  + nd.q H0(h, h, boolean) → h
  + nd.q I0(View) → e0
  + nd.q I1(View, boolean)
  + nd.q J0(Context, TypedArray, int) → ColorStateList
  + nd.q J1(View)
  + nd.q K0(Context, q3, int) → ColorStateList
  + nd.q K1(g5) → boolean
  + nd.q L0(Context, TypedArray, int, int) → int
  + nd.q L1(Ima
...✂

@jaynewstrom-stripe jaynewstrom-stripe marked this pull request as ready for review November 13, 2023 16:04
@jaynewstrom-stripe jaynewstrom-stripe requested review from a team as code owners November 13, 2023 16:04
Copy link
Collaborator

@tillh-stripe tillh-stripe left a comment

Choose a reason for hiding this comment

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

Love this change! Should we do something similar with CustomerSheet so that we don’t have to resolve the merchant name in the ViewModel?

config = viewModel.state?.config?.copy(
shippingDetails = value
val state = viewModel.state
if (state != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this different?

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're updating the config only, and the config looks nullable in the new version (because state is nullable). But this didn't change any behavior.

@@ -177,7 +180,7 @@ internal class DefaultFlowController @Inject internal constructor(
) {
configure(
mode = PaymentSheet.InitializationMode.PaymentIntent(paymentIntentClientSecret),
configuration = configuration,
configuration = configuration ?: PaymentSheet.Configuration.default(viewModel.getApplication()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will make it harder for us to convert this to a non-Android ViewModel. Can we solve this differently? Maybe the default() method just takes a label argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, it'll make it harder. But flow controller already has access to context. I just pulled it from here (because it was easy) instead of adding a new property to the flow controller that's explicitly a context. But can do that if you prefer.

@jaynewstrom-stripe
Copy link
Collaborator Author

Love this change! Should we do something similar with CustomerSheet so that we don’t have to resolve the merchant name in the ViewModel?

Yes

@jaynewstrom-stripe jaynewstrom-stripe merged commit 93907e7 into master Nov 13, 2023
10 checks passed
@jaynewstrom-stripe jaynewstrom-stripe deleted the jaynewstrom/payment-sheet-configuration-null branch November 13, 2023 18:12
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