Hello, I’m trying to use the Stripe Python API in conjunction with their javascript library to collect a customers card to charge later. I can retrieve the clientSecret and mount the Stripe card form within a column panel, but I’m not sure how to submit the confirmSetup javascript as I don’t know how to retrieve the values of the card details to include in the “elements” of the confirmSetup. Does anyone know how to do this?
Client Side Code:
def new_payment_method_click(self, **event_args):
client_secret = anvil.server.call('stripe_add_customer')
stripe = Stripe('pk_test_51OLt9QDPx8hqA545RX8FXts0pqFwPEM0fVOt9hrkutJX0011G4pBpqnTCvySlPOYnrU45ryPaoIVt5m6fyXSGVW30062kVKSCM')
elements = stripe.elements({'clientSecret':client_secret,'loader':'auto'})
payEl = elements.create('payment',{'layout':'tabs'})
payEl.mount(anvil.js.get_dom_node(self.payment_panel))
def card_submit_click(self,**event_args):
stripe = Stripe(‘test_key’)
elements = anvil.js.get_dom_node(self.payment_panel)
setupIntent_Result = stripe.confirmSetup({
elements,
‘redirect’:‘if_required’
})
print(setupIntent_Result)
I always used Anvil’s Stripe Integration, to bypass the ugly details. Perhaps you might find that easier to deal with?
1 Like
Agree with @p.colbert, you should use the Stripe integration from Anvil
Stripe documenation
This should be the way to go 
For test cards see test credit cards
I did try that at first, hoping it would work. The issue is when only trying to store a card for the customer, the card input form only shows “Pay” at the bottom, which becomes confusing for the customer. I looked in the forums and it didn’t appear anyone had found any way to change the text on the button of the Stripe Integration.
Even Using Stripe’s Python API, which bypasses most of the integration?
I use the Stripe Python API to initiate the SetupIntent and associate it with a customer and obtain the client secret, but then from my understanding you have to use client side javascript to mount the card element and then submit the element details. I don’t believe you can pass card details back through the server side, as that wouldn’t be considered secure and compliant.
For now, I’m just using Stripe’s customer portal and creating a session for the customer when they click the billing link. That way I don’t have to mess with it. I think I need to use a module and the stripe python api to be able to share the elements details between functions. I’m happy with the customer portal for now.