I am working on an implementation of REST API for a mobile application which encapsulates feature of redemption of earned points in form of money equivalent to points using Stripe as a payment gateway .
To accomplish it I have used Stripe payout API to transfer amount directly into destination bank account.
Following is code snippet of call to payout API of Stripe
$payout=\Stripe\Payout::create(array(
"amount" => 400,
"currency" => "usd",
"destination"=>$ID,/* ID of customer bank account ba_1CIZEOCHXaXPEwZByNehIJrY */
"source_type"=>'bank_account'
));
Upon execution of above code snippet I receive error message as response to call of payout API
The bank account ba_1CIZEOCHXaXPEwZByNehIJrY is not attached to this
Stripe account. External accounts can only be attached to Standard
accounts via the dashboard.
According to above error message it seems that same bank account needs to be attached to both customer and connected stripe account but I am unable to find appropriate solution to attach customer's bank account to merchant as an external account.
Please suggest me an appropriate solution to it.
Actually you can use the Stripe payout API to initiate a payout to either a bank account or debit card of a connected Stripe account.However you can create a transfer , To send funds from your Stripe account to a connected account.
https://stripe.com/docs/api/transfers/create
Below is the php code :
\Stripe\Stripe::setApiKey("sk_test_AjtBCFvy8Ah0x5vLmd5Ntemi");
\Stripe\Transfer::create([
"amount" => 400,
"currency" => "usd",
"destination" => "acct_1CPuerJ18us5u9z6",
"transfer_group" => "ORDER_95"
]);
I have also searched stripe documentation , to directly transfer the payment in the third party card / bank account, but did not find anything.
With Stripe Connect, you can make API requests on behalf of connected accounts using the Stripe-Account header as documented here. This applies to any API requests from creating a Charge or a Payout to listing all Refunds.
This obviously assumes that you use Stripe Connect and that the person receiving funds from you has their own connected accounts. You also have to use Custom or Express accounts if you want to be able to control their Payouts. This is not allowed with Standard accounts.
The code would look like this:
$payout=\Stripe\Payout::create(array(
"amount" => 400,
"currency" => "usd",
"destination"=> "ba_XXXX" // bank account id
),
array(
"stripe_account" => "acct_XXXX" // id of the connected account
));
This obviously assumes that you are familiar with Stripe Connect and are actively using it. It would be the only way to handle this and you can read more about this feature here.
Related
I am trying to use stripe Direct Charges and it's working when user user new card (with token id).
Problem: When trying with save customer id and save card id. When i am trying to charge with custom-id and source=> save card id It's giving error customer not exist. But Both customer and card id exist.
$charge = \Stripe\Charge::create([
"customer" => $userdata->stripe_id,
"amount" => $amount,
"currency" => "usd",
"source" => $findcard['card_id'],
"application_fee" => $fee,
], ["stripe_account" => $talent_stripeid]);
Error: No such customer: cus_EOwmc6nVmU7oNu
I was getting the same error and when reached out to Stripe support got the following answer which helped me to solve the issue:
The error you are running into is happening because the customer
object is on the platform account, but when you add the
"Stripe-account" parameter to your charge request, you're moving the
command to the connected account, and so can't reach the customer
object.
To make the customer available, you'll need to share the customer to
the connected account. You'll basically create a token or source from
the customer object on your platform, and then share that with the
connected account, to process a payment, or to save locally, so the
connected account can use it directly.
https://stripe.com/docs/connect/shared-customers
Alternatively, you can keep the customer information on your platform
account and perform Destination charges, just sending to the connected
account "their share" of the proceeds:
https://stripe.com/docs/connect/destination-charges
I was wondering for a bit of clarification and help regarding Stripe.
Basically, I have the following:
//get the card token from the stripe request
$customerTok = request('stripeToken');
//create the customer with this token
$customer = \Stripe\Customer::create(array(
"email" => \Auth::user()->email,
"source" => $customerTok,
));
Where customerTok is the bank token passed by Stripe.js (entering their card number, cvc and exp date), and I'm creating the customer in my Stripe Dashboard.
$cardTok = \Stripe\Token::create(array(
"card"=>$customer->sources->retrieve(default_source),
));`
Then I grab a token for their card? (I think this is wrong but this is the principle?)
I now need to make them into a connect managed account (I need users to be able to pay each other, like eBay)
$account = \Stripe\Account::create(
array(
"country" => "GB",
"managed" => true,
"external_account"=>$customer->id,
));
Obviously this isn't production ready code, I'm just trying to understand the flow and if I'm understanding this correctly.. Can anyone explain why this isn't working right now and what I'm getting wrong?
Thanks,
Generally, you cannot retokenize payment information from saved customers (outside of specific scenarios).
Note also that Stripe can only do payouts to debit cards (not credit cards), and only in the US. In all other countries, Stripe can only do payouts to bank accounts.
If your platform's users are both buyers and sellers, you will need to create two different resources for each of them:
a customer object to act as a payment source (when the user buys something)
an account object to act as a payment destination (when a user sells something)
I recommend that you reach out to Stripe's support at https://support.stripe.com/email to explain your business model so that you can receive personalized advice for your integration.
The scenario is there are 3 users in our website, Admin, Sender and Receiver.
Sender send payments to Receiver, but in our website Sender not directly send the payment to Receiver, the amount holds on Admin Stripe account and after the confirmation Receiver receive the payment from Admin Stripe account. For this process I create a platform from Admin Stripe Account , now Sender and Receiver both are connected to that platform.
Below are the codes we are using:
Sender Send Payment To Admin Strip Account
\Stripe\Stripe::setApiKey("sk_test_ADMIN_KEY");
\Stripe\Charge::create(array(
"amount" => 400,
"currency" => "usd",
"source" => "tok_18uL5yIXv4Heg2KDdPHJFo8A", // obtained with Stripe.js
"description" => "Charge for abigail.white#example.com"
));
Receiver Receive Payment From Admin Stripe Account
\Stripe\Stripe::setApiKey("sk_test_ADMIN_KEY.....");
\Stripe\Charge::create(array(
'amount' => 400,
'currency' => 'usd',
'source' => $token,
'destination' => 'acct_...' //
));
and more all of three users have their stripe accounts, and on test mode all of three have $0 Available Balance. and Amount is not added to Receiver Stripe Account after using the above code.
When accepting payments on behalf of third-parties, you cannot hold funds on the platform's account ("Admin"). For compliance reasons, you must set the destination account when you create the charge.
\Stripe\Stripe::setApiKey("sk_test_..."); // platform's API key
\Stripe\Charge::create(array(
'amount' => 400,
'currency' => 'usd',
'source' => $token,
'destination' => 'acct_...' // connected account's ID
));
This will charge the customer (via the payment method in $token) and add the funds to the connected account's balance. Once the funds become available, they can be transferred account to the connected account's associated bank account.
Note that because this charge is created "through the platform" (i.e. with the destination parameter), the platform will pay Stripe's fees and be responsible for chargebacks and refunds (cf. here). Because there is no application_fee parameter, the platform will effectively lose money on this transaction, as it will pay for Stripe's fees but not receive anything.
If you're using managed accounts, then you (as the platform) are also in control of transfers to the associated bank account. You can read more about this here.
With standalone accounts, the platform does not have control over bank transfers -- instead, each standalone account's owner does, via their own account settings.
I'm trying to implement payments with Stripe, i'm using Stripe connect.
I'm reading documentation for "Charging through the platform" and it says:
\Stripe\Stripe::setApiKey(PLATFORM_SECRET_KEY);
\Stripe\Charge::create(array(
'amount' => 1000,
'currency' => 'gbp',
'source' => {TOKEN},
'destination' => {CONNECTED_STRIPE_ACCOUNT_ID}
));
I have the PLATFORM_SECRET_KEY, and the CONNECTED_STRIPE_ACCOUNT_ID (Obtained from oauth flow with stripe connect), but what is the needed TOKEN?
I have readed that a token can be obtained from a "stripe form", but what is the point to "connect" the stripe account if i need to request card data to my users?
Do I missed something from the flow?
Is there a way to create a token from the user account?
Do i need to create a customer?
Note: I'm newbie with stripe payments.
Stripe Connect is used to create charges on behalf of your users. Let's say you're a marketplace for example, you allow John to sell lamps online. Then, Alice comes and wants to buy a lamp from John on your website. You use the code you mentioned before to charge Alice and send the funds to John's account directly.
It looks like what you want here though is to charge Alice for yourself instead. Alice doesn't need a Stripe account in that case. You need to collect Alice's card details using Stripe Checkout or building your own form using Stripe.js. This will give your a card token tok_XXX that you then send to your server where you use it to create a charge through the API as explained in the charges tutorial.
As far as I understand, regarding the Stripe transfers, you are able to send money to a credit card / bank account, even if those isn't registered with Stripe.
Following their API, I've come up with below code to send money to a credit card:
$amount = inputFilter($_POST['amount']);
$amount = $amount*100;
$destination = "card_6WWSXFfQsZEc66"; //Card data is a test card
#$customer = \Stripe\Customer::retrieve($userdata["stripe_id"]);
$transfer = \Stripe\Transfer::create(array(
"amount" => $amount,
"destination" => $destination,
"description" => "test payment"
));
$event_id = $tranfer->id;
$event = \Stripe\Event::retrieve($event_id);
die($event);
The response I am getting from above PHP code is this:
The card card_6WWSXFfQsZEc66 is not attached to this Stripe account.
External accounts can only be attached to standalone Stripe accounts
via the dashboard.
Have I misunderstood something? Aren't you supposed to be able to transfer funds from your own Stripe account to standalone bank/credit cards?
As far as I understand, regarding the Stripe transfers, you are able to send money to a credit card / bank account, even if those isn't registered with Stripe.
Actually, you cannot send money to a credit card or bank account if it is not linked to a connected account.