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
Related
I am having an issue that Stripe will count a new customer even if the card is declined. I have not figured out a way to prevent Stripe from counting these users in their Dashboard. (Technically it is a NEW customer, but they have no active subscription or charge on their card.)
However, my web application handles these just fine and it just asks the user to put in their credit card information again due to a declined credit card.
try{
$cusresp = \Stripe\Customer::create(array(
"description" => "Customer $membertbl[email], $membertbl[name]",
"email" => $membertbl[email],
"source" => $striptoken // obtained with Stripe.js
));
}
If this response has no catch exceptions, I then use create subscription and proceed normally.
Even if I go to the dashboard and delete this customer, the Stripe Dashboard still counts them.
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.
Problem Statement:
My Customers will have subscriptions with various publishers that have created their projects. I have to attach a customer to platform account and create a subscription which charges them behalf of the Connect custom accounts.
So how can I make a shared customer and subscribe them to various subscriptions in a connect account.
Once you have that customer on your platform account, you can share them with a connected account by first creating a one-time use token:
$token = \Stripe\Token::create(array(
"customer" => "cus_xxxx",
), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
Once you have this token, you could (a) use it to create a charge to that customer that lands directly in the connected account, but since you want to create a subscription you want to (b) use the token to copy the customer into the connected account and then create a subscription in that connected account for the copied customer. To copy a customer from platform to connected account you can do the following:
$copiedCustomer = \Stripe\Customer::create(array(
"description" => "Customer for xxx#xxx.com",
"source" => $token // obtained with Stripe.js
), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
This copied customer now has a new customer id in the connected account. Then you can setup the subscription on the connected account as follows:
\Stripe\Subscription::create(array(
"customer" => $copiedCustomer.id,
"plan" => "xxx"
), array("stripe_account" => "{CONNECTED_STRIPE_ACCOUNT_ID}"));
Step 3 here mentions the above method for creating subscriptions for shared customers (but doesn't show the example, their example is a one-off charge for shared customers) https://stripe.com/docs/connect/shared-customers
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.
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.