Recurly_Client::apiKey PHP Метод

apiKey() публичный Метод

Current API key
public apiKey ( ) : string
Результат string API key
    public function apiKey()
    {
        return empty($this->_apiKey) ? Recurly_Client::$apiKey : $this->_apiKey;
    }

Usage Example

 /**
  * Add new payment into database
  * 
  * @author coeus solutions
  * @param array $data the data from REST Client
  * @return \Zend\View\Model\JsonModel 
  */
 public function create($data = array())
 {
     try {
         $exist = $this->getService()->checkAlreadySubscribed($data['customer_id']);
         if (!$exist) {
             \Recurly_Client::$subdomain = 'incoverage123';
             \Recurly_Client::$apiKey = '1087e99b0df34eb4835412e55217dc6f';
             $account_code = uniqid();
             // Subscription
             $subscription = new \Recurly_Subscription();
             $subscription->plan_code = 'basic';
             $subscription->currency = 'USD';
             $account = new \Recurly_Account();
             //$subscription->account->account_code = 'john_rambo';
             $account->account_code = $account_code;
             $account->first_name = $data['first_name'];
             $account->last_name = $data['last_name'];
             $account->email = '*****@*****.**';
             $account->address->city = $data['city'];
             $account->address->state = $data['state'];
             $account->address->country = $data['country'];
             $account->address->zip = $data['postal_code'];
             $account->address->address1 = $data['address1'];
             $account->create();
             // Billing Infos
             $billing_info = new \Recurly_BillingInfo();
             $billing_info->account_code = $account_code;
             //$billing_info->first_name = $data['first_name'];
             //$billing_info->last_name = $data['last_name'];
             //$billing_info->number = $data['number'];
             //$billing_info->verification_value = '123';
             //$billing_info->month = $data['month'];
             //$billing_info->year = $data['year'];
             $billing_info->token_id = $data['token'];
             $account->billing_info = $billing_info;
             $subscription->account = $account;
             $subscription->create();
             $info = array('customerId' => $data['customer_id'], 'accountCode' => $account_code, 'planCode' => 'basic');
             $this->getService()->addPayment($info);
             /*// Adjustments
               $charge = new \Recurly_Adjustment();
               $charge->account_code = $account_code;
               $charge->description = 'Charge for extra bandwidth';
               $charge->unit_amount_in_cents = 5000; // $50.00
               $charge->currency = 'USD';
               $charge->quantity = 1;
               $charge->accounting_code = 'bandwidth';
               $charge->tax_exempt = false;
               $charge->create();*/
             //$billing_info->create();
         } else {
             $error = 'Already subscribed.';
         }
     } catch (\Recurly_NotFoundError $e) {
         $error = $e->getMessage();
     } catch (\Recurly_ValidationError $e) {
         // If there are multiple errors, they are comma delimited:
         //$messages = explode(',', $e->getMessage());
         //print 'Validation problems: ' . implode("\n", $messages);
         $error = $e->getMessage();
     } catch (\Recurly_ServerError $e) {
         $error = $e->getMessage();
     } catch (Exception $e) {
         // Assign the error message and use it to handle any customer
         // messages or logging
         $error = $e->getMessage();
     }
     if (isset($error)) {
         $result['data']['status'] = false;
         $result['data']['error'] = $error;
     } else {
         $result['data']['status'] = true;
     }
     return new JsonModel($result);
 }
All Usage Examples Of Recurly_Client::apiKey