@@ -4388,7 +4388,7 @@ func TestService_recreateStripeSession(t *testing.T) {
4388
4388
},
4389
4389
4390
4390
{
4391
- name : "success_email_from_session " ,
4391
+ name : "success_email_cust_from_session " ,
4392
4392
given : tcGiven {
4393
4393
ordRepo : & repository.MockOrder {
4394
4394
FnAppendMetadata : func (ctx context.Context , dbi sqlx.ExecerContext , id uuid.UUID , key , val string ) error {
@@ -4405,7 +4405,7 @@ func TestService_recreateStripeSession(t *testing.T) {
4405
4405
ID : "cs_test_id_old" ,
4406
4406
SuccessURL : "https://example.com/success" ,
4407
4407
CancelURL : "https://example.com/cancel" ,
4408
- Customer :
& stripe.
Customer {
Email :
"[email protected] " },
4408
+ Customer :
& stripe.
Customer {
ID : "cus_id" , Email :
"[email protected] " },
4409
4409
}
4410
4410
4411
4411
return result , nil
@@ -4455,6 +4455,79 @@ func TestService_recreateStripeSession(t *testing.T) {
4455
4455
},
4456
4456
},
4457
4457
4458
+ {
4459
+ name : "success_email_from_request_cust_without_email" ,
4460
+ given : tcGiven {
4461
+ ordRepo : & repository.MockOrder {
4462
+ FnAppendMetadata : func (ctx context.Context , dbi sqlx.ExecerContext , id uuid.UUID , key , val string ) error {
4463
+ if key == "stripeCheckoutSessionId" && val == "cs_test_id" {
4464
+ return nil
4465
+ }
4466
+
4467
+ return model .Error ("unexpected" )
4468
+ },
4469
+ },
4470
+ cl : & xstripe.MockClient {
4471
+ FnSession : func (ctx context.Context , id string , params * stripe.CheckoutSessionParams ) (* stripe.CheckoutSession , error ) {
4472
+ result := & stripe.CheckoutSession {
4473
+ ID : "cs_test_id_old" ,
4474
+ SuccessURL : "https://example.com/success" ,
4475
+ CancelURL : "https://example.com/cancel" ,
4476
+ Customer : & stripe.Customer {ID : "cus_id" },
4477
+ }
4478
+
4479
+ return result , nil
4480
+ },
4481
+
4482
+ FnFindCustomer : func (ctx context.Context , email string ) (* stripe.Customer , bool ) {
4483
+ return nil , false
4484
+ },
4485
+
4486
+ FnCreateSession : func (ctx context.Context , params * stripe.CheckoutSessionParams ) (* stripe.CheckoutSession , error ) {
4487
+ if params .Customer != nil {
4488
+ return nil , model .Error ("unexpected_customer" )
4489
+ }
4490
+
4491
+ if * params .
CustomerEmail != "[email protected] " {
4492
+ return nil , model .Error ("unexpected_customer_email" )
4493
+ }
4494
+
4495
+ result := & stripe.CheckoutSession {
4496
+ ID : "cs_test_id" ,
4497
+ PaymentMethodTypes : []string {"card" },
4498
+ Mode : stripe .CheckoutSessionModeSubscription ,
4499
+ SuccessURL : * params .SuccessURL ,
4500
+ CancelURL : * params .CancelURL ,
4501
+ ClientReferenceID : * params .ClientReferenceID ,
4502
+ Subscription : & stripe.Subscription {
4503
+ ID : "sub_id" ,
4504
+ Metadata : map [string ]string {
4505
+ "orderID" : * params .ClientReferenceID ,
4506
+ },
4507
+ },
4508
+ AllowPromotionCodes : true ,
4509
+ }
4510
+
4511
+ return result , nil
4512
+ },
4513
+ },
4514
+ ord : & model.Order {
4515
+ ID : uuid .Must (uuid .FromString ("facade00-0000-4000-a000-000000000000" )),
4516
+ Items : []model.OrderItem {
4517
+ {
4518
+ Quantity : 1 ,
4519
+ Metadata : datastore.Metadata {"stripe_item_id" : "stripe_item_id" },
4520
+ },
4521
+ },
4522
+ },
4523
+ oldSessID : "cs_test_id_old" ,
4524
+
4525
+ },
4526
+ exp : tcExpected {
4527
+ val : "cs_test_id" ,
4528
+ },
4529
+ },
4530
+
4458
4531
{
4459
4532
name : "success_email_from_request" ,
4460
4533
given : tcGiven {
@@ -4473,7 +4546,6 @@ func TestService_recreateStripeSession(t *testing.T) {
4473
4546
ID : "cs_test_id_old" ,
4474
4547
SuccessURL : "https://example.com/success" ,
4475
4548
CancelURL : "https://example.com/cancel" ,
4476
- Customer :
& stripe.
Customer {
Email :
"[email protected] " },
4477
4549
}
4478
4550
4479
4551
return result , nil
@@ -4564,7 +4636,84 @@ func TestCreateStripeSession(t *testing.T) {
4564
4636
4565
4637
tests := []testCase {
4566
4638
{
4567
- name : "success_found_customer" ,
4639
+ name : "success_cust_id" ,
4640
+ given : tcGiven {
4641
+ cl : & xstripe.MockClient {
4642
+ FnCreateSession : func (ctx context.Context , params * stripe.CheckoutSessionParams ) (* stripe.CheckoutSession , error ) {
4643
+ if params .Customer == nil || * params .Customer != "cus_id" {
4644
+ return nil , model .Error ("unexpected" )
4645
+ }
4646
+
4647
+ result := & stripe.CheckoutSession {ID : "cs_test_id" }
4648
+
4649
+ return result , nil
4650
+ },
4651
+
4652
+ FnFindCustomer : func (ctx context.Context , email string ) (* stripe.Customer , bool ) {
4653
+ panic ("unexpected_find_customer" )
4654
+ },
4655
+ },
4656
+
4657
+ req : createStripeSessionRequest {
4658
+ orderID : "facade00-0000-4000-a000-000000000000" ,
4659
+ customerID : "cus_id" ,
4660
+ successURL : "https://example.com/success" ,
4661
+ cancelURL : "https://example.com/cancel" ,
4662
+ trialDays : 7 ,
4663
+ items : []* stripe.CheckoutSessionLineItemParams {
4664
+ {
4665
+ Quantity : ptrTo [int64 ](1 ),
4666
+ Price : ptrTo ("stripe_item_id" ),
4667
+ },
4668
+ },
4669
+ },
4670
+ },
4671
+ exp : tcExpected {
4672
+ val : "cs_test_id" ,
4673
+ },
4674
+ },
4675
+
4676
+ {
4677
+ name : "success_cust_id_email" ,
4678
+ given : tcGiven {
4679
+ cl : & xstripe.MockClient {
4680
+ FnCreateSession : func (ctx context.Context , params * stripe.CheckoutSessionParams ) (* stripe.CheckoutSession , error ) {
4681
+ if params .Customer == nil || * params .Customer != "cus_id" {
4682
+ return nil , model .Error ("unexpected" )
4683
+ }
4684
+
4685
+ result := & stripe.CheckoutSession {ID : "cs_test_id" }
4686
+
4687
+ return result , nil
4688
+ },
4689
+
4690
+ FnFindCustomer : func (ctx context.Context , email string ) (* stripe.Customer , bool ) {
4691
+ panic ("unexpected_find_customer" )
4692
+ },
4693
+ },
4694
+
4695
+ req : createStripeSessionRequest {
4696
+ orderID : "facade00-0000-4000-a000-000000000000" ,
4697
+ customerID : "cus_id" ,
4698
+
4699
+ successURL : "https://example.com/success" ,
4700
+ cancelURL : "https://example.com/cancel" ,
4701
+ trialDays : 7 ,
4702
+ items : []* stripe.CheckoutSessionLineItemParams {
4703
+ {
4704
+ Quantity : ptrTo [int64 ](1 ),
4705
+ Price : ptrTo ("stripe_item_id" ),
4706
+ },
4707
+ },
4708
+ },
4709
+ },
4710
+ exp : tcExpected {
4711
+ val : "cs_test_id" ,
4712
+ },
4713
+ },
4714
+
4715
+ {
4716
+ name : "success_email_found_customer" ,
4568
4717
given : tcGiven {
4569
4718
cl : & xstripe.MockClient {
4570
4719
FnCreateSession : func (ctx context.Context , params * stripe.CheckoutSessionParams ) (* stripe.CheckoutSession , error ) {
@@ -4598,7 +4747,7 @@ func TestCreateStripeSession(t *testing.T) {
4598
4747
},
4599
4748
4600
4749
{
4601
- name : "success_customer_not_found " ,
4750
+ name : "success_email_customer_not_found " ,
4602
4751
given : tcGiven {
4603
4752
cl : & xstripe.MockClient {
4604
4753
FnFindCustomer : func (ctx context.Context , email string ) (* stripe.Customer , bool ) {
@@ -4636,7 +4785,7 @@ func TestCreateStripeSession(t *testing.T) {
4636
4785
},
4637
4786
4638
4787
{
4639
- name : "success_no_customer_email " ,
4788
+ name : "success_email_no_customer_email " ,
4640
4789
given : tcGiven {
4641
4790
cl : & xstripe.MockClient {
4642
4791
FnFindCustomer : func (ctx context.Context , email string ) (* stripe.Customer , bool ) {
@@ -4663,7 +4812,7 @@ func TestCreateStripeSession(t *testing.T) {
4663
4812
},
4664
4813
4665
4814
{
4666
- name : "success_no_trial_days " ,
4815
+ name : "success_email_no_trial_days " ,
4667
4816
given : tcGiven {
4668
4817
cl : & xstripe.MockClient {},
4669
4818
0 commit comments