public function testSetGetState() { $transaction = new FinancialTransaction(); $this->assertEquals(FinancialTransaction::STATE_NEW, $transaction->getState()); $transaction->setState(FinancialTransaction::STATE_PENDING); $this->assertEquals(FinancialTransaction::STATE_PENDING, $transaction->getState()); }
protected function createTransaction($amount, $currency) { $transaction = new FinancialTransaction(); $transaction->setState(FinancialTransactionInterface::STATE_PENDING); $transaction->setRequestedAmount($amount); $paymentInstruction = new PaymentInstruction($amount, $currency, 'sips', new ExtendedData()); $payment = new Payment($paymentInstruction, $amount); $payment->addTransaction($transaction); return $transaction; }
public function testApproveAndDepositCanceled() { $transaction = new FinancialTransaction(); $response = $this->getCanceledResponse(); $transaction->setExtendedData(new ExtendedData()); foreach ($response as $key => $val) { $transaction->getExtendedData()->set($key, $val); } $this->sipsPlugin->approveAndDeposit($transaction, false); $this->assertEquals(SipsPlugin::RESPONSE_CODE_CANCELED, $transaction->getResponseCode()); $this->assertEquals('Payment canceled', $transaction->getReasonCode()); }
public function testDeposit() { $controller = $this->getController(array(), false); $controller->addPlugin($plugin = $this->getPlugin()); $plugin->expects($this->once())->method('deposit'); $controller->expects($this->once())->method('buildFinancialTransaction')->will($this->returnCallback(function () { $transaction = new FinancialTransaction(); $transaction->setProcessedAmount(123.45); $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS); $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS); return $transaction; })); $payment = $this->getPayment(); $payment->setState(PaymentInterface::STATE_APPROVED); $payment->setApprovedAmount(123.45); $instruction = $payment->getPaymentInstruction(); $instruction->setState(PaymentInstructionInterface::STATE_VALID); $instruction->setApprovedAmount(10); $result = $this->callDeposit($controller, array($payment, 123.45)); $this->assertEquals(Result::STATUS_SUCCESS, $result->getStatus(), 'Result status is not success: ' . $result->getReasonCode()); $this->assertEquals(123.45, $payment->getDepositedAmount()); $this->assertEquals(123.45, $instruction->getDepositedAmount()); $this->assertEquals(PaymentInterface::STATE_DEPOSITED, $payment->getState()); $this->assertEquals(0, $payment->getDepositingAmount()); $this->assertEquals(0, $instruction->getDepositingAmount()); }
public function testDispatchesEvents() { $controller = $this->getController(array(), false, true); $payment = $this->getPayment(); $instruction = $payment->getPaymentInstruction(); $instruction->setState(PaymentInstructionInterface::STATE_VALID); $plugin = $this->getPlugin(); $plugin->expects($this->once())->method('approve'); $controller->addPlugin($plugin); $transaction = new FinancialTransaction(); $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS); $transaction->setProcessedAmount(50.12); $controller->expects($this->once())->method('buildFinancialTransaction')->will($this->returnValue($transaction)); $this->dispatcher->expects($this->at(0))->method('dispatch')->with('payment.state_change', new PaymentStateChangeEvent($payment, PaymentInterface::STATE_NEW)); $this->dispatcher->expects($this->at(1))->method('dispatch')->with('payment.state_change', new PaymentStateChangeEvent($payment, PaymentInterface::STATE_APPROVING)); $this->dispatcher->expects($this->at(2))->method('dispatch')->with('payment_instruction.state_change', new PaymentInstructionStateChangeEvent($instruction, PaymentInstructionInterface::STATE_VALID)); $this->callApprove($controller, array($payment, 100)); $controller->closePaymentInstruction($instruction); }
/** * @param string $amount * @param string $currency * @param array $extendedDataValues * * @return \JMS\Payment\CoreBundle\Entity\FinancialTransaction */ protected function createTransaction($amount, $currency, array $extendedDataValues = array('CN' => 'Foo Bar')) { $transaction = new FinancialTransaction(); $transaction->setRequestedAmount($amount); $extendedData = new ExtendedData(); foreach ($extendedDataValues as $key => $value) { $extendedData->set($key, $value); } $paymentInstruction = new PaymentInstruction($amount, $currency, 'ogone_caa', $extendedData); $payment = new Payment($paymentInstruction, $amount); $payment->addTransaction($transaction); return $transaction; }
public function testGetReverseCreditTransactions() { $credit = new Credit($this->getInstruction(), 100); $this->assertEquals(0, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT); $credit->addTransaction($transaction); $this->assertEquals(1, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT); $credit->addTransaction($transaction); $this->assertEquals(2, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $credit->addTransaction($transaction); $this->assertEquals(2, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT); $credit->addTransaction($transaction); $this->assertEquals(3, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $credit->addTransaction($transaction); $this->assertEquals(3, count($credit->getReverseCreditTransactions())); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_CREDIT); $credit->addTransaction($transaction); $this->assertEquals(4, count($credit->getReverseCreditTransactions())); }
/** * Creates a payment with sample financial transactions: * - 1 APPROVE transaction * - 3 DEPOSIT transactions * - 2 REVERSE_APPROVAL transactions * - 4 REVERSE_DEPOSIT transactions * * @return Payment */ protected function getPayment() { $payment = new Payment($this->getInstruction(), 123.45); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_APPROVE); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_APPROVAL); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_APPROVAL); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT); $payment->addTransaction($transaction); $transaction = new FinancialTransaction(); $transaction->setTransactionType(FinancialTransaction::TRANSACTION_TYPE_REVERSE_DEPOSIT); $payment->addTransaction($transaction); return $payment; }
/** * @param $amount * @param $currency * @param $data * @return \JMS\Payment\CoreBundle\Entity\FinancialTransaction */ protected function createTransaction($amount, $currency) { $transaction = new FinancialTransaction(); $transaction->setRequestedAmount($amount); $paymentInstruction = new PaymentInstruction($amount, $currency, 'paypal_express_checkout', new ExtendedData()); $payment = new Payment($paymentInstruction, $amount); $payment->addTransaction($transaction); return $transaction; }