Charging an account in Stripe - php

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.

Related

How to creating Paypal connected(seller onboarding before payment) account using API?

I want to create seller onboarding account before payment(connected account under master payal business account). For that we using below API to connect customer and create account.
https://developer.paypal.com/docs/platforms/seller-onboarding/before-payment/
After creating seller account we want to process MOTO payment (Telephony payment) into that seller account. Therefore we need API username, password and signature to process payment using Paypal API and process MOTO payment to that account.
Can you please help us to achieve this kind of functionality using Paypal API's.
Thanks
Onboarding requires being an approved PayPal partner, so you'll have to contact PayPal about this. Unless you do hear back with an approval and further guidance, any attempt to use onboarding APIs in production will result in a 401 Unauthorized response.
Username, Password, and Signature are used by the old legacy classic APIs. You should not be integrating with classic APIs, but rather the current PayPal REST APIs, such as v2/checkout/orders, which use a clientid and secret. If you need a seller's credentials, the way to get them is to ask. They can obtain them via an App in the "Live" tab of https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications , and copy them to your interface. You should then try to obtain an access token to verify that the credentials are valid, and prompt the user to re-enter valid credentials if they are not.

Stripe Creating Direct Charges to connect account

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

Transfer amount into customer's bank account using Stripe Payout API

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.

Stripe Connect and Managed Accounts

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.

Stripe- Send Payment to Customers

I want to use STRIPE PHP API for creating payments to customers and for that i have found the code to create the customers but not for to create payment for them.
Code to create customers:
https://stripe.com/docs/api#create_customer
require_once('./lib/Stripe.php');
Stripe::setApiKey("sk_test_k9NE13Q2LjsIvYTNQHiP5C5H");
Stripe_Customer::create(
array( "description" => "Customer for test#example.com",
"card" => "tok_1509ycG2gfbJDdl3oYWMe6yq" // obtained with Stripe.js
));
My Scenario is : I have some products and customers comes to my site and purchase the product but some of the customers will come from the affiliate banner and we need to pay some commission amount to the affiliate customers.
So, for such scenario i have to create customers and create payment for them and i have found PHP API code for creating the customers but not for the creating payment to that customers.
As I understand, you should use Stripe managed accounts for your customers to make Payouts.
https://stripe.com/docs/connect/managed-accounts
https://stripe.com/docs/connect/payouts
You'll need to collect additional customer verification data to make payouts to managed accounts:
https://stripe.com/docs/connect/identity-verification
https://stripe.com/docs/connect/updating-accounts#account-verification
https://stripe.com/docs/connect/required-verification-information
https://stripe.com/docs/connect/testing-verification
I think your problem here is that you're misunderstanding the customer option in the stripe dashboard.
A typical use would be you register a customer and once you've done that you can charge their card as required, i.e., they are still sending you money, which I believe isn't what you want.
Two options I can see for you.
It's possible to transfer money from your Stipe account to a 3rd party bank account or credit card. See stripe transfers and also this FAQ
Alternatively there is a now Stripe Connect which might just be the ticket for you.
Good luck!

Categories