Advertisement
claudious

stripe-php after chat

Apr 3rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1.             public function webHookReceiver ($request, $response, $args)
  2.     {
  3.         $config = $this->ci->config;
  4.  
  5.         $data = $request->getParsedBody();
  6.  
  7.         Stripe::setApiKey($config['stripe.secret_key']);
  8.  
  9.  
  10.         // You can find your endpoint's secret in your webhook settings
  11.         $endpoint_secret = $config['stripe.webhook_key'];
  12.  
  13.         $payload = $request->getBody();
  14.  
  15.         $sig_header = $request->getHeaderLine('Stripe-Signature');
  16.         $data = json_decode($payload, true);
  17.         $jsonError = json_last_error();
  18.         if ($data === null && $jsonError !== JSON_ERROR_NONE) {
  19.             $msg = "Invalid payload: $payload "
  20.               . "(json_last_error() was $jsonError)";
  21.             throw new \UnexpectedValueException($msg);
  22.         }
  23.         $event = Event::constructFrom($data);
  24.  
  25.         WebhookSignature::verifyHeader($payload, $sig_header, $endpoint_secret, 300);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement