1
votes

I am building a platform where I am using Stripe's concept of a parent "platform" account and Connected Stripe accounts that belong to this platform. (e.g. Lyft model) Following Stripe's documentation, when I create a new customer in Stripe, I create it under the main platform account and also store all the payment methods under that customer. When a customer buys something from the Connected account, I follow this doc, where I clone payment method and create a PaymentIntent that is attached to the specific Connected account. And it all works. However, when I try to get a history of customer's transactions (List of PaymentIntents), it returns an empty list because it runs it against the main platform account:

stripe.PaymentIntent.list(customer='cus_FJDHFGSJHDF')

When I specify a customer AND connected account id, it returns an empty list, because that customer doesn't exist in that Connected account, however, the paymentIntents are present in that Connected account.

So, what is the right way to create a PaymentIntent for a customer for a Connected account and then get the history of payments for that customer PER Connected Stripe account?

Here is how I clone PaymentMethod and create PaymentIntent:

payment_method = stripe.PaymentMethod.create(
        customer=customer,
        payment_method=customer.invoice_settings.default_payment_method,
        stripe_account=stripe_connect_id,
    )


    intent = stripe.PaymentIntent.create(
        payment_method=payment_method,
        amount=amount,
        currency='usd',
        confirm=True,
        application_fee_amount=fee_in_cents if fee_in_cents >= 1 else None,
        stripe_account=stripe_connect_id,
    )
2

2 Answers

2
votes

As far as I can see you have 2 options:

  1. Create the Customers on the connected Account and create charges there, then you have the relationship [0].
  2. Save the customer id in metadata of the PaymentIntent and then reconcile them in your code [1].

Hope that helps!

[0] https://stripe.com/docs/connect/cloning-saved-payment-methods#making-a-charge

[1] https://stripe.com/docs/api/metadata

1
votes

Here is the approach I decided to take. Since I specifically was interested in pulling Charges that the specific customer made in the specific Connected account, I've read up more on Charges and noticed that you can get a list of charges based on transfer_group='{ORDER10}'. So, here is my flow:

  • Customer and customer's payment methods are stored under the main platform account (so that I can keep track of the current default payment method in one place)
  • When a customer makes a payment to a specific Connected account, I clone their default payment method
  • Create a PaymentIntent and set transfer_group to the customer's phone number as it is a unique identifier throughout my platform.

Now, when I need to pull all charges for a specific customer, I loop through each Connected account that the customer is associated with (this relationship is stored on my platform) and simply pull all Charges using transfer_group and stripe_account_id:

def get_all_charges(user, stripe_account_id):
     return stripe.Charge.list(transfer_group=user.phone_number, stripe_account=stripe_account_id, limit=100).data