#bazylh-error-capture

1 messages · Page 1 of 1 (latest)

eager spoke
#

Hi there

#

Taking a look

shrewd crypt
#

Yeah, I think your docs should clarify this if it is on purpose. All the other Stripe API's return the object

eager spoke
#

So lets back up a sec.

#

You seem to be mixing PaymentIntents and SetupIntents here

#

Can you tell me exactly what you are trying to do?

shrewd crypt
#

SetupIntent gets the card info

#

PaymentIntent gets the funds off their card

#

We want to get card info up front and validate it, then they start a rental/storage-session/delivery using a locker. After it is completed we take the backend calculated amount off their card

#

I only showed code for the SetupIntent. Ignore the misleading naming

#

We were using captures before but decided to skip card capturing for now

eager spoke
#

Okay so when you create a PaymentIntent it will indeed return an ID

shrewd crypt
#
def capture_payment_intent(
    price: int,
    customer_id: str,
) -> dict:
    # payment_intent = stripe.PaymentIntent.capture(
    #     payment_intent=payment_intent_id,
    #     amount_to_capture=price.total_cost,
    #     application_fee_amount=price.total_fee,
    # )
    payment_intent = stripe.PaymentIntent.create(
        amount=price,
        customer=customer_id,
        currency="usd",
        off_session=True,
        confirm=True,
        automatic_payment_methods={"enabled": True},
        return_url="com.koloni.lockers.app://stripe-redirect",
    )

    return payment_intent```
#

Here is the actual PaymentIntent (called capture for the reason above)

#

This would happen on the backend when a user ends a rental

eager spoke
#

Yep that looks fine.

shrewd crypt
#

So I just want to know why we are getting and empty dict when calling SetupIntent

eager spoke
#

In this flow, the SetupIntent is going to return a PaymentMethod that you should pass with your PaymentIntent.

#

I don't see you passing a PaymentMethod at all above actually in your PaymentIntent creation.

shrewd crypt
#

hmm we want the automatic payment method functionality

#

We thought that happened in the mobile app

#

That using the ephemeral the mobile client updates the payment method, but we need to pass the payment intent id through the api for that to happen

eager spoke
#

No I think you are confused. You use the SetupIntent and its client secret to collect the PaymentMethod. Then you handle the PaymentIntent in this flow on the backend. https://stripe.com/docs/payments/save-and-reuse is the docs you want to follow.

shrewd crypt
#

Yepp I followed that link directly

#

I am referencing step 3

#

In their code

    customer=customer['id'],
  )```
#

They never pass the payment_method either

eager spoke
#

Right but that is for the SetupIntent

shrewd crypt
#

In their guide I realized just now we don't need to pass the SetupIntent ID, but we do need to pass client_secret

eager spoke
#

Yes exactly

shrewd crypt
#

But we cant get setupIntent.client_secret because it is still returning {}

#
>>> payment_intent = stripe.SetupIntent(
...     customer="cus_LyRYc43Qhj4Tgb",
...     on_behalf_of="acct_1KRVMKReFctt5EAK")
>>> print(payment_intent)
{}
>>> print(payment_intent.client_secret)
Traceback (most recent call last):
  File "/nix/store/d04mzrlnw6rcdjyc1wkgi5wfkzs5g7v2-python3-3.9.13-env/lib/python3.9/site-packages/stripe/stripe_object.py", line 90, in __getattr__
    return self[k]
  File "/nix/store/d04mzrlnw6rcdjyc1wkgi5wfkzs5g7v2-python3-3.9.13-env/lib/python3.9/site-packages/stripe/stripe_object.py", line 132, in __getitem__
    raise err
  File "/nix/store/d04mzrlnw6rcdjyc1wkgi5wfkzs5g7v2-python3-3.9.13-env/lib/python3.9/site-packages/stripe/stripe_object.py", line 120, in __getitem__
    return super(StripeObject, self).__getitem__(k)
KeyError: 'client_secret'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/d04mzrlnw6rcdjyc1wkgi5wfkzs5g7v2-python3-3.9.13-env/lib/python3.9/site-packages/stripe/stripe_object.py", line 92, in __getattr__
    raise AttributeError(*err.args)
AttributeError: client_secret
>>> 
eager spoke
#

The method is stripe.SetupIntent.create()

shrewd crypt
#

🤦🏽

#

Thanks

eager spoke
#

np!