-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efd905d
commit 387efde
Showing
17 changed files
with
370 additions
and
29 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
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
26 changes: 26 additions & 0 deletions
26
src/DependencyInjection/CompilerPass/AddSupportedRefundPaymentMethodPass.php
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class AddSupportedRefundPaymentMethodPass implements CompilerPassInterface | ||
{ | ||
private const SUPPORTED_GATEWAYS_PARAM_NAME = 'sylius_refund.supported_gateways'; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasParameter(self::SUPPORTED_GATEWAYS_PARAM_NAME)) { | ||
return; | ||
} | ||
|
||
/** @var array<string, mixed> $supportedGateways */ | ||
$supportedGateways = $container->getParameter(self::SUPPORTED_GATEWAYS_PARAM_NAME); | ||
$supportedGateways[] = 'tpay'; | ||
|
||
$container->setParameter(self::SUPPORTED_GATEWAYS_PARAM_NAME, $supportedGateways); | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Payum\Action; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Model\PaymentDetails; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\BaseApiAwareAction; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Exception\RefundCannotBeMadeException; | ||
use Payum\Core\GatewayAwareInterface; | ||
use Payum\Core\GatewayAwareTrait; | ||
use Payum\Core\Request\Refund; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Sylius\RefundPlugin\Entity\RefundPaymentInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class PartialRefundAction extends BaseApiAwareAction implements GatewayAwareInterface | ||
{ | ||
use GatewayAwareTrait; | ||
|
||
/** | ||
* @param Refund $request | ||
*/ | ||
public function execute(mixed $request): void | ||
{ | ||
/** @var RefundPaymentInterface $refundPayment */ | ||
$refundPayment = $request->getModel(); | ||
$payment = $this->extractPaymentFrom($refundPayment); | ||
$paymentDetails = PaymentDetails::fromArray($payment->getDetails()); | ||
$transactionId = $paymentDetails->getTransactionId(); | ||
|
||
if (null === $transactionId) { | ||
throw new RefundCannotBeMadeException('Tpay transaction id cannot be found.'); | ||
} | ||
|
||
if ($refundPayment->getAmount() === $payment->getAmount()) { | ||
$this->gateway->execute(new Refund($payment)); | ||
|
||
return; | ||
} | ||
|
||
$this->api->transactions()->createRefundByTransactionId( | ||
['amount' => $this->convertFromMinorToMajorCurrency($refundPayment->getAmount())], | ||
$transactionId, | ||
); | ||
} | ||
|
||
public function supports(mixed $request): bool | ||
{ | ||
return $request instanceof Refund && $request->getModel() instanceof RefundPaymentInterface; | ||
} | ||
|
||
private function extractPaymentFrom(RefundPaymentInterface $refundPayment): PaymentInterface | ||
{ | ||
$order = $refundPayment->getOrder(); | ||
$payment = $order->getLastPayment(); | ||
|
||
Assert::notNull($payment); | ||
|
||
return $payment; | ||
} | ||
|
||
private function convertFromMinorToMajorCurrency(int $amount): float | ||
{ | ||
return $amount / 100; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Refunding\Checker; | ||
|
||
use Sylius\RefundPlugin\Entity\RefundPaymentInterface; | ||
|
||
final class RefundPluginAvailabilityChecker implements RefundPluginAvailabilityCheckerInterface | ||
{ | ||
public function isAvailable(): bool | ||
{ | ||
return interface_exists(RefundPaymentInterface::class); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Refunding/Checker/RefundPluginAvailabilityCheckerInterface.php
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Refunding\Checker; | ||
|
||
interface RefundPluginAvailabilityCheckerInterface | ||
{ | ||
public function isAvailable(): bool; | ||
} |
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
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,2 @@ | ||
imports: | ||
- { resource: "@SyliusRefundPlugin/Resources/config/app/config.yml" } |
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,2 @@ | ||
sylius_refund: | ||
resource: "@SyliusRefundPlugin/Resources/config/routing.yml" |
Oops, something went wrong.