-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from sherlockode/feature/allow_retry_payment
Allow user to retry a new payment
- Loading branch information
Showing
11 changed files
with
152 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Sherlockode\SyliusCheckoutPlugin\Payum\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\ApiAwareInterface; | ||
use Payum\Core\Exception\LogicException; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\Generic; | ||
use Sherlockode\SyliusCheckoutPlugin\Checkout\Model\Charge; | ||
use Sherlockode\SyliusCheckoutPlugin\Payum\Request\Decline; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
|
||
/** | ||
* Class CreateChargeAction | ||
*/ | ||
class DeclineAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface | ||
{ | ||
use ApiAwareTrait; | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* @var SessionInterface | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* DeclineAction constructor. | ||
* | ||
* @param SessionInterface $session | ||
*/ | ||
public function __construct(SessionInterface $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* @param Generic $request | ||
* | ||
* @throws LogicException | ||
*/ | ||
public function execute($request): void | ||
{ | ||
/** @var $request Decline */ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
|
||
/** @var PaymentInterface $payment */ | ||
$payment = $request->getModel(); | ||
$details = $payment->getDetails(); | ||
|
||
$details['checkout']['state'] = Charge::STATE_DECLINED; | ||
|
||
if ($this->api->isRetryDeclinedPayment()) { | ||
$history = $details['checkout']['history'] ?? []; | ||
$current = array_merge($details['checkout'], ['date' => date('Y-d-m H:i:s')]); | ||
unset($current['history']); | ||
|
||
$details['checkout'] = [ | ||
'history' => array_merge($history, [$current]) | ||
]; | ||
|
||
$payment->setState(PaymentInterface::STATE_NEW); | ||
$this->session->getFlashBag()->add('info', 'sylius.payment.failed'); | ||
} | ||
|
||
$payment->setDetails($details); | ||
} | ||
|
||
/** | ||
* @param Generic $request | ||
* | ||
* @return bool | ||
*/ | ||
public function supports($request): bool | ||
{ | ||
return $request instanceof Decline && $request->getModel() instanceof PaymentInterface; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Sherlockode\SyliusCheckoutPlugin\Payum\Request; | ||
|
||
use Payum\Core\Request\Generic; | ||
|
||
/** | ||
* Class Decline | ||
*/ | ||
class Decline extends Generic | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters