2

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);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • Try passing in the Source ID through the `card`-parameter. I *think* that will fix your problem? If that still fails, try attaching a Token (eg. tok_xxx) to the Customer rather than a Source (eg. src_xxx). This might be because your Card objects are getting wrapped in Source objects, which aren't supported in the Shared Customer model. – korben Jul 12 '18 at 17:16
  • Thanks for the response @korben. Unfortunately the `card` parameter only accepts a `StripeCreditCardOptions` object which requires card number, address details etc. which I do not have. All I receive is the `src_...` string from the mobile app. – Rory McCrossan Jul 13 '18 at 09:42

1 Answers1

4

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.

koopajah
  • 23,792
  • 9
  • 78
  • 104
  • Thank you for the response. This was what Stripe support told me to try, however the issue is that I'm using their .Net SDK and that has no 'customer'. You can see this in the source of the StripeSourceCreateOptions object: https://github.com/stripe/stripe-dotnet/blob/master/src/Stripe.net/Services/Sources/StripeSourceCreateOptions.cs – Rory McCrossan Jul 13 '18 at 09:48
  • Also note that the `OriginalSource` property was only added to the SDK 12 hours ago, and has not yet been included in the release version – Rory McCrossan Jul 13 '18 at 09:51
  • @RoryMcCrossan it was released earlier today: in 17.2.0: https://github.com/stripe/stripe-dotnet/blob/master/CHANGELOG.md#1720---2018-07-13 – koopajah Jul 13 '18 at 13:57
  • So it was. Nuget is still showing 17.1 only. In either case there's still no `Customer` property, despite what the API documentation states – Rory McCrossan Jul 13 '18 at 13:59
  • @RoryMcCrossan you don't need the `customer` parameter in this case, it works without it but Stripe will push a new version soon after they fix the release for that one I think – koopajah Jul 13 '18 at 16:09
  • Stripe just pushed 17.3.0 which should appear shortly on Nuget! – koopajah Jul 13 '18 at 16:43
  • 3
    Apologies for the late reply. Your answer was the correct approach. Stripe customer support were telling me that I needed a Shard customer, not source, and after several days of back and forth with failing request and incomplete SDK problems I tried your solution and it worked first time! I should have just done that :) thanks again – Rory McCrossan Jul 20 '18 at 07:54