Hello, I read API page (https://stripe.com/docs/billing/subscriptions/overview) and trying to wright code in Python.
My scenario is like this.
- Create stripe user id
- Create payment method type 'card'.
- Attach card id to user
- Attach price key to user (subscription)
- Pay right now.
- Send receipt email.
I did make a code for 1~4 step.
But I don't know how to pay subscription in 5 step.
Can I pay subscription right now in code?
How can I send receipt email to customer ?
Here is my test code. Please check this what am I wrong..🥲
import stripe
stripe.api_key = 'sk_test_XXX'
#1. create stripe user id
stripe_customer = stripe.Customer.create()
stripe_customer_id = stripe_customer['id']
#2. Create payment method type 'card'.
payment_card = stripe.PaymentMethod.create(
type="card",
card={
"number": "4242424242424242",
"exp_month": 12,
"exp_year": 2022,
"cvc": "314",
},
)
#3. Attach card id to user //paid by default payment item
stripe.PaymentMethod.attach(
payment_card['id'],
customer=stripe_customer_id,
)
#4. Attach price key to user (subscription)
stripe_subscription = stripe.Subscription.create(
customer=stripe_customer_id,
items=[
{"price": "price_XXX"}, #this price setted for month
],
)
Can I pay subscription right now in code?
How can I send receipt email to customer ?