14
votes

I am trying to collect an application fee using the Stripe API. I am sure I am missing something in the request.

Stripe complaints that it needs either of these: OAuth key, the Stripe-Account header, or the destination parameter.

I am passing in the Stripe-Account header.

Could you please point me into the right direction?

Here is my curl request:

curl https://api.stripe.com/v1/charges \
    -u sk_test_<key>: \
    -H "Stripe-Account: acct_<key>" \
    -d amount=2000 -d currency=usd -d capture=true \
    -d card=tok_<key> -d description="curl" -d application_fee=48

Here is the response I get:

{
  "error": {
    "type": "invalid_request_error",
    "message": "Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter).",
    "param": "application_fee"
  }
}
2
Are you passing your own account id as the platform here? If so, can you try connecting a new account to the platfor, instead? - koopajah
99% of the time, that error happens when you try to charge your own platform and pass the account id acct_XXX of the platform in the Stripe-Account header. - koopajah
@koopajah It was the cause of my problem too. I created a new account (with a new email address) on Stripe, and then it was okay. - The Onin
This is a common testing-environment issue that should absolutely be explained in the Stripe documentation... - Flo Schild
I also encountered this issue, it was caused by me using the same account as the platform and the customer. - user2320239

2 Answers

9
votes

To add my experience of this issue to the comments above – when you include an application fee in the request, Stripe expects that you will be charging a customer on behalf of a connected account. The application fee is the amount that should go to your platform account, as your fee for the service you provide.

Stripe throws this error if it believes that the account being paid is the platform account, and therefore it makes no sense to process a separate application fee to the same account. Ways this can happen include passing in your platform account number instead of a connected account number in the request, or a destination parameter that is set to null.

The solution is to double check the account you are making payment to is not your platform account, or not include the application fee if the charge is going to your platform. I would add a link to the relevant part of the documentation, but I'm not aware of this being covered anywhere.

3
votes

This happened to me when I accidentally had a nil value for the recipient's stripe account number.

The solution was to make sure destination was a valid stripe account code: e.g. "acct_1HtSHv7fgYVxT5fZ"

    Stripe.api_key = 'sk_test_4eC39kjhkhgkhlhj1zdp7dc'

    payment_intent = Stripe::PaymentIntent.create({
      payment_method_types: ['card'],
      amount: @amount_minor_unit,
      currency: @currency,
      application_fee_amount: 123, 
      transfer_data: {
        destination: @stripe_account,
      },
    })

Stripe::InvalidRequestError (Can only apply an application_fee_amount when the
PaymentIntent is attempting a direct payment (using an OAuth key or Stripe-Account header)
or destination payment (using `transfer_data[destination]`).)

Once I had the correct value for @stripe_account (instead of nil), the above code worked