#mangeshsm_webhooks
1 messages ¡ Page 1 of 1 (latest)
đ 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/1303710293767098438
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Which webhook event(s) are you describing? checkout.session.completed?
charge.succeeded
if($event_type === 'charge.succeeded'){
try
{
$charge = $event->data->object;
// Retrieve the Payment Intent to access metadata and discounts
if (isset($charge->payment_intent)) {
$paymentIntentId = $charge->payment_intent;
$paymentIntent = \Stripe\PaymentIntent::retrieve($paymentIntentId);
$file = fopen('stripe_webhook_log', "a");
$data = PHP_EOL . 'System Webhook paymentIntent >>>>>>>>>>>>>>>>>>>> >>>> : ' . print_r($paymentIntent,true);
fwrite($file, $data);
fclose($file);
// Access the metadata and promo code if available
$promoCode = isset($paymentIntent->metadata->promotion_code) ? $paymentIntent->metadata->promotion_code : null;
if ($promoCode) {
// Process the promo code as needed, e.g., log it or apply further actions
error_log("Promo code applied: " . $promoCode);
} else {
error_log("No promo code found in metadata.");
}
}
$coupon = \Stripe\Coupon::create([
'amount_off' => 9900,
'currency' => 'usd',
'duration' => 'once',
'id' => 'WOV-' . $event['data']['object']['id'],
'name' => 'Words Of Veterans E-Gift',
'metadata' =>[]
]);
$promotion = \Stripe\PromotionCode::create([
'coupon' => $coupon->id,
'max_redemptions' => 1,
]);
send_e_gift_voucher_mail($email,$promotion->id);
fyr
Then yes, charge.succeeded will always fire whenever there's a successful payment on your account regardless of how it's made
any ways to identify if payment is coming from payment link buttton and another if from session checkout
i have troed to pass metadata too but not getting in either in payload or in events
How are you setting metadata?
$checkout_session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => $line_items,
'mode' => 'payment',
'success_url' => $_ENV['SITE_BASE_URL'] . '/book-printing/',
'cancel_url' => $_ENV['SITE_BASE_URL'] . '/book-printing/',
// 'metadata' => ['promotion_code' => $promo_code],
['metadata' => ['promotion_code' => 'xxxxxxxxxxxxxxxxx']],
'discounts' => $promo_code ? [[
'promotion_code' => $promo_code,
]] : [],
]);
If you set the metadata on the PI it should pass through to payment_intent.* events: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
charge.* events are generally not recommended. Use checkout.session.* or payment_intent.*
but on console i never got these
i did console of whole event too
in that never find that
Never find what?
You need to use a different parameter as I just linked
Right now you're setting it on the Checkout Session, so it's only available in checkout.session.* events
If you use that parameter then it'll be available in payment_intent.* events