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).
Related
I am using ngx-stripe (frontend) and stripe-php (backend) and trying to create a Subscription for a Customer
I have successfully implemented a card element on the frontend, which calls stripe-php to create PaymentIntent. Before the PaymentIntent is created, I use the submitted information to create a Customer
Checking the successful payment in Stripe I can see the created customer attached to the payment and the payment has a payment method but if I check the customer, it shows as no payment method attached so I cannot create a Subscription for the customer
Create customer:
$this->stripeClient->customers->create([
'name' => $customer->getName(),
'description' => $customer->getDescription(),
'email' => $customer->getEmail()
]);
Create payment intent:
$paymentIntent = $this->stripeClient->paymentIntents->create([
'customer' => $customerId,
'amount' => $amount,
'currency' => $currency,
'payment_method_types' => ['card']
]);
Which Stripe API methods(s) do I need to call to instruct Stripe to create a payment method for the customer using the submitted details?
If you’re using stripe.confirmCardPayment [0] to confirm the PaymentIntent, you can include setup_future_usage = off_session [1].
stripe.confirmCardPayment(clientSecret, {
setup_future_usage : 'off_session',
payment_method: {
card: card,
billing_details: {
name: 'Jenny Rosen'
}
}
...
Including the setup_future_usage parameter will attach the payment method to the Customer, if present, after the PaymentIntent is confirmed and any required actions from the user are complete.
off_session indicates that your customer may or may not be present in your checkout flow. This is especially important for Subscriptions where your Customers are usually not available to make recurring payments on-session.
However, note that you don't need to create a PaymentIntent for a Subscription. You could save the card on the Customer for future use [2], then create the Subscription by passing in the Customer [3] and default payment method [4].
[0]https://stripe.com/docs/js/payment_intents/confirm_card_payment
[1]https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-data-setup_future_usage
[2]https://stripe.com/docs/payments/save-and-reuse
[3]https://stripe.com/docs/api/subscriptions/create#create_subscription-customer
[4]https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method
I'm currently trying to create charges with the server side stripe api.
But i'm facing a problem; I'm using two ways to proceed with the paiement:
either the user can pay using the stripe element => I'm therefore using the generated token ('tok_somethingId') to effectuate the paiement
or, if the user already added some cards on is account he can select on of them in a list => The server then use the card id ('card_somethingId') and the customer id ('cus_smoethingId')
I was wondering if there was a way to generate a token with a card id and a customer id in order to use this token to create the charge instead of using the card id and the customer id to charge the user.
I already tried with https://stripe.com/docs/api/node#create_card_token but it doesn't seem to work.
stripe.tokens.create({
card: cardId,
customer: customerId
}, function(err, token) {
// do smthg here with the token
});
This give me this error message
If you are doing payment with stored card then no need to get token,
1- Create customer on stripe
$customer = \Stripe\Customer::create([
'email' => $customer_email,
]);
$response = ['status' => 'success', 'response' => $customer];
when you have created customer then you have customer_id
if(isset($response ['response']['id']))
$response ['customer_id'] = $response ['response']['id'];
2 - you can add card on stripe by the customer id and card token
$customer = \Stripe\Customer::retrieve($customer_id);
$creditCard = $customer->sources->create(array("source" => $cardToken));
$response = ['status' => 'success', 'response' => $creditCard];
Now you have card id like this
"id": "card_1D4plsDExLRkbD8k1UWdqwIr"
3- you can store multiple cards on customer and also can have retreive
$cards = \Stripe\Customer::retrieve($customer_id)->sources->all(array(
"object" => "card"
));
4 -you can payment via card card that is stored on customer account
$params = [
'currency' => 'USD',
'amount' => $total_amount * 100,
// converting dollars to cents
'description' => $description, //it may be blank
'customer' => $customer_id,
"card" => $card_id'
];
$transaction = \Stripe\Charge::create($params);
$response = ['status' => 'success', 'response' => $transaction['id']];
Here we are not using 'source' parameter because it is used when we are payment via card token.
You can not create a new token for an existing card as this would not make sense. The card is already saved on the customer and you can charge it.
The easiest solution here is likely to do the reverse and save the card on a customer when you get a token tok_XXXX. This way, you always charge a card by passing the customer parameter as the customer id cus_XXXX and the source parameter as the card id card_XXXX.
Otherwise, you need to handle this dynamically so that you know if you are getting a token (tok_XXXX) or a card id (card_XXXX) and pass different parameters based on that decision. Your front-end code should know which case you ended up in.
just pass the values in the body,
[{"key":"amount","value":"1000","description":""},{"key":"currency","value":"usd","description":""},{"key":"customer","value":"cus_ID","description":""},{"key":"description","value":"\"Charge for jenny.rosen#example.com\"","description":""},{"key":"card","value":"card_ID","description":""}]
this working for me
I am using stripe.js with php and I am having issue in creating token for existing/saved cards and for new card everything works fine. Is there any function to generate token based on cardId and customerId
It is neither necessary nor possible to create a new token from an existing Customer or Card object. Once a card has been stored on a Customer object, you can complete a charge using only your secret key and the Customer ID. From the docs:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Token is created using Stripe.js or Checkout!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
// Create a Customer:
$customer = \Stripe\Customer::create(array(
"email" => "paying.user#example.com",
"source" => $token,
));
// Charge the Customer instead of the card:
$charge = \Stripe\Charge::create(array(
"amount" => 1000,
"currency" => "usd",
"customer" => $customer->id
));
// YOUR CODE: Save the customer ID and other info in a database for later.
// YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
$charge = \Stripe\Charge::create(array(
"amount" => 1500, // $15.00 this time
"currency" => "usd",
"customer" => $customer_id
));
If you have any other questions about how to implement a particular payment flow on Stripe I'd recommend getting in touch with Stripe support.
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.
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'));