Skip to content

Commit

Permalink
Giropay payment method (#89)
Browse files Browse the repository at this point in the history
* added Giropay payment method

* changed plugin version in composer to 2.1.0
  • Loading branch information
hasanzade-hasan authored Sep 20, 2023
1 parent 749ba16 commit ce6f04f
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "better-payment/bp-plugin-shopware6-api2",
"description": "Better Payment plugin to implement payment methods using API2",
"version": "2.0.0",
"version": "2.1.0",
"type": "shopware-platform-plugin",
"license": "proprietary",
"authors": [
Expand Down
2 changes: 2 additions & 0 deletions src/Installer/PaymentMethodInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BetterPayment\Installer;

use BetterPayment\BetterPayment;
use BetterPayment\PaymentMethod\Giropay;
use BetterPayment\PaymentMethod\InvoiceB2B;
use BetterPayment\PaymentMethod\PaymentMethod;
use BetterPayment\PaymentMethod\CreditCard;
Expand All @@ -28,6 +29,7 @@ class PaymentMethodInstaller
Paydirekt::class,
Sofort::class,
Paypal::class,
Giropay::class,
SEPADirectDebit::class,
SEPADirectDebitB2B::class,
Invoice::class,
Expand Down
49 changes: 49 additions & 0 deletions src/PaymentHandler/GiropayHandler.php
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);
}
}
34 changes: 34 additions & 0 deletions src/PaymentMethod/Giropay.php
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
]
],
];
}
7 changes: 7 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<tag name="shopware.payment.method.async" />
</service>

<service id="BetterPayment\PaymentHandler\GiropayHandler">
<argument type="service" id="Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler" />
<argument type="service" id="BetterPayment\Util\BetterPaymentClient" />

<tag name="shopware.payment.method.async" />
</service>

<service id="BetterPayment\PaymentHandler\SEPADirectDebitHandler">
<argument type="service" id="BetterPayment\Util\PaymentStatusMapper" />
<argument type="service" id="BetterPayment\Util\BetterPaymentClient" />
Expand Down

0 comments on commit ce6f04f

Please sign in to comment.