Esempio n. 1
0
 public function process()
 {
     $values = $this->getValues();
     $lang = OW::getLanguage();
     $userId = OW::getUser()->getId();
     $billingService = BOL_BillingService::getInstance();
     $membershipService = MEMBERSHIP_BOL_MembershipService::getInstance();
     $url = OW::getRouter()->urlForRoute('membership_subscribe');
     if (!($plan = $membershipService->findPlanById($values['plan']))) {
         OW::getFeedback()->error($lang->text('membership', 'plan_not_found'));
         OW::getApplication()->redirect($url);
     }
     if ($plan->price == 0) {
         // trial plan
         // check if trial plan used
         $used = $membershipService->isTrialUsedByUser($userId);
         if ($used) {
             OW::getFeedback()->error($lang->text('membership', 'trial_used_error'));
             OW::getApplication()->redirect($url);
         } else {
             // give trial plan
             $userMembership = new MEMBERSHIP_BOL_MembershipUser();
             $userMembership->userId = $userId;
             $userMembership->typeId = $plan->typeId;
             $userMembership->expirationStamp = time() + (int) $plan->period * 3600 * 24;
             $userMembership->recurring = 0;
             $userMembership->trial = 1;
             $membershipService->setUserMembership($userMembership);
             $membershipService->addTrialPlanUsage($userId, $plan->id, $plan->period);
             OW::getFeedback()->info($lang->text('membership', 'trial_granted', array('days' => $plan->period)));
             OW::getApplication()->redirect($url);
         }
     }
     if (empty($values['gateway']['url']) || empty($values['gateway']['key'])) {
         OW::getFeedback()->error($lang->text('base', 'billing_gateway_not_found'));
         OW::getApplication()->redirect($url);
     }
     $gateway = $billingService->findGatewayByKey($values['gateway']['key']);
     if (!$gateway || !$gateway->active) {
         OW::getFeedback()->error($lang->text('base', 'billing_gateway_not_found'));
         OW::getApplication()->redirect($url);
     }
     // create membership plan product adapter object
     $productAdapter = new MEMBERSHIP_CLASS_MembershipPlanProductAdapter();
     // sale object
     $sale = new BOL_BillingSale();
     $sale->pluginKey = 'membership';
     $sale->entityDescription = $membershipService->getFormattedPlan($plan->price, $plan->period, $plan->recurring);
     $sale->entityKey = $productAdapter->getProductKey();
     $sale->entityId = $plan->id;
     $sale->price = floatval($plan->price);
     $sale->period = $plan->period;
     $sale->userId = $userId ? $userId : 0;
     $sale->recurring = $plan->recurring;
     $saleId = $billingService->initSale($sale, $values['gateway']['key']);
     if ($saleId) {
         // sale Id is temporarily stored in session
         $billingService->storeSaleInSession($saleId);
         $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl());
         // redirect to gateway form page
         OW::getApplication()->redirect($values['gateway']['url']);
     }
 }
Esempio n. 2
0
 public function process()
 {
     $values = $this->getValues();
     $lang = OW::getLanguage();
     $userId = OW::getUser()->getId();
     $billingService = BOL_BillingService::getInstance();
     $membershipService = MEMBERSHIP_BOL_MembershipService::getInstance();
     if (empty($values['gateway']['url']) || empty($values['gateway']['key']) || !($gateway = $billingService->findGatewayByKey($values['gateway']['key']) || !$gateway->active)) {
         OW::getFeedback()->error($lang->text('base', 'billing_gateway_not_found'));
         OW::getApplication()->redirect(OW::getRouter()->urlForRoute('membership_subscribe'));
     }
     if (!($plan = $membershipService->findPlanById($values['plan']))) {
         OW::getFeedback()->error($lang->text('membership', 'plan_not_found'));
         OW::getApplication()->redirect(OW::getRouter()->urlForRoute('membership_subscribe'));
     }
     // create membership plan product adapter object
     $productAdapter = new MEMBERSHIP_CLASS_MembershipPlanProductAdapter();
     // sale object
     $sale = new BOL_BillingSale();
     $sale->pluginKey = 'membership';
     $sale->entityDescription = $membershipService->getFormattedPlan($plan->price, $plan->period, $plan->recurring);
     $sale->entityKey = $productAdapter->getProductKey();
     $sale->entityId = $plan->id;
     $sale->price = floatval($plan->price);
     $sale->period = $plan->period;
     $sale->userId = $userId ? $userId : 0;
     $sale->recurring = $plan->recurring;
     $saleId = $billingService->initSale($sale, $values['gateway']['key']);
     if ($saleId) {
         // sale Id is temporarily stored in session
         $billingService->storeSaleInSession($saleId);
         $billingService->setSessionBackUrl($productAdapter->getProductOrderUrl());
         // redirect to gateway form page
         OW::getApplication()->redirect($values['gateway']['url']);
     }
 }