示例#1
0
 /**
  * This method adds a Credit container to this PaymentInstruction.
  *
  * This method is called automatically from Credit::__construct().
  *
  * @param Credit $credit
  * @return void
  */
 public function addCredit(Credit $credit)
 {
     if ($credit->getPaymentInstruction() !== $this) {
         throw new \InvalidArgumentException('This credit container belongs to another instruction.');
     }
     $this->credits->add($credit);
 }
 /**
  * @return \JMS\Payment\CoreBundle\Entity\ExtendedData|null
  */
 public function getExtendedData()
 {
     if (null !== $this->extendedData) {
         return $this->extendedData;
     }
     if (null !== $this->payment) {
         return $this->payment->getPaymentInstruction()->getExtendedData();
     } else {
         if (null !== $this->credit) {
             return $this->credit->getPaymentInstruction()->getExtendedData();
         }
     }
     return null;
 }
 /**
  * @dataProvider getTestAmountsForDependentCredit
  * @expectedException \InvalidArgumentException
  */
 public function testCreditOnlyAcceptsValidAmountsForDependentCredit($amount)
 {
     $controller = $this->getController();
     $instruction = new PaymentInstruction(111, 'EUR', 'foo', new ExtendedData());
     $instruction->setState(PaymentInstruction::STATE_VALID);
     $credit = new Credit($instruction, 100);
     $payment = new Payment($instruction, 10);
     $payment->setState(Payment::STATE_APPROVED);
     $credit->setPayment($payment);
     $instruction->setDepositedAmount(10);
     $payment->setDepositedAmount(5.0);
     $payment->setCreditingAmount(0.01);
     $payment->setCreditedAmount(0.01);
     $payment->setReversingDepositedAmount(0.01);
     $this->callCredit($controller, array($credit, $amount));
 }
 public function testHasPendingTransactionOnCredit()
 {
     $instruction = $this->getInstruction();
     $credit = new Credit($instruction, 123.45);
     $this->assertFalse($instruction->hasPendingTransaction());
     $transaction = new FinancialTransaction();
     $credit->addTransaction($transaction);
     $transaction->setState(FinancialTransaction::STATE_PENDING);
     $this->assertTrue($instruction->hasPendingTransaction());
 }
 public function testSetGetPayment()
 {
     $credit = new Credit($instruction = $this->getInstruction(), 11);
     $this->assertNull($credit->getPayment());
     $credit->setPayment($payment = new Payment($instruction, 100));
     $this->assertSame($payment, $credit->getPayment());
 }
 protected function getTransaction($withCredit = false)
 {
     $instruction = new PaymentInstruction(123, 'EUR', 'foo', new ExtendedData());
     $transaction = new FinancialTransaction();
     if (!$withCredit) {
         $payment = new Payment($instruction, 100);
         $payment->addTransaction($transaction);
     } else {
         $credit = new Credit($instruction, 123.45);
         $credit->addTransaction($transaction);
     }
     return $transaction;
 }