Skip to content

Instantly share code, notes, and snippets.

Last active Jan 23, 2017
What would you like to do?
Webhook Snipcart
namespace POS\Webhooks\Http\Controllers;
use POS\Webhooks\Validators\Snipcart;
class SnipcartController extends WebHookController
public function postOrderCompleted()
$body = json_decode(file_get_contents('php://input'), true);
// Validate and clean the request.
// 1. Save the response from snipcart to the database if we need to take a look in the future
// 2. Throw a Bad Request (400) if anything is wrong with the request.
// 3. Set the right type for each variable, like (int) for every items quantity.
$snipcart = Snipcart::validateRequest($body);
// Create (or update) the customer
$customer = Snipcart::createOrUpdateCustomer($snipcart->customer);
// Create the order
$order = Snipcart::createOrder($snipcart->order, $snipcart->items);
// Create the transaction
// Return a valid status code
return Response::json(array('error' => false), 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment