@@ -59,7 +59,7 @@ func convertFlatFeeChargeToAPI(source flatfee.Charge) (api.BillingChargeFlatFee,
5959 AmountAfterProration : ConvertDecimalToCurrencyAmount (source .ChargeBase .State .AmountAfterProration ),
6060 BillingPeriod : ConvertClosedPeriodToAPI (intent .BillingPeriod ),
6161 CreatedAt : source .ChargeBase .ManagedResource .ManagedModel .CreatedAt ,
62- Currency : ConvertCurrencyCodeToAPI (source .ChargeBase .Intent .GetCurrency ()),
62+ Currency : ConvertCurrencyCodeToAPI (source .ChargeBase .Intent .GetCurrency (). GetCode () ),
6363 Customer : ConvertCustomerIDToReference (source .ChargeBase .Intent .GetCustomerID ()),
6464 DeletedAt : source .ChargeBase .ManagedResource .ManagedModel .DeletedAt ,
6565 Description : intent .Description ,
@@ -109,7 +109,7 @@ func convertUsageBasedChargeToAPI(source usagebased.Charge) (api.BillingChargeUs
109109 AdvanceAfter : source .State .AdvanceAfter ,
110110 BillingPeriod : ConvertClosedPeriodToAPI (intent .BillingPeriod ),
111111 CreatedAt : source .ChargeBase .ManagedResource .ManagedModel .CreatedAt ,
112- Currency : ConvertCurrencyCodeToAPI (source .ChargeBase .Intent .GetCurrency ()),
112+ Currency : ConvertCurrencyCodeToAPI (source .ChargeBase .Intent .GetCurrency (). GetCode () ),
113113 Customer : ConvertCustomerIDToReference (source .ChargeBase .Intent .GetCustomerID ()),
114114 DeletedAt : source .ChargeBase .ManagedResource .ManagedModel .DeletedAt ,
115115 Description : intent .Description ,
@@ -504,8 +504,8 @@ func convertAPIChargeStatus(s string) (meta.ChargeStatus, error) {
504504 }
505505}
506506
507- func convertFlatFeeChargeAPIToIntent ( customerID string , flatFee api.CreateChargeFlatFeeRequest ) (billingcharges.ChargeIntent , error ) {
508- var zero billingcharges.ChargeIntent
507+ func fromAPICreateChargeFlatFeeRequest ( namespace , customerID string , flatFee api.CreateChargeFlatFeeRequest ) (billingcharges.CreateCustomerChargeInput , error ) {
508+ var zero billingcharges.CreateCustomerChargeInput
509509
510510 taxConfig , err := billingprofiles .FromAPIBillingTaxConfig (flatFee .TaxConfig )
511511 if err != nil {
@@ -549,37 +549,36 @@ func convertFlatFeeChargeAPIToIntent(customerID string, flatFee api.CreateCharge
549549 }
550550 }
551551
552- return billingcharges .NewChargeIntent (flatfee.Intent {
553- Intent : meta.Intent {
554- ManagedBy : billing .ManuallyManagedLine ,
555- CustomerID : customerID ,
556- Currency : currencyx .Code (flatFee .Currency ),
557- TaxConfig : productcatalog .TaxCodeConfigFrom (taxConfig ),
558- UniqueReferenceID : flatFee .UniqueReferenceId ,
559- Subscription : nil ,
560- },
561- IntentMutableFields : flatfee.IntentMutableFields {
562- IntentMutableFields : meta.IntentMutableFields {
563- Name : flatFee .Name ,
564- Description : flatFee .Description ,
565- Metadata : metadata ,
566- ServicePeriod : timeutil .ClosedPeriod (flatFee .ServicePeriod ),
567- FullServicePeriod : timeutil .ClosedPeriod (lo .FromPtrOr (flatFee .FullServicePeriod , flatFee .ServicePeriod )),
568- BillingPeriod : timeutil .ClosedPeriod (lo .FromPtrOr (flatFee .BillingPeriod , flatFee .ServicePeriod )),
552+ return billingcharges.CreateCustomerChargeInput {
553+ Namespace : namespace ,
554+ CustomerID : customerID ,
555+ CurrencyCode : currencyx .Code (flatFee .Currency ),
556+ TaxConfig : productcatalog .TaxCodeConfigFrom (taxConfig ),
557+ UniqueReferenceID : flatFee .UniqueReferenceId ,
558+ FlatFee : & billingcharges.CreateCustomerChargeFlatFeeInput {
559+ IntentMutableFields : flatfee.IntentMutableFields {
560+ IntentMutableFields : meta.IntentMutableFields {
561+ Name : flatFee .Name ,
562+ Description : flatFee .Description ,
563+ Metadata : metadata ,
564+ ServicePeriod : timeutil .ClosedPeriod (flatFee .ServicePeriod ),
565+ FullServicePeriod : timeutil .ClosedPeriod (lo .FromPtrOr (flatFee .FullServicePeriod , flatFee .ServicePeriod )),
566+ BillingPeriod : timeutil .ClosedPeriod (lo .FromPtrOr (flatFee .BillingPeriod , flatFee .ServicePeriod )),
567+ },
568+ InvoiceAt : flatFee .InvoiceAt ,
569+ PaymentTerm : productcatalog .PaymentTermType (flatFee .PaymentTerm ),
570+ PercentageDiscounts : discount ,
571+ ProRating : proRating ,
572+ AmountBeforeProration : amountBeforeProration ,
569573 },
570- InvoiceAt : flatFee .InvoiceAt ,
571- PaymentTerm : productcatalog .PaymentTermType (flatFee .PaymentTerm ),
572- PercentageDiscounts : discount ,
573- ProRating : proRating ,
574- AmountBeforeProration : amountBeforeProration ,
574+ FeatureKey : flatFee .FeatureKey ,
575+ SettlementMode : productcatalog .SettlementMode (flatFee .SettlementMode ),
575576 },
576- FeatureKey : flatFee .FeatureKey ,
577- SettlementMode : productcatalog .SettlementMode (flatFee .SettlementMode ),
578- }), nil
577+ }, nil
579578}
580579
581- func convertUsageBaseChargeAPIToIntent ( customerID string , usageBasedFee api.CreateChargeUsageBasedRequest ) (billingcharges.ChargeIntent , error ) {
582- var zero billingcharges.ChargeIntent
580+ func fromAPICreateChargeUsageBasedRequest ( namespace , customerID string , usageBasedFee api.CreateChargeUsageBasedRequest ) (billingcharges.CreateCustomerChargeInput , error ) {
581+ var zero billingcharges.CreateCustomerChargeInput
583582
584583 taxConfig , err := billingprofiles .FromAPIBillingTaxConfig (usageBasedFee .TaxConfig )
585584 if err != nil {
@@ -618,29 +617,28 @@ func convertUsageBaseChargeAPIToIntent(customerID string, usageBasedFee api.Crea
618617 if err != nil {
619618 return zero , fmt .Errorf ("invalid price: %w" , err )
620619 }
621- return billingcharges .NewChargeIntent (usagebased.Intent {
622- Intent : meta.Intent {
623- ManagedBy : billing .ManuallyManagedLine ,
624- CustomerID : customerID ,
625- Currency : currencyx .Code (usageBasedFee .Currency ),
626- TaxConfig : productcatalog .TaxCodeConfigFrom (taxConfig ),
627- UniqueReferenceID : usageBasedFee .UniqueReferenceId ,
628- Subscription : nil ,
629- },
630- IntentMutableFields : usagebased.IntentMutableFields {
631- IntentMutableFields : meta.IntentMutableFields {
632- Name : usageBasedFee .Name ,
633- Description : usageBasedFee .Description ,
634- Metadata : metadata ,
635- ServicePeriod : timeutil .ClosedPeriod (usageBasedFee .ServicePeriod ),
636- FullServicePeriod : timeutil .ClosedPeriod (lo .FromPtrOr (usageBasedFee .FullServicePeriod , usageBasedFee .ServicePeriod )),
637- BillingPeriod : timeutil .ClosedPeriod (lo .FromPtrOr (usageBasedFee .BillingPeriod , usageBasedFee .ServicePeriod )),
620+ return billingcharges.CreateCustomerChargeInput {
621+ Namespace : namespace ,
622+ CustomerID : customerID ,
623+ CurrencyCode : currencyx .Code (usageBasedFee .Currency ),
624+ TaxConfig : productcatalog .TaxCodeConfigFrom (taxConfig ),
625+ UniqueReferenceID : usageBasedFee .UniqueReferenceId ,
626+ UsageBased : & billingcharges.CreateCustomerChargeUsageBasedInput {
627+ IntentMutableFields : usagebased.IntentMutableFields {
628+ IntentMutableFields : meta.IntentMutableFields {
629+ Name : usageBasedFee .Name ,
630+ Description : usageBasedFee .Description ,
631+ Metadata : metadata ,
632+ ServicePeriod : timeutil .ClosedPeriod (usageBasedFee .ServicePeriod ),
633+ FullServicePeriod : timeutil .ClosedPeriod (lo .FromPtrOr (usageBasedFee .FullServicePeriod , usageBasedFee .ServicePeriod )),
634+ BillingPeriod : timeutil .ClosedPeriod (lo .FromPtrOr (usageBasedFee .BillingPeriod , usageBasedFee .ServicePeriod )),
635+ },
636+ InvoiceAt : usageBasedFee .InvoiceAt ,
637+ Price : * price ,
638+ Discounts : discounts ,
638639 },
639- InvoiceAt : usageBasedFee .InvoiceAt ,
640- Price : * price ,
641- Discounts : discounts ,
640+ FeatureKey : usageBasedFee .FeatureKey ,
641+ SettlementMode : productcatalog .SettlementMode (usageBasedFee .SettlementMode ),
642642 },
643- FeatureKey : usageBasedFee .FeatureKey ,
644- SettlementMode : productcatalog .SettlementMode (usageBasedFee .SettlementMode ),
645- }), nil
643+ }, nil
646644}
0 commit comments