1 | <?php |
||||
2 | |||||
3 | namespace Pronamic\WordPress\Pay\Gateways\Buckaroo; |
||||
4 | |||||
5 | use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
||||
6 | use Pronamic\WordPress\Pay\Core\PaymentMethods as Core_PaymentMethods; |
||||
7 | use Pronamic\WordPress\Pay\Core\Server; |
||||
8 | use Pronamic\WordPress\Pay\Payments\Payment; |
||||
9 | |||||
10 | /** |
||||
11 | * Title: Buckaroo gateway |
||||
12 | * Description: |
||||
13 | * Copyright: 2005-2020 Pronamic |
||||
14 | * Company: Pronamic |
||||
15 | * |
||||
16 | * @author Remco Tolsma |
||||
17 | * @version 2.0.4 |
||||
18 | * @since 1.0.0 |
||||
19 | */ |
||||
20 | class Gateway extends Core_Gateway { |
||||
21 | /** |
||||
22 | * Client. |
||||
23 | * |
||||
24 | * @var Client |
||||
25 | */ |
||||
26 | protected $client; |
||||
27 | |||||
28 | /** |
||||
29 | * Constructs and initializes an Buckaroo gateway |
||||
30 | * |
||||
31 | * @param Config $config Config. |
||||
32 | */ |
||||
33 | public function __construct( Config $config ) { |
||||
34 | parent::__construct( $config ); |
||||
35 | |||||
36 | $this->set_method( self::METHOD_HTML_FORM ); |
||||
37 | |||||
38 | $this->client = new Client(); |
||||
39 | $this->client->set_website_key( $config->get_website_key() ); |
||||
40 | $this->client->set_secret_key( $config->get_secret_key() ); |
||||
41 | $this->client->set_excluded_services( $config->get_excluded_services() ); |
||||
42 | $this->client->set_invoice_number( $config->get_invoice_number() ); |
||||
43 | $this->client->set_push_url( add_query_arg( 'buckaroo_push', '', home_url( '/' ) ) ); |
||||
44 | |||||
45 | if ( self::MODE_TEST === $config->mode ) { |
||||
46 | $this->client->set_payment_server_url( Client::GATEWAY_TEST_URL ); |
||||
47 | } |
||||
48 | } |
||||
49 | |||||
50 | /** |
||||
51 | * Get issuers. |
||||
52 | * |
||||
53 | * @since 1.2.4 |
||||
54 | * @see Pronamic_WP_Pay_Gateway::get_issuers() |
||||
55 | */ |
||||
56 | public function get_issuers() { |
||||
57 | $groups = array(); |
||||
58 | |||||
59 | try { |
||||
60 | $result = $this->client->get_issuers(); |
||||
61 | |||||
62 | $groups[] = array( |
||||
63 | 'options' => $result, |
||||
64 | ); |
||||
65 | } catch ( \Exception $e ) { |
||||
66 | $this->error = new \WP_Error( 'buckaroo', $e->getMessage() ); |
||||
67 | } |
||||
68 | |||||
69 | return $groups; |
||||
70 | } |
||||
71 | |||||
72 | /** |
||||
73 | * Get supported payment methods |
||||
74 | * |
||||
75 | * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods() |
||||
76 | */ |
||||
77 | public function get_supported_payment_methods() { |
||||
78 | return array( |
||||
79 | Core_PaymentMethods::BANK_TRANSFER, |
||||
80 | Core_PaymentMethods::BANCONTACT, |
||||
81 | Core_PaymentMethods::CREDIT_CARD, |
||||
82 | Core_PaymentMethods::GIROPAY, |
||||
83 | Core_PaymentMethods::IDEAL, |
||||
84 | Core_PaymentMethods::PAYPAL, |
||||
85 | Core_PaymentMethods::SOFORT, |
||||
86 | ); |
||||
87 | } |
||||
88 | |||||
89 | /** |
||||
90 | * Start |
||||
91 | * |
||||
92 | * @param Payment $payment Payment. |
||||
93 | * |
||||
94 | * @see Core_Gateway::start() |
||||
95 | */ |
||||
96 | public function start( Payment $payment ) { |
||||
97 | $payment->set_action_url( $this->client->get_payment_server_url() ); |
||||
98 | } |
||||
99 | |||||
100 | /** |
||||
101 | * Get output HTML |
||||
102 | * |
||||
103 | * @param Payment $payment Payment. |
||||
104 | * |
||||
105 | * @return string |
||||
106 | * |
||||
107 | * @see Core_Gateway::get_output_html() |
||||
108 | * @since 1.1.1 |
||||
109 | * @version 2.0.4 |
||||
110 | */ |
||||
111 | public function get_output_fields( Payment $payment ) { |
||||
112 | $payment_method = $payment->get_method(); |
||||
113 | |||||
114 | switch ( $payment_method ) { |
||||
115 | case Core_PaymentMethods::IDEAL: |
||||
116 | $this->client->set_payment_method( PaymentMethods::IDEAL ); |
||||
117 | $this->client->set_ideal_issuer( $payment->get_issuer() ); |
||||
118 | |||||
119 | break; |
||||
120 | case Core_PaymentMethods::CREDIT_CARD: |
||||
121 | $this->client->add_requested_service( PaymentMethods::AMERICAN_EXPRESS ); |
||||
122 | $this->client->add_requested_service( PaymentMethods::MAESTRO ); |
||||
123 | $this->client->add_requested_service( PaymentMethods::MASTERCARD ); |
||||
124 | $this->client->add_requested_service( PaymentMethods::VISA ); |
||||
125 | |||||
126 | break; |
||||
127 | case Core_PaymentMethods::BANK_TRANSFER: |
||||
128 | case Core_PaymentMethods::BANCONTACT: |
||||
129 | case Core_PaymentMethods::MISTER_CASH: |
||||
130 | case Core_PaymentMethods::GIROPAY: |
||||
131 | case Core_PaymentMethods::PAYPAL: |
||||
132 | case Core_PaymentMethods::SOFORT: |
||||
133 | $this->client->set_payment_method( PaymentMethods::transform( $payment_method ) ); |
||||
134 | |||||
135 | break; |
||||
136 | default: |
||||
137 | if ( '0' !== $payment_method ) { |
||||
138 | // Leap of faith if the WordPress payment method could not transform to a Buckaroo method? |
||||
139 | $this->client->set_payment_method( $payment_method ); |
||||
140 | } |
||||
141 | |||||
142 | break; |
||||
143 | } |
||||
144 | |||||
145 | // Locale. |
||||
146 | $locale = ''; |
||||
147 | |||||
148 | if ( null !== $payment->get_customer() ) { |
||||
149 | $locale = $payment->get_customer()->get_locale(); |
||||
150 | } |
||||
151 | |||||
152 | // Buckaroo uses 'nl-NL' instead of 'nl_NL'. |
||||
153 | $culture = str_replace( '_', '-', $locale ); |
||||
154 | |||||
155 | $this->client->set_payment_id( $payment->get_id() ); |
||||
156 | $this->client->set_culture( $culture ); |
||||
157 | $this->client->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ); |
||||
158 | $this->client->set_description( $payment->get_description() ); |
||||
159 | $this->client->set_amount( $payment->get_total_amount()->get_value() ); |
||||
160 | $this->client->set_invoice_number( Util::get_invoice_number( $this->client->get_invoice_number(), $payment ) ); |
||||
161 | $this->client->set_return_url( $payment->get_return_url() ); |
||||
162 | $this->client->set_return_cancel_url( $payment->get_return_url() ); |
||||
163 | $this->client->set_return_error_url( $payment->get_return_url() ); |
||||
164 | $this->client->set_return_reject_url( $payment->get_return_url() ); |
||||
165 | |||||
166 | return $this->client->get_fields(); |
||||
167 | } |
||||
168 | |||||
169 | /** |
||||
170 | * Update status of the specified payment |
||||
171 | * |
||||
172 | * @param Payment $payment Payment. |
||||
173 | */ |
||||
174 | public function update_status( Payment $payment ) { |
||||
175 | $method = Server::get( 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); |
||||
176 | |||||
177 | $data = array(); |
||||
178 | |||||
179 | switch ( $method ) { |
||||
180 | case 'GET': |
||||
181 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
||||
182 | $data = $_GET; |
||||
183 | |||||
184 | break; |
||||
185 | case 'POST': |
||||
186 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
||||
187 | $data = $_POST; |
||||
188 | |||||
189 | break; |
||||
190 | } |
||||
191 | |||||
192 | $data = Util::urldecode( $data ); |
||||
193 | |||||
194 | $data = stripslashes_deep( $data ); |
||||
195 | |||||
196 | $data = $this->client->verify_request( $data ); |
||||
197 | |||||
198 | if ( $data ) { |
||||
199 | $payment->set_transaction_id( $data[ Parameters::PAYMENT ] ); |
||||
200 | $payment->set_status( Statuses::transform( $data[ Parameters::STATUS_CODE ] ) ); |
||||
201 | $payment->set_consumer_iban( $data[ Parameters::SERVICE_IDEAL_CONSUMER_IBAN ] ); |
||||
0 ignored issues
–
show
|
|||||
202 | $payment->set_consumer_bic( $data[ Parameters::SERVICE_IDEAL_CONSUMER_BIC ] ); |
||||
0 ignored issues
–
show
The function
Pronamic\WordPress\Pay\P...nfo::set_consumer_bic() has been deprecated: 2.2.6 Use Payment::set_consumer_bank_details()->set_bic() instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
203 | $payment->set_consumer_name( $data[ Parameters::SERVICE_IDEAL_CONSUMER_NAME ] ); |
||||
0 ignored issues
–
show
The function
Pronamic\WordPress\Pay\P...fo::set_consumer_name() has been deprecated: 2.2.6 Use Payment::set_consumer_bank_details()->set_name() instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
204 | |||||
205 | $labels = array( |
||||
206 | Parameters::PAYMENT => __( 'Payment', 'pronamic_ideal' ), |
||||
207 | Parameters::PAYMENT_METHOD => __( 'Payment Method', 'pronamic_ideal' ), |
||||
208 | Parameters::STATUS_CODE => __( 'Status Code', 'pronamic_ideal' ), |
||||
209 | Parameters::STATUS_CODE_DETAIL => __( 'Status Code Detail', 'pronamic_ideal' ), |
||||
210 | Parameters::STATUS_MESSAGE => __( 'Status Message', 'pronamic_ideal' ), |
||||
211 | Parameters::INVOICE_NUMBER => __( 'Invoice Number', 'pronamic_ideal' ), |
||||
212 | Parameters::AMOUNT => __( 'Amount', 'pronamic_ideal' ), |
||||
213 | Parameters::CURRENCY => __( 'Currency', 'pronamic_ideal' ), |
||||
214 | Parameters::TIMESTAMP => __( 'Timestamp', 'pronamic_ideal' ), |
||||
215 | Parameters::SERVICE_IDEAL_CONSUMER_ISSUER => __( 'Service iDEAL Consumer Issuer', 'pronamic_ideal' ), |
||||
216 | Parameters::SERVICE_IDEAL_CONSUMER_NAME => __( 'Service iDEAL Consumer Name', 'pronamic_ideal' ), |
||||
217 | Parameters::SERVICE_IDEAL_CONSUMER_IBAN => __( 'Service iDEAL Consumer IBAN', 'pronamic_ideal' ), |
||||
218 | Parameters::SERVICE_IDEAL_CONSUMER_BIC => __( 'Service iDEAL Consumer BIC', 'pronamic_ideal' ), |
||||
219 | Parameters::TRANSACTIONS => __( 'Transactions', 'pronamic_ideal' ), |
||||
220 | ); |
||||
221 | |||||
222 | $note = ''; |
||||
223 | |||||
224 | $note .= '<p>'; |
||||
225 | $note .= __( 'Buckaroo data:', 'pronamic_ideal' ); |
||||
226 | $note .= '</p>'; |
||||
227 | |||||
228 | $note .= '<dl>'; |
||||
229 | |||||
230 | foreach ( $labels as $key => $label ) { |
||||
231 | if ( isset( $data[ $key ] ) ) { |
||||
232 | $note .= sprintf( '<dt>%s</dt>', esc_html( $label ) ); |
||||
233 | $note .= sprintf( '<dd>%s</dd>', esc_html( $data[ $key ] ) ); |
||||
234 | } |
||||
235 | } |
||||
236 | |||||
237 | $note .= '</dl>'; |
||||
238 | |||||
239 | $payment->add_note( $note ); |
||||
240 | } |
||||
241 | } |
||||
242 | } |
||||
243 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.