Created
October 28, 2022 06:31
-
-
Save warrenkc/0cbe1e7f3d8d754d76b3fdb49b888a97 to your computer and use it in GitHub Desktop.
Create payment link for Square in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from square.client import Client | |
import os | |
import uuid | |
environment='production' | |
idempotency_key = str(uuid.uuid4()) | |
# Returns Error: [{'category': 'INVALID_REQUEST_ERROR', 'code': 'INVALID_EMAIL_ADDRESS', 'detail': "This account's email is linked to a current Weebly Account."}] | |
location_id = '' | |
access_token = '' | |
client = Client( | |
access_token=access_token, | |
environment=environment) | |
def create_payment_link(): | |
result = client.checkout.create_payment_link( | |
body={ | |
"idempotency_key": idempotency_key, | |
"quick_pay": { | |
"name": "Auto Detailing", | |
"price_money": { | |
"amount": 12500, | |
"currency": "USD" | |
}, | |
"location_id": location_id | |
} | |
} | |
) | |
if result.is_success(): | |
print(f"Payment Link: {result.body['payment_link']['url']}") | |
elif result.is_error(): | |
print(result.errors) | |
def main(): | |
create_payment_link() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment