from faststripe.core import StripeApi
import os
# Initialize the API
= StripeApi(os.environ['STRIPE_SECRET_KEY']) sapi
How to Accept One-Time Payments
Create payment links for single purchases
This guide shows you how to create one-time payment links using FastStripe’s simplified API.
Problem
You want to accept a one-time payment for a product or service without dealing with the complexity of creating products, prices, and checkout sessions manually.
Solution
Use FastStripe’s one_time_payment()
method which handles all the setup automatically.
Basic one-time payment
# Create a simple payment link
= sapi.one_time_payment(
checkout ='Digital Course',
product_name=4999, # $49.99
amount_cents='https://yoursite.com/success',
success_url='https://yoursite.com/cancel'
cancel_url
)
print(f"Payment URL: {checkout.url}")
Payment URL: https://billing.answer.ai/c/pay/cs_test_a1aD4GmxAkLT2DC7D90Okf5shUsexvDIkFWjNq1822ULt3LoTvtVB4Kf4u#fidkdWxOYHwnPyd1blpxYHZxWjA0VDFNMTFOQm10THI8VV1oX0xtbUt8R0RvX3RicGtMXWBKVm1oN01uYTF8VXZBSXRVSTVxazNqcUcxXHc0V1FGZEpdbDxGZElAc0BUZzNJZHVhfEZcM2tDNTV%2FSXZvYTRtTicpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl
Different currencies
FastStripe supports all currencies that Stripe accepts:
# Euro payment
= sapi.one_time_payment(
eur_checkout ='European Product',
product_name=2500, # €25.00
amount_cents='https://yoursite.com/success',
success_url='https://yoursite.com/cancel',
cancel_url='eur'
currency
)
print(f"EUR Payment URL: {eur_checkout.url}")
EUR Payment URL: https://billing.answer.ai/c/pay/cs_test_a1anFd3Qd3AeImckaCvhVS9lcltaLpCHKSDW5SKcwrQCHv65uCcz6TlQ0t#fidkdWxOYHwnPyd1blpxYHZxWjA0VDFNMTFOQm10THI8VV1oX0xtbUt8R0RvX3RicGtMXWBKVm1oN01uYTF8VXZBSXRVSTVxazNqcUcxXHc0V1FGZEpdbDxGZElAc0BUZzNJZHVhfEZcM2tDNTV%2FSXZvYTRtTicpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl
Manual approach
If you need more control, you can create products, prices, and checkout sessions manually:
# Create product
= sapi.products.post(
product ='Advanced Course',
name='Complete Python development course'
description
)
# Create price
= sapi.prices.post(
price =product.id,
product=9999, # $99.99
unit_amount='usd'
currency
)
# Create checkout session
= sapi.checkout.sessions_post(
checkout ='payment',
mode=[{
line_items'price': price.id,
'quantity': 1
}],='https://yoursite.com/success',
success_url='https://yoursite.com/cancel'
cancel_url
)
print(f"Manual checkout URL: {checkout.url}")
Manual checkout URL: https://billing.answer.ai/c/pay/cs_test_a18dXJDe9wvbORZhoQfHZIFzp2CPLxATMwRD38IRTRUqjYtkYh67AFiTCl#fidkdWxOYHwnPyd1blpxYHZxWjA0VDFNMTFOQm10THI8VV1oX0xtbUt8R0RvX3RicGtMXWBKVm1oN01uYTF8VXZBSXRVSTVxazNqcUcxXHc0V1FGZEpdbDxGZElAc0BUZzNJZHVhfEZcM2tDNTV%2FSXZvYTRtTicpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl
Tips
- Use test mode (keys starting with
sk_test_
) during development - FastStripe automatically creates products and prices if they don’t exist
- Store the checkout session ID for tracking payments
- Use webhooks to handle successful payments in your application