stripe endpoint creation php

Aug 27, 2020 PHP stripe

stripe custom webhook

Dashboard triggered

<?php
Stripe key insert
//
// check the webhook signature
// https://stripe.com/docs/webhooks/signatures#verify-official-libraries
//
$endpoint_secret ='At the endpoint of the End Point Dashboard';


$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;

try {
    $event = \Stripe\Webhook::constructEvent(
        $payload, $sig_header, $endpoint_secret
    );
} catch(\UnexpectedValueException $e) {
    // Invalid payload
    http_response_code(400); // PHP 5.4 or greater
    exit();
} catch(\Stripe\Error\SignatureVerification $e) {
    // Invalid signature
    http_response_code(400); // PHP 5.4 or greater
    exit();
}

//
// process for $event
//
$event_json = json_decode($payload);
// $event_json = json_decode($payload);
// It doesn't work because it is 0 in the dashboard test.
// $event_id = $event_json->id;
// try {
// $event = \Stripe\Event::retrieve($event_id);
//} catch(\Stripe\Error\InvalidRequest $e) {
// // Invalid payload
// http_response_code(400);
// exit();
//} catch(\Stripe\Error $e) {
// // Invalid payload
// http_response_code(400);
// exit();
//}

if ($event->type =='customer.created') {
}
if ($event->type =='account.updated') {
  $account = $event->data->object;
  handleAccountUpdate($account);
  // var_dump($event_json);
}

// when and where it worked
if ($event->type =='checkout.session.completed') {
db, email, etc.
      var_dump($event_json);



      
}

if ($event->type =='customer.subscription.deleted') (
}

if ($event->type =='customer.subscription.updated') {
}

if ($event->type =='invoice.payment_succeeded') (
}

http_response_code(200);

function handleAccountUpdate($account) {
  // Fulfill the purchase.
  echo $account;
};
?>