Skip to content

Instantly share code, notes, and snippets.

@jedateach
Created April 2, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedateach/2287180 to your computer and use it in GitHub Desktop.
Save jedateach/2287180 to your computer and use it in GitHub Desktop.
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');
//adding info to payment
$data = array(
'Amount' => 100.00,
'PaidFor' => $buyable
);
$payment->setData($data);
//could have a few setters
$payment->setAmount(100.00); //could prevent negative payment values
$payment->setPaidFor($buyable);
//arrange where to redirect to after payment
//if this payment is to be processed within the same request, the link can be stored in session, otherwise we can't really rely on session. Either store link in database, or somehow store the need to call Link('success') on buyable.
//I don't like this solution. Can we mimic Form processing somehow? ...pass a controller and action somewhere?
$payment->redirectTo($buyable->Link('success'));
//or
$controller = $this->controller;
$action = 'vieworder';
$id = $buyable->ID;
$payment->returnTo($controller,$action,$id,$data);
//perform check/validation on payment
$payment->validate();
//start payment process
//records IP address
Director::redirect($payment->redirect());
//or
$payment->process();
return;
//check payment status
//make another payment
@jedateach
Copy link
Author

My ideas about how payment could work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment