#Chiko0401-checkout

1 messages · Page 1 of 1 (latest)

odd terrace
#

Hi! Is this a screenshot of a Checkout Session? Can you clarify what you are trying to do?

coarse kestrel
#

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

odd terrace
#

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.

coarse kestrel
#

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?

odd terrace
#

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.

coarse kestrel
#

Understand, but I need it to be embedded to our website

odd terrace
#

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.

coarse kestrel
#

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

odd terrace
#

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?

coarse kestrel
#

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

odd terrace
#

Got it! But what is the issue? Are you getting an error message, or some information is missing?

coarse kestrel
#

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?

odd terrace
coarse kestrel
#

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

odd terrace
#

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.

coarse kestrel
#

Ok. Is PaymentIntent more secure than CreateToken? Why is it better?

odd terrace
#

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.

coarse kestrel
#

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?

odd terrace
coarse kestrel
#

req_Sn8EKYLZpsTHYN

pulsar forge
#

Hello. Taking over for soma here. Give me a moment to catch up on context

coarse kestrel
#

Ok

pulsar forge
#

Since that is a GET request I can't view the response body. Can you paste it here?

coarse kestrel
#

{
"customer": "cus_LcxnS8NOc6uBDV",
"subscription_items": {
"0": {
"price": "price_1JJx7qGmVCU04B2t1G2gxzOc"
}
},
"automatic_tax": {
"enabled": "true"
},
"subscription_trial_end": "1651755855"
}

#

So I do next things:

#
  1. Create token - req_bBqKN2WXGU8Il2
pulsar forge
#

That's not the response body

#

That's the request's query params

coarse kestrel
pulsar forge
#

You would have to make the request again to see the response body

coarse kestrel
#

Is it okay now?

pulsar forge
#

Is what okay?

coarse kestrel
#

Response:

pulsar forge
#

Ah ok thanks

coarse kestrel
#

So with subscription_trial_end I see it:

#

But without this field it works properly:

#

So I do next things:

  1. Create token - req_bBqKN2WXGU8Il2
  2. Create user - req_UbUvjc6IAI2nI9
  3. Create upcoming invoice - req_Sn8EKYLZpsTHYN
pulsar forge
#

Ok thanks. Let me ask a colleague about this

coarse kestrel
#

Sure

pulsar forge
#

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?

coarse kestrel
#

No, it's before I'm creating subscription

#

I need to know tax rate calculation before I'm creating subscription

pulsar forge
#

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

coarse kestrel
#

But if i want to get all these fields

#

Ok. I got it