From dfd6658bb277c98cd475faace0a4e528a92caacc Mon Sep 17 00:00:00 2001 From: Jihell Date: Fri, 25 Jan 2019 12:39:27 +0100 Subject: [PATCH 1/5] Update PluginController.php --- PluginController/PluginController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PluginController/PluginController.php b/PluginController/PluginController.php index cab22eb..547a843 100644 --- a/PluginController/PluginController.php +++ b/PluginController/PluginController.php @@ -956,8 +956,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(); From 660d8085c518393a7d28195f9b314ee520245efd Mon Sep 17 00:00:00 2001 From: Jihell Date: Fri, 25 Jan 2019 12:41:00 +0100 Subject: [PATCH 2/5] Update PluginControllerInterface.php --- PluginController/PluginControllerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From eb13c500481bc15f3c045803d07ffffdfd88376e Mon Sep 17 00:00:00 2001 From: Jihell Date: Fri, 25 Jan 2019 16:14:33 +0100 Subject: [PATCH 3/5] Update PluginController.php --- PluginController/PluginController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PluginController/PluginController.php b/PluginController/PluginController.php index 547a843..74e23f3 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.'); } From 81cdbdf268f19bdec9c90a75ec183d73c1d1942c Mon Sep 17 00:00:00 2001 From: Jihell Date: Fri, 25 Jan 2019 16:45:34 +0100 Subject: [PATCH 4/5] Update PluginController.php --- PluginController/PluginController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PluginController/PluginController.php b/PluginController/PluginController.php index 74e23f3..7025c95 100644 --- a/PluginController/PluginController.php +++ b/PluginController/PluginController.php @@ -474,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.'); } From 04e89a1ee552d88e5b62f03d8ada8f241e7ef805 Mon Sep 17 00:00:00 2001 From: Jihell Date: Fri, 25 Jan 2019 16:54:28 +0100 Subject: [PATCH 5/5] Update PluginController.php --- PluginController/PluginController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/PluginController/PluginController.php b/PluginController/PluginController.php index 7025c95..01045bc 100644 --- a/PluginController/PluginController.php +++ b/PluginController/PluginController.php @@ -986,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);