Python and Square Payment Form in Windows

Hi, Everyone.

I’ve been working with the payment for walkthrough and everything was looking good. Unfortunately, I’m really stuck now trying to integrate Square payment into our website. I’ve been trying to use some of the connect-api-examples from github but most of these seem to be only “pieces” of what I need.

Does anyone know where I can find a complete example to follow to get the Square payments form working in Python in Windows?

Thanks very much for any help you can offer, it is very much appreciated.

Hi @mkleinsdf, welcome to the forums!

Here is a complete working example of Python with Square Payment form, and creating the payment: https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/python_payment. If you’re still having trouble, or you have further questions or concerns, let me know!

Thanks very much, Stephen. I tried to use the HTML, JS and CSS from the example but I just don’t know how to put it together into a working page. (Unfortunately my experience with HTML, etc. is very limited.)

Thanks again for pointing me to the examples.

The README of the example should be everything you need to do to get it up and running, are you running into any errors? To be clear, the payment form completely relies on Javascript, and if you want to customize it, you’ll need to use CSS/JS.

If you prefer something that doesn’t require coding, feel free to take a look at Square Checkout Links, or our App Marketplace.

Thanks again for the help. Does Square provide any type of hourly consulting that we could use to get the Square payment form running in our application?

No, unfortunately not. We can help with directly working with APIs, but if it’s more programming in general, that’s outside of our scope of support unfortunately.

Trying to call the “process_card.py” provided in the example. (Renamed it as “process_payment.py”.) I have been able to run other Python scripts as CGI on the server, but am not sure why the Javascript isn’t able to find the process_payment.py being referenced by the Javascript “fetch” as shown here:

fetch(’/cgi/process_payment.py’, {
method: ‘POST’,
//credentials: ‘same-origin’,
credentials: ‘include’,
headers: {
‘X-CSRFToken’: csrfToken,
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
body: JSON.stringify({
nonce: nonce,
idempotency_key: idempotency_key,
total_amount: 100, // amount in cents (or smallest denomination of the currency)
total_amount_currency: ‘USD’ // ISO 4217 formatted currency code
//location_id: locationID
})
})

I have checked permissions on the “cgi” folder, and this folder is also set up in IIS as a subfolder of the Python/Django website.

Thanks very much for any help you might be able to provide on this.

Hello @sjosey I have been following the README file and I am confused at what to do on the credentials step. I have changed the config.ini.example file to my sandbox and production credentials but I am getting an error that looks like this:

CONFIG_TYPE = config.get(“DEFAULT”, “environment”).upper()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

raise NoOptionError(option, section)
configparser.NoOptionError: No option ‘environment’ in section: ‘DEFAULT’

was there something else in the main.py or configparser.py that I needed to change for the uvicorn main:app --reload command to work?

Did you create a new config.ini and configure your credentials? The file we provide is just an example and you will need to make a copy an configure that. :slightly_smiling_face:

1 Like

I restarted the entire process to ensure I did it right. I copied the config.ini file and changed the credentials info to mine and kept it in the same folder as python_payment. The following error showed up:

Process SpawnProcess-1:
Traceback (most recent call last):
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py”, line 314, in _bootstrap
self.run()
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py”, line 108, in run
self._target(*self._args, **self._kwargs)
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn_subprocess.py”, line 76, in subprocess_started
target(sockets=sockets)
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py”, line 59, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py”, line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py”, line 118, in run
return self.loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py”, line 66, in serve
config.load()
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\config.py”, line 471, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\importer.py”, line 21, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 1206, in _gcd_import
File “”, line 1178, in _find_and_load
File “”, line 1149, in _find_and_load_unlocked
File “”, line 690, in _load_unlocked
File “”, line 940, in exec_module
File “”, line 241, in _call_with_frames_removed
File “C:\Users\vickkram.ramarethina.QUANTA\gitrepos\connect-api-examples\connect-examples\v2\python_payment\main.py”, line 24, in
APPLICATION_ID = config.get(CONFIG_TYPE, “square_application_id”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\configparser.py”, line 797, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\vickkram.ramarethina.QUANTA\AppData\Local\Programs\Python\Python311\Lib\configparser.py”, line 1168, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: ‘’