-
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.
* added Giropay payment method * changed plugin version in composer to 2.1.0
- Loading branch information
1 parent
749ba16
commit ce6f04f
Showing
5 changed files
with
93 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BetterPayment\PaymentHandler; | ||
|
||
use BetterPayment\Util\BetterPaymentClient; | ||
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler; | ||
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; | ||
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface; | ||
use Shopware\Core\Checkout\Payment\Exception\AsyncPaymentProcessException; | ||
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class GiropayHandler implements AsynchronousPaymentHandlerInterface | ||
{ | ||
private OrderTransactionStateHandler $orderTransactionStateHandler; | ||
private BetterPaymentClient $betterPaymentClient; | ||
|
||
public function __construct( | ||
OrderTransactionStateHandler $orderTransactionStateHandler, | ||
BetterPaymentClient $betterPaymentClient | ||
){ | ||
$this->orderTransactionStateHandler = $orderTransactionStateHandler; | ||
$this->betterPaymentClient = $betterPaymentClient; | ||
} | ||
|
||
public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $dataBag, SalesChannelContext $salesChannelContext): RedirectResponse | ||
{ | ||
try { | ||
$redirectUrl = $this->betterPaymentClient->request($transaction)->action_data->url; | ||
} catch (\Exception $e) { | ||
throw new AsyncPaymentProcessException( | ||
$transaction->getOrderTransaction()->getId(), | ||
'An error occurred during the communication with external payment gateway' . PHP_EOL | ||
. $e->getMessage() . PHP_EOL | ||
. 'TRACE: ' . $e->getTraceAsString() | ||
); | ||
} | ||
|
||
return new RedirectResponse($redirectUrl); | ||
} | ||
|
||
public function finalize(AsyncPaymentTransactionStruct $transaction, Request $request, SalesChannelContext $salesChannelContext): void | ||
{ | ||
$context = $salesChannelContext->getContext(); | ||
$this->orderTransactionStateHandler->paid($transaction->getOrderTransaction()->getId(), $context); | ||
} | ||
} |
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,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace BetterPayment\PaymentMethod; | ||
|
||
use BetterPayment\PaymentHandler\GiropayHandler; | ||
|
||
class Giropay extends PaymentMethod | ||
{ | ||
public const UUID = '9aa2dc141a97415c802b0a3775e55c6c'; | ||
public const SHORTNAME = 'giro'; | ||
|
||
protected string $id = self::UUID; | ||
protected string $handler = GiropayHandler::class; | ||
protected string $name = 'Giropay'; | ||
protected string $shortname = self::SHORTNAME; | ||
protected string $description = ''; | ||
protected string $icon = ''; | ||
protected array $translations = [ | ||
'de-DE' => [ | ||
'name' => 'Giropay', | ||
'description' => '', | ||
'customFields' => [ | ||
'shortname' => self::SHORTNAME | ||
] | ||
], | ||
'en-GB' => [ | ||
'name' => 'Giropay', | ||
'description' => '', | ||
'customFields' => [ | ||
'shortname' => self::SHORTNAME | ||
] | ||
], | ||
]; | ||
} |
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