Understanding the payment api

I don’t understand the payment api, how is the source id generated and how do I pass the user card or other payment options information when in the body request there is nothing like that.

The Square Web Payments SDK is designed to handle the secure collection and tokenization of payment information, including card details, so you don’t have to worry about handling sensitive data directly. To generate a source ID, you’ll first need to integrate the Web Payments SDK into your website. This will allow you to create a payment form where users can enter their payment information.

Once the user submits their payment information through the SDK’s payment form, the SDK will communicate with Square’s servers to securely generate a source ID, also known as a nonce. This is a unique identifier that represents the payment information, which you can then use in your API request to process the payment.

In your API request, you won’t include the actual payment details in the body; instead, you’ll include the source ID provided by the Web Payments SDK. :slightly_smiling_face:

Thanks for the response, I still need more clarity. Below is my create payment function

def create_payment_body(source_id, amount, user_id, description, assistance_id):
    body = {
        'source_id': source_id,
        'idempotency_key': f'{str(uuid4())}',
        'amount_money': {
            'amount': amount,
            'currency': 'USD'
        'autocomplete': True,
        'customer_id': f'{user_id}',
        'reference_id': f'{assistance_id}',
        'note': f'payment for {description}'
    return body

how do I capture the source_id to be used by these function after the frontend send in the request.

The source_id is a one time use token for making a payment or storing a card on file. You don’t need to store it in your database. :slightly_smiling_face: