'/transaction', 'initializeUrl'=>'/initialize', 'verifyUrl'=>'/verify', 'chargeUrl'=>'/charge_authorization', 'beforeSend'=>'', 'afterSend'=>'' ); public $customer = array( 'baseUrl'=>'/customer', 'beforeSend'=>'', 'afterSend'=>'' ); public $subaccount = array( 'baseUrl'=>'/subaccount', 'beforeSend'=>'', 'afterSend'=>'' ); public $plan = array( 'baseUrl'=>'/plan', 'beforeSend'=>'', 'afterSend'=>'' ); public $page = array( 'baseUrl'=>'/page', 'slugAvailabilityUrl'=>'/check_slug_availability', 'beforeSend'=>'', 'afterSend'=>'' ); public $subscription = array( 'baseUrl'=>'/subscription', 'beforeSend'=>'', 'afterSend'=>'' ); public $settlement = array( 'baseUrl'=>'/settlement', 'beforeSend'=>'', 'afterSend'=>'' ); public function transaction() { return new Transaction($this); } public function customer() { return new Customer($this); } public function subaccount() { return new SubAccount($this); } public function plan() { return new Plan($this); } public function subscription() { return new Subscription($this); } public function page() { return new Page($this); } public function settlement() { return new Settlement($this); } public function init() { parent::init(); $this->setApiUrl(); $this->setAuthorization(); } protected function getSecretKey() { return (strtolower($this->environment) == strtolower(self::ENV_LIVE))?$this->liveSecretKey:$this->testSecretKey; } public function getAuthKeys() { if (strtolower($this->environment) == strtolower(self::ENV_LIVE)) { return array('secret_key'=>$this->liveSecretKey,'public_key'=>$this->livePublicKey); } else { return array('secret_key'=>$this->testSecretKey,'public_key'=>$this->testPublicKey); } } protected function setAuthorization() { $this->authHeader = array('Authorization: Bearer '.$this->getSecretKey()); } public function setHeader($headers = array()) { $this->header = array_merge($this->authHeader,$headers); } public function getHeader() { return $this->header?$this->header:$this->authHeader; } protected function setApiUrl($url = null) { if ($url == null) { if (!isset($this->apiUrl) || empty($this->apiUrl)) $this->apiUrl = $this->defaultApiUrl; } else { $this->apiUrl = $url; } return $this; } public function getApiUrl() { if (!isset($this->apiUrl) || empty($this->apiUrl)) $this->apiUrl = $this->defaultApiUrl; return $this->apiUrl; } public static function generateRef($length = 10) { $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } }