geatzo Posted May 13, 2023 Share Posted May 13, 2023 I have made a stripe checkout which works great but now i need to change my coding so instead of a 1 time payment i need it to create a subsection ive been reading though stripe and it states i can not set a dynamic price ? I have to create a new plan inside the panel and set a price. But i need it so the user can set the price there selling for, $lineItems = [ [ 'price_data' => [ 'currency' => 'usd', 'product_data' => [ 'name' => 'ice', ], 'unit_amount' => 9.99 * 100, // convert to cents 'tax_behavior' => 'exclusive' ], 'quantity' => 1 ], [ 'price_data' => [ 'currency' => 'usd', 'product_data' => [ 'name' => 'ice2', ], 'unit_amount' => 11.99 * 100, // convert to cents 'tax_behavior' => 'exclusive' ], 'quantity' => 2 ], [ 'price_data' => [ 'currency' => 'usd', 'product_data' => [ 'name' => 'Tip (not taxed)', ], 'unit_amount' => 5 * 100, // convert to cents ], 'quantity' => 1, ] ]; // Create Stripe checkout session $checkoutSession = $stripe->checkout->sessions->create([ 'line_items' => $lineItems, 'mode' => 'payment', 'success_url' => 'https://dfgdfgfgd.com/paypal/checkout-success.php?provider_session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'https://dfgfdg.com/paypal/cart.php?provider_session_id={CHECKOUT_SESSION_ID}' ]); // Retrieve provider_session_id. Store in database. //$checkoutSession->id; // Send user to Stripe header('Content-Type: application/json'); header("HTTP/1.1 303 See Other"); header("Location: " . $checkoutSession->url); exit; Quote Link to comment Share on other sites More sharing options...
requinix Posted May 13, 2023 Share Posted May 13, 2023 Last time you asked about this, on our Discord as well as StackOverflow, and I believe you made a thread too, people pointed you to the API documentation. I'm reading through it right now and I don't see anything that says you cannot use custom prices for subscriptions. I do see really obvious ways to specify (1) that the checkout session is for a subscription, and (2) what price you want on each item. Have you even tried creating a (test) subscription with a custom price yet? Or are you just assuming that it's not possible? Quote Link to comment Share on other sites More sharing options...
geatzo Posted May 15, 2023 Author Share Posted May 15, 2023 On 5/13/2023 at 10:44 PM, requinix said: Last time you asked about this, on our Discord as well as StackOverflow, and I believe you made a thread too, people pointed you to the API documentation. I'm reading through it right now and I don't see anything that says you cannot use custom prices for subscriptions. I do see really obvious ways to specify (1) that the checkout session is for a subscription, and (2) what price you want on each item. Have you even tried creating a (test) subscription with a custom price yet? Or are you just assuming that it's not possible? Ive looked at the tutorials they all say i need to add a plan id in the script then the plan id is used to get the price from the stripe dashboard but i need a custom price Quote Link to comment Share on other sites More sharing options...
geatzo Posted May 15, 2023 Author Share Posted May 15, 2023 $stripe = new \Stripe\StripeClient(STRIPE_SECRET_KEY); // The price ID passed from the front end. // $priceId = $_POST['priceId']; $priceId = '123'; $stripe->prices->all(['product' => '{{prod_NtsRaD5NAgvE4T}}', 'active' => true]); $session = \Stripe\Checkout\Session::create([ 'success_url' => 'https://example.com/success.html?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'https://example.com/canceled.html', 'mode' => 'subscription', 'line_items' => [[ 'price' => '123', // For metered billing, do not pass quantity 'quantity' => 1, ]], ]); this is what ive coded now im getting No such product: '{{prod_NtsRaD5NAgvE4T}}' Quote Link to comment Share on other sites More sharing options...
requinix Posted May 15, 2023 Share Posted May 15, 2023 4 hours ago, geatzo said: Ive looked at the tutorials they all say i need to add a plan id in the script then the plan id is used to get the price from the stripe dashboard but i need a custom price If the tutorial is telling you to do something you don't want to do then why are you using the tutorial? Tutorials are not documentation. Try reading the documentation. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.