Created
May 25, 2010 17:54
-
-
Save davidcoallier/413445 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Action Paymentby | |
* | |
* This action is used to process the payments for "x" user. | |
* | |
* @link http://getfrapi.com | |
* @author Frapi <[email protected]> | |
* @link /payment/buy | |
*/ | |
class Action_Paymentby extends Frapi_Action implements Frapi_Action_Interface | |
{ | |
/** | |
* Required parameters | |
* | |
* @var An array of required parameters. | |
*/ | |
protected $requiredParams = array('partnerId', 'productId'); | |
/** | |
* The data container to use in toArray() | |
* | |
* @var A container of data to fill and return in toArray() | |
*/ | |
private $data = array(); | |
/** | |
* To Array | |
* | |
* This method returns the value found in the database | |
* into an associative array. | |
* | |
* @return array | |
*/ | |
public function toArray() | |
{ | |
return $this->data; | |
} | |
/** | |
* Default Call Method | |
* | |
* This method is called when no specific request handler has been found | |
* | |
* @return array | |
*/ | |
public function executeAction() | |
{ | |
return $this->toArray(); | |
} | |
/** | |
* Get Request Handler | |
* | |
* This method is called when a request is a GET | |
* | |
* @return array | |
*/ | |
public function executeGet() | |
{ | |
return $this->toArray(); | |
} | |
/** | |
* Post Request Handler | |
* | |
* This method is called when a request is a POST | |
* | |
* @return array | |
*/ | |
public function executePost() | |
{ | |
$valid = $this->hasRequiredParameters($this->requiredParams); | |
if ($valid instanceof Frapi_Error) { | |
return $valid; | |
} | |
$partnerId = $this->getParam('partnerId', self::TYPE_DOUBLE); | |
$productId = $this->getParam('productId', self::TYPE_DOUBLE); | |
// That's your model that you created that interacts with your database | |
// This is obviously an example and not a real class. YOU need to do this. | |
$model = new Model_DropShipper(); | |
// If we don't have more stock then we throw an API error | |
if (!$model->hasMoreStock($productId)) { | |
throw new Frapi_Error( | |
'NO_LONGER_AVAIL', | |
'This product is no longer available', | |
404 | |
); | |
} | |
// If we got here then we have the product | |
$return = $model->purchase($partnerId, $productId); // Any other parameters you need | |
if ($return === false) { | |
throw new Frapi_Error( | |
'ERROR_BUYING', | |
'There was an error purchasing your product' | |
); | |
} | |
/** | |
* $model->purchase could return an array of information regarding the customer who's | |
* just done the purchase as such: | |
* $return = array( | |
* 'confirmation' => 'XXXX', | |
* 'address' => array( | |
* 'street' => '151 street name', | |
* 'city' => 'Washington', | |
* 'state' => 'DC', | |
* 'country' => 'United States of America', | |
* ), | |
* 'anyOtherInformationYouWant' => array(), | |
* ); | |
* | |
* Or in case the purchase failed, your method could simply return false | |
*/ | |
// Stick an array of data in $this->data to populate the output. | |
$this->data = $return; | |
return $this->toArray(); | |
} | |
/** | |
* Put Request Handler | |
* | |
* This method is called when a request is a PUT | |
* | |
* @return array | |
*/ | |
public function executePut() | |
{ | |
return $this->toArray(); | |
} | |
/** | |
* Delete Request Handler | |
* | |
* This method is called when a request is a DELETE | |
* | |
* @return array | |
*/ | |
public function executeDelete() | |
{ | |
return $this->toArray(); | |
} | |
/** | |
* Head Request Handler | |
* | |
* This method is called when a request is a HEAD | |
* | |
* @return array | |
*/ | |
public function executeHead() | |
{ | |
return $this->toArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment