1
votes

I am trying to implement an Application fee on all transactions sent through a Stripe charge. I have created a stripe platform and connected an account to it however whenever I add the application fee to the charge it doesn't come up in stripe dashboard.

The following code works and makes a charge to the platform.

Stripe::setApiKey("sk_test_#platformcode");

Stripe_Charge::create(
 array(
  "amount" => 10000,
  "currency" => "usd",
  "source" => $_POST['stripeToken'],      
 ));

This code also works. It sends the entire charge to the connected account and charges the platform the stripe fees.

Stripe::setApiKey("sk_test_#platformcode");

Stripe_Charge::create(
 array(
  "amount" => 10000,
  "currency" => "usd",
  "source" => $_POST['stripeToken'],
  "desitnation" => 'acct_#connectedaccountid'     
 ));

But the following doesn't work even though its from the stripe website.

Stripe::setApiKey("sk_test_#platformcode");

Stripe_Charge::create(
 array(
  "amount" => 10000,
  "currency" => "usd",
  "source" => $_POST['stripeToken'],
  "application_fee" => 1000   
 ),array("stripe_account" => 'acct_#connectedaccountid'));

This code returns and tells the website that the payment was made but when I check stripe its never there in either account and not in collected fees.

Further info: the token uses the platform's pk_test#platformcode.

4
UPDATE: The system was not producing an error like it should. It now is. The error I get is The second argument to Stripe API method calls is an optional per-request apiKey, which must be a string. (HINT: you can set a global apiKey by "Stripe::setApiKey()")Jahax

4 Answers

0
votes

Using the destination parameter allows you to create a charge through the platform's account. In this case, the platform will pay Stripe's fees and is responsible for refunds and chargebacks.

\Stripe\Stripe::setApiKey({PLATFORM_SECRET_KEY});
\Stripe\Charge::create(array(
  'amount' => 10000,
  'currency' => 'usd',
  'application_fee' => 1000,
  'source' => $_POST['stripeToken'],
  'destination' => {CONNECTED_STRIPE_ACCOUNT_ID}
));

Authenticating as the connected account, you can create a charge directly on it:

\Stripe\Stripe::setApiKey({PLATFORM_SECRET_KEY});
\Stripe\Charge::create(
  array(
    'amount' => 10000,
    'currency' => 'usd',
    'application_fee' => 1000,
    'source' => $_POST['stripeToken']
  ),
  array('stripe_account' => {CONNECTED_STRIPE_ACCOUNT_ID})
);

In both these examples, {PLATFORM_SECRET_KEY} is the platform's secret API key (starts with sk_) and {CONNECTED_STRIPE_ACCOUNT_ID} is the ID of the connected account (starts with acct_).

If the second sample doesn't work for you, you might want to make sure you're using the latest version of the Stripe PHP bindings.

0
votes

You should charge the destination charges similar to this

Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"

charge = Stripe::Charge.create({
  :amount => 1000,
  :currency => "usd",
  :source => "tok_visa",
  :destination => {
    :amount => 877,
    :account => "{CONNECTED_STRIPE_ACCOUNT_ID}",
  }
})

This is working solution for ruby. Refer this link to understand more about the flow of funds between connected account and platform account

0
votes

Generally, stripe support the application fee in this case. The service doesn't get the fee directly. When a customer send money to another customer by using a service(or host site) that using stripe for transaction, the there will be 2 kind of fees should be exist.

First kind of fee is produced for the stripe. Another kind of fee is produced for the service(host site).

So that the service(host site) could get profit from customers.

First I recommend you to check out this url: https://stripe.com/docs/connect/direct-charges

And it says: "Charges created directly on the connected account are only reported on that account; they aren’t shown in your platform’s Dashboard, exports, or other reporting, although you can always retrieve this information via the API."

-1
votes

Fixed: Post the answer here for future people using application fee on Stripe as I couldn't find the answer anywhere.

Code is below. But the main problem is you shouldn't use the connect account ID. You should be using the sk_test_#code# that was generated when connecting the accounts together. It is not the platform or connect users sk_test_#code#. It is the code generated by Oauth when the user connects with stripe platform. There is also a modification to the code.

Stripe::setApiKey("sk_test_#platformcode");

Stripe_Charge::create(
 array(
  "amount" => 10000,
  "currency" => "usd",
  "source" => $_POST['stripeToken'],
  "application_fee" => 1000   
 ), sk_test_#connectioncode'));