Rory McCrossan
Rory McCrossan

Reputation: 337560

How to create a direct charge by using a shared customer?

I am attempting to create a direct charge to a connected account from my platform. I have been advised by Stripe support to do this by using a shared customer, however that has just created more issues.

The code itself is very simple, if it worked. It updates the platform customer with the src_... token provided by an iOS app. This works. It then attempts to create a shared customer using the StripeTokenService(). This does not work, despite following the documentation to the letter. The error I receive is:

You provided a customer without specifying a source. The default source of the customer is a source and cannot be shared from existing customers.

I can see no method of providing a source to the shared customer in the Stripe .Net SDK. All I can provide is a Card or BankAccount, neither of which I want to do as the API should remain agnostic of sensitive user information.

What exactly am I doing wrong here?

StripeConfiguration.SetApiKey(Settings.Stripe.SecretKey);
var businessRequestOptions = new StripeRequestOptions { StripeConnectAccountId = businessOwner.StripeAccountId };

var customerService = new StripeCustomerService();
customerService.Update(userDetail.StripeCustomerId, new StripeCustomerUpdateOptions
{    
  SourceToken = stripeToken // = 'src_...'
});

var tokenService = new StripeTokenService();
// this is the call that generates the error I mentioned above \/ \/ 
var token = tokenService.Create(new StripeTokenCreateOptions
{
  CustomerId = userDetail.StripeCustomerId // = 'cus_...'
}, businessRequestOptions);

// create a direct charge to the business account (taking out application fee)
var chargeService = new StripeChargeService();
var stripeCharge = chargeService.Create(new StripeChargeCreateOptions
{
  Amount = Convert.ToInt32(fee),
  Currency = currency,
  Description = $"Payment to {businessOwner.BusinessName} through Service X",
  ApplicationFee = applicationFee,
  SourceTokenOrExistingSourceId = token.Id, // use shared customerId here
}, businessRequestOptions);

Upvotes: 2

Views: 843

Answers (1)

koopajah
koopajah

Reputation: 25552

When using Sources you have to use a different approach which is documented here: https://stripe.com/docs/sources/connect#shared-card-sources

The idea is that you are going to "clone" the Source from the platform to the connected account. This is done using the original_source when creating a new Source. You will then get a new Source object with a different id src_XXXX that you can then charge directly on the connected account.

Upvotes: 4

Related Questions