#damonstrr
1 messages · Page 1 of 1 (latest)
maybe i should paste my full code??
$response = app('stripe')->checkout->sessions->create([
'payment_method_types' => ['card'],
'amount_subtotal' => 1000,
'amount_total' => 1000,
'mode' => 'subscription',
'line_items' => [
[
'price_data' => [
'currency' => 'usd',
'unit_amount' => $plan->price->getAmount(),
'product_data' => [
'name' => $productName,
],
'recurring' => ['interval' => $plan->abbreviation],
],
'quantity' => 1,
],
],
'subscription_data' => [
'application_fee_percent' => 10,
'metadata' => [
'post_id' => $latestPost->id,
'user_id' => $blog->user->id,
'user_email' => $blog->user->email,
'name' => $plan->abbreviation,
'reader_id' => Auth::user()->id,
'price_id' => $plan->stripe_price_id,
'product_id' => $plan->stripe_product_id,
]
],
'client_reference_id' => Auth::user()->id,
'success_url' => route('blog.checkout.success', ['blog' => $blog->name, 'plan' => $plan->slug]),
'cancel_url' => route('blog.post.show', [$blog->name, 'post' => $latestPost->slug]),
'metadata' => [
'post_id' => $latestPost->id,
'user_id' => Auth::user()->id,
'name' => $plan->abbreviation
],
'customer_email' => Auth::user()->email,
], [
'stripe_account' => $stripeAccount,
]);
Those fields are in the line_items array, you currently are passing those fields in in the wrong place https://stripe.com/docs/api/payment_links/payment_links/object#payment_link_object-line_items-data-amount_subtotal
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I did that too but i still get error
Received unknown parameters: amount_total, amount_subtotal
Apologies, wrong link and wrong info
$response = app('stripe')->checkout->sessions->create([
'payment_method_types' => ['card'],
'mode' => 'subscription',
'line_items' => [
[
'amount_subtotal' => 1000,
'amount_total' => 1000,
So those are results of what you pass in
When actually creating the session, you supply prices and quantities https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-unit_amount
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So you don't directly say that the amount total is $10, you include items and then Stripe calculates that their total is $10 and outputs that in the Checkout Session object that is created
yeah but how do i display it on the checkout??
It will automatically be displayed on the page
Can you send me a screenshot of what you are seeing? The total shows up for me in test mode
That’s what I’m seeing
Also I want to add google pay but couldn’t add google_pay to payment method
It shows $10 in the upper left of the page. What are you looking for it to say?
If you only have one subscription item, we won't show sub-items. It looks like you only have one $10 item so we are only showing the total
Try your code again but with two items in the line items array:
[
'price_data' => [
'currency' => 'usd',
'unit_amount' => $plan->price->getAmount(),
'product_data' => [
'name' => $productName,
],
'recurring' => ['interval' => $plan->abbreviation],
],
'quantity' => 1,
],
[
'price_data' => [
'currency' => 'usd',
'unit_amount' => $plan->price->getAmount(),
'product_data' => [
'name' => 'Another product',
],
'recurring' => ['interval' => $plan->abbreviation],
],
'quantity' => 1,
],
],```
how about the google pay?? is that possible to add?
Also when i check my customer.subscription.created after checkout session has been completed the productId and Priceid seems to be different from the one inside the product in stripe dashboard
It should be possible to add Google Pay. Can you send me the ID of a Checkout Session so that I can look in to why Google Pay did not show up? (cs_test_1234)
You are using price_data and product_data which create new ad-hoc product objects. If you want to use the price and product from your dashboard, you should pass the price's ID (price_1234) into the price parameter instead of using price_data
cs_test_a1yVKW52iy4g4I2MuptENgkzz4h7oprbqxQwXa1LNOcC5gy0MEzSWrOKOw
so that will go inside the line_items.data.price right ??
Correct
And thank you for the ID, we will check in to that
Ah, so google pay shows up for me when I go to that checkout link
So the issue is that you don't have Google Pay set up on your current device/browser
So make sure you are logged in to Google and can see a clickable GPay button at the top of this doc
https://stripe.com/docs/stripe-js/elements/payment-request-button
Google has a suite of test cards if you want to add them to your wallet instead of real cards
https://developers.google.com/pay/api/android/guides/resources/test-card-suite
but when i visit other platform i see it but anyways i did this
'line_items' => [
[
'price' => [
'id' => $plan->stripe_price_id,
'currency' => "usd",
// 'unit_amount' => $plan->price->getAmount(),
'recurring' => [
'interval' => $latestMonthlyPlan->abbreviation
],
],
``` but i get this error ```Invalid string: {:recurring=>{:interval=>"month"}, :id=>"price_1NhzWYRPCk44sUIFp1otPaVA", :currency=>"usd"}```
Did you check the other platform on the same device in the same browser? I can see GPay on your same Checkout Session so it should be visible if you have the proper setup on this device
how about the other question??
Unsure about the invalid string, that looks to be a local php error, not one that Stripe is throwing
Can you try changing or removing each of those parameters to see if one makes the error go away?
this works by the way
alright let me do that
i have done that but i still get that same error unsure why
??
Hi 👋
I'm taking over as @eternal drift has to go.
Can you set your line_items to their own variable and log them before attempting to create the Checkout Session?
i did that
[
'price' => [
'id' => $plan->stripe_price_id,
'currency' => "usd",
// 'unit_amount' => $plan->price->getAmount(),
'recurring' => [
'interval' => $latestMonthlyPlan->abbreviation
],
],```
Invalid string: {:recurring=>{:interval=>"month"}, :id=>"price_1NhzWYRPCk44sUIFp1otPaVA", :currency=>"usd"}
Is that separate from when you are creating a Checkout Session? What is the full code for creating the session?
hold on let me send now
'payment_method_types' => ['card'],
'mode' => 'subscription',
'line_items' => [
[
'price' => [
'id' => $plan->stripe_price_id,
'currency' => 'usd',
'unit_amount' => $plan->price->getAmount(),
'recurring' => [
'interval' => $latestMonthlyPlan->abbreviation
],
],
'quantity' => 1,
],
],
'subscription_data' => [
'application_fee_percent' => 10,
'metadata' => [
'post_id' => $latestPost->id,
'user_id' => $blog->user->id,
'user_email' => $blog->user->email,
'name' => $plan->abbreviation,
'reader_id' => Auth::user()->id,
'price_id' => $plan->stripe_price_id,
'product_id' => $plan->stripe_product_id,
]
],
'client_reference_id' => Auth::user()->id,
'success_url' => route('blog.checkout.success', ['blog' => $blog->name, 'plan' => $plan->slug]),
'cancel_url' => route('blog.post.show', [$blog->name, 'post' => $latestPost->slug]),
'metadata' => [
'post_id' => $latestPost->id,
'user_id' => Auth::user()->id,
'name' => $plan->abbreviation
],
'customer_email' => Auth::user()->email,
], [
'stripe_account' => $stripeAccount,
]);```
Okay so you are not doing what I said
I asked you to set the line items as their own variable and print them out before you attempt to create a Checkout Session
Like
$line_items = [....]
oh my bad
$line_items = [
[
'price' => [
'id' => $plan->stripe_price_id,
'currency' => 'usd',
'unit_amount' => 1000,
'recurring' => [
'interval' => $latestMonthlyPlan->abbreviation
],
],
'quantity' => 1,
],
];
dd($line_items);
``` and
array:1 [▼ // app/Http/Controllers/Blog/Post/PostController.php:153
0 => array:2 [▼
"price" => array:4 [▼
"id" => "price_1NhzWYRPCk44sUIFp1otPaVA"
"currency" => "usd"
"unit_amount" => 1000
"recurring" => array:1 [▼
"interval" => "month"
]
]
"quantity" => 1
]
]
If you have the price ID you don't need to rest of that information
You can see an example in our API reference docs: https://stripe.com/docs/api/checkout/sessions/create?lang=php
$stripe->checkout->sessions->create([
'success_url' => 'https://example.com/success',
'line_items' => [
[
'price' => 'price_H5ggYwtDq4fbrJ',
'quantity' => 2,
],
],
'mode' => 'payment',
]);