Skip to content

Instantly share code, notes, and snippets.

View marcguyer's full-sized avatar

Marc Guyer marcguyer

View GitHub Profile
@marcguyer
marcguyer / customers.xml
Created November 2, 2010 18:36
Example CheddarGetter API responses
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer id="89fdd0e4-c775-11de-8728-40407c9117fd" code="test_customer">
<firstName>Joe</firstName>
<lastName>Schmoe</lastName>
<company/>
<email>[email protected]</email>
<notes/>
<gatewayToken>SIMULATED</gatewayToken>
<isVatExempt>0</isVatExempt>
@marcguyer
marcguyer / zf1-webhook-controller.php
Last active December 11, 2015 07:19
Basic ZF1 controller for handling CheddarGetter webhooks
<?php
class HookController extends Zend_Controller_Action {
public function preDispatch() {
$this->_helper->viewRenderer->setNoRender(true);
if (!$this->_request->isPost()) {
throw new Exception('POST required');
}
@marcguyer
marcguyer / cheddargetter-webhook-raw.php
Last active December 11, 2015 07:19
Raw PHP example for validating CheddarGetter webhook.
<?php
if (empty($_SERVER['HTTP_X_CG_SIGNATURE'])) {
//invalid
}
$rawBody = file_get_contents('php://input');
$token = md5($rawBody);
// check signature
@marcguyer
marcguyer / cheddargetter-webhooks.rb
Last active December 11, 2015 07:19
A Ruby example for validating a CheddarGetter webhook.
require 'openssl'
require 'digest'
product_key = 'YOUR_PRODUCT_KEY'
if !defined?(request) || request.nil? || request.env.nil? # not rails
# signature = {value of X-CG-SIGNATURE here}
# request_body = {value of raw request body here}
else # assume it's a ROR ActionController::AbstractRequest object
signature = request.env['X-CG-SIGNATURE']
@marcguyer
marcguyer / cheddargetter-webhook.cs
Last active December 18, 2015 23:09
A c# example for verifying a CheddarGetter webhook
/// Grab The Authorization Header
var authorizationHeader = request.Headers["X-CG-SIGNATURE"];
if (string.IsNullOrEmpty(authorizationHeader))
{
throw new Domain.Exceptions.Exception();
}
request.InputStream.Seek(0, SeekOrigin.Begin);
@marcguyer
marcguyer / SupervisordMemory.py
Last active August 29, 2015 13:58
Supervisord memory check plugin for serverdensity.io
#!/usr/bin/env python
"""
Server Density Supervisord plugin.
Track the number of processes in each state.
For possible states see the docs at
http://supervisord.org/subprocess.html#process-states
"""
#!/usr/bin/env python
"""
Server Density Supervisord plugin.
Track the number of processes in each state.
For possible states see the docs at
http://supervisord.org/subprocess.html#process-states
"""
@marcguyer
marcguyer / create_customer_example.php
Last active September 14, 2017 19:57
Create Customer Examples
<?php
$client->newCustomer([
'code' => 'TEST_CUSTOMER',
'firstName' => 'Example',
'lastName' => 'Customer',
'email' => '[email protected]',
'subscription' => [
'planCode' => 'PLAN_CODE'
]
]);
@marcguyer
marcguyer / SubdomainToPathMiddleware.php
Created October 18, 2018 21:20
PSR-7 PSR-15 middleware to convert subdomain to base path
<?php
declare(strict_types=1);
namespace Api\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
@marcguyer
marcguyer / AbstractInputFilterTest.php
Last active May 1, 2019 12:28
Zend Framework Input Validation with Dependencies
<?php
declare(strict_types=1);
namespace ApiTest\InputFilter;
use PHPUnit\Framework\TestCase;
use Zend\InputFilter\InputFilter;