0

I try to use Stripe to charge on behalf of someone. I did the connect part with success, but I tried to create a token/charge after that and it doesn't work.

Some info on parameters used in the code:

  • "acct_158fBBAOizDDfp9B" - Get from the Connect user;
  • WebConfig.AppSettings.StripeClientId - My client Id get from Stripe dashboard;
  • WebConfig.AppSettings.StripeSecretApiKey - My Stripe Secret API Key;
  • "sk_test_5E9d7UHs9CVa3Ansop2JzIxI" - Private API key get from Connect user.

Here is my code:

StripeRequestOptions requestOptions = new StripeRequestOptions();
requestOptions.StripeConnectAccountId = "acct_158fBBAOizDDfp9B"; 

var myToken = new StripeTokenCreateOptions();


myToken.Card = new StripeCreditCardOptions()
{
    // set these properties if passing full card details (do not
    // set these properties if you set TokenId)
    Number = "4242424242424242",
    ExpirationYear = "2022",
    ExpirationMonth = "10",
    AddressCountry = "US",                // optional
    AddressLine1 = "24 Beef Flank St",    // optional
    AddressLine2 = "Apt 24",              // optional
    AddressCity = "Biggie Smalls",        // optional
    AddressState = "NC",                  // optional
    AddressZip = "27617",                 // optional
    Name = "Joe Meatballs",               // optional
    Cvc = "1223"                          // optional
};

// set this property if using a customer (stripe connect only)
myToken.CustomerId = WebConfig.AppSettings.StripeClientId; // My client ID get from Stripe dashboard.               

//var tokenService = new StripeTokenService(WebConfig.AppSettings.StripeSecretApiKey);                
var tokenService = new StripeTokenService("sk_test_5E9d7UHs9CVa3Ansop2JzIxI");                
            StripeToken stripeToken = tokenService.Create(myToken, requestOptions);

I've got a «You must pass a valid card ID for this customer.» error.

Jonathan Anctil
  • 1,025
  • 3
  • 20
  • 44

1 Answers1

2

A couple things:

Since you're using Stripe Connect, you can only create tokens using Stripe.js or Stripe Checkout, your server should never have access to the card info. Also I don't know why you're setting the token's customerId to a client id, clients are not customers.

Also the API key should be your API key, since you're using the Stripe account header, the option is either (your API key and the account id of the connected account) or (access token). This is discussed in the authentication portion of the Stripe Connect documentation.

Matthew Arkin
  • 4,460
  • 2
  • 27
  • 28