Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with DEPOSITED flow #89

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Entity/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,9 @@ public function getUpdatedAt()
{
return $this->updatedAt;
}

public function isAllowRefund()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename this to isRefundAllowed?

{
return $this->getState() == PaymentInterface::STATE_DEPOSITED;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use shallow comparisons when possible, i.e. ===.

}
}
1 change: 1 addition & 0 deletions Model/PaymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ function setReversingApprovedAmount($amount);
function setReversingCreditedAmount($amount);
function setReversingDepositedAmount($amount);
function setState($state);
function isAllowRefund();
}
17 changes: 10 additions & 7 deletions PluginController/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JMS\Payment\CoreBundle\PluginController;

use JMS\Payment\CoreBundle\PluginController\Event\PaymentStateChangeEvent;
use JMS\Payment\CoreBundle\Entity\Payment;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -420,8 +421,8 @@ protected function doCreateDependentCredit(PaymentInterface $payment, $amount)
}

$paymentState = $payment->getState();
if (PaymentInterface::STATE_APPROVED !== $paymentState && PaymentInterface::STATE_EXPIRED !== $paymentState) {
throw new InvalidPaymentException('Payment\'s state must be APPROVED, or EXPIRED.');
if (!$payment->isAllowRefund()) {
throw new InvalidPaymentException('Payment\'s state must be DEPOSITED.');
}

$credit = $this->buildCredit($instruction, $amount);
Expand Down Expand Up @@ -462,10 +463,11 @@ protected function doCredit(CreditInterface $credit, $amount)
}

if (false === $credit->isIndependent()) {
/** @var PaymentInterface $payment */
$payment = $credit->getPayment();
$paymentState = $payment->getState();
if (PaymentInterface::STATE_APPROVED !== $paymentState && PaymentInterface::STATE_EXPIRED !== $paymentState) {
throw new InvalidPaymentException('Payment\'s state must be APPROVED, or EXPIRED.');
if (!$payment->isAllowRefund()) {
throw new InvalidPaymentException('Payment\'s state must be DEPOSITED.');
}

if (1 === Number::compare($amount, $max = $payment->getDepositedAmount() - $payment->getReversingDepositedAmount() - $payment->getCreditingAmount() - $payment->getCreditedAmount())) {
Expand Down Expand Up @@ -495,10 +497,10 @@ protected function doCredit(CreditInterface $credit, $amount)
}

if (false === $credit->isIndependent()) {
/** @var Payment $payment */
$payment = $credit->getPayment();
$paymentState = $payment->getState();
if (PaymentInterface::STATE_APPROVED !== $paymentState && PaymentInterface::STATE_EXPIRED !== $paymentState) {
throw new InvalidPaymentException('Payment\'s state must be APPROVED, or EXPIRED.');
if (!$payment->isAllowRefund()) {
throw new InvalidPaymentException('Payment\'s state must be DEPOSITED.');
}

if (1 === Number::compare($amount, $payment->getCreditingAmount())) {
Expand All @@ -516,6 +518,7 @@ protected function doCredit(CreditInterface $credit, $amount)
$plugin = $this->getPlugin($instruction->getPaymentSystemName());

try {
$transaction->setPayment($credit->getPayment());
$plugin->credit($transaction, $retry);
$processedAmount = $transaction->getProcessedAmount();

Expand Down