#HM-subs
1 messages · Page 1 of 1 (latest)
Do I need to create an invoice?
no you wouldn't need to. when you create the subscription, the default collection_method is charge_automatically [0]. Stripe will automatically attempt to create the invoice and charge the customer.
The receipt will also be automatically sent in live mode. But it won't be sent automatically in test mode. [1]
[0] https://stripe.com/docs/api/subscriptions/create#create_subscription-collection_method
[1] https://stripe.com/docs/receipts#receipts-with-billing
I'd suggest you take a look at this guide : https://stripe.com/docs/billing/subscriptions/build-subscription
You mean, I make "stripe.Subscription.create", it mean already paid subscription by customer. Also stripe will send reciept mail on live mode? Am I understand right?
yes that's right
Okay Thank you! 🙂
import stripe
stripe.api_key = 'sk_test_51JK049EhcKQZEEpHOehQwZF2MnLxzLWzylwbJh7KwhmBel4yiqyIWSibMXA2Ljg0jGKlfDhZ8mw9lcVwsUxQEmqc00vLNuhimM'
#1. create stripe user id
stripe_customer = stripe.Customer.create()
stripe_customer_id = stripe_customer['id']
print("1111111111111111111111111")
#2. Create payment method type 'card'.
payment_card = stripe.PaymentMethod.create(
type="card",
card={
"number": "4242424242424242",
"exp_month": 12,
"exp_year": 2022,
"cvc": "314",
},
)
print("22222222222222222222222222")
#3. Attach card id to user //paid by default payment item
stripe.PaymentMethod.attach(
payment_card['id'],
customer=stripe_customer_id,
)
print("33333333333333333333333333333")
#4. Attach price key to user (subscription)
stripe_subscription = stripe.Subscription.create(
customer=stripe_customer_id,
items=[
{"price": "price_1K1RE1EhcKQZEEpHRx6yObTg"
}, #this price setted for month
],
)
print("444444444444444444444444444")
#https://discord.com/channels/841573134531821608/919787386450366515
print(stripe_subscription)
@stark kestrel
I run this code, I got that result .
1111111111111111111111111
22222222222222222222222222
33333333333333333333333333333
Traceback (most recent call last):
File "E:\SVN\Backend\CriminalIP\CriminalIP_B2C\Payment\test_stripe.py", line 85, in <module>
stripe_subscription = stripe.Subscription.create(
File "C:\Python39\lib\site-packages\stripe\api_resources\abstract\createable_api_resource.py", line 22, in create
response, api_key = requestor.request("post", url, params, headers)
File "C:\Python39\lib\site-packages\stripe\api_requestor.py", line 122, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "C:\Python39\lib\site-packages\stripe\api_requestor.py", line 399, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "C:\Python39\lib\site-packages\stripe\api_requestor.py", line 159, in handle_error_response
raise err
stripe.error.InvalidRequestError: Request req_5xSQDtzVjooYuv: This customer has no attached payment source or default payment method.
.
.
.
.
I already did attach payment soruce to customer.
#3. Attach card id to user //paid by default payment item
stripe.PaymentMethod.attach(
payment_card['id'],
customer=stripe_customer_id,
)
But I got that message.
" This customer has no attached payment source or default payment method. "
Did I wrong something?
@onyx flare you will need to set the default payment method of the customer using invoice_settings.default_payment_method [0]
[0] https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Okay! I will try!!! Thank you for yor feedback
Okay! I success!!
yay!