/**
  * Test case for oePayPalIPNRequestPaymentSetter::getRequestOrderPayment
  * Test case for oePayPalIPNRequestPaymentSetter::setRequestOrderPayment
  * Test case for oePayPalIPNRequestPaymentSetter::_prepareOrderPayment
  * Test case for oePayPalIPNRequestPaymentSetter::getRequest
  * Test case for oePayPalIPNRequestPaymentSetter::getAction
  * Test case for oePayPalIPNRequestPaymentSetter::getAmount
  *
  * @param array  $aParams        parameters for POST imitating PayPal.
  * @param string $expectedAction Expected action for resulting payment.
  *
  * @dataProvider providerGetRequestOrderPayment
  */
 public function testGetRequestOrderPayment($aParams, $expectedAction)
 {
     $oPayPalExpectedPayment = new oePayPalOrderPayment();
     if (!empty($aParams)) {
         $oPayPalExpectedPayment->setStatus($aParams['payment_status']);
         $oPayPalExpectedPayment->setTransactionId($aParams['txn_id']);
         $oPayPalExpectedPayment->setCurrency($aParams['mc_currency']);
         $oPayPalExpectedPayment->setAmount(abs($aParams['mc_gross']));
         $oPayPalExpectedPayment->setAction($expectedAction);
         $correlationId = empty($aParams['correlation_id']) ? $aParams['ipn_track_id'] : $aParams['correlation_id'];
         $oPayPalExpectedPayment->setCorrelationId($correlationId);
         $oPayPalExpectedPayment->setDate(date('Y-m-d H:i:s', strtotime($aParams['payment_date'])));
     } else {
         $oPayPalExpectedPayment->setStatus(null);
         $oPayPalExpectedPayment->setTransactionId(null);
         $oPayPalExpectedPayment->setCurrency(null);
         $oPayPalExpectedPayment->setAmount(null);
         $oPayPalExpectedPayment->setCorrelationId(null);
         $oPayPalExpectedPayment->setDate(null);
         $oPayPalExpectedPayment->setAction('capture');
     }
     $_POST = $aParams;
     $oRequest = new oePayPalRequest();
     $oPayPalPayment = new oePayPalOrderPayment();
     $oPayPalIPNRequestSetter = new oePayPalIPNRequestPaymentSetter();
     $oPayPalIPNRequestSetter->setRequest($oRequest);
     $oPayPalIPNRequestSetter->setRequestOrderPayment($oPayPalPayment);
     $oRequestOrderPayment = $oPayPalIPNRequestSetter->getRequestOrderPayment();
     $this->assertEquals($oPayPalExpectedPayment, $oRequestOrderPayment, 'Payment object do not have request parameters.');
 }
 /**
  * Testing new payment creation with correct data after PayPal request is processed
  */
 public function testProcess_NewPaymentCreated_WithCorrectData()
 {
     $sTransactionId = 'transactionId';
     $sCorrelationId = 'correlationId';
     $sStatus = 'Completed';
     $dAmount = 59.67;
     $sCurrency = 'EUR';
     $sDate = 'date';
     $aPayPalResponseMethods = array('getTransactionId' => $sTransactionId, 'getCorrelationId' => $sCorrelationId, 'getPaymentStatus' => $sStatus, 'getCapturedAmount' => $dAmount, 'getCurrency' => $sCurrency);
     $oPayPalResponse = $this->_createStub('oePayPalResponseDoCapture', $aPayPalResponseMethods);
     $oPayment = new oePayPalOrderPayment();
     $oPayment->setDate($sDate);
     $oPayment->setTransactionId($sTransactionId);
     $oPayment->setCorrelationId($sCorrelationId);
     $oPayment->setAction('capture');
     $oPayment->setStatus($sStatus);
     $oPayment->setAmount($dAmount);
     $oPayment->setCurrency($sCurrency);
     $oPaymentList = $this->_getPaymentList(array('addPayment'));
     $oPaymentList->expects($this->once())->method('addPayment')->with($oPayment)->will($this->returnValue($oPayment));
     $oOrder = $this->_getOrder(array('getPaymentList'));
     $oOrder->expects($this->once())->method('getPaymentList')->will($this->returnValue($oPaymentList));
     $oAction = $this->_getAction($oPayPalResponse, $oOrder);
     $oAction->process();
 }
 /**
  * Test case for adding / getting PayPal Order Payment history item
  */
 public function testCreatePayPalOrderPayment()
 {
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setOrderId('123');
     $oOrderPayment->setTransactionId('transactionId');
     $oOrderPayment->setCorrelationId('correlationId');
     $oOrderPayment->setAmount(50);
     $oOrderPayment->setRefundedAmount(12.13);
     $oOrderPayment->setAction('capture');
     $oOrderPayment->setDate('2012-04-13 15:16:32');
     $oOrderPayment->setStatus('status');
     $oOrderPayment->setCurrency('LTL');
     $oOrderPayment->save();
     $oOrderPaymentLoaded = new oePayPalOrderPayment();
     $oOrderPaymentLoaded->load($oOrderPayment->getPaymentId());
     $this->assertEquals('123', $oOrderPaymentLoaded->getOrderId());
     $this->assertEquals('transactionId', $oOrderPaymentLoaded->getTransactionId());
     $this->assertEquals('correlationId', $oOrderPaymentLoaded->getCorrelationId());
     $this->assertEquals(50, $oOrderPaymentLoaded->getAmount());
     $this->assertEquals(12.13, $oOrderPaymentLoaded->getRefundedAmount());
     $this->assertEquals('capture', $oOrderPaymentLoaded->getAction());
     $this->assertEquals('2012-04-13 15:16:32', $oOrderPaymentLoaded->getDate());
     $this->assertEquals('status', $oOrderPaymentLoaded->getStatus());
     $this->assertEquals('LTL', $oOrderPaymentLoaded->getCurrency());
 }
 /**
  * Testing new payment creation with correct data after PayPal request is processed
  */
 public function testProcess_NewPaymentCreated_WithCorrectData()
 {
     $sAuthentificationId = 'authentificationId';
     $sCorrelationId = 'correlationId';
     $dAmount = 2.99;
     $sDate = 'date';
     $aPayPalResponseMethods = array('getAuthorizationId' => $sAuthentificationId, 'getCorrelationId' => $sCorrelationId);
     $oPayPalResponse = $this->_createStub('oePayPalResponseDoVoid', $aPayPalResponseMethods);
     $oPayment = new oePayPalOrderPayment();
     $oPayment->setDate($sDate);
     $oPayment->setTransactionId($sAuthentificationId);
     $oPayment->setCorrelationId($sCorrelationId);
     $oPayment->setAction('void');
     $oPayment->setStatus('Voided');
     $oPayment->setAmount($dAmount);
     $oPaymentList = $this->_getPaymentList(array('addPayment'));
     $oPaymentList->expects($this->once())->method('addPayment')->with($oPayment)->will($this->returnValue($this->_getPayment()));
     $oOrder = $this->_getOrder(array('getPaymentList', 'getRemainingOrderSum'));
     $oOrder->expects($this->once())->method('getRemainingOrderSum')->will($this->returnValue($dAmount));
     $oOrder->expects($this->once())->method('getPaymentList')->will($this->returnValue($oPaymentList));
     $oAction = $this->_getAction($oPayPalResponse, $oOrder);
     $oAction->process();
 }
 /**
  * Prepare PayPal payment. Fill up with request values.
  *
  * @param oePayPalOrderPayment $oRequestOrderPayment order to set params.
  */
 protected function _prepareOrderPayment($oRequestOrderPayment)
 {
     $oRequest = $this->getRequest();
     $oRequestOrderPayment->setStatus($oRequest->getRequestParameter(self::PAYPAL_PAYMENT_STATUS));
     $oRequestOrderPayment->setTransactionId($oRequest->getRequestParameter(self::PAYPAL_TRANSACTION_ID));
     $oRequestOrderPayment->setCurrency($oRequest->getRequestParameter(self::MC_CURRENCY));
     $oRequestOrderPayment->setAmount($this->getAmount());
     $oRequestOrderPayment->setAction($this->getAction());
     $correlationId = $oRequest->getRequestParameter(self::CORRELATION_ID);
     if (!$correlationId) {
         $correlationId = $oRequest->getRequestParameter(self::IPN_TRACK_ID);
     }
     $oRequestOrderPayment->setCorrelationId($correlationId);
     $date = 0 < strlen($oRequest->getRequestParameter(self::PAYMENT_DATE)) ? date('Y-m-d H:i:s', strtotime($oRequest->getRequestParameter(self::PAYMENT_DATE))) : null;
     $oRequestOrderPayment->setDate($date);
 }
 /**
  * Test case for oePayPalOrderPayment::hasPendingPayment()
  * Checks if list has pending payments
  *
  * @return null
  */
 public function testAddPayment()
 {
     $oOrderPaymentList = new oePayPalOrderPaymentList();
     $oOrderPaymentList->load("order");
     $this->assertEquals(0, count($oOrderPaymentList));
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setOrderId("order");
     $oOrderPayment->save();
     $oOrderPaymentList = new oePayPalOrderPaymentList();
     $oOrderPaymentList->load("order");
     $this->assertEquals(1, count($oOrderPaymentList));
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setDate('2013-01-12');
     $oOrderPayment->setAction('Pending');
     $oOrderPaymentList->addPayment($oOrderPayment);
     $oOrderPaymentList = new oePayPalOrderPaymentList();
     $oOrderPaymentList->load("order");
     $this->assertEquals(2, count($oOrderPaymentList));
 }