1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Gateway |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2019 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\Adyen |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
12
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
14
|
|
|
use Pronamic\WordPress\Pay\Core\PaymentMethods; |
15
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Gateway |
19
|
|
|
* |
20
|
|
|
* @author Remco Tolsma |
21
|
|
|
* @version 2.0.0 |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
* @link https://github.com/adyenpayments/php/blob/master/generatepaymentform.php |
24
|
|
|
*/ |
25
|
|
|
class Gateway extends Core_Gateway { |
26
|
|
|
/** |
27
|
|
|
* Slug of this gateway |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SLUG = 'adyen'; |
32
|
|
|
|
33
|
|
|
///////////////////////////////////////////////// |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructs and initializes an InternetKassa gateway |
37
|
|
|
* |
38
|
|
|
* @param Pronamic_WP_Pay_GatewayConfig $config |
|
|
|
|
39
|
|
|
*/ |
40
|
|
|
public function __construct( Config $config ) { |
41
|
|
|
parent::__construct( $config ); |
42
|
|
|
|
43
|
|
|
$this->set_method( self::METHOD_HTTP_REDIRECT ); |
44
|
|
|
$this->set_has_feedback( true ); |
|
|
|
|
45
|
|
|
$this->set_amount_minimum( 0.01 ); |
|
|
|
|
46
|
|
|
$this->set_slug( self::SLUG ); |
47
|
|
|
|
48
|
|
|
$this->client = new Adyen(); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
///////////////////////////////////////////////// |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Start |
55
|
|
|
* |
56
|
|
|
* @param Pronamic_Pay_Payment $payment |
|
|
|
|
57
|
|
|
* @see Pronamic_WP_Pay_Gateway::start() |
58
|
|
|
*/ |
59
|
|
|
public function start( Payment $payment ) { |
60
|
|
|
$url = 'https://checkout-test.adyen.com/v40/paymentMethods'; |
61
|
|
|
|
62
|
|
|
$data = (object) array( |
63
|
|
|
'merchantAccount' => $this->config->merchant_account, |
64
|
|
|
'allowedPaymentMethods' => array( |
65
|
|
|
// 'ideal', |
66
|
|
|
), |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$response = wp_remote_post( $url, array( |
70
|
|
|
'headers' => array( |
71
|
|
|
'X-API-key' => $this->config->api_key, |
72
|
|
|
'Content-Type' => 'application/json', |
73
|
|
|
), |
74
|
|
|
'body' => wp_json_encode( $data ), |
75
|
|
|
) ); |
76
|
|
|
|
77
|
|
|
$body = wp_remote_retrieve_body( $response ); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$result = json_decode( $body ); |
80
|
|
|
|
81
|
|
|
$payment_methods = $result->paymentMethods; |
82
|
|
|
$payment_method = reset( $payment_methods ); |
|
|
|
|
83
|
|
|
|
84
|
|
|
$url = 'https://checkout-test.adyen.com/v40/payments'; |
85
|
|
|
|
86
|
|
|
$data = (object) array( |
87
|
|
|
'amount' => (object) array( |
88
|
|
|
'currency' => $payment->get_total_amount()->get_currency()->get_alphabetic_code(), |
89
|
|
|
'value' => $payment->get_total_amount()->get_cents(), |
90
|
|
|
), |
91
|
|
|
'reference' => $payment->get_id(), |
92
|
|
|
'paymentMethod' => (object) array( |
93
|
|
|
'type' => 'ideal', |
94
|
|
|
), |
95
|
|
|
'returnUrl' => $payment->get_return_url(), |
96
|
|
|
'merchantAccount' => $this->config->merchant_account, |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
$response = wp_remote_post( $url, array( |
100
|
|
|
'headers' => array( |
101
|
|
|
'X-API-key' => $this->config->api_key, |
102
|
|
|
'Content-Type' => 'application/json', |
103
|
|
|
), |
104
|
|
|
'body' => wp_json_encode( $data ), |
105
|
|
|
) ); |
106
|
|
|
|
107
|
|
|
if ( '200' !== strval( wp_remote_retrieve_response_code( $response ) ) ) { |
|
|
|
|
108
|
|
|
return; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$body = wp_remote_retrieve_body( $response ); |
112
|
|
|
|
113
|
|
|
$result = json_decode( $body ); |
114
|
|
|
|
115
|
|
|
if ( isset( $result->redirect, $result->redirect->url ) ) { |
116
|
|
|
$payment->set_action_url( $result->redirect->url ); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
///////////////////////////////////////////////// |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get output HTML |
124
|
|
|
* |
125
|
|
|
* @see Pronamic_WP_Pay_Gateway::get_output_html() |
126
|
|
|
*/ |
127
|
|
|
public function get_output_html() { |
128
|
|
|
return $this->client->get_html_fields(); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths