Skip to content

Commit f4bce78

Browse files
committed
Update: add payment gateway pre/post configure options event
1 parent fa85170 commit f4bce78

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace IDCI\Bundle\PaymentBundle\Gateway\Event;
4+
5+
use IDCI\Bundle\PaymentBundle\Model\PaymentGatewayConfigurationInterface;
6+
use IDCI\Bundle\PaymentBundle\Model\Transaction;
7+
8+
class PaymentGatewayEvent
9+
{
10+
/**
11+
* @var Transaction
12+
*/
13+
protected $transaction;
14+
15+
/**
16+
* @var PaymentGatewayConfigurationInterface
17+
*/
18+
protected $paymentGatewayConfiguration;
19+
20+
/**
21+
* @var array
22+
*/
23+
protected $options = [];
24+
25+
/**
26+
* PaymentGatewayEvent constructor.
27+
*/
28+
public function __construct(
29+
Transaction $transaction,
30+
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
31+
array &$options = []
32+
) {
33+
$this->transaction = $transaction;
34+
$this->paymentGatewayConfiguration = $paymentGatewayConfiguration;
35+
$this->options = &$options;
36+
}
37+
38+
/**
39+
* Get transaction.
40+
*/
41+
public function getTransaction(): Transaction
42+
{
43+
return $this->transaction;
44+
}
45+
46+
/**
47+
* Get paymentGatewayConfiguration.
48+
*/
49+
public function getPaymentGatewayConfiguration(): PaymentGatewayConfigurationInterface
50+
{
51+
return $this->paymentGatewayConfiguration;
52+
}
53+
54+
/**
55+
* Get options.
56+
*/
57+
public function getOptions(): array
58+
{
59+
return $this->options;
60+
}
61+
62+
/**
63+
* Set options.
64+
*/
65+
public function setOptions(array $options): self
66+
{
67+
$this->options = $options;
68+
69+
return $this;
70+
}
71+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace IDCI\Bundle\PaymentBundle\Gateway\Event;
4+
5+
final class PaymentGatewayEvents
6+
{
7+
const PRE_CONFIGURE_OPTIONS = 'idci_payment.payment_gateway.pre_configure_options';
8+
const POST_CONFIGURE_OPTIONS = 'idci_payment.payment_gateway.post_configure_options';
9+
}

Gateway/SofincoCACFPaymentGateway.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace IDCI\Bundle\PaymentBundle\Gateway;
44

55
use IDCI\Bundle\PaymentBundle\Gateway\Client\SofincoCACFPaymentGatewayClient;
6+
use IDCI\Bundle\PaymentBundle\Gateway\Event\PaymentGatewayEvent;
7+
use IDCI\Bundle\PaymentBundle\Gateway\Event\PaymentGatewayEvents;
68
use IDCI\Bundle\PaymentBundle\Model\GatewayResponse;
79
use IDCI\Bundle\PaymentBundle\Model\PaymentGatewayConfigurationInterface;
810
use IDCI\Bundle\PaymentBundle\Model\Transaction;
@@ -38,7 +40,9 @@ private function buildOptions(
3840
Transaction $transaction,
3941
array $options
4042
): array {
41-
return array_replace_recursive([
43+
$this->dispatcher->dispatch(new PaymentGatewayEvent($transaction, $paymentGatewayConfiguration, $options), PaymentGatewayEvents::PRE_CONFIGURE_OPTIONS);
44+
45+
$options = array_replace_recursive([
4246
'businessContext' => [
4347
'providerContext' => [
4448
'businessProviderId' => $paymentGatewayConfiguration->get('business_provider_id'),
@@ -56,6 +60,10 @@ private function buildOptions(
5660
],
5761
],
5862
], $options);
63+
64+
$this->dispatcher->dispatch(new PaymentGatewayEvent($transaction, $paymentGatewayConfiguration, $options), PaymentGatewayEvents::POST_CONFIGURE_OPTIONS);
65+
66+
return $options;
5967
}
6068

6169
/**

0 commit comments

Comments
 (0)