|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa; |
|
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: OmniKassa |
|
11
|
|
|
* Description: |
|
12
|
|
|
* Copyright: 2005-2019 Pronamic |
|
13
|
|
|
* Company: Pronamic |
|
14
|
|
|
* |
|
15
|
|
|
* @author Remco Tolsma |
|
16
|
|
|
* @version 2.0.0 |
|
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 OmniKassa gateway |
|
29
|
|
|
* |
|
30
|
|
|
* @param Config $config Config. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( Config $config ) { |
|
33
|
|
|
parent::__construct( $config ); |
|
34
|
|
|
|
|
35
|
|
|
$this->set_method( self::METHOD_HTML_FORM ); |
|
36
|
|
|
|
|
37
|
|
|
// Client. |
|
38
|
|
|
$this->client = new Client(); |
|
39
|
|
|
|
|
40
|
|
|
$action_url = Client::ACTION_URL_PRUDCTION; |
|
41
|
|
|
|
|
42
|
|
|
if ( self::MODE_TEST === $config->mode ) { |
|
43
|
|
|
$action_url = Client::ACTION_URL_TEST; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->client->set_action_url( $action_url ); |
|
47
|
|
|
$this->client->set_merchant_id( $config->merchant_id ); |
|
48
|
|
|
$this->client->set_key_version( $config->key_version ); |
|
49
|
|
|
$this->client->set_secret_key( $config->secret_key ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get supported payment methods |
|
54
|
|
|
* |
|
55
|
|
|
* @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
|
56
|
|
|
*/ |
|
57
|
|
|
public function get_supported_payment_methods() { |
|
58
|
|
|
return array( |
|
59
|
|
|
PaymentMethods::IDEAL, |
|
60
|
|
|
PaymentMethods::CREDIT_CARD, |
|
61
|
|
|
PaymentMethods::DIRECT_DEBIT, |
|
62
|
|
|
PaymentMethods::BANCONTACT, |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Start |
|
68
|
|
|
* |
|
69
|
|
|
* @see Pronamic_WP_Pay_Gateway::start() |
|
70
|
|
|
* |
|
71
|
|
|
* @param Payment $payment Payment. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function start( Payment $payment ) { |
|
74
|
|
|
$transaction_reference = $payment->get_meta( 'omnikassa_transaction_reference' ); |
|
75
|
|
|
|
|
76
|
|
|
if ( empty( $transaction_reference ) ) { |
|
77
|
|
|
$transaction_reference = md5( uniqid( '', true ) ); |
|
78
|
|
|
|
|
79
|
|
|
$payment->set_meta( 'omnikassa_transaction_reference', $transaction_reference ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$payment->set_transaction_id( $transaction_reference ); |
|
83
|
|
|
$payment->set_action_url( $this->client->get_action_url() ); |
|
84
|
|
|
|
|
85
|
|
|
$language = null; |
|
86
|
|
|
|
|
87
|
|
|
if ( null !== $payment->get_customer() ) { |
|
88
|
|
|
$language = $payment->get_customer()->get_language(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$this->client->set_customer_language( LocaleHelper::transform( $language ) ); |
|
92
|
|
|
$this->client->set_currency_numeric_code( $payment->get_total_amount()->get_currency()->get_numeric_code() ); |
|
93
|
|
|
$this->client->set_order_id( $payment->format_string( $this->config->order_id ) ); |
|
94
|
|
|
$this->client->set_normal_return_url( home_url( '/' ) ); |
|
|
|
|
|
|
95
|
|
|
$this->client->set_automatic_response_url( home_url( '/' ) ); |
|
96
|
|
|
$this->client->set_amount( $payment->get_total_amount()->get_cents() ); |
|
97
|
|
|
$this->client->set_transaction_reference( $transaction_reference ); |
|
98
|
|
|
|
|
99
|
|
|
switch ( $payment->get_method() ) { |
|
100
|
|
|
/* |
|
101
|
|
|
* If this field is not supplied in the payment request, then |
|
102
|
|
|
* by default the customer will be redirected to the Rabo |
|
103
|
|
|
* OmniKassa payment page. On the payment page, the |
|
104
|
|
|
* customer can choose from the payment methods |
|
105
|
|
|
* offered by the Rabo OmniKassa. These are the payment |
|
106
|
|
|
* methods: IDEAL, VISA, MASTERCARD, |
|
107
|
|
|
* MAESTRO, V PAY and BCMC. |
|
108
|
|
|
* |
|
109
|
|
|
* Exception: the register services INCASSO (direct debit), |
|
110
|
|
|
* ACCEPTGIRO (giro collection form) and REMBOURS |
|
111
|
|
|
* (cash on delivery) are not displayed on the Rabo |
|
112
|
|
|
* OmniKassa payment page by default. |
|
113
|
|
|
* If you wish to offer these register services to the |
|
114
|
|
|
* customer on the payment page, then you need to |
|
115
|
|
|
* always populate the paymentMeanBrandList field with |
|
116
|
|
|
* all the payment methods you wish to offer (provided |
|
117
|
|
|
* these have been requested and activated): IDEAL, |
|
118
|
|
|
* VISA, MASTERCARD, MAESTRO, VPAY, BCMC, |
|
119
|
|
|
* INCASSO, ACCEPTGIRO, REMBOURS. |
|
120
|
|
|
* |
|
121
|
|
|
* If you let the customer choose the payment method |
|
122
|
|
|
* while still in your webshop, then you must populate |
|
123
|
|
|
* this field of the payment request with only the selected |
|
124
|
|
|
* payment method. Populating this field with only one |
|
125
|
|
|
* payment method will instruct the Rabo OmniKassa to |
|
126
|
|
|
* redirect the customer directly to the payment page for |
|
127
|
|
|
* this payment method. |
|
128
|
|
|
*/ |
|
129
|
|
|
case PaymentMethods::BANCONTACT: |
|
130
|
|
|
case PaymentMethods::MISTER_CASH: |
|
|
|
|
|
|
131
|
|
|
$this->client->add_payment_mean_brand( Methods::BCMC ); |
|
132
|
|
|
|
|
133
|
|
|
break; |
|
134
|
|
|
case PaymentMethods::CREDIT_CARD: |
|
135
|
|
|
$this->client->add_payment_mean_brand( Methods::MAESTRO ); |
|
136
|
|
|
$this->client->add_payment_mean_brand( Methods::MASTERCARD ); |
|
137
|
|
|
$this->client->add_payment_mean_brand( Methods::VISA ); |
|
138
|
|
|
$this->client->add_payment_mean_brand( Methods::VPAY ); |
|
139
|
|
|
|
|
140
|
|
|
break; |
|
141
|
|
|
case PaymentMethods::DIRECT_DEBIT: |
|
142
|
|
|
$this->client->add_payment_mean_brand( Methods::INCASSO ); |
|
143
|
|
|
|
|
144
|
|
|
break; |
|
145
|
|
|
case PaymentMethods::MAESTRO: |
|
146
|
|
|
$this->client->add_payment_mean_brand( Methods::MAESTRO ); |
|
147
|
|
|
|
|
148
|
|
|
break; |
|
149
|
|
|
case PaymentMethods::IDEAL: |
|
150
|
|
|
$this->client->add_payment_mean_brand( Methods::IDEAL ); |
|
151
|
|
|
|
|
152
|
|
|
break; |
|
153
|
|
|
default: |
|
154
|
|
|
$this->client->add_payment_mean_brand( Methods::IDEAL ); |
|
155
|
|
|
$this->client->add_payment_mean_brand( Methods::VISA ); |
|
156
|
|
|
$this->client->add_payment_mean_brand( Methods::MASTERCARD ); |
|
157
|
|
|
$this->client->add_payment_mean_brand( Methods::MAESTRO ); |
|
158
|
|
|
$this->client->add_payment_mean_brand( Methods::VPAY ); |
|
159
|
|
|
$this->client->add_payment_mean_brand( Methods::BCMC ); |
|
160
|
|
|
$this->client->add_payment_mean_brand( Methods::INCASSO ); |
|
161
|
|
|
$this->client->add_payment_mean_brand( Methods::ACCEPTGIRO ); |
|
162
|
|
|
$this->client->add_payment_mean_brand( Methods::REMBOURS ); |
|
163
|
|
|
|
|
164
|
|
|
break; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get the output HTML |
|
170
|
|
|
* |
|
171
|
|
|
* @since 1.1.2 |
|
172
|
|
|
* @see Pronamic_WP_Pay_Gateway::get_output_html() |
|
173
|
|
|
*/ |
|
174
|
|
|
public function get_output_fields() { |
|
175
|
|
|
return $this->client->get_fields(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Update status of the specified payment |
|
180
|
|
|
* |
|
181
|
|
|
* @param Payment $payment Payment. |
|
182
|
|
|
*/ |
|
183
|
|
|
public function update_status( Payment $payment ) { |
|
184
|
|
|
$input_data = filter_input( INPUT_POST, 'Data' ); |
|
185
|
|
|
$input_seal = filter_input( INPUT_POST, 'Seal', FILTER_SANITIZE_STRING ); |
|
186
|
|
|
|
|
187
|
|
|
$data = Client::parse_piped_string( $input_data ); |
|
188
|
|
|
|
|
189
|
|
|
$seal = Client::compute_seal( $input_data, $this->config->secret_key ); |
|
190
|
|
|
|
|
191
|
|
|
// Check if the posted seal is equal to our seal. |
|
192
|
|
|
if ( 0 === strcasecmp( $input_seal, $seal ) ) { |
|
193
|
|
|
$response_code = $data['responseCode']; |
|
194
|
|
|
|
|
195
|
|
|
$status = ResponseCodes::transform( $response_code ); |
|
196
|
|
|
|
|
197
|
|
|
// Set the status of the payment. |
|
198
|
|
|
$payment->set_status( $status ); |
|
199
|
|
|
|
|
200
|
|
|
$labels = array( |
|
201
|
|
|
'amount' => __( 'Amount', 'pronamic_ideal' ), |
|
|
|
|
|
|
202
|
|
|
'captureDay' => _x( 'Capture Day', 'creditcard', 'pronamic_ideal' ), |
|
|
|
|
|
|
203
|
|
|
'captureMode' => _x( 'Capture Mode', 'creditcard', 'pronamic_ideal' ), |
|
204
|
|
|
'currencyCode' => __( 'Currency Code', 'pronamic_ideal' ), |
|
205
|
|
|
'merchantId' => __( 'Merchant ID', 'pronamic_ideal' ), |
|
206
|
|
|
'orderId' => __( 'Order ID', 'pronamic_ideal' ), |
|
207
|
|
|
'transactionDateTime' => __( 'Transaction Date Time', 'pronamic_ideal' ), |
|
208
|
|
|
'transactionReference' => __( 'Transaction Reference', 'pronamic_ideal' ), |
|
209
|
|
|
'keyVersion' => __( 'Key Version', 'pronamic_ideal' ), |
|
210
|
|
|
'authorisationId' => __( 'Authorisation ID', 'pronamic_ideal' ), |
|
211
|
|
|
'paymentMeanBrand' => __( 'Payment Mean Brand', 'pronamic_ideal' ), |
|
212
|
|
|
'paymentMeanType' => __( 'Payment Mean Type', 'pronamic_ideal' ), |
|
213
|
|
|
'responseCode' => __( 'Response Code', 'pronamic_ideal' ), |
|
214
|
|
|
); |
|
215
|
|
|
|
|
216
|
|
|
$note = ''; |
|
217
|
|
|
|
|
218
|
|
|
$note .= '<p>'; |
|
219
|
|
|
$note .= __( 'OmniKassa transaction data in response message:', 'pronamic_ideal' ); |
|
220
|
|
|
$note .= '</p>'; |
|
221
|
|
|
|
|
222
|
|
|
$note .= '<dl>'; |
|
223
|
|
|
|
|
224
|
|
|
foreach ( $labels as $key => $label ) { |
|
225
|
|
|
if ( isset( $data[ $key ] ) ) { |
|
226
|
|
|
$note .= sprintf( '<dt>%s</dt>', esc_html( $label ) ); |
|
|
|
|
|
|
227
|
|
|
$note .= sprintf( '<dd>%s</dd>', esc_html( $data[ $key ] ) ); |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
$note .= '</dl>'; |
|
232
|
|
|
|
|
233
|
|
|
$payment->add_note( $note ); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|