Inheritance: extends Recurly_Resource
 protected function uri() {
   if (!empty($this->_href))
     return $this->getHref();
   else if (!empty($this->account_code))
     return Recurly_BillingInfo::uriForBillingInfo($this->account_code);
   else
     throw new Recurly_Error("'account_code' not specified.");
 }
 public function testDeleteForAccount()
 {
     Recurly_BillingInfo::deleteForAccount('abcdef1234567890', $this->client);
 }
 /**
  * get_fullMemberData 
  *
  * retrieves a fill set of data for a member
  * 
  * tests to see if a mac address exists and if it is associated with the
  * current member defined in the member model ($this)
  *
  * @author magicandmight
  * @param user_id = the user whos info you want
  * @param id_type = the type of userid you are passing
  */
 function get_fullMemberData($user_id, $id_type = NULL)
 {
     $sql = "   \n        select\n        user.id as id, user.first_name, user.last_name, user.rfid, user.wp_users_id,user.twitter,user.behance,user.location_id, user.membership_status_luid,\n        wpmember_users.user_login,\n        wpmember_users.user_url as website,\n        email.id as 'email_id',\n        email.address as 'email',\n        phone.id as phone_id,\n        phone.number as phone,\n        company.id as 'company_id',\n        company.name as 'company_name',\n        company.description as 'company_description',\n        subscription_sync.plan_code as 'plan_code',\n        subscription_sync.state as 'subscription_state',\n        subscription_sync.total_amount_in_cents as 'total_amount_in_cents',\n        subscription_sync.current_period_ends_at as 'current_period_ends_at'\n        \n        from \n                user \n                left outer join wpmember_users on wpmember_users.ID = user.wp_users_id\n                left outer join email on email.user_id = user.id and email.is_primary = 1\n                left outer join phone on phone.user_id = user.id and phone.is_primary = 1\n                left outer join company on company.id = user.company_id\n                left outer join subscription_sync on subscription_sync.user_id = user.id\n        where ";
     // if we don't know what kind of we have, we assume it is a grind ID
     $id_type = !isset($id_type) ? UserIdType::ID : $id_type;
     switch ($id_type) {
         case UserIdType::ID:
             $sql .= " user.id = " . $user_id;
             break;
         case UserIdType::RFID:
             $sql .= " user.rfid = '" . $user_id . "'";
             break;
         case UserIdType::WORDPRESSID:
             $sql .= " user.wp_users_id = '" . $user_id . "'";
             break;
     }
     $query = $this->db->query($sql);
     $results = $query->result();
     $this->member = $results[0];
     // need to trap error here
     $account = Recurly_Account::get($this->member->id);
     $billing_info = Recurly_BillingInfo::get($account->account_code);
     $this->member->billing_info = $billing_info;
     error_log("member_grind_uid" . get_user_meta($this->member->wp_users_id, 'grind_uid', true), 0);
     $this->member->grind_uid = get_user_meta($this->member->wp_users_id, 'grind_uid', true);
     // returns a member array
     return $this->member;
 }
 public function createRecurlySubscription2(Recurly_Account $account, $planCode, $billingFirstName, $billingLastName, $billingAddr1, $billingAddr2 = "", $billingCity, $billingState, $billingZIP, $billingCountry = "US", $ccNumber, $ccExpMonth, $ccExpYear, $ccVerificationValue)
 {
     $billing_info = new Recurly_BillingInfo();
     $billing_info->account_code = $account->account_code;
     $billing_info->first_name = $billingFirstName;
     $billing_info->last_name = $billingLastName;
     $billing_info->address1 = $billingAddr1;
     $billing_info->address2 = $billingAddr2;
     $billing_info->city = $billingCity;
     $billing_info->state = $billingState;
     $billing_info->country = $billingCountry;
     $billing_info->zip = $billingZIP;
     $billing_info->year = intval($ccExpYear);
     $billing_info->month = intval($ccExpMonth);
     if (trim($ccVerificationValue) != "") {
         $billing_info->verification_value = $ccVerificationValue;
     }
     if (substr($ccNumber, 0, 5) != "*****") {
         $billing_info->number = $ccNumber;
     }
     $billing_info->ip_address = $_SERVER['REMOTE_ADDR'];
     $account_info = $billing_info->update();
     $account_info = null;
     $currentSubscription = self::getSubscription($account->account_code);
     $currentPlanCode = "";
     $currentPlanCost = 0;
     $newPlanCost = 0;
     if ($planCode != "" && $planCode != "daily") {
         $newPlan = Recurly_Plan::get($planCode);
         $newPlanCost = $newPlan->unit_amount_in_cents;
     }
     if ($currentSubscription) {
         $currentPlanCode = $currentSubscription->plan_code;
         $currentPlan = Recurly_Plan::get($currentPlanCode);
         $currentPlanCost = $currentSubscription->unit_amount_in_cents;
     }
     if ($planCode == "" || $planCode == "daily") {
         // if the plan is being moved from a monthly plan to daily, then we have to cancel subscription.
         if ($currentSubscription) {
             $currentSubscription->cancel();
         }
     } else {
         // if the plan is being moved from one monthly plan to another, then we have to
         // upgrade or downgrade.
         if ($currentSubscription) {
             $currentSubscription->plan_code = $planCode;
             // get the current plan's amount and compare to the new one
             if ($newPlanCost > $currentPlanCost) {
                 // upgrade
                 $currentSubscription->updateImmediately();
             } elseif ($newPlanCost < $currentPlanCost) {
                 $currentSubscription->updateAtRenewal();
             }
         } else {
             // no current subscription and we want a monthly, so just add a new one
             $subscription = new Recurly_Subscription();
             $subscription->plan_code = $planCode;
             $subscription->currency = "USD";
             $account->billing_info = $billing_info;
             $subscription->account = $account;
             $subscription->create();
         }
     }
     return $account_info;
 }
 public function wpGetRecurlyBillingInfo()
 {
     session_start();
     echo json_encode(Recurly_BillingInfo::get($_SESSION['wpuser']['id']));
 }