#Killbotdba-Checkout

1 messages · Page 1 of 1 (latest)

tidal kindle
#

Hi there, your code looks good to me, this is the correct way to set a metadata to a CheckoutSession.

blissful jetty
#

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?

tidal kindle
#

So you want to retrieve the metadata in the success page?

blissful jetty
#

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

tidal kindle
blissful jetty
#

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

tidal kindle
#

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

blissful jetty
#

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

tidal kindle
#

And what's on line 133 of /var/www/vhosts/mflhistory.com/httpdocs/success.php?

blissful jetty
tidal kindle
#

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.

blissful jetty
#

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();```
tidal kindle
#

Please remove the secret key from the code that you pasted

#

discord is a public place, everyone can see what you wrote in thread

blissful jetty
#

ok done

tidal kindle
#
$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?

blissful jetty
#

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

tidal kindle
blissful jetty
#

ok I watched that video already...

#

I'm going out for 15 will you still be here?

tidal kindle
#

Yes. I'll be here

blissful jetty
#

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

tidal kindle
#

what's on line 11?

blissful jetty
#
$checkout_session = \Stripe\Checkout\Session::create([```
tidal kindle
#

Are you using the sample code from github?

blissful jetty
#

I see I'm missing that line from github

tidal kindle
#

If you are using the github sample code, make sure you run composer install to install the dependencies

blissful jetty
#

ok let me start from scratch

blissful jetty
#

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

tidal kindle
#

Does composer install succeeded?

blissful jetty
#
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

tidal kindle
blissful jetty
#

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

tidal kindle
blissful jetty
#

ok I can pass the session ID in the URL

#

now how do I retrieve it

#

wait wait

tidal kindle
blissful jetty
#
View CheckoutSession response:

    "metadata": {
        "MFLHistoryID": "12"
    },```
#

yes!

#

I think it's working

#

I just took out all the other stuff

#

This is the value when I echo the $metadata

#

Stripe\StripeObject JSON: { "MFLHistoryID": "12" }