Esempio n. 1
0
 public function testCancel()
 {
     $paymentMethod = $this->getMock('Magento\\Payment\\Model\\Method\\AbstractMethod', ['canVoid'], [], '', false);
     $this->helper->expects($this->once())->method('getMethodInstance')->will($this->returnValue($paymentMethod));
     $this->payment->setMethod('any');
     // check fix for partial refunds in Payflow Pro
     $paymentMethod->expects($this->once())->method('canVoid')->with(new \PHPUnit_Framework_Constraint_IsIdentical($this->payment))->will($this->returnValue(false));
     $this->assertEquals($this->payment, $this->payment->cancel());
 }
Esempio n. 2
0
 protected function setUp()
 {
     $this->eventManagerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Manager')->disableOriginalConstructor()->getMock();
     $context = $this->getMockBuilder('Magento\\Framework\\Model\\Context')->disableOriginalConstructor()->getMock();
     $context->expects($this->once())->method('getEventDispatcher')->will($this->returnValue($this->eventManagerMock));
     $this->helperMock = $this->getMockBuilder('Magento\\Payment\\Helper\\Data')->disableOriginalConstructor()->setMethods(['getMethodInstance'])->getMock();
     $this->priceCurrencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\PriceCurrency')->disableOriginalConstructor()->setMethods(['format'])->getMock();
     $this->priceCurrencyMock->expects($this->any())->method('format')->willReturnCallback(function ($value) {
         return $value;
     });
     $this->paymentMethodMock = $this->getMockBuilder('Magento\\Payment\\Model\\Method\\AbstractMethod')->disableOriginalConstructor()->setMethods(['canVoid', 'authorize', 'getConfigData', 'getConfigPaymentAction', 'validate'])->getMock();
     $this->helperMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($this->paymentMethodMock));
     $this->orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->setMethods(['getConfig', 'setState', 'getStoreId', 'getBaseGrandTotal', 'getBaseCurrency', 'getBaseCurrencyCode', 'getTotalDue', 'getBaseTotalDue'])->getMock();
     $this->payment = (new \Magento\TestFramework\Helper\ObjectManager($this))->getObject('Magento\\Sales\\Model\\Order\\Payment', ['context' => $context, 'paymentData' => $this->helperMock, 'priceCurrency' => $this->priceCurrencyMock]);
     $this->payment->setMethod('any');
     $this->payment->setOrder($this->orderMock);
 }
Esempio n. 3
0
 public function executeBuy($request)
 {
     $this->user = $this->getUser()->getSubscriber();
     $this->step = 1;
     $this->form = new BuyStep1Form();
     if ($request->isMethod('post') || $request->getParameter('jotag')) {
         // if direct access, stop on step 1
         if (!$request->isMethod('post')) {
             $request->setParameter('step', 1);
         }
         $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag'))));
         if ($this->form->isValid()) {
             // step 1 OK
             $this->jotag_object = $this->form->getValue('jotag_object');
             $this->step = 2;
             if ($this->user->getCredits() || $this->isWebserviceCall()) {
                 if (!$this->user->getCredits()) {
                     // ok, webservice call, but we don't have credits
                     $this->form = null;
                     return sfView::ERROR;
                 }
                 // REDEEM FORK
                 $this->setTemplate('redeem');
                 $this->form = new RedeemStep2Form(array('jotag' => strtolower($this->form->getValue('jotag'))));
                 if ($request->getParameter('step') > 1) {
                     $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag')), 'confirm_jotag' => strtolower($request->getParameter('confirm_jotag'))));
                     if ($this->form->isValid()) {
                         // step 2 OK, here we create new jotag
                         $this->step = 3;
                         if ($this->jotag_object) {
                             $jotag = $this->jotag_object;
                             $ptype = PaymentPeer::PT_RENEW;
                         } else {
                             $jotag = new Tag();
                             $jotag->setJotag(strtolower($this->form->getValue('jotag')));
                             $jotag->setStatus(TagPeer::ST_NEW);
                             $jotag->setUser($this->getUser()->getSubscriber());
                             $jotag->setIsPrimary(false);
                             $ptype = PaymentPeer::PT_NEW;
                         }
                         // mark this jotag as FREE, so we can automatically give credits
                         $jotag->setIsCredit(true);
                         // calculate new expiration date
                         $jotag->setValidUntil($jotag->calcNewDate($this->user->getCredits() * OptionPeer::retrieveOption('BONUS_DAYS_PER_CREDIT'), true));
                         $jotag->setStatus(TagPeer::ST_ACTIVE);
                         // create payment
                         $payment = new Payment();
                         $payment->setTag($jotag);
                         $payment->setMethod(PaymentPeer::PT_CREDITS);
                         $payment->setAmount(0);
                         $payment->setDuration($this->user->getCredits() * OptionPeer::retrieveOption('BONUS_DAYS_PER_CREDIT'));
                         $payment->setCredits($this->user->getCredits());
                         $payment->setUser($this->getUser()->getSubscriber());
                         $payment->setStatus(PaymentPeer::ST_PAID);
                         $payment->setType($ptype);
                         // save
                         $jotag->save();
                         $payment->save();
                         // remove credits from user account
                         $this->user->setCredits(0);
                         $this->user->save();
                         // remove from interest list
                         $this->user->delInterest($jotag->getJotag());
                         $this->payment = $payment;
                         $this->jotag = $jotag;
                         // send receipt to the user
                         Mailer::sendEmail($payment->getUser()->getPrimaryEmail(), 'paymentConfirmation', array('payment' => $payment), $this->getUser()->getSubscriber()->getPreferedLanguage());
                     }
                 }
             } else {
                 // BUY FORK
                 $this->form = new BuyStep2Form(array('jotag' => strtolower($this->form->getValue('jotag'))));
                 if ($request->getParameter('step') > 1) {
                     $this->form->bind(array('jotag' => strtolower($request->getParameter('jotag')), 'confirm_jotag' => strtolower($request->getParameter('confirm_jotag')), 'duration' => $request->getParameter('duration')));
                     if ($this->form->isValid()) {
                         // step 2 OK, create payment
                         $payment = new Payment();
                         if ($this->jotag_object) {
                             $payment->setTag($this->jotag_object);
                             $payment->setType(PaymentPeer::PT_RENEW);
                         } else {
                             $payment->setJotag(strtolower($this->form->getValue('jotag')));
                             $payment->setType(PaymentPeer::PT_NEW);
                         }
                         $payment->setMethod(PaymentPeer::PT_PAYPAL);
                         $payment->setAmount((double) sprintf("%0.2f", $this->form->getValue('duration') * OptionPeer::retrieveOption('BUY_PRICE')));
                         $payment->setDuration($this->form->getValue('duration'));
                         $payment->setUser($this->getUser()->getSubscriber());
                         $payment->setCredits(0);
                         $payment->setStatus(PaymentPeer::ST_NEW);
                         $payment->save();
                         $this->payment = $payment;
                         $this->getUser()->setPaymentId($payment->getId());
                         $this->step = 3;
                         $this->form = new BuyStep3Form(array('jotag' => strtolower($this->form->getValue('jotag')), 'confirm_jotag' => strtolower($this->form->getValue('confirm_jotag')), 'duration' => $this->form->getValue('duration')));
                     }
                 }
             }
         } else {
             if (get_class($this->form["jotag"]->getError()->getValidator()) == "buyJotagValidator") {
                 $this->already_exists = $this->form["jotag"]->getError()->getValidator()->getAlreadyExists();
             }
         }
         $this->suggestions = $this->user->getSuggestions($request->getParameter('jotag'));
     } else {
         $this->suggestions = $this->user->getSuggestions();
     }
 }