Quantcast
Channel: Square Developer Forums - Latest topics
Viewing all articles
Browse latest Browse all 1475

Creating a Payment Link in Google App Script

$
0
0

Here is the function from my script:

> function generatePaymentLink(amount, form_org) {
>   var accessToken = debugMode ? "SANDBOX_ACCESS_TOKEN" : "PRODUCTION_ACCESS_TOKEN";
>   var apiBaseUrl = debugMode ? "https://connect.squareupsandbox.com" : "https://connect.squareup.com";
>   var locationId = debugMode ? "SANDBOX_LOCATION_ID" : "PRODUCTION_LOCATION_ID";
> 
>   var requestBody = {
>   idempotency_key: Utilities.getUuid(),
>   order: {
>     location_id: locationId,
>     line_items: [{
>       name: "Parking Pass Purchase",
>       quantity: "1",
>       base_price_money: {
>         amount: amount * 100,
>         currency: "CAD"
>       }
>     }]
>   },
>   redirect_url: "https://pridewinnipeg.com/",
>   ask_for_shipping_address: false
> };
> 
>   var options = {
>     method: "post",
>     contentType: "application/json",
>     headers: {
>       "Authorization": "Bearer " + accessToken
>     },
>     payload: JSON.stringify(requestBody),
>     muteHttpExceptions: true
>   };
> 
>   // Log the request body
>   Logger.log("Request Body: " + JSON.stringify(requestBody));
> 
>   var response = UrlFetchApp.fetch(apiBaseUrl + "/v2/locations/" + locationId + "/checkouts", options);
> 
>   // Log the entire API response
>   Logger.log("API Response: " + response.getContentText());
> 
>   var jsonResponse = JSON.parse(response.getContentText());
> 
>   if (response.getResponseCode() == 200) {
>     return jsonResponse.checkout.checkout_page_url;
>   } else {
>     // Handle errors
>     Logger.log("Error creating Square checkout: " + jsonResponse.errors[0].detail);
>     return null;
>   }
> }

The response I keep getting however is:

Mar 24, 2024, 4:07:18 PM

Info

API Response: {“errors”:[{“category”:“INVALID_REQUEST_ERROR”,“code”:“MISSING_REQUIRED_PARAMETER”,“detail”:“Missing required parameter.”,“field”:“order”}]}

REFRESH

I am really struggling with how to interpret or troubleshoot this and would appreciate if anybody could weigh in…

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1475

Trending Articles