-
-
Save orditeck/037b8e74123fb6f5233f to your computer and use it in GitHub Desktop.
Webhook Snipcart
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
<?php | |
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 | |
Snipcart::createTransaction($order); | |
// 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