1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Gateway. |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2021 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\ING\KassaCompleet |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\ING\KassaCompleet; |
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 as Core_PaymentMethods; |
16
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Title: ING Kassa Compleet |
20
|
|
|
* Description: |
21
|
|
|
* Copyright: 2005-2021 Pronamic |
22
|
|
|
* Company: Pronamic |
23
|
|
|
* |
24
|
|
|
* @author Reüel van der Steege |
25
|
|
|
* @version 2.0.3 |
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 ING Kassa Compleet 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
|
|
|
$this->client = new Client( $config->api_key ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get issuers |
57
|
|
|
* |
58
|
|
|
* @see Core_Gateway::get_issuers() |
59
|
|
|
*/ |
60
|
|
|
public function get_issuers() { |
61
|
|
|
$groups = array(); |
62
|
|
|
|
63
|
|
|
$result = $this->client->get_issuers(); |
64
|
|
|
|
65
|
|
|
if ( is_array( $result ) ) { |
66
|
|
|
$groups[] = array( |
67
|
|
|
'options' => $result, |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$error = $this->client->get_error(); |
72
|
|
|
|
73
|
|
|
if ( is_wp_error( $error ) ) { |
74
|
|
|
$this->error = $error; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $groups; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get supported payment methods |
82
|
|
|
* |
83
|
|
|
* @see Core_Gateway::get_supported_payment_methods() |
84
|
|
|
*/ |
85
|
|
|
public function get_supported_payment_methods() { |
86
|
|
|
return array( |
87
|
|
|
Core_PaymentMethods::BANCONTACT, |
88
|
|
|
Core_PaymentMethods::BANK_TRANSFER, |
89
|
|
|
Core_PaymentMethods::CREDIT_CARD, |
90
|
|
|
Core_PaymentMethods::IDEAL, |
91
|
|
|
Core_PaymentMethods::PAYCONIQ, |
92
|
|
|
Core_PaymentMethods::PAYPAL, |
93
|
|
|
Core_PaymentMethods::SOFORT, |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Start |
99
|
|
|
* |
100
|
|
|
* @param Payment $payment Payment. |
101
|
|
|
* |
102
|
|
|
* @see Core_Gateway::start() |
103
|
|
|
*/ |
104
|
|
|
public function start( Payment $payment ) { |
105
|
|
|
$request = new OrderRequest(); |
106
|
|
|
|
107
|
|
|
$request->currency = $payment->get_total_amount()->get_currency()->get_alphabetic_code(); |
108
|
|
|
$request->amount = $payment->get_total_amount()->get_minor_units()->format( 0, '', '' ); |
|
|
|
|
109
|
|
|
$request->merchant_order_id = $payment->get_order_id(); |
110
|
|
|
$request->description = $payment->get_description(); |
111
|
|
|
$request->return_url = $payment->get_return_url(); |
112
|
|
|
|
113
|
|
|
// To make the 'Test' meta box work, set payment method to iDEAL if an issuer_id has been set. |
114
|
|
|
$issuer = $payment->get_issuer(); |
115
|
|
|
|
116
|
|
|
$payment_method = $payment->get_method(); |
117
|
|
|
|
118
|
|
|
if ( Core_PaymentMethods::IDEAL === $payment_method ) { |
119
|
|
|
$request->issuer = $issuer; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$request->method = PaymentMethods::transform( $payment_method ); |
123
|
|
|
|
124
|
|
|
$order = $this->client->create_order( $request ); |
125
|
|
|
|
126
|
|
|
if ( $order ) { |
127
|
|
|
$payment->set_transaction_id( $order->id ); |
128
|
|
|
|
129
|
|
|
// Set action URL to order pay URL. |
130
|
|
|
if ( isset( $order->order_url ) ) { |
131
|
|
|
$payment->set_action_url( $order->order_url ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// Set action URL to transaction payment URL (only if payment method is set). |
135
|
|
|
if ( isset( $order->transactions[0]->payment_url ) ) { |
136
|
|
|
$payment->set_action_url( $order->transactions[0]->payment_url ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// Bank transfer instructions. |
140
|
|
|
if ( Core_PaymentMethods::BANK_TRANSFER === $payment_method && isset( $order->transactions[0]->id ) ) { |
141
|
|
|
$payment->set_action_url( |
142
|
|
|
\sprintf( |
143
|
|
|
'https://api.kassacompleet.nl/pay/%s/completed/', |
144
|
|
|
esc_html( $order->transactions[0]->id ) |
145
|
|
|
) |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$error = $this->client->get_error(); |
151
|
|
|
|
152
|
|
|
if ( is_wp_error( $error ) ) { |
153
|
|
|
$this->error = $error; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Update status of the specified payment |
159
|
|
|
* |
160
|
|
|
* @param Payment $payment Payment. |
161
|
|
|
*/ |
162
|
|
|
public function update_status( Payment $payment ) { |
163
|
|
|
$transaction_id = $payment->get_transaction_id(); |
164
|
|
|
|
165
|
|
|
if ( empty( $transaction_id ) ) { |
166
|
|
|
return; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
$order = $this->client->get_order( $transaction_id ); |
170
|
|
|
|
171
|
|
|
if ( ! is_object( $order ) ) { |
172
|
|
|
return; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
$payment->set_status( Statuses::transform( $order->status ) ); |
176
|
|
|
|
177
|
|
|
if ( isset( $order->transactions[0]->payment_method_details ) ) { |
178
|
|
|
$consumer_bank_details = $payment->get_consumer_bank_details(); |
179
|
|
|
|
180
|
|
|
if ( null === $consumer_bank_details ) { |
181
|
|
|
$consumer_bank_details = new BankAccountDetails(); |
182
|
|
|
|
183
|
|
|
$payment->set_consumer_bank_details( $consumer_bank_details ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$details = $order->transactions[0]->payment_method_details; |
187
|
|
|
|
188
|
|
|
if ( isset( $details->consumer_name ) ) { |
189
|
|
|
$consumer_bank_details->set_name( $details->consumer_name ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if ( isset( $details->consumer_iban ) ) { |
193
|
|
|
$consumer_bank_details->set_iban( $details->consumer_iban ); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$error = $this->client->get_error(); |
198
|
|
|
|
199
|
|
|
if ( is_wp_error( $error ) ) { |
200
|
|
|
$this->error = $error; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.