protected function uri() { if (!empty($this->_href)) { return $this->getHref(); } else { return Recurly_Account::uriForAccount($this->account_code); } }
public function testGatweayError() { $this->client->addResponse('GET', '/accounts/abcdef1234567890', 'client/gateway-unavailable-502.xml'); try { $account = Recurly_Account::get('abcdef1234567890', $this->client); $this->fail("Expected Recurly_ConnectionError"); } catch (Recurly_ConnectionError $e) { } }
protected function uri() { if (!empty($this->_href)) { return $this->getHref(); } else { if (!empty($this->uuid)) { return Recurly_Account::uriForTransaction($this->uuid); } else { throw new Recurly_Error('"uuid" is not supplied'); } } }
public function ProcessDailyInvoices($id) { $verificationGuid = 'da68e4ab-dadd-4b15-94ef-a90be9fd7095'; if ($id === $verificationGuid) { log_message('debug', 'Daily Invoices: Start'); $screenOutput = "<h3>Daily Invoicing</h3>"; try { $this->load->model("usermodel"); $userList = $this->usermodel->getUsers(); log_message('debug', 'Daily Invoices: Found ' . count($userList) . ' users'); $screenOutput .= 'Daily Invoices: Found ' . count($userList) . ' users<br/><br/>'; foreach ($userList as $user) { $account = Recurly_Account::get($user->id); //if ($user->email_address === "*****@*****.**") { // $account->chargeAccount(12.34, 'Charging $12.34 to account from unittest'); //} if (isset($account)) { $invoice = Recurly_Invoice::invoicePendingCharges($account->account_code); if (isset($invoice)) { $screenOutput .= 'Invoiced account: Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>'; log_message('debug', 'Daily Invoices: Invoiced user. Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id); } else { $screenOutput .= 'No charges for account: Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>'; } } else { $screenOutput .= 'No Recurly account found for ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>'; } } } catch (Exception $e) { $screenOutput .= 'Error occurred: Reason: ' + $e->getMessage() . '<br/>'; log_message('error', 'Daily Invoices: Failed. Reason: ' + $e->getMessage()); } $screenOutput .= '<br/>Invoicing complete'; log_message('debug', 'Daily Invo ices: Finished'); $to = EMAIL_G_ADMIN; $subject = "[GRIND INVOICING REPORT]"; $body = $screenOutput; $headers = "From: " . EMAIL_G_ADMIN . "\r\n" . "Reply-To: " . EMAIL_G_ADMIN . "\r\n" . "X-Mailer: PHP/" . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $body, $headers); echo $screenOutput; } else { echo 'Invalid calling entity'; log_message('error', 'Daily Invoices: Cron job is passing the wrong id parameter value. It should be ' . $verificationGuid); } }
/** * 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); }
/** * ingest * * This method provides the ability to grab and insert all of the current recurly data * and insert it into the grind database * it loops through all of the active users and gets their subscription information * it adds it to the table subscription_sync * * ** WARNING ** * This function is only meant to be used on an empty database. Clear the table first * then run this method. * * @joshcampbell * */ public function ingest() { $this->load->helper('date'); $this->db->select('id'); $query = $this->db->get_where('user', array('membership_status_luid' => 4)); $this->db->trans_start(); foreach ($query->result() as $row) { try { $account = Recurly_Account::get($row->id); } catch (Exception $e) { continue; } $subscriptions = Recurly_SubscriptionList::getForAccount($account->account_code, array('state' => 'active')); $subscription = $subscriptions->current(); $data = array(); $data["user_id"] = $row->id; $plan = $subscription != null && isset($subscription->plan) ? $subscription->plan : null; if (isset($plan)) { $data["plan_code"] = $plan->plan_code; $data["state"] = $subscription->state; $data["quantity"] = $subscription->quantity; $data["total_amount_in_cents"] = $subscription->unit_amount_in_cents; $data["activated_at"] = $subscription->activated_at != "" ? $subscription->activated_at->format('Y-m-d H:i:s') : null; $data["canceled_at"] = $subscription->canceled_at != "" ? $subscription->canceled_at->format('Y-m-d H:i:s') : null; $data["expires_at"] = $subscription->expires_at != "" ? $subscription->expires_at->format('Y-m-d H:i:s') : null; $data["current_period_started_at"] = $subscription->current_period_started_at != "" ? $subscription->current_period_started_at->format('Y-m-d H:i:s') : null; $data["current_period_ends_at"] = $subscription->current_period_ends_at != "" ? $subscription->current_period_ends_at->format('Y-m-d H:i:s') : null; $data["trial_started_at"] = $subscription->trial_started_at != "" ? $subscription->trial_started_at->format('Y-m-d H:i:s') : null; $data["trial_ends_at"] = $subscription->trial_ends_at != "" ? $subscription->trial_ends_at->format('Y-m-d H:i:s') : null; } else { $data["plan_code"] = "daily"; $data["state"] = "active"; } $this->db->insert("subscription_sync", $data); } $this->db->trans_complete(); echo "import complete"; }
public function delete($account_code = NULL) { try { if (isset($account_code)) { // set the account code without initializing the model $this->recurlyAccount = Recurly_Account::get($account_code); $this->recurlyAccount->close(); } } catch (Exception $e) { error_log("could not delete recurly account: " . $this->account->account_code, 0); } }
/** * checkin * * checks a user into GRIND for the day * * @author magicandmight * @param the member is implied ($this->member) assumes the model has been initiated already with * member data * @param location = the physical location we are signing the member into * @param signInMethod = the type of sign in, RFID, WIFI, ADMIN */ function checkin($location_id, $sign_in_method) { error_log("check in:" . $location_id . " " . $sign_in_method, 0); /* Logic: If the user is a monthly user, then leave payment to the scheduled agreement already set in Recurly. If the user is a daily user, then auto charge for the current day. If there is an error with the processing, return an error code, otherwise return empty string. */ $currentTime = date(DATE_ISO8601); error_log("member trying to check in:" . $this->member->id); // simplified this query //$sql = "select * from signin_sheet where user_id = ".$this->member->id." AND ".$currentTime." = ".DATE(NOW())." order by sign_in DESC LIMIT 1"; $sql = "select * from v_checkins_today where id = " . $this->member->id . " order by sign_in DESC LIMIT 1"; error_log($sql, 0); $query = $this->db->query($sql); if ($query->num_rows > 0) { // in the future if people are abusing the checkin and checking in lots of different people // additional logic could be included here to track the number of sign in attempts (because // we don't know how the wifi network will behave, it is better to leave this functionality out // for the initial release. We also have to worry about the table filling up with entries // here we know that users have checked into today so we don't need to check them in again //$this->db->free_result(); return true; // user is already checked in today } else { try { $account = Recurly_Account::get($this->member->id); //check if account has a "chargeable" subscription if ($subscription = self::getSubscription($this->member->id)) { //no charge, signin $result = $this->signin($this->member->id, $location_id, $sign_in_method, $currentTime); error_log("monthly checkin insert id" . $result, 0); if (!$result) { issue_log($this->member->id, "Unable to add user checkin to database", MemberIssueType::SIGNIN); } return $result; } else { //no active subscription, so charge daily if ($this->charge_daily($this->member->id, 1, $location_id)) { return $this->signin($this->member->id, $location_id, $sign_in_method, $currentTime); } error_log("checkin failed", 0); return false; // checkin failed } } catch (Recurly_Error $e) { issue_log($this->member->id, "Unable to retrieve the account for user while checking in:", MemberIssueType::SIGNIN); return false; } } }
$account = new Recurly_Account(uniqid()); $account->billing_info = new Recurly_BillingInfo(); $account->billing_info->token_id = $app->request->params('recurly-token'); $account->create(); } catch (Exception $e) { $error = $e->getMessage(); } if ($error) { $app->redirect("ERROR_URL?error={$error}"); } else { $app->redirect("SUCCESS_URL"); } }); $app->put('/api/accounts/:account_code', function ($account_code) use($app) { try { $account = Recurly_Account::get($account_code); $account->first_name = $app->request->params('first-name'); $account->last_name = $app->request->params('last-name'); $account->billing_info = new Recurly_BillingInfo(); $account->billing_info->token_id = $app->request->params('recurly-token'); $account->update(); } catch (Exception $e) { $error = $e->getMessage(); } if ($error) { $app->redirect("ERROR_URL?error={$error}"); } else { $app->redirect("SUCCESS_URL"); } }); $app->run();
function getChargesAndCredits($userId) { $retval = array(); $acct = Recurly_Account::get($userId); if ($acct) { $charges = Recurly_AdjustmentList::get($userId, array('type' => 'charge')); $credits = Recurly_AdjustmentList::get($userId, array('type' => 'credit')); /* echo "<pre>"; print_r($charges); echo "</pre>"; */ if ($charges) { foreach ($charges as $id => $charge) { $retval[$charge->created_at . "D"]->amount = $charge->amount_in_cents / 100; $retval[$charge->created_at . "D"]->description = $charge->description; $retval[$charge->created_at . "D"]->date = date("m/d/Y H:i:s", $charge->created_at); $retval[$charge->created_at . "D"]->invoice = $charge->invoice_number; } } if ($credits) { foreach ($credits as $id => $credit) { $retval[$credit->created_at . "C"]->amount = $credit->amount_in_cents / 100; $retval[$credit->created_at . "C"]->description = $credit->description; $retval[$credit->created_at . "C"]->date = date("m/d/Y H:i:s", $credit->created_at); $retval[$credit->created_at . "C"]->invoice = $credit->invoice_number; } } ksort($retval); $revRetval = array_reverse($retval); } return $revRetval; }
public function testCreateWithBillingInfoToken() { $this->client->addResponse('POST', '/accounts', 'accounts/create-201.xml'); $account = new Recurly_Account(null, $this->client); $account->account_code = 'abcdef1234567890'; $account->billing_info = new Recurly_BillingInfo(); $account->billing_info->token_id = 'abc123'; $account->create(); $this->assertInstanceOf('Recurly_Account', $account); }
mysql_select_db(DB_NAME, $con); // invoicing configuration $include_monthly = TRUE; $no_charges = ""; $charges = ""; $msg = ""; // begin routine error_log("Starting Daily Invoice Routine", 0); $sql = "select * from subscription_sync;"; $results = mysql_query($sql); // insert db query here try { while ($row = mysql_fetch_assoc($results)) { if ($include_monthly == TRUE || $row["plan_code"] == "daily") { try { $account = Recurly_Account::get($row["user_id"]); $invoice = Recurly_Invoice::invoicePendingCharges($account->account_code); if (isset($invoice)) { $m = "Invoice created for member id: " . $row["user_id"] . "\n"; $charges .= $m; // error_log($m,0); } else { $m = "no charges for member id: " . $row["user_id"] . "\n"; $no_charges .= $m; // error_log($m,0); } // end invoice } catch (Recurly_Error $e) { error_log("exception: " . $e->getMessage() . "\n", 0); //skip monthly user or account not found }
public function testParsingXMLToNewObject() { $this->client->addResponse('GET', '/accounts/abcdef1234567890', 'accounts/empty.xml'); $account = Recurly_Account::get('abcdef1234567890', $this->client); $this->assertNull($account); }
public function update($id = null) { error_log("are we even updating?", 0); $this->db->where('user_login', $this->email->address); $this->db->from('wpmember_users'); $count = $this->db->count_all_results(); if ($count < 1) { //New email is unique if ($this->email->is_primary) { //because it is the primary email address // we need to change it in GRIND DB, BILLING DB, AND WPDB $this->db->trans_begin(); //first update wordpress $sql = "update wpmember_users wp JOIN user u ON wp.id = u.wp_users_id SET wp.user_login = '******', wp.user_email = '" . $this->email->address . "' WHERE u.id=" . $this->email->user_id; $result = $this->db->query($sql); if ($this->db->trans_status() === FALSE) { error_log("Couldn't update wordpress", 0); $this->db->trans_rollback(); throw new exception("Couldn't update wordpress"); } //now update grind $this->db->set("user_id", $this->email->user_id); $this->db->set("is_primary", $this->email->is_primary); $this->db->set("email_type_luid", $this->email->email_type_luid); $this->db->set("address", $this->email->address); $this->db->where("id", $this->email->id); $result = $this->db->update('email'); error_log("grind failed", 0); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); throw new exception("Couldn't update grind"); } //now update recurly $account = Recurly_Account::get($this->email->user_id); $account->email = $this->email->address; $account->username = $this->email->address; $result = $account->update(); if (!$result) { $this->db->trans_rollback(); error_log("recurly failed", 0); throw new exception("Couldn't update recurly"); } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); error_log("something went wrong with email update", 0); } else { error_log("email shoud be updated logging email update", 0); $this->db->trans_commit(); } } else { // not the primary email address so just update it in Grind error_log("thinks not primary address", 0); $this->db->set("user_id", $this->email->user_id); $this->db->set("is_primary", $this->email->is_primary); $this->db->set("email_type_luid", $this->email->email_type_luid); $this->db->set("address", $this->email->address); $this->db->where("id", $this->email->id); $result = $this->db->update('email'); } } else { error_log("thinks email already taken", 0); throw new exception("Email Address is already taken"); } }
function GetUserRecurlyAccount() { session_start(); return Recurly_Account::get($_SESSION['wpuser']['id']); }
public function wpUpdateEmail() { session_start(); try { if (isset($_POST['email'])) { //Check for unique email address/username in Wordpress $this->db->where('user_login', $_POST['email']); $this->db->from('wpmember_users'); $count = $this->db->count_all_results(); if ($count < 1) { //New email is unique //Change username and email in WP db $data = array('user_login' => $_POST['email'], 'user_email' => $_POST['email']); $this->db->where('ID', $_SESSION['wpuser']['wp_users_id']); $this->db->update('wpmember_users', $data); //Change primary email address in Grind db $this->load->model("usermodel", "", true); $this->usermodel->init($_SESSION['wpuser']['wp_users_id'], UserIdType::WORDPRESSID); $this->usermodel->wpUpdateEmail($_POST); //Update recurly email address $account = Recurly_Account::get($_SESSION['wpuser']['id']); $account->email = $_POST['email']; $account->username = $_POST['email']; $account->update(); //Return success echo json_encode(array("success" => 1)); } else { //new email is not unique echo json_encode(array("success" => 0, "reason" => "NOTUNIQUE")); } } else { echo json_encode(array("success" => 0, "reason" => "EMAILEMPTY")); } } catch (Exception $e) { echo json_encode(array("success" => 0, "reason" => "SYSTEMERROR")); } }