Jonathan Anctil
Jonathan Anctil

Reputation: 1037

Stripe.net - Try to charge on behalf

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:

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.

Upvotes: 0

Views: 1476

Answers (1)

Matthew Arkin
Matthew Arkin

Reputation: 4648

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.

Upvotes: 2

Related Questions