New Stripe Checkout

Anyone taken a look at this? Lots to like here, but it looks like it bounces to Stripe and back, which is problematic for Anvil and SPAs in general.

https://stripe.com/payments/checkout

Ideas, thoughts or plans at Anvil?

John

1 Like

I’ve used it with my current project, which uses a static site for the storefront with some Javascript calls out to Anvil endpoints to store orders. It works well, and I was able to integrate payouts to contractors into the Anvil backend.

I’m curious how you handled the stripe connected accounts for your contractors. Did you use the stripe library to create their accounts or did you use the standard method with callbacks? I’m trying to do this myself but I need to figure out how to handle callbacks.

I used the Stripe library, and made calls against that. No callbacks were involved.

A little more info now that I have some more time to type. Everything for the contractors is driven by actions they take in the Anvil app.

I store their Stripe connected account id in their users record. If that isn’t there, then they’re shown a button to connect to it. That button just creates the account on Stripe:

  import stripe
  stripe.api_key = anvil.secrets.get_secret("stripe_key")
  
  result = stripe.Account.create(
    type="standard",
    country="US",
    email=user['email'],
  ) 

Then there’s the onboarding process where they need to setup that account. If their user record has a Stripe account id, but the flag that tells me if it’s ready or not says it isn’t, then I get the link for them to go to to setup their Stripe account:

    # They're not quite finished, so Get the onboarding link so they can 
    # go back and try again
    account_link = stripe.AccountLink.create(
      account=user['stripe_author_account'],
      refresh_url=APP_URL+'#authors/profile',
      return_url=APP_URL+'#authors/profile',
      type='account_onboarding',
    )
    
    profile_info['stripe_url'] = account_link['url']

I detect if their account is ready by keeping a flag in the user record, and checking the charges_enabled field on the Stripe account itself:

    account = stripe.Account.retrieve(user['stripe_author_account'])
    
    if account['charges_enabled']:
      user['stripe_author_account_ready'] = True

Those are all the pieces. It works well in test mode, but I haven’t released it into the wild yet.

Forgot about the actual payout to contractors. After all the error checking (do they have a Stripe account, is it ready, have they been paid enough to request a payout, etc), actually transferring money to them boils down to this call:

    transfer = stripe.Transfer.create(
      amount=int(amount),
      currency="usd",
      destination=author['stripe_author_account'],
      metadata={
        'email': author['email']
      }
    )

1 Like

Very informative! This is exactly what I have been working on. Nice method for keeping a flag in the user record, i’ll implement that for sure. The callbacks I referred to in a previous post was the refresh_url and the return_url. Stripe Onboarding suggests that both these urls are linked to specific functions but your method almost seems easier. I may just implement an else statement that directs the user back into the onboarding process if the account is not ready.

Glad to hear it! If @jshaffstall’s answers have been helpful for your Stripe question, don’t forget to mark one of them as a Solution :smile:

I’m looking into Stripe Checkout now… but between the integration with Anvil and adding the relevant Javascript to the Native Library, I haven’t quite got it to work successfully.

Considering @junderhill’s original post was not really addressed (sidetracked by using Stripe to pay out contractors directly), a solution may still be desired. Would anyone be willing to share a bare bones sample code of Anvil integrating Stripe Checkout? Perhaps something that implements this:

https://stripe.com/docs/billing/subscriptions/checkout/fixed-price