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