|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Gateway. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2020 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3; |
|
12
|
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Banks\BankAccountDetails; |
|
14
|
|
|
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
|
15
|
|
|
use Pronamic\WordPress\Pay\Core\PaymentMethods; |
|
16
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Title: iDEAL Advanced v3+ gateway |
|
20
|
|
|
* Description: |
|
21
|
|
|
* Copyright: 2005-2020 Pronamic |
|
22
|
|
|
* Company: Pronamic |
|
23
|
|
|
* |
|
24
|
|
|
* @author Remco Tolsma |
|
25
|
|
|
* @version 2.0.5 |
|
26
|
|
|
* @since 1.0.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
class Gateway extends Core_Gateway { |
|
29
|
|
|
/** |
|
30
|
|
|
* Client. |
|
31
|
|
|
* |
|
32
|
|
|
* @var Client |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $client; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Constructs and initializes an iDEAL Advanced v3 gateway |
|
38
|
|
|
* |
|
39
|
|
|
* @param Config $config Config. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( Config $config ) { |
|
42
|
|
|
parent::__construct( $config ); |
|
43
|
|
|
|
|
44
|
|
|
$this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
45
|
|
|
|
|
46
|
|
|
// Supported features. |
|
47
|
|
|
$this->supports = array( |
|
48
|
|
|
'payment_status_request', |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
// Client. |
|
52
|
|
|
$client = new Client(); |
|
53
|
|
|
|
|
54
|
|
|
$client->set_acquirer_url( (string) $config->get_payment_server_url() ); |
|
55
|
|
|
|
|
56
|
|
|
$client->merchant_id = (string) $config->get_merchant_id(); |
|
57
|
|
|
$client->sub_id = (string) $config->get_sub_id(); |
|
58
|
|
|
$client->private_key = (string) $config->get_private_key(); |
|
59
|
|
|
$client->private_key_password = (string) $config->get_private_key_password(); |
|
60
|
|
|
$client->private_certificate = (string) $config->get_private_certificate(); |
|
61
|
|
|
|
|
62
|
|
|
$this->client = $client; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get issuers |
|
67
|
|
|
* |
|
68
|
|
|
* @see Core_Gateway::get_issuers() |
|
69
|
|
|
* @return array<int, array<string, array<string, string>|string>> |
|
70
|
|
|
*/ |
|
71
|
|
|
public function get_issuers() { |
|
72
|
|
|
$groups = array(); |
|
73
|
|
|
|
|
74
|
|
|
try { |
|
75
|
|
|
$directory = $this->client->get_directory(); |
|
76
|
|
|
} catch ( \Exception $e ) { |
|
77
|
|
|
$this->error = new \WP_Error( 'ideal_advanced_v3_error', $e->getMessage() ); |
|
78
|
|
|
|
|
79
|
|
|
return $groups; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ( null === $directory ) { |
|
83
|
|
|
return $groups; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
foreach ( $directory->get_countries() as $country ) { |
|
87
|
|
|
$issuers = array(); |
|
88
|
|
|
|
|
89
|
|
|
foreach ( $country->get_issuers() as $issuer ) { |
|
90
|
|
|
$id = $issuer->get_id(); |
|
91
|
|
|
$name = $issuer->get_name(); |
|
92
|
|
|
|
|
93
|
|
|
if ( null === $id || null === $name ) { |
|
94
|
|
|
continue; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$issuers[ $id ] = $name; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$groups[] = array( |
|
101
|
|
|
'name' => $country->get_name(), |
|
102
|
|
|
'options' => $issuers, |
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $groups; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Get supported payment methods |
|
111
|
|
|
* |
|
112
|
|
|
* @see Core_Gateway::get_supported_payment_methods() |
|
113
|
|
|
* @return array<int, string> |
|
114
|
|
|
*/ |
|
115
|
|
|
public function get_supported_payment_methods() { |
|
116
|
|
|
return array( |
|
117
|
|
|
PaymentMethods::IDEAL, |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Is payment method required to start transaction? |
|
123
|
|
|
* |
|
124
|
|
|
* @see Core_Gateway::payment_method_is_required() |
|
125
|
|
|
* @since 1.1.5 |
|
126
|
|
|
*/ |
|
127
|
|
|
public function payment_method_is_required() { |
|
128
|
|
|
return true; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Start |
|
133
|
|
|
* |
|
134
|
|
|
* @see Pronamic_WP_Pay_Gateway::start() |
|
135
|
|
|
* |
|
136
|
|
|
* @param Payment $payment Payment. |
|
137
|
|
|
*/ |
|
138
|
|
|
public function start( Payment $payment ) { |
|
139
|
|
|
// Purchase ID. |
|
140
|
|
|
$purchase_id = $payment->format_string( $this->config->get_purchase_id() ); |
|
141
|
|
|
|
|
142
|
|
|
$payment->set_meta( 'purchase_id', $purchase_id ); |
|
143
|
|
|
|
|
144
|
|
|
// Transaction. |
|
145
|
|
|
$transaction = new Transaction(); |
|
146
|
|
|
$transaction->set_purchase_id( $purchase_id ); |
|
147
|
|
|
$transaction->set_amount( $payment->get_total_amount()->get_value() ); |
|
148
|
|
|
$transaction->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ); |
|
149
|
|
|
$transaction->set_expiration_period( 'PT30M' ); |
|
150
|
|
|
$transaction->set_description( $payment->get_description() ); |
|
151
|
|
|
$transaction->set_entrance_code( $payment->get_entrance_code() ); |
|
152
|
|
|
|
|
153
|
|
|
$customer = $payment->get_customer(); |
|
154
|
|
|
|
|
155
|
|
|
if ( null !== $customer ) { |
|
156
|
|
|
$transaction->set_language( $customer->get_language() ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
// Create transaction. |
|
160
|
|
|
$result = $this->client->create_transaction( $transaction, $payment->get_return_url(), (string) $payment->get_issuer() ); |
|
161
|
|
|
|
|
162
|
|
|
if ( null !== $result->issuer ) { |
|
163
|
|
|
$authentication_url = $result->issuer->get_authentication_url(); |
|
164
|
|
|
|
|
165
|
|
|
if ( null !== $authentication_url ) { |
|
166
|
|
|
$payment->set_action_url( $authentication_url ); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
if ( null !== $result->transaction ) { |
|
171
|
|
|
$payment->set_transaction_id( $result->transaction->get_id() ); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Update status of the specified payment |
|
177
|
|
|
* |
|
178
|
|
|
* @param Payment $payment Payment. |
|
179
|
|
|
*/ |
|
180
|
|
|
public function update_status( Payment $payment ) { |
|
181
|
|
|
try { |
|
182
|
|
|
// Try to retrieve payment status. |
|
183
|
|
|
$transaction_id = (string) $payment->get_transaction_id(); |
|
184
|
|
|
|
|
185
|
|
|
$result = $this->client->get_status( $transaction_id ); |
|
186
|
|
|
} catch ( \Exception $e ) { |
|
187
|
|
|
return; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
// Check transaction result. |
|
191
|
|
|
if ( null === $result->transaction ) { |
|
192
|
|
|
return; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
// Update payment with transaction data. |
|
196
|
|
|
$transaction = $result->transaction; |
|
197
|
|
|
|
|
198
|
|
|
$payment->set_status( $transaction->get_status() ); |
|
199
|
|
|
|
|
200
|
|
|
$consumer_bank_details = $payment->get_consumer_bank_details(); |
|
201
|
|
|
|
|
202
|
|
|
if ( null === $consumer_bank_details ) { |
|
203
|
|
|
$consumer_bank_details = new BankAccountDetails(); |
|
204
|
|
|
|
|
205
|
|
|
$payment->set_consumer_bank_details( $consumer_bank_details ); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
$consumer_bank_details->set_name( $transaction->get_consumer_name() ); |
|
209
|
|
|
$consumer_bank_details->set_iban( $transaction->get_consumer_iban() ); |
|
210
|
|
|
$consumer_bank_details->set_bic( $transaction->get_consumer_bic() ); |
|
211
|
|
|
} |
|
212
|
|
|
} |
|
213
|
|
|
|