@@ -19,14 +19,19 @@ interface CoflCoinOption {
1919 googlePlayProductId : string
2020}
2121
22+ export interface PurchaseCodes {
23+ creatorCode ?: string
24+ discountCode ?: string
25+ }
26+
2227interface Props {
2328 selectedOption : CoflCoinOption
2429 onBack : ( ) => void
2530 countryCode ?: string
2631 coflCoins : number
27- onPayPalPay : ( productId : string , coflCoins ?: number ) => void
28- onStripePay : ( productId : string , coflCoins ?: number ) => void
29- onLemonSqueezyPay : ( productId : string , coflCoins ?: number ) => void
32+ onPayPalPay : ( productId : string , coflCoins ?: number , codes ?: PurchaseCodes ) => void
33+ onStripePay : ( productId : string , coflCoins ?: number , codes ?: PurchaseCodes ) => void
34+ onLemonSqueezyPay : ( productId : string , coflCoins ?: number , codes ?: PurchaseCodes ) => void
3035 onGooglePlayPay : ( productId : string , coflCoins ?: number ) => void
3136 loadingProductId : string
3237 isGooglePlayAvailable ?: boolean
@@ -137,15 +142,15 @@ function CoflCoinPaymentSelection({ selectedOption, onBack, countryCode, coflCoi
137142 }
138143
139144 const getProviderForComponent = ( providerSlug : string , productSlug : string ) => {
140- return getProvider ( pricingData , providerSlug , productSlug )
145+ return getProvider ( pricingData , productSlug , providerSlug )
141146 }
142147
143148 const getProviderPriceForComponent = ( providerSlug : string , productSlug : string ) : number | null => {
144- return getProviderPrice ( pricingData , providerSlug , productSlug )
149+ return getProviderPrice ( pricingData , productSlug , providerSlug )
145150 }
146151
147152 const getProviderOriginalPriceForComponent = ( providerSlug : string , productSlug : string ) : number | null => {
148- return getProviderOriginalPrice ( pricingData , providerSlug , productSlug )
153+ return getProviderOriginalPrice ( pricingData , productSlug , providerSlug )
149154 }
150155
151156 const getGooglePlayProductId = ( ) : string => {
@@ -195,17 +200,11 @@ function CoflCoinPaymentSelection({ selectedOption, onBack, countryCode, coflCoi
195200 return undefined
196201 }
197202
198- // Append creator/discount codes as query params to a product slug so they reach the checkout endpoint
199- const buildProductIdWithCodes = ( productId : string ) : string => {
200- const queryParams : string [ ] = [ ]
201- if ( appliedCreatorCode ) {
202- queryParams . push ( `creatorCode=${ encodeURIComponent ( appliedCreatorCode ) } ` )
203- }
204- if ( validatedDiscount ?. code ) {
205- queryParams . push ( `discountCode=${ encodeURIComponent ( validatedDiscount . code ) } ` )
206- }
207- return queryParams . length > 0 ? `${ productId } ?${ queryParams . join ( '&' ) } ` : productId
208- }
203+ // Codes to forward in the checkout request body (topup endpoints read them from TopUpArguments, not the URL)
204+ const getPurchaseCodes = ( ) : PurchaseCodes => ( {
205+ creatorCode : appliedCreatorCode || undefined ,
206+ discountCode : validatedDiscount ?. code || undefined
207+ } )
209208
210209 const discountPercent = pricingData ?. discountPercent || 0
211210 const hasDiscount = discountPercent > 0
@@ -343,14 +342,14 @@ function CoflCoinPaymentSelection({ selectedOption, onBack, countryCode, coflCoi
343342 stripePrice = { dynamicPrices . stripe }
344343 lemonsqueezyPrice = { dynamicPrices . lemonsqueezy }
345344 googlePlayPrice = { dynamicPrices . googlepay }
346- paypalProductId = { buildProductIdWithCodes ( selectedOption . paypalProductId ) }
347- stripeProductId = { buildProductIdWithCodes ( selectedOption . stripeProductId ) }
348- lemonsqueezyProductId = { buildProductIdWithCodes ( selectedOption . lemonsqueezyProductId ) }
345+ paypalProductId = { selectedOption . paypalProductId }
346+ stripeProductId = { selectedOption . stripeProductId }
347+ lemonsqueezyProductId = { selectedOption . lemonsqueezyProductId }
349348 googlePlayProductId = { dynamicGooglePlayProductId }
350349 countryCode = { countryCode }
351- onPayPalPay = { onPayPalPay }
352- onStripePay = { onStripePay }
353- onLemonSqeezyPay = { onLemonSqueezyPay }
350+ onPayPalPay = { ( productId , coflCoins ) => onPayPalPay ( productId , coflCoins , getPurchaseCodes ( ) ) }
351+ onStripePay = { ( productId , coflCoins ) => onStripePay ( productId , coflCoins , getPurchaseCodes ( ) ) }
352+ onLemonSqeezyPay = { ( productId , coflCoins ) => onLemonSqueezyPay ( productId , coflCoins , getPurchaseCodes ( ) ) }
354353 onGooglePlayPay = { onGooglePlayPay }
355354 loadingProductId = { loadingProductId }
356355 disabledTooltip = { undefined }
0 commit comments