@@ -3,17 +3,22 @@ import { useMemo, useEffect, useRef } from 'preact/hooks';
33
44import { PayPalService } from '../services/PayPalService' ;
55import { useAmount } from '../../../core/Context/AmountProvider' ;
6+ import { useCoreContext } from '../../../core/Context/CoreProvider' ;
7+ import type { PayPalFetchContentOptions , PayPalMessageElement } from '../paypal-js-types' ;
68
79export const PayPalMessaging = ( {
810 paypalService,
9- countryCode
11+ countryCode,
12+ messagingContentOptions
1013} : Readonly < {
1114 paypalService : PayPalService ;
1215 countryCode ?: string ;
16+ messagingContentOptions ?: Pick < PayPalFetchContentOptions , 'logoType' | 'logoPosition' | 'textColor' > ;
1317} > ) => {
1418 const payPalSDKInstance = useMemo ( ( ) => paypalService . getInstance ( ) , [ paypalService ] ) ;
15- const messageElementRef = useRef < HTMLElement | null > ( null ) ;
19+ const messageElementRef = useRef < PayPalMessageElement | null > ( null ) ;
1620 const { amount } = useAmount ( ) ;
21+ const { i18n } = useCoreContext ( ) ;
1722
1823 useEffect ( ( ) => {
1924 const fetchMessageContent = async ( ) : Promise < void > => {
@@ -22,13 +27,18 @@ export const PayPalMessaging = ({
2227 currencyCode : amount . currency
2328 } ) ;
2429
30+ const amountString = i18n . amount ( amount . value , amount . currency , {
31+ style : 'decimal' ,
32+ minimumFractionDigits : 0 ,
33+ signDisplay : 'never'
34+ } ) ;
35+
2536 await messagesInstance . fetchContent ( {
26- textColor : 'BLACK' ,
27- logoPosition : 'LEFT' ,
28- logoType : 'TEXT' ,
29- amount : String ( amount . value / 100 ) ,
37+ textColor : messagingContentOptions ?. textColor ?? 'BLACK' ,
38+ logoPosition : messagingContentOptions ?. logoPosition ?? 'LEFT' ,
39+ logoType : messagingContentOptions ?. logoType ?? 'TEXT' ,
40+ amount : amountString ,
3041 onReady : content => {
31- // @ts -ignore - messageElement is guaranteed to be a PayPalMessageElement
3242 messageElementRef . current ?. setContent ( content ) ;
3343 }
3444 } ) ;
0 commit comments