cartalyst / stripe-laravel

Cartalyst Stripe package integration for Laravel.
BSD 3-Clause "New" or "Revised" License
335 stars 57 forks source link

Creating a charge with application fee in a connected account #29

Closed kezern closed 7 years ago

kezern commented 7 years ago

I have successfully create a charge to a connected account to my connect platform with this code. $stripe = Stripe::make('');

    $charge = $stripe->charges()->create([
        'currency' => 'EUR',
        'amount'   => 100,
        'source' => "tok_es",
        "application_fee" => 1,
    ],[
        'stripe_account' => '<connected account id>'
    ]);

It works fine. But I have a problem when I try to add an application fee. I'm trying this code.

  $stripe = Stripe::make('<test key>');

    $charge = $stripe->charges()->create([
        'currency' => 'EUR',
        'amount'   => 100,
        'source' => "tok_es",
        "application_fee" => 1,
    ],[
        'stripe_account' => '<connected account id>'
    ]);

I get following error.

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).

How can I collect application fees?

Best regards

brunogaspar commented 7 years ago

Just use the accountId() method when using connected accounts.

Our methods doesn't accept headers to be set like that.

kezern commented 7 years ago

Sorry I don't understand what you are saying. How should I use that method?

brunogaspar commented 7 years ago
$stripe->accountId('connected-account-id-here')->charges()->create([ .. ]);
kezern commented 7 years ago

Hi Brunogaspar, I'm getting this error with that code.

Call to undefined method Cartalyst\Stripe\Api\Account::charges()

brunogaspar commented 7 years ago

It's accountId() instead of account(), i updated my example.

kezern commented 7 years ago

Thank you! that worked! I only have one question. with the first code, I can see the payment in my own account. If I use the second method, the payment appears only in the payment section of the connected account. Is that normal?

brunogaspar commented 7 years ago

Yes, in this situation it's normal and expected.

This is very well explained here.