php - Stripe Webhook not working -
so i'm trying simple stripe webhook. ideally shouldn't difficult.
i'm using webhook
so here code:
<?php require_once('lib/stripe.php'); // replace "xyz" stripe secret live key // stripe::setapikey("xxx"); $body = @file_get_contents('php://input'); $event_json = json_decode($body); // setup: // 1. customize settings (stripe api key, email settings, email text) // 2. put code somewhere it's accessible url on server. // 3. add url of location settings @ https://manage.stripe.com/#account/webhooks // 4. have fun! // set secret key: remember change live secret key in production // see keys here https://manage.stripe.com/account // retrieve request's body , parse json $body = @file_get_contents('php://input'); $event_json = json_decode($body); // security, retrieve stripe api $event_id = $event_json->id; $event = stripe_event::retrieve($event_id); // send receipts on succesful invoices if ($event->type === 'invoice.payment_succeeded') { email_invoice_receipt($event->data->object); } function email_invoice_receipt($invoice) { $customer = stripe_customer::retrieve($invoice->customer); //make sure customize address $subject = 'your payment has been received'; $headers = 'from: "myapp support" <support@myapp.com>'; mail($customer->email, $subject, message_body(), $headers); } function format_stripe_amount($amount) { return sprintf('$%0.2f', $amount / 100.0); } function format_stripe_timestamp($timestamp) { return strftime("%m/%d/%y", $timestamp); } function payment_received_body($invoice, $customer) { $subscription = $invoice->lines->subscriptions[0]; return <<<eof dear {$customer->email}: receipt subscription. receipt, no payment due. continued support! ------------------------------------------------- subscription receipt email: {$customer->email} plan: {$subscription->plan->name} amount: {format_stripe_amount($invoice->total)} (usd) service between {format_stripe_timestamp($subscription->period->start)} , {format_stripe_timestamp($subscription->period->end)} ------------------------------------------------- eof; } ?>
the sign page here: http://www.strategic-options.com/trade/sign_up webhook here: http://www.strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/stripe_webhook.php
my transactions going thru, casue see them in dashboard. have set webhook on dashboard appropriately right link. when try test on webhook feature fail because evt_000000000 doesn't response. don't know of other way test webhook, other using dashboard?
<br/> <b>fatal error</b>: uncaught exception 'stripe_invalidrequesterror' message 'no such event: evt_00000000000000' in /home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apirequestor.php:152 stack trace: #0 /home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apirequestor.php(212): stripe_apirequestor->handleapierror('{\n "error": {\n...', 404, array) #1 /home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apirequestor.php(114): stripe_apirequestor->_interpretresponse('{\n "error": {\n...', 404) #2 /home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apiresource.php(24): stripe_apirequestor->request('get', '/v1/events/evt_...', array) #3 /home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apiresource.php(8): stripe_apiresource->refresh() #4 /home/strategicop in <b>/home/strategicoptions/strategic-options.com/trade/3_party/simple-bootstrap-stripe-payment-form/lib/stripe/apirequestor.php</b> on line <b>152</b><br/>
the issue here event trying retrieve through api evt_00000000000000
doesn't exist in account why fails.
when use "send test webhook..." button in dashboard sends generic event fake data in it. identifiers have 0
there no way retrieve through retrieve event api.
what need here instead use real events in account. that, can create customer or charge in dashboard in test mode automatically send event customer.created
or charge.created
webhook endpoint , code should work expected.
Comments
Post a Comment