#HM-subs

1 messages · Page 1 of 1 (latest)

stark kestrel
onyx flare
#

Do I need to create an invoice?

stark kestrel
onyx flare
#

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?

stark kestrel
#

yes that's right

onyx flare
#

Okay Thank you! 🙂

onyx flare
#

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?

stark kestrel
onyx flare
#

Okay! I will try!!! Thank you for yor feedback

onyx flare
#

Okay! I success!!

stark kestrel
#

yay!