-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOgonePaymentGateway.php
124 lines (110 loc) · 3.52 KB
/
OgonePaymentGateway.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace IDCI\Bundle\PaymentBundle\Gateway;
use IDCI\Bundle\PaymentBundle\Model\GatewayResponse;
use IDCI\Bundle\PaymentBundle\Model\PaymentGatewayConfigurationInterface;
use IDCI\Bundle\PaymentBundle\Model\Transaction;
use Symfony\Component\HttpFoundation\Request;
class OgonePaymentGateway extends AbstractPaymentGateway
{
/**
* Get Ogone server url.
*
* @method getServerUrl
*/
private function getServerUrl(): string
{
return 'https://secure.ogone.com/ncol/test/orderstandard.asp'; // raw (for test)
}
/**
* Build payment gateway options.
*
* @method buildOptions
*/
private function buildOptions(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Transaction $transaction
): array {
return [
'ACCEPTURL' => $paymentGatewayConfiguration->get('return_url'),
'AMOUNT' => $transaction->getAmount(),
'CANCELURL' => $paymentGatewayConfiguration->get('return_url'),
//'CN' => '',
'CURRENCY' => $transaction->getCurrencyCode(),
'DECLINEURL' => $paymentGatewayConfiguration->get('return_url'),
'EMAIL' => $transaction->getCustomerEmail(),
'EXCEPTIONURL' => $paymentGatewayConfiguration->get('return_url'),
'LANGUAGE' => 'fr_FR',
'ORDERID' => $transaction->getId(),
//'OWNERADDRESS' => '',
//'OWNERCTY' => '',
//'OWNERTELNO' => '',
//'OWNERTOWN' => '',
//'OWNERZIP' => '',
'PSPID' => $paymentGatewayConfiguration->get('client_id'),
];
}
/**
* {@inheritdoc}
*/
public function initialize(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Transaction $transaction,
array $options = []
): array {
$options = $this->buildOptions($paymentGatewayConfiguration, $transaction);
$shasign = '';
foreach ($options as $key => $value) {
if (!empty($value)) {
$shasign .= sprintf('%s=%s%s', $key, $value, $paymentGatewayConfiguration->get('client_secret'));
} else {
unset($options[$key]);
}
}
$options['SHASIGN'] = mb_strtoupper(sha1($shasign));
return $options;
}
/**
* {@inheritdoc}
*/
public function buildHTMLView(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Transaction $transaction,
array $options = []
): string {
$initializationData = $this->initialize($paymentGatewayConfiguration, $transaction);
return $this->templating->render('@IDCIPayment/Gateway/ogone.html.twig', [
'initializationData' => $initializationData,
]);
}
/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}
/**
* {@inheritdoc}
*/
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return null;
}
/**
* {@inheritdoc}
*/
public static function getParameterNames(): ?array
{
return array_merge(
parent::getParameterNames(),
[
'client_id',
'client_secret',
]
);
}
}