Created
April 2, 2012 21:03
-
-
Save jedateach/2287180 to your computer and use it in GitHub Desktop.
New payment API example
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 | |
//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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My ideas about how payment could work.