You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import stripe
|
|
from django.conf import settings
|
|
|
|
# Configure Stripe with your secret key
|
|
stripe.api_key = settings.STRIPE_SECRET_KEY
|
|
|
|
def create_payment_intent(amount, currency=settings.STRIPE_CURRENCY, metadata=None):
|
|
"""
|
|
Create a payment intent with Stripe
|
|
|
|
Args:
|
|
amount: Amount in cents (e.g., 1000 for €10.00)
|
|
currency: Currency code (default: settings.STRIPE_CURRENCY)
|
|
metadata: Additional info to attach to the payment intent
|
|
|
|
Returns:
|
|
The created payment intent object
|
|
"""
|
|
intent = stripe.PaymentIntent.create(
|
|
amount=amount,
|
|
currency=currency,
|
|
metadata=metadata or {},
|
|
)
|
|
return intent
|
|
|
|
def create_checkout_session(line_items, success_url, cancel_url, metadata=None):
|
|
"""
|
|
Create a Stripe Checkout Session for one-time payments
|
|
|
|
Args:
|
|
line_items: List of items to purchase
|
|
success_url: URL to redirect on successful payment
|
|
cancel_url: URL to redirect on canceled payment
|
|
metadata: Additional info to attach to the session
|
|
|
|
Returns:
|
|
The created checkout session
|
|
"""
|
|
session = stripe.checkout.Session.create(
|
|
payment_method_types=['card'],
|
|
line_items=line_items,
|
|
mode='payment',
|
|
success_url=success_url,
|
|
cancel_url=cancel_url,
|
|
metadata=metadata or {},
|
|
)
|
|
return session
|
|
|