Simple Payment Link Retrival JSON or Jscript

Hi Everybody.

I am really new to the square API, im not new to JSON or Jscript and i am currently developing a website that actually uses JSON and SJSCRIPT allready. However im a complete novice when it comes to API and so i am trying to use the simple option of payment links for a payment option on a website i am developing www.cudluv.com - Currently in testing i have simply generated Payment links that are activated through the customer clicking the Buy Now Button and this works ok. However i need to expand this into the API and JSON/Jscript so i can add dynamic data to the payment link.

I understand that it is a simple JSON send and return funtion that will return JSON with a payment link that i can use, However as a novice i am not sure how to impliment this in my website.

I am hoping to have a BUYNOW button that will initiate the JSON call and return the Payment link with the dynamic data sent through the FORM and BUTTON.

So my question is, Does anybody know where i can find either example code or can anybody provide me a working example that i can work upon.

If i could see the code for myself i would quickly begin to understand it, But currently i have not found anything that is making sense to me…

So please, if anybody can point me to a Video, or a tutorial or Working example. or even supply me with Code that i could play about with i would be very greatfull.

i understand i have to add my own token and this i can deal with i know how to get my tokens ect. Its just the Code itself im at a loss . Is it a simple AJAX / JSON call to the Square API that then return JSON with the link i need… or is ther more to it.

I have been watching the developer videos and reading through the developer help pages, But i still have not yet seen a code that i can actually understand and impliment into my own website.

I know its a case of initiating a JSON/AJAX call . but im at a loss of where to begin.

Please help.

thank you.

:wave: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Get Started
Build on Mobile Web
Get Started

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

To create a payment link dynamically, you would use the CreatePaymentLink endpoint of the Checkout API. This endpoint allows you to create a checkout page with just a name and price, or with a more detailed order.

Here’s a basic example of how you might use this endpoint:

  1. First, you need to make a POST request to the endpoint https://connect.squareupsandbox.com/v2/checkout/create-payment-link.

  2. The body of the request would be a JSON object that includes the details of the payment link you want to create. For example:

{
  "idempotency_key": "your_unique_key",
  "checkout": {
    "order": {
      "order": {
        "line_items": [
          {
            "name": "Name of the item",
            "quantity": "1",
            "base_price_money": {
              "amount": 100,
              "currency": "USD"
            }
          }
        ]
      }
    }
  }
}
  1. In the headers of the request, you would include your access token like this: Authorization: Bearer YOUR_ACCESS_TOKEN.

  2. The response from the API will be a JSON object that includes a checkout_page_url field. This is the URL of the payment link that you can then use in your application.

Remember to replace YOUR_ACCESS_TOKEN and your_unique_key with your actual access token and a unique idempotency key respectively. The amount and currency fields should be replaced with the actual price and currency of the item you’re selling.

This is a simplified example and in a real-world application, you would need to handle errors and edge cases appropriately. Also, remember to switch the base URL to https://connect.squareup.com when you’re ready to move to production.

This answer was reviewed by @Bryan-Square.

Thank you. i allready read this, But actually implimenting it into my website is what i am needing.

as in i need a Jscript function that is called when button is pressed.

i am presuming i would simply initiate a JSON API call to [quote=“Square-Dev-AI, post:3, topic:15899”]
https://connect.squareupsandbox.com/v2/checkout/create-payment-link
[/quote]

And then i will receive the Data back in JSON. with the payment link.

You will however that will need to be your server side code that sends the request. This is because access tokens are secret and should never be available on the client side. :slightly_smiling_face:

Yes i read this on stackoverflow also…

This has also got me a little confused, i mean i can use PHP so that should be ok i guess. but id of prefered to use Jscrtipt, but even dynamically adding the key in PHP into Jscript will still show in developer. So how do you suggest i get around this. Pure PHP ?

Surely there are some examples of a working Code for this… Why Square not provided a GOOD working solution that can be utilised by the less experienced. ???

At this time there isn’t an example with the Checkout API that provide the UI as well as the server side code to create the Payment Link. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face:

Will this do it ?

I found this. Might help. looks like a working Example.

Hello Every one A solution would be much appreciated. I need the Zap for the form to be valuable to my business. It’s also taken a lot of time to figure out how to build the Zap