#mangeshsm_webhooks

1 messages ¡ Page 1 of 1 (latest)

knotty frostBOT
#

👋 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.

cinder wigeon
#

Which webhook event(s) are you describing? checkout.session.completed?

prisma compass
#

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

cinder wigeon
#

Then yes, charge.succeeded will always fire whenever there's a successful payment on your account regardless of how it's made

prisma compass
#

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

cinder wigeon
#

How are you setting metadata?

prisma compass
#

$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,
                ]] : [],
            ]);
knotty frostBOT
cinder wigeon
#

charge.* events are generally not recommended. Use checkout.session.* or payment_intent.*

prisma compass
#

but on console i never got these

#

i did console of whole event too
in that never find that

cinder wigeon
#

Never find what?

prisma compass
#

metadata is always getting blank

#

metadata is always getting blank
*

cinder wigeon
#

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

prisma compass
#

Okay, checking again.

#

Thanks , have a good day.