I’m trying to set up a payment feature in my app using Stripe. I have both one-time payment and subscription-based payment options.
I have successfully connected my app to my Stripe account and am running it in Test Mode now.
I have followed the Anvil documents and built separate client-side functions for each payment option. The one-time payment function works correctly and I see the transaction on my Stripe dashboard.
However, the subscription function throws this error on this like of code: “subscription = stripe.checkout.subscribe…”. The error id changes each time:
anvil.server.InternalError: Internal server error: 1cd1f7e768bd
The more odd part of this is that the transaction appears to be successful! Each time I run this function, I get this error, but the transaction posts as a new subscription in my Stripe dashboard.
I’ve checked my Stripe dashboard showing the audit log for the transaction, and Stripe shows is was successful. The error appears to be on Anvil’s side, possibly in reading the Stripe response.
I don’t see any way to further investigate this error.
Code Sample:
from ._anvil_designer import pp_StripeTemplate
from anvil import *
import anvil.server
import stripe.checkout
import anvil.google.auth, anvil.google.drive
from anvil.google.drive import app_files
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
class pp_Stripe(pp_StripeTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
def button_one_time_payment_click(self, **event_args):
try:
charge = stripe.checkout.charge(
currency="USD",
amount=6500,
title="One-Time Payment",
description="Purchase of Pinpoint Matchups",
billing_address=False
)
if charge['result'] == 'succeeded':
print(charge)
alert("Payment successful!")
else:
print(charge)
alert("Payment failed.")
except Exception as e:
print(charge)
alert(f"Payment process was interrupted: {e}")
def button_subscription_click(self, **event_args):
# Initiating subscription payment via Stripe
subscription = stripe.checkout.subscribe(
plan="price_1QdyJzIwCDmer6CRlsLFK8lN",
title="Subscription Payment",
description="Annual Pinpoint Matchups Subscription",
billing_address=False
)
# Check subscription result
if subscription['result'] == 'succeeded':
print(subscription)
alert("Subscription successful!")
else:
print(subscription)
alert("Subscription failed.")