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()
Related
I'm trying to onboard a customer for a Stripe Express account by using the Stripe API. I create an account requesting the relevant capabilities, providing simple information like first name, last name and email, and the account is created successfully. I expected the Stripe website to come up to request the missing information from the customer (like DOB, bank account info,...), but instead, the account creation just finishes and the account is restricted due to the missing information. Do I have to redirect the user after checking what the status of the account is? What's the flow?
This is the start_onboarding() method of my teacher_us object:
// methods
function start_onboarding() {
// load Stripe library--- moved to the main plugin file
// require_once('..\vendor\autoload.php');
global $stripe_api_key;
$stripe = new \Stripe\StripeClient($stripe_api_key);
$stripe_account = $stripe->accounts->create([
'type' => 'express',
'country' => 'US',
'business_type' => 'individual',
'email' => $this->get_email(),
'individual' => [
'first_name' => $this->get_first_name(),
'last_name' => $this->get_last_name(),
],
'capabilities' => [
'transfers' => ['requested' => true],
'card_payments' => ['requested' => true],
],
]);
It seems that just calling this method doesn't make Stripe to collect the missing info. What am I missing?
This does not happen automatically. After creating the Express account, you must create an Account Link for Connect Onboarding, and redirect your user to the url it includes to go through the onboarding flow to provide the rest of the required information.
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
How to save card details in stripe payment gateway and use card details for next payment for particular user who entered the card details before
thank you
Before saving card you need to create customer first like below
Right now I am giving you an example with PHP language.
Creating customer :
$customer = \Stripe\Customer::create([
'name' => 'Test User',
'email' => 'cardtestuser#gmail.com',
'description' => 'My First Test Customer',
]);
You can refer the link for more detail : https://stripe.com/docs/api/customers/create
It will return the object with customer id e.g : cust_**** that you need to keep with you for later used else you can get it from Stripe dashboard.
Now we need to generate token for the card that we need to add to the customer that recently created in stripe
$token = \Stripe\Token::create([
'card' => [
'number' => '4242424242424242',
'exp_month' => 3,
'exp_year' => 2021,
'cvc' => '314',
],
]);
Above code return the card token e.g tok_*** that you need to use to save card to the customer
Here is the code to create new card to customer
\Stripe\Customer::createSource(
$customer->id,
['source' => $token->id]
);
You can save customeId(cust_###) and cardId(card_###) in database or somewhere else so you can use it later while making payment from card
Hope this will help you
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'
));
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'));