#Wayne-Tenaciousw
1 messages · Page 1 of 1 (latest)
Can you share the product id with me so I can further review this?
price_1NJKFSFiXzwG2LgbbKlnelzI
price_1NJKFfFiXzwG2LgbzDL2rmXY
price_1NJKFkFiXzwG2LgbIZKbOg3L
price_1NJKFwFiXzwG2LgbjkCrHpQW
its 4 products
monthly, 3 months, 6 months and yearly
this was the create session code I was using that was working before going to live mode
header('Content-Type: application/json');
$email = "wayne.allenfdsdfs.hs@gmail.com";
$channel = $_POST['channel'];
$key = $_POST['key'];
$tid = $_POST['tid'];
$YOUR_DOMAIN = 'https://twitch.so/public';
try {
$prices = \Stripe\Price::all([
// retrieve lookup_key from form data POST body
'lookup_keys' => [$_POST['lookup_key']],
'expand' => ['data.product']
]);
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
'price' => $prices->data[0]->id,
'quantity' => 1,
]],
'customer' => $customer->id,
'mode' => 'subscription',
'success_url' => $YOUR_DOMAIN . '/success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $YOUR_DOMAIN . '/../main.php?p=members',
'allow_promotion_codes' => true,
'subscription_data' => ["metadata" => ["channel" => $channel, "tid" => $tid, "key" => $key]],
],
);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}```
Yeah, in this case, it looks like you'd need update the prices, https://stripe.com/docs/api/prices/update#update_price-lookup_key. I'll provide this feedback to the team for future product reiterations.
@stable granite - making sure that you saw my response
instead of using a lookup key can I change it so my drop down on my previous page uses the product id instead?
Im guessing I would have to change this line $checkout_session = \Stripe\Checkout\Session::create([ 'line_items' => [[ 'price' => $prices->data[0]->id, 'quantity' => 1, ]],
Hmm, price_data, https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data is passed to generate a new price object.
I think you'd want to change the code above, https://stripe.com/docs/api/prices/list#list_prices-product and list the prices by that product id.
Then, pass that price id when creating the Checkout Session: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price
I think this seems to work, I just have to change the dropdown value to match the item ids
header('Content-Type: application/json');
$email = "wayne.allenfdsdfs.hs@gmail.com";
$channel = $_POST['channel'];
$key = $_POST['key'];
$tid = $_POST['tid'];
$YOUR_DOMAIN = 'https://twitch.so/public';
try {
$productId = $_POST['lookup_key'];
//print_r($productId);
//exit();
$price = \Stripe\Price::retrieve($productId);
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
'price' => $price->id,
'quantity' => 1,
]],
'customer' => $customer->id,
'mode' => 'subscription',
'success_url' => $YOUR_DOMAIN . '/success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $YOUR_DOMAIN . '/../main.php?p=members',
'allow_promotion_codes' => true,
'subscription_data' => ["metadata" => ["channel" => $channel, "tid" => $tid, "key" => $key]],
],
);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
``` fingers crossed it looks like it works now
Great to hear!
thank you for your help
Happy to help