/** * 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()); }
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.'); }
/** * 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); }