diff --git a/PluginController/PluginController.php b/PluginController/PluginController.php index cab22eb..01045bc 100644 --- a/PluginController/PluginController.php +++ b/PluginController/PluginController.php @@ -429,7 +429,11 @@ protected function doCreateDependentCredit(PaymentInterface $payment, $amount) } $paymentState = $payment->getState(); - if (PaymentInterface::STATE_APPROVED !== $paymentState && PaymentInterface::STATE_EXPIRED !== $paymentState) { + if (!in_array($paymentState, [ + PaymentInterface::STATE_APPROVED, + PaymentInterface::STATE_EXPIRED, + PaymentInterface::STATE_DEPOSITED, + ])) { throw new InvalidPaymentException('Payment\'s state must be APPROVED, or EXPIRED.'); } @@ -470,10 +474,15 @@ protected function doCredit(CreditInterface $credit, $amount) throw new \InvalidArgumentException(sprintf('$amount cannot be greater than %.2f (Credit restriction).', $credit->getTargetAmount())); } + $payment = null; if (false === $credit->isIndependent()) { $payment = $credit->getPayment(); $paymentState = $payment->getState(); - if (PaymentInterface::STATE_APPROVED !== $paymentState && PaymentInterface::STATE_EXPIRED !== $paymentState) { + if (!in_array($paymentState, [ + PaymentInterface::STATE_APPROVED, + PaymentInterface::STATE_DEPOSITED, + PaymentInterface::STATE_EXPIRED, + ])) { throw new InvalidPaymentException('Payment\'s state must be APPROVED, or EXPIRED.'); } @@ -956,8 +965,11 @@ protected function doReverseDeposit(PaymentInterface $payment, $amount) throw new InvalidPaymentInstructionException('PaymentInstruction must be in STATE_VALID.'); } - if (PaymentInterface::STATE_APPROVED !== $payment->getState()) { - throw new InvalidPaymentException('Payment must be in STATE_APPROVED.'); + if (!in_array($payment->getState(), [ + PaymentInterface::STATE_APPROVED, + PaymentInterface::STATE_DEPOSITED, + ])) { + throw new InvalidPaymentException('Payment must be in STATE_APPROVED or STATE_DEPOSITED.'); } $transaction = $instruction->getPendingTransaction(); @@ -974,6 +986,7 @@ protected function doReverseDeposit(PaymentInterface $payment, $amount) $transaction->setTransactionType(FinancialTransactionInterface::TRANSACTION_TYPE_REVERSE_DEPOSIT); $transaction->setState(FinancialTransactionInterface::STATE_PENDING); $transaction->setRequestedAmount($amount); + $payment->addTransaction($transaction); $payment->setReversingDepositedAmount($amount); $instruction->setReversingDepositedAmount($instruction->getReversingDepositedAmount() + $amount); diff --git a/PluginController/PluginControllerInterface.php b/PluginController/PluginControllerInterface.php index 0ff8ea8..bb65e33 100644 --- a/PluginController/PluginControllerInterface.php +++ b/PluginController/PluginControllerInterface.php @@ -496,7 +496,7 @@ public function reverseCredit($creditId, $amount); * * The implementation will ensure that: * - PaymentInstruction is in STATE_VALID - * - Payment is in STATE_APPROVED + * - Payment is in STATE_APPROVED or STATE_DEPOSITED * - any pending transaction is belonging to this payment, and is a reverseDeposit transaction * - for non-retry transactions: requested amount <= PaymentInstruction.depositedAmount - PaymentInstruction.reversingDepositedAmount * - for non-retry transactions: requested amount <= Payment.depositedAmount