コード例 #1
0
ファイル: CliController.php プロジェクト: shahmaulik/zfcore
 public function checkStatusAction()
 {
     // $ php public/index.php subscriptions cli check-status
     $this->printMessage('Check and set Inactive status to expired subscriptions', Core_Controller_Action_Cli::INFO_MESSAGE);
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     $subscriptionManager->setInactiveStatusExpiredSubscriptions();
 }
コード例 #2
0
ファイル: IndexController.php プロジェクト: shahmaulik/zfcore
 /**
  * @throws Zend_Controller_Action_Exception
  */
 public function planInfoAction()
 {
     //Get user
     $identity = Zend_Auth::getInstance()->getIdentity();
     $userId = $identity->id;
     //Get current subscription
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     $currentSubscription = $subscriptionManager->getCurrentSubscription($userId);
     if ($currentSubscription) {
         $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
         $subscriptionPlan = $subscriptionPlansTable->getById($currentSubscription->subscriptionPlanId);
         $this->view->currentSubscription = $currentSubscription;
         $this->view->subscriptionPlan = $subscriptionPlan;
     } else {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
 }
コード例 #3
0
 public function testCallbackActionCorrectTxnId()
 {
     //Fake data
     $orderType = Subscriptions_Model_Subscription::ORDER_TYPE_SUBSCRIPTION;
     $planId = '3';
     $price = '50';
     //Create user
     $account = new Users_Model_User();
     $account->avatar = null;
     $account->login = '******' . date('YmdHis');
     $account->email = 'testCallbackActionCorrectTxnId' . time() . '@example.org';
     $account->password = md5('password');
     $account->role = Users_Model_User::ROLE_USER;
     $account->status = Users_Model_User::STATUS_ACTIVE;
     $account->save();
     //Create order
     $orderManager = new Payments_Model_Order_Manager();
     $order = $orderManager->createOrder($account->id, $price);
     $mock = $this->getMock('Payments_Model_Order_Manager', array('checkPaypalPostParams'));
     $mock->expects($this->any())->method('checkPaypalPostParams')->will($this->returnValue(true));
     $mock->setDbTable('Payments_Model_Order_Table');
     //Create custom param
     $customParam = implode('-', array($orderType, $order->id));
     $params = array('custom' => '111', 'subscr_id' => 111, 'mc_gross' => 0, 'txn_type' => 111, 'txn_id' => 111);
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     $subscriptionManager->createPaidSubscription($account->id, $planId, $order->id);
     //Test incorrect custom param
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test ok.
     }
     //Test incorrect custom param
     $params['custom'] = '0-0';
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test ok.
     }
     $params['custom'] = $customParam;
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test empty $amount.
     }
     $params['mc_gross'] = $price;
     $this->assertTrue($mock->handlePaypalRequest($params));
     //Test payOrder() incorrect orderType
     $params['custom'] = implode('-', array('incorrect', $order->id));
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test ok.
     }
     //Test payOrder() incorrect orderId
     $params['custom'] = implode('-', array('incorrect', '12345678'));
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test ok.
     }
     //Test Cancel Subscription
     $params['txn_type'] = 'subscr_cancel';
     $params['custom'] = $customParam;
     $this->assertTrue($mock->handlePaypalRequest($params));
     //Test Cancel Subscription incorrect orderType
     $params['custom'] = implode('-', array('incorrect', $order->id));
     try {
         $mock->handlePaypalRequest($params);
         $this->fail('An expected exception has not been raised.');
     } catch (Exception $ex) {
         // Test ok.
     }
 }
コード例 #4
0
 public function testCompleteAction()
 {
     //Save fake user to DB
     $account = new Users_Model_User();
     $account->avatar = null;
     $account->login = '******' . date('YmdHis');
     $account->email = 'testCompleteAction' . time() . '@example.org';
     $account->password = md5('password');
     $account->role = Users_Model_User::ROLE_USER;
     $account->status = Users_Model_User::STATUS_ACTIVE;
     $account->save();
     //Login
     Zend_Auth::getInstance()->getStorage()->write($account);
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     $subscriptionManager->createFreeSubscription($account->id, 1);
     $this->dispatch('/subscriptions/index/complete');
     $this->assertModule('subscriptions');
     $this->assertController('index');
     $this->assertAction('complete');
     $this->assertContains('Current plan', $this->getResponse()->getBody());
 }
コード例 #5
0
ファイル: ManagerTest.php プロジェクト: shahmaulik/zfcore
 public function testGetExpirationDate()
 {
     //Create user
     $account = new Users_Model_User();
     $account->avatar = null;
     $account->login = '******' . date('YmdHis');
     $account->email = 'testGetExpirationDate' . time() . '@example.org';
     $account->password = md5('password');
     $account->role = Users_Model_User::ROLE_USER;
     $account->status = Users_Model_User::STATUS_ACTIVE;
     $account->save();
     //Get subscription plan
     $subscriptionPlansTable = new Subscriptions_Model_SubscriptionPlans_Table();
     $subscriptionManager = new Subscriptions_Model_Subscription_Manager();
     //Get plan with infinite subscription
     $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_INFINITE);
     $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id);
     $this->assertNull($expirationDate);
     //Get plan with monthly subscription
     $subscriptionPlan = $subscriptionPlansTable->getByType(Subscriptions_Model_SubscriptionPlan::PLAN_TYPE_MONTHLY);
     $expirationDate = $subscriptionManager->getExpirationDate($account->id, $subscriptionPlan->id);
     $this->assertEquals(date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 30, date("Y"))), $expirationDate);
 }