@@ -23,9 +23,9 @@ const authenticate = async (bodyParams) => {
2323 const params = {
2424 grant_type : "client_credentials" ,
2525 response_type : "id_token" ,
26- ...bodyParams
26+ ...bodyParams ,
2727 } ;
28-
28+
2929 // pass the url encoded value as the body of the post call
3030 const urlEncodedParams = new URLSearchParams ( params ) . toString ( ) ;
3131 try {
@@ -36,14 +36,9 @@ const authenticate = async (bodyParams) => {
3636 PAYPAL_CLIENT_ID + ":" + PAYPAL_CLIENT_SECRET ,
3737 ) . toString ( "base64" ) ;
3838
39- let body = "grant_type=client_credentials&response_type=id_token" ;
40- if ( targetCustomerId ) {
41- body += `&target_customer_id=${ targetCustomerId } ` ;
42- }
43-
4439 const response = await fetch ( `${ base } /v1/oauth2/token` , {
4540 method : "POST" ,
46- body,
41+ body : urlEncodedParams ,
4742 headers : {
4843 Authorization : `Basic ${ auth } ` ,
4944 } ,
@@ -94,6 +89,7 @@ const createOrder = async (cart) => {
9489 experience_context : {
9590 return_url : "http://example.com" ,
9691 cancel_url : "http://example.com" ,
92+ shipping_preference : "NO_SHIPPING" ,
9793 } ,
9894 } ,
9995 } ,
@@ -180,7 +176,9 @@ app.post("/api/orders/:orderID/capture", async (req, res) => {
180176// render checkout page with client id & user id token
181177app . get ( "/" , async ( req , res ) => {
182178 try {
183- const { jsonResponse } = await authenticate ( req . query . customerID ) ;
179+ const { jsonResponse } = await authenticate ( {
180+ target_customer_id : req . query . customerID ,
181+ } ) ;
184182 res . render ( "checkout" , {
185183 clientId : PAYPAL_CLIENT_ID ,
186184 userIdToken : jsonResponse . id_token ,
0 commit comments