How do I check the result of anvil.stripe.Customer.charge(...)?

I’ve decided to follow Anvil’s examples, and use Anvil’s Stripe API to create Stripe customers. Continuing Anvil’s examples, I use the resulting customer object to charge a customer, e.g.,

charge = stripe_customer.charge(amount = amount_in_pennies, currency = 'USD')

This returns an anvil.stripe.Charge object. Now, according to Stripe’s documentation, a charge object has a status member, that should be checked for success or failure.

The customer object’s id member is addressed as customer['id'], so I’ve tried to address the charge’s status member as charge['status'], to no avail. This produces a KeyError.

So, what is the Anvil-approved way to check the charge object’s status?

In general, I don’t mind that Anvil’s Stripe documentation leans heavily on Stripe’s. However, where the two APIs differ, it will be important to make the differences explicit, if only to keep developers like me from driving down lots of dead ends…

Documentation that should be added:
API for anvil.stripe.Customer object.
API for anvil.stripe.Charge object.

Thanks for letting us know that this didn’t work - it was a bug in our Stripe integration, which is now fixed.

We’re right in the middle of updating our Stripe docs, but in the meantime your approach was absolutely correct, and you should now find that charge['status'] works exactly as it should.

Hope that helps!

That’s great! And quick.

Which attributes, specifically, are passed along? The next one I tried to read, receipt_url, produced this message:

KeyError: “No such Stripe attribute ‘receipt_url’”

That’s an excellent question. We were under the impression that anything available in Stripe should be available here, but it turns out that it’s only those things explicitly implemented in the stripe-java client library, which we use behind the scenes. We’re a few versions behind at the moment, and receipt_url was added more recently. We’ll be upgrading this very soon as part of a wider Stripe update, but in the meantime this is the version we use right now.

Thanks! I’ll do my best to make sense of it. Stripe’s change log seems to use dates rather than version numbers, but the link you gave me uses both. :+1:

It will probably help to explicitly list the Stripe API version date in Anvil’s docs. That way, when we go visit Stripe’s API docs and changelog, we will be able to match things up.

Yes, and sadly the dates on the stripe-java API versions don’t match the date-like version numbers of the underlying Stripe API. For example, there’s no mention of receipt_url in the Stripe Changelog anywhere, so it has presumably been there forever. But it was only added to the client library recently. All of which is by way of saying: Listing a Stripe API version wouldn’t actually have helped here, although you’re absolutely right that we should do it anyway!

Such are the joys of integration.

My hat is off, my heart goes out to you folks for making things work, in spite of such messes. I’m starting to see just how much work you have to do behind the scenes. You see our frustrations, but we seldom see yours. This should serve as a reminder to us, and all of Anvil’s developer-users, that you’re all working hard to support us.

I, for one, appreciate it very much!

1 Like

If you’re in the middle of Stripe-related fixes, you might run into this one, too:

A post was merged into an existing topic: Anvil Documentation Suggestions [ON-GOING]