#thehollytoats_code

1 messages ¡ Page 1 of 1 (latest)

merry sonnetBOT
prisma mapleBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

merry sonnetBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1243450523781300226

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

blissful kraken
#

hello! can you share an example Checkout Session id?

finite knot
#

// Set your secret key
\Stripe\Stripe::setApiKey($stripeSecretKey);

// Function to get the 'mac' metadata associated with a session ID
function get_info_from_session($session_id, $key) {
try {
// Retrieve the Checkout Session from Stripe using the session ID
$checkout_session = \Stripe\Checkout\Session::retrieve($session_id);

    // Get the metadata associated with the session
    $metadata = $checkout_session->metadata;

    // Check if 'mac' metadata exists in the session metadata
    if(isset($metadata[$key])) {
        // 'mac' metadata exists, retrieve it
        $order_id = $metadata[$key];
        return $order_id;
    } else {
        return null; // 'mac' metadata not found
    }
} catch(Exception $e) {
    echo "error";
    // Handle any errors
    return null;
}

}

// Check if session_id parameter is provided in the URL
if(isset($_GET['session_id'])) {
global $woocommerce;
$woocommerce->cart->empty_cart();

// Retrieve session ID from the URL parameter
$session_id = $_GET['session_id'];

// Get the 'mac' metadata associated with the session
$order_id = get_info_from_session($session_id, 'oid');
$mac = get_info_from_session($session_id, 'mac');
$quantity = get_info_from_session($session_id, 'qtt');
//need to get the card owner as the customer name is empty
//?? ask stripe

}

#

I call that php file as part of the return_url in checkout session:

$checkout_session = $stripe->checkout->sessions->create([
'ui_mode' => 'embedded',
'line_items' => [[
'price_data' => [
'currency' => $currency,
'unit_amount' => $cart_total * 100, // Amount in cents ($10.00)
'product_data' => [
'name' => $content, // Replace with your product name
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'metadata' => ['oid' => $order_id, 'mac' => $mac, 'qtt' => $quantity],
'return_url' => $YOUR_DOMAIN . 'pay_auth_ok.php?session_id={CHECKOUT_SESSION_ID}',
'automatic_tax' => [
'enabled' => true,
'liability' => [ 'type' => 'self'],
//'liability' => [ 'type' => 'account', 'account' => $connected_account_id],
],
'payment_intent_data' => [
'setup_future_usage' => 'off_session',
'capture_method' => 'manual',
'transfer_data' => array(
'destination' => $connected_account_id, // Charge the connected account
'amount' => $cart_total *100 - $application_fee_amount,
),
]
]);

blissful kraken
#

the Checkout Sessions id is an id with the prefix cs_test

finite knot
#

Yes, one i have, for example is cs_test_a10COkx3u1KqENo...

blissful kraken
#

i need the full id

finite knot
#

cs_test_a10COkx3u1KqENoOWnp0kjUuzYDbwsFlyBeqzVgwt8j2KH34S09bCH9JeH

blissful kraken
#

gimme a while to take a look

#

assuming you have the Checkout Session object, you need to make another request to retrieve the corresponding PaymentIntent : https://docs.stripe.com/api/payment_intents/retrieve, and expand the https://docs.stripe.com/api/payment_intents/object#payment_intent_object-payment_method. See https://docs.stripe.com/api/expanding_objects for more details on how to expand