Advertisement
claudious

stripe-php from docs

Apr 3rd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 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.  
  17.         try {
  18.             $event = Webhook::constructEvent(
  19.                 $payload, $sig_header, $endpoint_secret
  20.             );
  21.         } catch(\UnexpectedValueException $e) {
  22.             // Invalid payload
  23.             return $response->withStatus(400);
  24.         } catch(\Stripe\Error\SignatureVerification $e) {
  25.             // Invalid signature
  26.             throw $e;
  27.             return $response->withStatus(401);
  28.         }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement