#Chiko0401-checkout
1 messages · Page 1 of 1 (latest)
Hi! Is this a screenshot of a Checkout Session? Can you clarify what you are trying to do?
Yes. On our old website we used to forward our users to Stripe Checkout page. Now on our new website we want to display it on our website, include all these tax values
So you want to stop using Checkout Session, and instead use Subscriptions + Payment Element? Note that we recommend merchant to use Checkout Session since it's a lot simpler to implement.
I used something like this:
$stripe = new \Stripe\StripeClient('');
$token = $stripe->tokens->create([
'card' => [
'name' => 'Nickolay Gubkin',
'number' => '4242424242424242',
'exp_month' => 4,
'exp_year' => 2023,
'cvc' => '314',
'address_line1' => '2801-2899 N 24th St',
'address_zip' => '19019',
'address_city' => 'philadelphia',
'address_state' => 'Pennsylvania'
],
]);
$customer = $stripe->customers->create([
'email' => 'nickolayg@kidas.net',
'name' => 'Nickolay Gubkin',
'source' => $token
]);
$invoice = $stripe->invoices->upcoming([
'customer' => $customer->id,
'subscription_items' => [
['price' => 'price_1JJx7qG...xzOc'],
],
'automatic_tax[enabled]' => true,
'subscription_trial_end' => strtotime("+1 days")
]);
$stripe->subscriptions->create([
'customer' => $customer->id,
'items' => [
['price' => 'price_1JJx7q...G2gxzOc'],
],
'trial_period_days' => 30,
'coupon' => 'TestCoupon'
]);
So, is it called Subscription + Payment?
Checkout Session means a user will be forwarded to a Stripe Page?
I see a few issues with your code.
Checkout Session means a user will be forwarded to a Stripe Page?
Yes, Checkout Session is the Stripe hosted payment page, that we recommend using.
What you should do if you don't want to use Checkout Session if follow this guide: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
Understand, but I need it to be embedded to our website
Understand, but I need it to be embedded to our website
Then yes you should use Subscription + Payment Element. Please look at the link I shared above.
I looked. It's almost what I did. I collect user card information, create token from it, then create customer and then create subscription for this customer
My problem that for to know tax rate I need to use this function:
$invoice = $stripe->invoices->upcoming([
'customer' => $customer->id,
'subscription_items' => [
['price' => 'price_1JJx7qG...xzOc'],
],
'automatic_tax[enabled]' => true,
'subscription_trial_end' => strtotime("+1 days")
]);
So, it means I can't know tax rate without creating user before. It's weird
create token from it
We don't recommend to use token, this is an old API. Instead you should use PaymentIntent as mentioned in the link I shared
So, it means I can't know tax rate without creating user before. It's weird
What do you mean?
I want to do something simple - I need to send price, trial end and promocode , and as a response to get Subtotal, Sales Tax, Total after trial, Total due today
Got it! But what is the issue? Are you getting an error message, or some information is missing?
As I already told you, I don't understand why I need to create Customer object for retrieving it?
Like here
$invoice = $stripe->invoices->upcoming([
'customer' => $customer->id,
'subscription_items' => [
['price' => 'price_1JJx7qG...xzOc'],
],
'automatic_tax[enabled]' => true,
'subscription_trial_end' => strtotime("+1 days")
]);
Why I can't know tax rate without creating customer?
To use automatic tax, Stripe needs to know information about your customer. Because the location of the customer will impact how to compute tax.
This is explained here: https://stripe.com/docs/tax/customer-locations
But how it works in a Stripe window?
look at here. I didn't create customer here. Only provided billing address
Actually, I provided here billing address, price, coupon and trial. That's it
Is it hidden API that I can't use
Yes Checkout Session is easier to implement: it directly asks the customer to enter their billing address in order to compute the tax.
If you don't want to use Checkout Session, then you need to create the customer yourself with a valid location, otherwise automatic tax can't work.
Ok. Is PaymentIntent more secure than CreateToken? Why is it better?
There is some information mentioned here https://stripe.com/docs/api/tokens
You should use our recommended payments integrations to perform this process client-side. This ensures that no sensitive card data touches your server, and allows your integration to operate in a PCI-compliant way.
Another question. When I'm using this code:
$invoice = $stripe->invoices->upcoming([
'customer' => $customer->id,
'subscription_items' => [
['price' => 'price_1JJx7qG...xzOc'],
],
'automatic_tax[enabled]' => true,
'subscription_trial_end' => strtotime("+1 days")
]);
It doesn't work properly. It displays tax=0, but when I remove subscription_trial_end, it works properly and also tax looks good.
Maybe you know why it can happen?
Can you share the requests ID (req_xxx)? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_Sn8EKYLZpsTHYN
Hello. Taking over for soma here. Give me a moment to catch up on context
Ok
Since that is a GET request I can't view the response body. Can you paste it here?
{
"customer": "cus_LcxnS8NOc6uBDV",
"subscription_items": {
"0": {
"price": "price_1JJx7qGmVCU04B2t1G2gxzOc"
}
},
"automatic_tax": {
"enabled": "true"
},
"subscription_trial_end": "1651755855"
}
So I do next things:
- Create token - req_bBqKN2WXGU8Il2
- Create user -
You would have to make the request again to see the response body
Is it okay now?
Is what okay?
Ah ok thanks
So with subscription_trial_end I see it:
But without this field it works properly:
So I do next things:
- Create token - req_bBqKN2WXGU8Il2
- Create user - req_UbUvjc6IAI2nI9
- Create upcoming invoice - req_Sn8EKYLZpsTHYN
Ok thanks. Let me ask a colleague about this
Sure
When you call $invoice = $stripe->invoices->upcoming([ 'customer' => $customer->id, 'subscription_items' => [ ['price' => 'price_1JJx7qG...xzOc'], ], 'automatic_tax[enabled]' => true, 'subscription_trial_end' => strtotime("+1 days") ]);
Does the customer used above have an existing subscription?
No, it's before I'm creating subscription
I need to know tax rate calculation before I'm creating subscription
Ok so when including the subscription_trial_end parameter with that call, on a customer that doesn't have a subscription already, a zero dollar invoice is returned (the first one for the fresh sub since my customer didn't have anything existing), so the tax would also be 0. You can see the amount is also 0 in your screenshot
If you need to know tax, just don't pass subscription_trial_end