Application Fee on Stripe Charge - stripe-payments

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.

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.

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

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

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'));

Related

Place a hold on the credit card and charge using Stripe paymentIntent

I want to build the process below
When a client presses the Book button, we need to place a hold on the credit card for the amount of the transaction
I think the hold does not charge the card, ie the money does not leave the card
The hold just checks that the money is available and reserves it for a few days
Within these 7 days, I call another API to complete the charge, to cancel the hold, or just let the hold expire.
If a client books an appointment, the money goes on hold and then, after a day or so, he cancels, the hold should be released
I checked the Stripe API doc, but I am not sure how to do this process.
I think it must to using the paymentIntent API.
Please explain to me what process I must do.
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET_KEY'));
$getPaymentMethod = $stripe->paymentMethods->all([
'customer' => $request->customerId,
'type' => 'card',
]);
$createIntent = $stripe->paymentIntents->create([
'amount' => $request->price * 100,
'currency' => 'usd',
'payment_method' => $getPaymentMethod->data[0]->id,
'payment_method_types' => [$request->paymentType],
'customer' => $request->customerId,
'capture_method' => 'manual',
'description' => 'The payment of the appointment',
]);
$confirmPaymentIntent = $stripe->paymentIntents->confirm(
$createIntent->id,
['payment_method' => $getPaymentMethod->data[0]->id]
);
$captureIntent = $stripe->paymentIntents->retrieve($confirmPaymentIntent->id);
$results = $captureIntent->capture($confirmPaymentIntent->id);
return $results;
I tried this code so it is working and the payment capture.
But it didn't charge the money on the stripe and the balance is $0.00.
I am not sure it is correct and how to do next step for complete.
Please help me. what should I?

Testing manual confirmation of Stripe's PaymentIntent

I am trying to write tests for the new SCA Stripe integration using Elements & their API. I am stuck testing the manual confirmation of a PaymentIntent.
I am able to create the PaymentIntent. Usually it returns a client_secret that is then used with Stripe.js handleCardAction() which then returns a PaymentIntent id that I can confirm using PaymentIntent::retrieve().
Since my tests are running on the PHP-side I am not able to fire the handleCardAction() and if I skip that step and use the client_secret I get this exception:
Stripe\Exception\InvalidRequestException : No such payment_intent: pi_1FFIp5HU59FHbUqraBNXk9Br_secret_agKRuHJx4y83RFnjpKkGmd29W
How do I get a PaymentIntent ID that is ready for confirmation without using Stripe.js?
Apparently I could just use
$intent = PaymentIntent::create([
'payment_method' => 'pm_card_threeDSecure2Required',
'amount' => 1000,
'currency' => 'USD',
'description' => 'blabla',
'confirmation_method' => 'manual',
'confirm' => true,
]);
// $intent->id can be used with PaymentIntent::retrieve()

The provided key does not have access to account in stripe

This is my stripe code in which I receive the error
The provided key does not have access to account in stripe
\Stripe\Stripe::setApiKey('sk_test_...');
$fees=($request->amount*10)/100;
$fees=$fees*100;
$withfee = \Stripe\Charge::create(
array(
"amount" => 10000,//1000, //$amount amount in cents
"currency" => "usd",
"source" => "tok_1BGovzDnnXvdHsSaayDkULRU",//'tok_18L6hjL6useUrEYbtObKz15s',
//$token
"description" => "Example charge",//"Example charge", //$title
"application_fee" => 1000 // amount in cents //$fees
),
array("stripe_account" => "cus_Be21HSwLO1XMhF" ) // $acc_token
);
You are passing a customer ID ("cus_...") in the stripe_account field.
When processing a charge with Connect, you need to provide the ID of the account ("acct_...") on behalf of which you are processing the charge. Customers are payment sources (i.e. they provide funds) while accounts are payment destinations (i.e. they receive funds).

Stripe Checkout and Customer Creation

I was having some difficulties figuring out how to add a customer and card with no charge to Stripe using the API where I think I came across a solution that seems to work but am not sure if I am creating issues that I cannot see.
What I am doing is using the Checkout option with strip and in my charge.php file I am deleting the below code so that no charge is made:
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 5000,
'currency' => 'usd'
));
I am only keeping the below code:
$customer = \Stripe\Customer::create(array(
'email' => 'customer#example.com',
'source' => $token
));
As far as I can tell, the customer is being created, I can use that customer data to charge the card in the future and no charge is being made to the card when they submit the form.
Am I missing something here?
As per the documentation here https://stripe.com/docs/charges#saving-credit-card-details-for-later - it's possible to store the customer's card details for a future date.
Using the following will store the customer and their card details for later:
$customer = \Stripe\Customer::create(array(
'email' => 'customer#example.com',
'source' => $token
));
Nothing else is needed. When you get ready to charge the customer in the future, you'll fetch their data (via their customer ID), and then run the following code:
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 9999,
'currency' => 'usd'
));

Stripe API transfer to Bank Account

Does anyone know how to transfer to a bank account using Stripe API?
In the Stripe Reference it looks very simple: https://stripe.com/docs/api/python#create_transfer
stripe.Transfer.create(
amount=400,
currency="usd",
destination="acct_19MKfXGyOv0GIG6Z",
description="Transfer for test#example.com"
)
I don't understand where the destination id comes from. How can I get the destination id of a bank account?
Thanks
There are two types of transfers with Stripe:
internal transfers, from a Stripe platform account to one of its connected accounts. This is known as a "special-case transfer".
external transfers, from a Stripe account to its associated bank account.
If you only have a single bank account for a given currency, you can use the special value "default_for_currency" for the destination parameter.
E.g. if you run this code:
stripe.Transfer.create(
amount=400,
currency="usd",
destination="default_for_currency",
description="Transfer for test#example.com"
)
then $4.00 would be sent to your USD bank account.
EDIT: On newer API versions (>= 2017-04-06), "internal transfers" are now simply known as "transfers", and "external transfers" are now known as "payouts". Cf. this doc page for more information.
I have to use the below code in my existing project
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
// Create a Charge:
$charge = \Stripe\Charge::create([
'amount' => 1300,
'currency' => 'GBP',
'customer' => 'cus_FM5OdvqpYD7AbR', // customer id
'transfer_group' => date('y-m-d_h:i:s'),
'transfer_data' => [
'destination' => 'acct_1EuyLUIpWjdwbl8y', // destination id
'amount' => 700
]
]);
dd($charge);
https://stripe.com/docs/connect/custom-accounts
this above link will let you know how to get bank account id
stripe.accounts.create({
country: "US",
type: "custom"
}).then(function(acct) {
// asynchronously called
});
you can get
this code will give acc. id in response that you can use in destination.

Resources