Skip to content

Instantly share code, notes, and snippets.

View jedateach's full-sized avatar
🤓

Jeremy Shipman jedateach

🤓
View GitHub Profile
@jedateach
jedateach / paymentexample.php
Created April 2, 2012 21:03
New payment API example
<?php
//buyable has one or many payments
//should this be absolutely required?
$buyable;
//creating a new payment
//this will inject the appropriate gateway automatically, if one exists
$payment = new PaypalPayment(); //or
$payment = Payment::create('PaypalPayment');
<?php
//
$payment->returnTo($controller,$action,$id);
$payment->process();
class PaymentGatewayController extends Controller{
@jedateach
jedateach / gist:2289055
Created April 3, 2012 03:25
Planning new ShoppingCart system
<?php
/*
* goal: build SQL filter, based on parameter array
*/
//a hypothetical filter(parameters) for a new order item.
//This data would typically come from request parameters.
$filter = array(
'Size' => 20,
@jedateach
jedateach / MatchObjectFilter.php
Created April 15, 2012 23:50
Planning the ShoppingCart custom products system
<?php
/**
* Helper class to create a filter for matching a dataobject,
* using field values or relationship ids and only those ids.
*
* Combining fields defines a way to uniquely identify an object.
*
* Useful for finding if a dataobject with given field values exists.
* Protects against SQL injection, and searching on unauthroised fields.
@jedateach
jedateach / Weight.php
Created April 26, 2012 22:25
SilverStripe Weight Field
<?php
class Weight extends Decimal{
function Nice(){
//return in format appropriate to value eg 2grams instead of 0.002kg
}
}
@jedateach
jedateach / RunningTotalExtension.php
Created May 3, 2012 03:39
Running Total Extension for DataObjectSet
<?php
class RunningTotalExtension extends Extension{
private static $runningtotal = 0;
function RunningTotal(){
return self::$runningtotal ++;
}
@jedateach
jedateach / Payment.php
Created May 15, 2012 03:38
Payment Prototype
<?php
class Payment extends DataObject{
}
interface PaymentProcessor{
function setup(); //prepare for
}
@jedateach
jedateach / PaymentController.php
Created May 17, 2012 03:34
Payment Example Draft Code
<?php
/**
* Catch gateway-triggered requests
*/
class PaymentController extends Controller{
function init(){
$this->processor = $this->getProcessorForPayment(); //somehow get the right processor to continue handling
//Perhaps the processor class is sent in the url, eg: mysite/paymentcontrol/PayPal/?extradata=....
@jedateach
jedateach / MyController.php
Created June 13, 2012 00:16
Basic controller
<?php
class MyController extends Controller{
static $url_segment = 'mycontroller';
function Link($action = ""){
return Controller::join_links(self::$url_segment,$action);
}
}
@jedateach
jedateach / dummypayment.yaml
Created June 25, 2012 00:39
Payment config files stored in mysite/_config/
Name: dummypayment
---
Director:
rules:
'dummy/external/$Action/$ID': 'DummyExternalGateway_Controller'
'payment/$MethodName/$Action/$ID': 'Payment_Controller_GatewayHosted'
# first idea (tied to gateway):