function updateShippingAddress() { header('Content-Type: application/json'); validateParameters($_POST); try { $result = ChargeBee_Subscription::update(getSubscriptionId(), array("shipping_address" => $_POST['shipping_address'])); $jsonResponse = array("forward" => "/ssp-php/subscription"); print json_encode($jsonResponse, true); } catch (ChargeBee_InvalidRequestException $e) { handleInvalidRequestErrors($e); } catch (Exception $e) { handleGeneralErrors($e); } }
public function reactivateAccount($inData) { ChargeBee_Environment::configure("rocketmailmerge", "Chargebee api token"); $data = array(); $card = array("number" => $inData['number'], "expiryMonth" => $inData['expiryMonth'], "expiryYear" => $inData['expiryYear'], "cvv" => $inData['cvv'], "billingZip" => $inData['billingZip']); try { $chargebee_result = ChargeBee_Subscription::update($inData['token'], array("planId" => "base_rate", "trialEnd" => 0, "card" => $card)); } catch (Exception $e) { header('Location: https://app.rocketmailmerge.com/account/reactivate.html?id=' . $inData['token'] . "&crd=0"); die; } //Reactivate their subscription $query = "UPDATE user_subscriptions set subscription_status = 'active'\r\n\t\t\t\t WHERE chargebee_id = ?"; $stmt = $this->sql->link->prepare($query); if (!$stmt) { die('Invalid query: ' . $this->sql->link->error); } else { $stmt->bind_param('s', $inData['token']); $resultFromExec = $stmt->execute(); } //Log them in $this->lookupUser(array("id" => $inData['token'])); $session = new iSession(); $session->mod_var("logged_in", 1); $session->mod_var("user_id", $this->outData['data']['user_id']); $session->update_session(); header('Location: https://app.rocketmailmerge.com/dashboard/?tut=1'); }
public function requestPlanChange($inData) { $userID = $this->session->get_user_var('id'); $plans = array('free', 'contractor', 'professional', 'small_business', 'office', 'enterprise', 'cancel', 'reactivate', 'card_update'); if (in_array($inData['plan'], $plans)) { /************** * Locate user'S SUBSCRIPTION ID *****************************/ $row_tmb = array(); $data = array(); $query = "SELECT chargebee_id\n\t\t\t\t\t FROM user_subscriptions\n\t\t\t\t\t WHERE user_id = ?"; $stmt = $this->sql->link->prepare($query); if (!$stmt) { die('Invalid query: ' . $this->sql->link->error); } else { $stmt->bind_param('i', $userID); $resultFromExec = $stmt->execute(); $stmt->store_result(); stmt_bind_assoc($stmt, $returnResults); // loop through all result rows while ($stmt->fetch()) { foreach ($returnResults as $key => $value) { $row_tmb[$key] = $value; } $data = $row_tmb; } } try { ChargeBee_Environment::configure("rocketmailmerge", "1opwNtcdAXu19XWee9cdCFe6E3FfYcCvUF"); switch ($inData['plan']) { case "card_update": $result = ChargeBee_HostedPage::updateCard(array("customer" => array("id" => $data['chargebee_id']))); $hostedPage = $result->hostedPage(); $output['success'] = 1; $output['text'] = "Successfully fetched the card update page."; $output['url'] = $hostedPage->__get('url'); $output['return'] = 1; break; case "cancel": $result = ChargeBee_Subscription::cancel($data['chargebee_id'], array("end_of_term" => 'true')); $subscription_status = $result->subscription()->__get('status'); $query = "UPDATE user_subscriptions set subscription_status = ?\n\t\t\t\t\t\t\t\t WHERE user_id = ?"; $stmt = $this->sql->link->prepare($query); if (!$stmt) { die('Invalid query: ' . $this->sql->link->error); } else { $stmt->bind_param('si', $subscription_status, $userID); $resultFromExec = $stmt->execute(); } $output['success'] = 1; $output['text'] = "Successfully cancelled your subscription."; $output['return'] = 4; break; case "reactivate": $result = ChargeBee_Subscription::reactivate($data['chargebee_id']); $subscription_status = $result->subscription()->__get('status'); $query = "UPDATE user_subscriptions set subscription_status = ?\n\t\t\t\t\t\t\t\t WHERE user_id = ?"; $stmt = $this->sql->link->prepare($query); if (!$stmt) { die('Invalid query: ' . $this->sql->link->error); } else { $stmt->bind_param('si', $subscription_status, $userID); $resultFromExec = $stmt->execute(); } $output['success'] = 1; $output['text'] = "Successfully reactivated your subscription."; $output['return'] = 5; break; case "free": $this->fetchDashboardData(); if ($this->outData['totals']['document_count'] <= 3 && $this->outData['totals']['document_count'] <= 3 && $this->outData['totals']['document_count'] <= 3) { $result = ChargeBee_Subscription::update($data['chargebee_id'], array("planId" => "free")); $output['success'] = 1; $output['text'] = "Successfully updated your account to free."; $output['return'] = 2; } else { $output['success'] = 1; $output['text'] = "Your account does not meet the criteria for the free subscription."; $output['return'] = 6; } break; default: $result = ChargeBee_HostedPage::checkoutExisting(array("subscription" => array("id" => $data['chargebee_id'], "planId" => $inData['plan']))); $hostedPage = $result->hostedPage(); $output['success'] = 1; $output['text'] = "Successfully fetched the plan change page."; $output['url'] = $hostedPage->__get('url'); $output['return'] = 1; break; } $this->outData = $output; return $output; } catch (Exception $e) { $output['success'] = 0; $output['text'] = "Unable to fetch the plan change page."; $output['return'] = 3; $this->outData = $output; return $output; } } }