1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3; |
4
|
|
|
|
5
|
|
|
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
6
|
|
|
use Pronamic\WordPress\Pay\Core\PaymentMethods; |
7
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Title: iDEAL Advanced v3+ gateway |
11
|
|
|
* Description: |
12
|
|
|
* Copyright: Copyright (c) 2005 - 2018 |
13
|
|
|
* Company: Pronamic |
14
|
|
|
* |
15
|
|
|
* @author Remco Tolsma |
16
|
|
|
* @version 2.0.2 |
17
|
|
|
* @since 1.0.0 |
18
|
|
|
*/ |
19
|
|
|
class Gateway extends Core_Gateway { |
20
|
|
|
/** |
21
|
|
|
* Client. |
22
|
|
|
* |
23
|
|
|
* @var Client |
24
|
|
|
*/ |
25
|
|
|
protected $client; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructs and initializes an iDEAL Advanced v3 gateway |
29
|
|
|
* |
30
|
|
|
* @param Config $config Config. |
31
|
|
|
*/ |
32
|
|
|
public function __construct( Config $config ) { |
33
|
|
|
parent::__construct( $config ); |
34
|
|
|
|
35
|
|
|
$this->supports = array( |
36
|
|
|
'payment_status_request', |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$this->set_method( self::METHOD_HTTP_REDIRECT ); |
40
|
|
|
|
41
|
|
|
// Client. |
42
|
|
|
$client = new Client(); |
43
|
|
|
|
44
|
|
|
$client->set_acquirer_url( $config->get_payment_server_url() ); |
45
|
|
|
|
46
|
|
|
$client->merchant_id = $config->merchant_id; |
47
|
|
|
$client->sub_id = $config->sub_id; |
48
|
|
|
$client->private_key = $config->private_key; |
49
|
|
|
$client->private_key_password = $config->private_key_password; |
50
|
|
|
$client->private_certificate = $config->private_certificate; |
51
|
|
|
|
52
|
|
|
$this->client = $client; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get issuers |
57
|
|
|
* |
58
|
|
|
* @see Core_Gateway::get_issuers() |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function get_issuers() { |
63
|
|
|
$directory = $this->client->get_directory(); |
64
|
|
|
|
65
|
|
|
if ( ! $directory ) { |
|
|
|
|
66
|
|
|
$this->error = $this->client->get_error(); |
67
|
|
|
|
68
|
|
|
return array(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$groups = array(); |
72
|
|
|
|
73
|
|
|
foreach ( $directory->get_countries() as $country ) { |
74
|
|
|
$issuers = array(); |
75
|
|
|
|
76
|
|
|
foreach ( $country->get_issuers() as $issuer ) { |
77
|
|
|
$issuers[ $issuer->get_id() ] = $issuer->get_name(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$groups[] = array( |
81
|
|
|
'name' => $country->get_name(), |
82
|
|
|
'options' => $issuers, |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $groups; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get supported payment methods |
91
|
|
|
* |
92
|
|
|
* @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
93
|
|
|
*/ |
94
|
|
|
public function get_supported_payment_methods() { |
95
|
|
|
return array( |
96
|
|
|
PaymentMethods::IDEAL, |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Is payment method required to start transaction? |
102
|
|
|
* |
103
|
|
|
* @see Core_Gateway::payment_method_is_required() |
104
|
|
|
* @since 1.1.5 |
105
|
|
|
*/ |
106
|
|
|
public function payment_method_is_required() { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Start |
112
|
|
|
* |
113
|
|
|
* @see Pronamic_WP_Pay_Gateway::start() |
114
|
|
|
* |
115
|
|
|
* @param Payment $payment Payment. |
116
|
|
|
*/ |
117
|
|
|
public function start( Payment $payment ) { |
118
|
|
|
// Purchase ID. |
119
|
|
|
$purchase_id = $payment->format_string( $this->config->purchase_id ); |
120
|
|
|
|
121
|
|
|
$payment->set_meta( 'purchase_id', $purchase_id ); |
122
|
|
|
|
123
|
|
|
// Transaction. |
124
|
|
|
$transaction = new Transaction(); |
125
|
|
|
$transaction->set_purchase_id( $purchase_id ); |
126
|
|
|
$transaction->set_amount( $payment->get_total_amount()->get_value() ); |
127
|
|
|
$transaction->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ); |
128
|
|
|
$transaction->set_expiration_period( 'PT30M' ); |
129
|
|
|
$transaction->set_description( $payment->get_description() ); |
130
|
|
|
$transaction->set_entrance_code( $payment->get_entrance_code() ); |
131
|
|
|
|
132
|
|
|
if ( null !== $payment->get_customer() ) { |
133
|
|
|
$transaction->set_language( $payment->get_customer()->get_language() ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
// Create transaction. |
137
|
|
|
$result = $this->client->create_transaction( $transaction, $payment->get_return_url(), $payment->get_issuer() ); |
138
|
|
|
|
139
|
|
|
$error = $this->client->get_error(); |
140
|
|
|
|
141
|
|
|
if ( is_wp_error( $error ) ) { |
|
|
|
|
142
|
|
|
$this->set_error( $error ); |
143
|
|
|
|
144
|
|
|
return; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$payment->set_action_url( $result->issuer->get_authentication_url() ); |
148
|
|
|
$payment->set_transaction_id( $result->transaction->get_id() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Update status of the specified payment |
153
|
|
|
* |
154
|
|
|
* @param Payment $payment Payment. |
155
|
|
|
*/ |
156
|
|
|
public function update_status( Payment $payment ) { |
157
|
|
|
$result = $this->client->get_status( $payment->get_transaction_id() ); |
158
|
|
|
|
159
|
|
|
$error = $this->client->get_error(); |
160
|
|
|
|
161
|
|
|
if ( is_wp_error( $error ) ) { |
|
|
|
|
162
|
|
|
$this->set_error( $error ); |
163
|
|
|
} else { |
164
|
|
|
$transaction = $result->transaction; |
165
|
|
|
|
166
|
|
|
$payment->set_status( $transaction->get_status() ); |
167
|
|
|
$payment->set_consumer_name( $transaction->get_consumer_name() ); |
168
|
|
|
$payment->set_consumer_iban( $transaction->get_consumer_iban() ); |
169
|
|
|
$payment->set_consumer_bic( $transaction->get_consumer_bic() ); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|