To use Anvil's Stripe wrapper, *must* I create a Stripe Customer?

It’s there in every example. But after skimming Stripe’s documentation, that seems like overkill.

I want to accept a payment. But if I must create and manage additional customer-specific data, in order to do so, then that adds more behind-the-scenes responsibilities to my business.

Is there a way to accept a payment without having to create a persistent Stripe Customer object?

Hi @p.colbert,

Yes, you can accept payments without creating a persistent “Customer” object in Stripe using Stripe’s Python API.

Taking the code from your previous forum post, you could accept a payment without creating a customer by adding these lines:

token, user_info = stripe.checkout.get_token( 
    currency='USD', 
    amount=2495, 
    title='DARMA(tm) by InjAnnuity, Inc.',
    description='DARMA(tm) 30-day Voucher',
    raw=True
)
anvil.server.call('charge', token)

The Server Function is as follows:

@anvil.server.callable
def charge(token):
  charge = stripe.Charge.create(
    currency='USD', 
    amount=2495, 
    description='DARMA(tm) 30-day Voucher',
    source=token
  )

Much appreciated, @bridget .

After much internal debate, I’m going to go ahead and create a Stripe Customer. It should help me manage data in my Stripe Dashboard.

Charging thru a Stripe Customer created another problem, this time, procedural in nature.

We can create a Customer from their first payment Token. But on a subsequent payment Token, the first card may be nearing nearing a limit, so they may elect to use a different credit card, the next time get_token() is called. This possibility raises two issues:

  1. When the card is different, then obviously we should add that new payment Token to that Customer. But because payment Tokens are opaque, we have no way of knowing whether this is the case, or not. So we don’t know whether to add that payment Token to the Customer, or not. (This is one of the maintenance responsibilities implied in my original post.)
  2. If we ignore the payment Token, and instead charge the Customer directly (like we did immediately after creating them), then we would be charging the previously-entered card. But if the new payment Token is for a different card, then we’d be charging the wrong card. Obviously, we mustn’t do that.

In light of the above, it seems that the only sensible thing to do is to always charge the payment Token directly, as in your example above, not through a Stripe Customer.

In future Stripe-related documentation, these are issues that probably should be addressed.