#Killbotdba-Checkout
1 messages · Page 1 of 1 (latest)
Hi there, your code looks good to me, this is the correct way to set a metadata to a CheckoutSession.
ok great, now the trouble I'm having is on the success page
do you have an example of how I can call that metadata?
So you want to retrieve the metadata in the success page?
yes that's correct
basically the user is just going to pay for a new subscription to the site
and I need to pass through their unique ID from my admin site to the success page
Got it, I believe this doc should help you https://stripe.com/docs/payments/checkout/custom-success-page#modify-success-url
that way I can write a SQL update to update the DB so they are current
yes I found this
and I tried it and it didn't work
Basically you can add a session_id={CHECKOUT_SESSION_ID}" to the end of the success page URL, and Stripe will attach the checkout session ID as one URL query param
ok let me show you the error
one sec
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Slim\App::__construct(), 0 passed in /var/www/vhosts/mflhistory.com/httpdocs/success.php on line 13 and at least 1 expected in /var/www/vhosts/mflhistory.com/httpdocs/vendor/slim/slim/Slim/App.php:61 Stack trace: #0 /var/www/vhosts/mflhistory.com/httpdocs/success.php(13): Slim\App->__construct() #1 {main} thrown in /var/www/vhosts/mflhistory.com/httpdocs/vendor/slim/slim/Slim/App.php on line 61
And what's on line 133 of /var/www/vhosts/mflhistory.com/httpdocs/success.php?
OK, it seems like there's a problem in the way your code handles the request. To this point the Stripe related code isn't executed yet.
yes I'm not sure what's going on
could it be something to do with slim?
I've put the code in my success.php just like this
<?php
// This example sets up an endpoint using the Slim framework.
// Watch this video to get started: https://youtu.be/sGcNPFX1Ph4.
require 'vendor/autoload.php';
use Slim\Http\Request;
use Slim\Http\Response;
use Stripe\Stripe;
$app = new \Slim\App;
$app->add(function ($request, $response, $next) {
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('###');
return $next($request, $response);
});
$app->get('/order/success', function (Request $request, Response $response) {
$session = \Stripe\Checkout\Session::retrieve($request->get('session_id'));
$customer = \Stripe\Customer::retrieve($session->customer);
return $response->write("<html><body><h1>Thanks for your order, $customer->MFLHistoryID!</h1></body></html>");
});
$app->run();```
Please remove the secret key from the code that you pasted
discord is a public place, everyone can see what you wrote in thread
ok done
$app->add(function ($request, $response, $next) {
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('###');
return $next($request, $response);
});
I'm not familiar with Slim, what's the purpose of $app->add here?
This is literally in the code sample you sent me...
I'm not familiar with Slim either but it's used here
on the PHP tab
Can you refer to this video https://youtu.be/sGcNPFX1Ph4. to setup the project?
In this edition of Stripe Developer Office Hours, follow along as CJ Avilla walks through the fundamentals of PHP with Slim.
Resources
- Slim web framework http://www.slimframework.com/
- curl command line tool https://curl.haxx.se/
- phpdotenv https://github.com/vlucas/phpdotenv
- Stripe Webhooks Guide https://stripe.com/docs/webhooks/bui...
Yes. I'll be here
Alternatively you can use this sample code to setup your project without the need of using slim framework https://github.com/stripe-samples/accept-a-payment/tree/main/prebuilt-checkout-page/server/php
Learn how to accept a payment from customers around the world with a variety of payment methods. - accept-a-payment/prebuilt-checkout-page/server/php at main · stripe-samples/accept-a-payment
ok I'm back
I'm going to look at that link
one sec
atal error: Uncaught Error: Call to a member function retrieve() on null in /var/www/vhosts/mflhistory.com/httpdocs/success.php:11 Stack trace: #0 {main} thrown in /var/www/vhosts/mflhistory.com/httpdocs/success.php on line 11
what's on line 11?
$checkout_session = \Stripe\Checkout\Session::create([```
Are you using the sample code from github?
I see I'm missing that line from github
If you are using the github sample code, make sure you run composer install to install the dependencies
ok let me start from scratch
Fatal error: Uncaught Error: Class 'Dotenv\Dotenv' not found in C:\wamp64\www\MFLhistory\shared.php:26 Stack trace: #0 C:\wamp64\www\MFLhistory\create-checkout-session.php(2): require_once() #1 {main} thrown in C:\wamp64\www\MFLhistory\shared.php on line 26
lol this is actually getting more confusing
Does composer install succeeded?
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
7 packages you are using are looking for funding.
Use the `composer fund` command to find out more!```
I had the checkout page working and now I've got nothing working... seems like I'm going backwards
https://github.com/stripe-samples/accept-a-payment/tree/main/prebuilt-checkout-page/server/php#how-to-run did you follow the readme file and setup the .env file?
Learn how to accept a payment from customers around the world with a variety of payment methods. - accept-a-payment/prebuilt-checkout-page/server/php at main · stripe-samples/accept-a-payment
yes I did that
it didn't work
there must be a different way
The way I was doing it before creates a session
I don't know why I can't get it back
require '../vendor/autoload.php';
// This is your test secret API key.
\Stripe\Stripe::setApiKey('##');
header('Content-Type: application/json');
$YOUR_DOMAIN = 'http://www.mflhistory.com';
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => 'price_1LYCH2Ks11D5pGt5Dd6Yda8g',
'quantity' => 1,
]],
'mode' => 'subscription',
'success_url' => $YOUR_DOMAIN . '/success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
'metadata' => ['MFLHistoryID' => '12'],
'automatic_tax' => [
'enabled' => true,
],
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
?>```
This works in calling checkout and the Session is being created
I don't know why there isn't a more straightforward way of getting the metadata on the success paghe
https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/php/public/success.php this sample file shows you how to retrieve the checkout_session, and you can get the metadata from it
Learn how to accept a payment from customers around the world with a variety of payment methods. - accept-a-payment/success.php at main · stripe-samples/accept-a-payment
https://github.com/stripe-samples/accept-a-payment/blob/main/prebuilt-checkout-page/server/php/public/success.php#L5 it's in the code that I shared earlier. Add this line to get the metadata
$metadata = $checkout_session->metadata