@@ -24,6 +24,12 @@ async function onPayPalLoaded() {
2424 paymentMethods . getDetails ( "paylater" ) ;
2525 setupPayLaterButton ( sdkInstance , paylaterPaymentMethodDetails ) ;
2626 }
27+
28+ if ( paymentMethods . isEligible ( "credit" ) ) {
29+ const paypalCreditPaymentMethodDetails =
30+ paymentMethods . getDetails ( "credit" ) ;
31+ setupPayPalCreditButton ( sdkInstance , paypalCreditPaymentMethodDetails ) ;
32+ }
2733 } catch ( error ) {
2834 console . error ( error ) ;
2935 }
@@ -107,6 +113,31 @@ async function setupPayLaterButton(sdkInstance, paylaterPaymentMethodDetails) {
107113 } ) ;
108114}
109115
116+ async function setupPayPalCreditButton (
117+ sdkInstance ,
118+ paypalCreditPaymentMethodDetails ,
119+ ) {
120+ const paypalCreditPaymentSession =
121+ sdkInstance . createPayPalCreditOneTimePaymentSession ( paymentSessionOptions ) ;
122+
123+ const { countryCode } = paypalCreditPaymentMethodDetails ;
124+ const paypalCreditButton = document . querySelector ( "#paypal-credit-button" ) ;
125+
126+ paypalCreditButton . countryCode = countryCode ;
127+ paypalCreditButton . removeAttribute ( "hidden" ) ;
128+
129+ paypalCreditButton . addEventListener ( "click" , async ( ) => {
130+ try {
131+ await paypalCreditPaymentSession . start (
132+ { presentationMode : "auto" } ,
133+ createOrder ( ) ,
134+ ) ;
135+ } catch ( error ) {
136+ console . error ( error ) ;
137+ }
138+ } ) ;
139+ }
140+
110141async function getBrowserSafeClientToken ( ) {
111142 const response = await fetch ( "/paypal-api/auth/browser-safe-client-token" , {
112143 method : "GET" ,
0 commit comments