/**
  * @covers oePayPalOrderRefundAction::process
  * @covers oePayPalOrderRefundActionHandler::getPayPalResponse
  * @covers oePayPalOrderRefundActionHandler::getPayPalRequest
  * @covers oePayPalOrderRefundActionData::getAmount
  * @covers oePayPalOrderRefundActionData::getType
  */
 public function testActionRefund()
 {
     $aRequestParams = array('refund_amount' => '10', 'refund_type' => 'Complete', 'transaction_id' => 'capturedTransaction');
     $aResponseParams = array('REFUNDTRANSACTIONID' => 'TransactionId', 'REFUNDSTATUS' => 'Pending', 'GROSSREFUNDAMT' => '9.01', 'CURRENCYCODE' => 'EUR');
     $oCapturedPayment = new oePayPalOrderPayment();
     $oCapturedPayment->setOrderId('testOrderId');
     $oCapturedPayment->setTransactionId('capturedTransaction');
     $oCapturedPayment->save();
     $oAction = $this->_createAction('refund', 'testOrderId', $aRequestParams, $aResponseParams);
     $oAction->process();
     $oOrder = $this->_getOrder('testOrderId');
     $this->assertEquals('9.01', $oOrder->getRefundedAmount());
     $aPaymentList = $oOrder->getPaymentList()->getArray();
     $this->assertEquals(2, count($aPaymentList));
     $oPayment = array_shift($aPaymentList);
     $this->assertEquals('refund', $oPayment->getAction());
     $this->assertEquals('testOrderId', $oPayment->getOrderId());
     $this->assertEquals('9.01', $oPayment->getAmount());
     $this->assertEquals('Pending', $oPayment->getStatus());
     $this->assertEquals('EUR', $oPayment->getCurrency());
     $oCapturedPayment = array_shift($aPaymentList);
     $this->assertEquals('9.01', $oCapturedPayment->getRefundedAmount());
     $oPayment->delete();
     $oCapturedPayment->delete();
     $oOrder->delete();
 }
 /**
  * Returns payment to refund.
  *
  * @return float
  */
 public function getPaymentBeingRefunded()
 {
     if (is_null($this->_oPaymentBeingRefunded)) {
         $this->_oPaymentBeingRefunded = oxNew("oePayPalOrderPayment");
         $this->_oPaymentBeingRefunded->loadByTransactionId($this->getTransactionId());
     }
     return $this->_oPaymentBeingRefunded;
 }
 public function testSetGetRequestOrderPayment()
 {
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setCurrency('EUR');
     $oOrderPayment->setAmount('12.23');
     $oPayPalIPNRequestValidator = new oePayPalIPNPaymentValidator();
     $oPayPalIPNRequestValidator->setRequestOrderPayment($oOrderPayment);
     $this->assertEquals($oOrderPayment, $oPayPalIPNRequestValidator->getRequestOrderPayment(), 'Getter should return same as set in setter.');
 }
 /**
  * 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 loading of payment by transaction id
  */
 public function testGetPaymentBeingRefunded_LoadedByTransactionId_TransactionIdSet()
 {
     $sTransactionId = 'test_transId';
     $oPayment = new oePayPalOrderPayment();
     $oPayment->setTransactionId($sTransactionId);
     $oPayment->setOrderId('_testOrderId');
     $oPayment->save();
     $aParams = array('transaction_id' => $sTransactionId);
     $oRequest = $this->_createStub('oePayPalRequest', array('getPost' => $aParams));
     $oOrder = $this->_getOrder();
     $oActionData = new oePayPalOrderRefundActionData($oRequest, $oOrder);
     $oPayment = $oActionData->getPaymentBeingRefunded();
     $this->assertEquals($sTransactionId, $oPayment->getTransactionId());
 }
 /**
  * @dataProvider providerHandleRequest
  */
 public function testHandleRequest($sShopOwnerPayPal, $aResponseFromPayPal, $blRequestHandledExpected, $OrderStatusAfterRequest, $blFailureMessageExist, $sTransactionIdPayPal, $dPaymentAmountPayPal, $sPaymentCurrencyPayPal, $sPaymentStatusPayPal, $sTransactionIdShop, $dPaymentAmountShop, $sPaymentCurrencyShop, $PaymentStatusAfterRequest)
 {
     $sOrderId = '__handleRequest_order';
     $this->_preparePayPalRequest($sShopOwnerPayPal, $sPaymentStatusPayPal, $sTransactionIdPayPal, $dPaymentAmountPayPal, $sPaymentCurrencyPayPal);
     $oOrder = $this->_createPayPalOrder($sOrderId);
     $this->_createOrderPayment($sOrderId, $sTransactionIdShop, $dPaymentAmountShop, $sPaymentCurrencyShop);
     // Mock curl so we do not call PayPal to check if request originally from PayPal.
     $oIPNRequestVerifier = $this->_createPayPalResponse($aResponseFromPayPal);
     $oPayPalIPNHandler = new oePayPalIPNHandler();
     $oPayPalIPNHandler->setIPNRequestVerifier($oIPNRequestVerifier);
     $blRequestHandled = $oPayPalIPNHandler->handleRequest();
     $oOrder->load();
     $oPayment = new oePayPalOrderPayment();
     $oPayment->loadByTransactionId($sTransactionIdShop);
     $this->assertEquals($blRequestHandledExpected, $blRequestHandled, 'Request is not handled as expected.');
     $this->assertEquals($PaymentStatusAfterRequest, $oPayment->getStatus(), 'Status did not change to one returned from PayPal.');
     $this->assertEquals($OrderStatusAfterRequest, $oOrder->getPaymentStatus(), 'Status did not change to one returned from PayPal.');
     $this->assertEquals($dPaymentAmountShop, $oPayment->getAmount(), 'Payment amount should not change to get from PayPal.');
     $this->assertEquals($sPaymentCurrencyShop, $oPayment->getCurrency(), 'Payment currency should not change to get from PayPal.');
     if (!$blFailureMessageExist) {
         $this->assertEquals(0, count($oPayment->getCommentList()), 'There should be no failure comment.');
     } else {
         $aComments = $oPayment->getCommentList();
         $aComments = $aComments->getArray();
         $sComment = $aComments[0]->getComment();
         // Failure comment should have all information about request and original payment.
         $blCommentHasAllInformation = strpos($sComment, (string) $dPaymentAmountPayPal) !== false && strpos($sComment, (string) $sPaymentCurrencyPayPal) !== false && strpos($sComment, (string) $dPaymentAmountShop) !== false && strpos($sComment, (string) $sPaymentCurrencyShop) !== false;
         $this->assertEquals(1, count($aComments), 'There should failure comment.');
         $this->assertTrue($blCommentHasAllInformation, 'Failure comment should have all information about request and original payment: ' . $sComment);
     }
 }
 /**
  * Tests isPayPalActionValid
  *
  * @dataProvider isActionValid_dataProvider
  */
 public function testIsActionAvailable($sPayment, $dAmount, $dRefunded, $sState, $sAction, $dIsValid)
 {
     $oPayment = new oePayPalOrderPayment();
     $oPayment->setAction($sPayment);
     $oPayment->setAmount($dAmount);
     $oPayment->setRefundedAmount($dRefunded);
     $oPayment->setStatus($sState);
     $oActionManager = new oePayPalOrderPaymentActionManager();
     $oActionManager->setPayment($oPayment);
     $this->assertEquals($dIsValid, $oActionManager->isActionAvailable($sAction));
 }
 /**
  * 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();
 }
 /**
  * Test case add comment to payment
  */
 public function testGetCommentList_noComments_instanceOfCommentList()
 {
     $oOrderPayment = new oePayPalOrderPayment();
     $this->assertTrue($oOrderPayment->getCommentList() instanceof oePayPalOrderPaymentCommentList, 'No comments - default value empty array.');
 }
 /**
  * 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);
 }
Esempio n. 11
0
 /**
  * Returns not yet captured (remaining) order sum.
  *
  * @param oePayPalOrderPayment $oPayment order payment
  *
  * @return oePayPalOrderPayment
  */
 public function addPayment(oePayPalOrderPayment $oPayment)
 {
     //order payment info
     if ($this->getOrderId()) {
         $oPayment->setOrderId($this->getOrderId());
         $oPayment->save();
     }
     $this->load($this->getOrderId());
     return $oPayment;
 }
 /**
  * Add Payment Status information to object from database from object created from from PayPal request.
  *
  * @param oePayPalOrderPayment $oRequestOrderPayment
  * @param oePayPalOrderPayment $oOrderPayment
  *
  * @return oePayPalOrderPayment
  */
 protected function _changePaymentStatusInfo($oRequestOrderPayment, $oOrderPayment)
 {
     $oOrderPayment->setStatus($oRequestOrderPayment->getStatus());
     return $oOrderPayment;
 }
 /**
  * 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));
 }
 /**
  * Prepare OrderPayment object.
  *
  * @return oePayPalOrderPayment
  */
 protected function getOrderPayment()
 {
     oePayPalEvents::addOrderPaymentsTable();
     oePayPalEvents::addOrderTable();
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setTransactionId('asdadsd45a4sd5a4sd54a5');
     $oOrderPayment->setOrderId('order');
     return $oOrderPayment;
 }
 /**
  * Add comment for request payment if comment exists.
  * Function must only be called when the payment object this
  * comment is related to is already stored in the database and has an oxid.
  * Comment will be immediately saved to database.
  *
  * @param  oePayPalOrderPayment $paypalOrderPayment
  *
  * @return oePayPalOrderPayment
  */
 private function addRequestPaymentComment($paypalOrderPayment)
 {
     $request = $this->getRequest();
     $memo = $request->getRequestParameter(self::PAYPAL_IPN_MEMO);
     if ($memo) {
         $comment = oxNew('oePayPalOrderPaymentComment');
         $comment->setComment($memo);
         $paypalOrderPayment->addComment($comment);
         if (0 < $paypalOrderPayment->getId()) {
             $paypalOrderPayment->save();
         }
     }
     return $paypalOrderPayment;
 }
 /**
  * Wrapper to create order payment.
  *
  * @param string $sTransactionId     transaction id.
  * @param bool   $blValid            if payment should be marked as not valid.
  * @param string $sValidationMessage validation message
  *
  * @return oePayPalOrderPayment
  */
 protected function _prepareOrderPayment($sTransactionId, $blValid = true, $sValidationMessage = '')
 {
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setPaymentId('__a24das5das45');
     $oOrderPayment->setOrderId('_sOrderId');
     $oOrderPayment->setTransactionId($sTransactionId);
     if (!$blValid) {
         $oOrderPayment->setIsValid(false);
     }
     if ($sValidationMessage) {
         $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
         $oOrderPayment->addComment($sDate, $sValidationMessage);
     }
     return $oOrderPayment;
 }
 /**
  * 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.');
 }
 /**
  * Create order payment with some transaction id and same order id as order in _prepareOrder().
  *
  * @param string $sOrderId order id.
  *
  * @return oePayPalOrderPayment
  */
 protected function _prepareOrderPayment($sOrderId)
 {
     $oOrderPayment = new oePayPalOrderPayment();
     $oOrderPayment->setTransactionId('_asdadsd45a4sd5a4sd54a5');
     $oOrderPayment->setOrderId($sOrderId);
     return $oOrderPayment;
 }