Jump to content

PHP Stripe subsection


geatzo

Recommended Posts

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;

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

$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}}'

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.