@@ -29,6 +29,7 @@ import {
29
29
CheckoutSummaryListItem
30
30
} from "../../../model/checkout" ;
31
31
import { CheckoutFundingInvoice } from "../../../model/checkout/fundingInvoice" ;
32
+ import MembershipProductService from "../../entities/membershipProducts/services/MembershipProductService" ;
32
33
import {
33
34
CHECKOUT_MEMBERSHIP_COLUMNS ,
34
35
CHECKOUT_PRODUCT_COLUMNS ,
@@ -187,6 +188,14 @@ export const mergeInvoicePaymentPlans = (paymentPlans: InvoicePaymentPlan[]) =>
187
188
} ) ) ;
188
189
} ;
189
190
191
+ export const getCheckoutModelMembershipsValidTo = async ( model : CheckoutModel ) => {
192
+ for ( const node of model . contactNodes ) {
193
+ for ( const mem of node . memberships ) {
194
+ mem . validTo = await MembershipProductService . getCheckoutModel ( mem . productId , node . contactId ) . then ( res => res . expiresOn ) ;
195
+ }
196
+ }
197
+ } ;
198
+
190
199
export const getCheckoutModel = (
191
200
state : CheckoutState ,
192
201
paymentPlans : CheckoutPaymentPlan [ ] ,
@@ -358,6 +367,7 @@ export const getInvoiceLineKey = (entity: CheckoutEntity) => {
358
367
} ;
359
368
360
369
const getInvoiceLinePrices = ( item : CheckoutItem , lines : AbstractInvoiceLine [ ] , itemOriginal : CheckoutItem ) => {
370
+
361
371
const id = item . type === "course" && item . class ? item . class . id : item . id ;
362
372
const lineKey = getInvoiceLineKey ( item . type ) ;
363
373
const targetLine = lines . find ( l => l [ lineKey ] && ( l [ lineKey ] . productId === id || l [ lineKey ] . classId === id ) ) ;
@@ -401,10 +411,15 @@ const getInvoiceLinePrices = (item: CheckoutItem, lines: AbstractInvoiceLine[],
401
411
price : 0
402
412
} ;
403
413
414
+ const validTo = item . type === "membership" ? {
415
+ validTo : lines [ 0 ] ?. membership ?. validTo
416
+ } : { } ;
417
+
404
418
return {
405
419
...item ,
406
420
...paymentPlansObj ,
407
- ...prices
421
+ ...prices ,
422
+ ...validTo
408
423
} ;
409
424
} ;
410
425
@@ -549,7 +564,7 @@ export const checkoutCourseMap = (courseBase, skipCheck?: boolean): CheckoutCour
549
564
return course ;
550
565
} ;
551
566
552
- export const calculateVoucherOrMembershipExpiry = ( item : CheckoutItem ) => {
567
+ export const calculateVoucherExpiry = ( item : CheckoutItem ) => {
553
568
switch ( item . type ) {
554
569
case "voucher" : {
555
570
if ( item . expiryDays ) {
@@ -559,25 +574,6 @@ export const calculateVoucherOrMembershipExpiry = (item: CheckoutItem) => {
559
574
}
560
575
break ;
561
576
}
562
- case "membership" : {
563
- if ( item . expiryType === "Never (Lifetime)" ) {
564
- item . expireNever = item . expiryType ;
565
- } else {
566
- if ( item . expiryType === "Days" ) {
567
- const today = new Date ( ) ;
568
- today . setDate ( today . getDate ( ) + Number ( item . expiryDays ) ) ;
569
- item . validTo = format ( today , YYYY_MM_DD_MINUSED ) ;
570
- }
571
- if ( item . expiryType === "1st July" ) {
572
- const date = getExpireDate ( 6 ) ;
573
- item . validTo = format ( date , YYYY_MM_DD_MINUSED ) ;
574
- }
575
- if ( item . expiryType === "1st January" ) {
576
- const date = getExpireDate ( 0 ) ;
577
- item . validTo = format ( date , YYYY_MM_DD_MINUSED ) ;
578
- }
579
- }
580
- }
581
577
}
582
578
} ;
583
579
@@ -592,7 +588,7 @@ export const processCheckoutSale = (row, type) => {
592
588
if ( type === "voucher" ) {
593
589
row . restrictToPayer = false ;
594
590
}
595
- calculateVoucherOrMembershipExpiry ( row ) ;
591
+ calculateVoucherExpiry ( row ) ;
596
592
} ;
597
593
598
594
export const getCheckoutCurrentStep = ( step : CheckoutCurrentStepType ) : number => {
0 commit comments