Skip to main content

Making your first purchase

The SimpleCheckout API allows you to create and manage checkouts programmatically.

Create an API Key​

Navigate to the API Keys page and create a new api key. Give your key a descriptive name and copy it.

Complete Example​

Here's a complete script that creates a checkout and monitors it until completion:

import requests
import time

api_key = "YOUR_API_KEY"

# Step 1: Create a checkout
headers = {
"api-key": api_key,
"Content-Type": "application/json"
}

payload = {
"url": "https://buy.stripe.com/test_cNi3cvg0GeLkagX1un6Ri0m",
"user_data": {"email": "[email protected]"}
}


checkout = requests.post(
"https://api.simplecheckout.ai/v0/checkouts",
json=payload,
headers=headers
).json()

print(f"Checkout created: {checkout}")


# Step 2: Poll for completion
status_url = f"https://api.simplecheckout.ai/v0/checkouts/{checkout['id']}"

while True:
checkout_data = requests.get(status_url, headers=headers).json()

print(f"Status: {checkout_data['status']}", end="")

if checkout_data['status'] in ['completed', 'failed']:
break

print("... waiting 30 seconds before checking again")
time.sleep(30)

How It Works​

The script follows the same process as the web interface:

The payload contains these components:

  • "url" - The product URL (same Stripe test URL from the web demo)
  • "user_data" - All the information needed to complete the purchase (just email for this Stripe test)

Status polling works exactly like checking status in the web interface - the checkout starts as processing and we check every 30 seconds until it becomes completed or failed.

Note: The same rules apply as the web interface - if you don't provide enough information in user_data, the checkout will fail and you'll need to retry with complete details.

Using Customers' Credit Cards​

If you want to use your customers' credit card information instead of your own, you can collect and tokenize their payment details securely. When creating a checkout session, include the credit_card_token parameter which represents the tokenized version of your customer's credit card:

{
"url": "https://example.com/product",
"user_data": {
"email": "[email protected]"
},
"credit_card_token": "cct_sandbox_xyz123"
}

For detailed instructions on how to collect and tokenize customer credit cards, see our Tokenizing Credit Cards guide.