Created
December 15, 2020 19:06
-
-
Save vigikaran/cec42b8e831912eca9324ea54b7950d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function stripe(Request $request){ | |
try{ | |
$result = true; | |
\Stripe\Stripe::setApiKey(config('services.stripe.secret_key')); | |
$payload = $request->getContent(); | |
Log::info('stripe-webhook',[ | |
'payload' => $payload | |
]); | |
$endpoint_secret = config('services.stripe.webhook.secret'); | |
$sig_header = $request->server->get('HTTP_STRIPE_SIGNATURE'); | |
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret); | |
if ($event->type == 'checkout.session.completed') { | |
$data = $event->data->object; | |
/// We will call our internal method to update Stripe customer ID | |
$result = true; | |
} | |
if ($event->type == 'mandate.updated') { | |
$data = $event->data->object; | |
/// We will call our internal method to updaye Mandate Details | |
$result = true; | |
} | |
return [ | |
'result' => $result | |
]; | |
} | |
catch(\UnexpectedValueException $e) { | |
return response([ | |
'result' => false, | |
'error' => $e->getMessage() | |
],400); | |
}catch(\Stripe\Exception\SignatureVerificationException $e) { | |
return response([ | |
'result' => false, | |
'error' => $e->getMessage() | |
],400); | |
} | |
catch(\Exception $e){ | |
return response([ | |
'result' => false, | |
'error' => $e->getMessage() | |
],400); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment