public function saveAction()
 {
     $post_data = $this->getRequest()->getPost();
     if ($post_data) {
         $api_mode = Mage::getStoreConfig('payment/pagarme_settings/mode');
         $api_key = Mage::getStoreConfig('payment/pagarme_settings/apikey_' . $api_mode);
         Pagarme::setApiKey($api_key);
         $post_data['trial_days'] = '0';
         // Always OFF.
         try {
             $plan = new PagarMe_Plan(array_merge($post_data, array('amount' => intval(floatval($post_data['amount']) * 100))));
             $result = $plan->create();
             $post_data['remote_id'] = $result['id'];
             $post_data['payment_methods'] = implode(',', $post_data['payment_methods']);
             if (empty($post_data['charges'])) {
                 $post_data['charges'] = new Zend_Db_Expr('NULL');
             }
             $model = Mage::getModel("pagarme/plans")->addData($post_data)->setId($this->getRequest()->getParam("id"))->save();
             Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Plans was successfully saved"));
             Mage::getSingleton("adminhtml/session")->setPlansData(false);
             if ($this->getRequest()->getParam("back")) {
                 $this->_redirect("*/*/edit", array("id" => $model->getId()));
                 return;
             }
             $this->_redirect("*/*/");
             return;
         } catch (Exception $e) {
             Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
             Mage::getSingleton("adminhtml/session")->setPlansData($this->getRequest()->getPost());
             $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
             return;
         }
     }
     $this->_redirect("*/*/");
 }
예제 #2
0
	public function testValidate() {
		$plan = new PagarMe_Plan();

		$this->expectException(new IsAExpectation('PagarMe_Exception'));
		$plan->setAmount('0');
		$plan->create();
		$plan->setAmount('10000');

		$this->expectException(new IsAExpectation('PagarMe_Exception'));
		$plan->days('0');
		$plan->create();
		$plan->setDays('30');

		$this->expectException(new IsAExpectation('PagarMe_Exception'));
		$plan->setTrialDays('-1');
		$plan->create();
		$plan->setTrialDays("10");

		$this->expectException(new IsAExpectation('PagarMe_Exception'));
		$plan->setName('');
		$plan->create();
		$plan->setName('Plan');

		$plan->create();

		$plan->assertTrue($plan->getId());
	}
 public function criarPlano($plano)
 {
     $dados = $this->contaPagarme();
     Pagarme::setApiKey($dados['key_api']);
     $plan = new PagarMe_Plan(array('amount' => str_replace(".", "", $plano['valor']), 'days' => intval($plano['meses']) * 30, 'name' => $plano['plano']));
     $plan->create();
     return $plan->id;
 }
예제 #4
0
 public function testUpdatePlan()
 {
     $subscription = self::createTestSubscription();
     $plan = self::createTestPlan();
     $plan->create();
     $subscription->setPlan($plan);
     $subscription->create();
     $plan2 = new PagarMe_Plan(array('name' => 'Plano 2', 'days' => '10', 'amount' => 4500, 'payment_method' => "credit_card", 'trial_days' => "3"));
     $plan2->create();
     $subscription->plan = $plan2;
     $subscription->save();
     $s2 = PagarMe_Subscription::findById($subscription->id);
     $this->assertEqual($s2->plan->id, $plan2->id);
 }