Skip to content

Instantly share code, notes, and snippets.

@benluxford
Last active June 10, 2017 16:52
Show Gist options
  • Save benluxford/ef432d92df5b2b1eba6b94c0c5f2fbb8 to your computer and use it in GitHub Desktop.
Save benluxford/ef432d92df5b2b1eba6b94c0c5f2fbb8 to your computer and use it in GitHub Desktop.
Stripe Webhook Controller with Event Checking for Laravel 5
<?php
namespace App\Http\Controllers;
use Stripe\Stripe;
use Stripe\Event;
use Illuminate\Http\Request;
class WebhooksController extends Controller
{
function __construct(){
Stripe::setApiKey(config('services.stripe.secret'));
}
public function webhookReceiver(Request $request){
$confirmation = $this->verifyWebhook($request['id']);
return $confirmation;
}
public function verifyWebhook($eventId){
try {
$event = Event::retrieve($eventId);
} catch (\Exception $e) {
return response($e->getMessage()); // Got it, but error.
}
return $this->handleTheEvent($event);
}
public function eventToMethod($event){
return 'when' . studly_case(str_replace('.', '_', $event));
}
public function handleTheEvent($event){
$method = $this->eventToMethod($event['type']);
if (method_exists($this, $method)) {
return $this->$method($event);
};
}
public function whenAccountUpdated($event){
return response('hit');
}
public function whenAccountApplicationDeauthorized($event){
return response('hit');
}
public function whenAccountExternalAccountCreated($event){
return response('hit');
}
public function whenAccountExternalAccountDeleted($event){
return response('hit');
}
public function whenAccountExternalAccountUpdated($event){
return response('hit');
}
public function whenApplicationFeeCreated($event){
return response('hit');
}
public function whenApplicationFeeRefunded($event){
return response('hit');
}
public function whenApplicationFeeRefundUpdated($event){
return response('hit');
}
public function whenBalanceAvailable($event){
return response('hit');
}
public function whenBitcoinReceiverCreated($event){
return response('hit');
}
public function whenBitcoinReceiverFilled($event){
return response('hit');
}
public function whenBitcoinReceiverUpdated($event){
return response('hit');
}
public function whenBitcoinReceiverTransactionCreated($event){
return response('hit');
}
public function whenChargeCaptured($event){
return response('hit');
}
public function whenChargeFailed($event){
return response('hit');
}
public function whenChargePending($event){
return response('hit');
}
public function whenChargeRefunded($event){
return response('hit');
}
public function whenChargeSucceeded($event){
return response('hit');
}
public function whenChargeUpdated($event){
return response('hit');
}
public function whenChargeDisputeClosed($event){
return response('hit');
}
public function whenChargeDisputeCreated($event){
return response('hit');
}
public function whenChargeDisputeFundsReinstated($event){
return response('hit');
}
public function whenChargeDisputeFundsWithdrawn($event){
return response('hit');
}
public function whenChargeDisputeUpdated($event){
return response('hit');
}
public function whenCouponCreated($event){
return response('hit');
}
public function whenCouponDeleted($event){
return response('hit');
}
public function whenCouponUpdated($event){
return response('hit');
}
public function whenCustomerCreated($event){
return response('hit');
}
public function whenCustomerDeleted($event){
return response('hit');
}
public function whenCustomerUpdated($event){
return response('hit');
}
public function whenCustomerDiscountCreated($event){
return response('hit');
}
public function whenCustomerDiscountDeleted($event){
return response('hit');
}
public function whenCustomerDiscountUpdated($event){
return response('hit');
}
public function whenCustomerSourceCreated($event){
return response('hit');
}
public function whenCustomerSourceDeleted($event){
return response('hit');
}
public function whenCustomerSourceUpdated($event){
return response('hit');
}
public function whenCustomerSubscriptionCreated($event){
return response('hit');
}
public function whenCustomerSubscriptionDeleted($event){
return response('hit');
}
public function whenCustomerSubscriptionTrialWillEnd($event){
return response('hit');
}
public function whenCustomerSubscriptionUpdated($event){
return response('hit');
}
public function whenInvoiceCreated($event){
return response('hit');
}
public function whenInvoicePaymentFailed($event){
return response('hit');
}
public function whenInvoicePaymentSucceeded($event){
return response('hit');
}
public function whenInvoiceSent($event){
return response('hit');
}
public function whenInvoiceUpdated($event){
return response('hit');
}
public function whenInvoiceitemCreated($event){
return response('hit');
}
public function whenInvoiceitemDeleted($event){
return response('hit');
}
public function whenInvoiceitemUpdated($event){
return response('hit');
}
public function whenOrderCreated($event){
return response('hit');
}
public function whenOrderPaymentFailed($event){
return response('hit');
}
public function whenOrderPaymentSucceeded($event){
return response('hit');
}
public function whenOrderUpdated($event){
return response('hit');
}
public function whenOrderReturnCreated($event){
return response('hit');
}
public function whenPlanCreated($event){
return response('hit');
}
public function whenPlanDeleted($event){
return response('hit');
}
public function whenPlanUpdated($event){
return response('hit');
}
public function whenProductCreated($event){
return response('hit');
}
public function whenProductDeleted($event){
return response('hit');
}
public function whenProductUpdated($event){
return response('hit');
}
public function whenRecipientCreated($event){
return response('hit');
}
public function whenRecipientDeleted($event){
return response('hit');
}
public function whenRecipientUpdated($event){
return response('hit');
}
public function whenReviewClosed($event){
return response('hit');
}
public function whenReviewOpened($event){
return response('hit');
}
public function whenSkuCreated($event){
return response('hit');
}
public function whenSkuDeleted($event){
return response('hit');
}
public function whenSkuUpdated($event){
return response('hit');
}
public function whenSourceCanceled($event){
return response('hit');
}
public function whenSourceChargeable($event){
return response('hit');
}
public function whenSourceFailed($event){
return response('hit');
}
public function whenSourceTransactionCreated($event){
return response('hit');
}
public function whenTransferCreated($event){
return response('hit');
}
public function whenTransferFailed($event){
return response('hit');
}
public function whenTransferPaid($event){
return response('hit');
}
public function whenTransferReversed($event){
return response('hit');
}
public function whenTransferUpdated($event){
return response('hit');
}
public function whenPing($event){
return response('hit');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment