1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Drop-in gateway |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2020 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 Exception; |
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
use Locale; |
16
|
|
|
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway; |
17
|
|
|
use Pronamic\WordPress\Pay\Core\PaymentMethods; |
18
|
|
|
use Pronamic\WordPress\Pay\Core\Util as Core_Util; |
19
|
|
|
use Pronamic\WordPress\Pay\Payments\Payment; |
20
|
|
|
use Pronamic\WordPress\Pay\Plugin; |
21
|
|
|
use WP_Error; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Drop-in gateway |
25
|
|
|
* |
26
|
|
|
* @link https://github.com/adyenpayments/php/blob/master/generatepaymentform.php |
27
|
|
|
* |
28
|
|
|
* @author Remco Tolsma |
29
|
|
|
* @version 1.0.5 |
30
|
|
|
* @since 1.0.0 |
31
|
|
|
*/ |
32
|
|
|
class DropInGateway extends AbstractGateway { |
33
|
|
|
/** |
34
|
|
|
* Web SDK version. |
35
|
|
|
* |
36
|
|
|
* @link https://docs.adyen.com/developers/checkout/web-sdk/release-notes-web-sdk |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
const SDK_VERSION = '3.4.0'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Payment redirect. |
44
|
|
|
* |
45
|
|
|
* @param Payment $payment Payment. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function payment_redirect( Payment $payment ) { |
50
|
|
|
$url_script = sprintf( |
51
|
|
|
'https://checkoutshopper-%s.adyen.com/checkoutshopper/sdk/%s/adyen.js', |
52
|
|
|
( self::MODE_TEST === $payment->get_mode() ? 'test' : 'live' ), |
53
|
|
|
self::SDK_VERSION |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Version is part of URL. |
57
|
|
|
wp_register_script( |
58
|
|
|
'pronamic-pay-adyen-checkout', |
59
|
|
|
$url_script, |
60
|
|
|
array(), |
61
|
|
|
null, |
62
|
|
|
false |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$url_stylesheet = sprintf( |
66
|
|
|
'https://checkoutshopper-%s.adyen.com/checkoutshopper/sdk/%s/adyen.css', |
67
|
|
|
( self::MODE_TEST === $payment->get_mode() ? 'test' : 'live' ), |
68
|
|
|
self::SDK_VERSION |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Version is part of URL. |
72
|
|
|
wp_register_style( |
73
|
|
|
'pronamic-pay-adyen-checkout', |
74
|
|
|
$url_stylesheet, |
75
|
|
|
array(), |
76
|
|
|
null |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Payment methods. |
81
|
|
|
*/ |
82
|
|
|
$payment_methods = $this->client->get_payment_methods(); |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Adyen checkout configuration. |
86
|
|
|
* |
87
|
|
|
* @link https://docs.adyen.com/checkout/drop-in-web |
88
|
|
|
* @link https://docs.adyen.com/checkout/components-web |
89
|
|
|
*/ |
90
|
|
|
$configuration = (object) array( |
91
|
|
|
'locale' => 'en-US', |
92
|
|
|
'environment' => ( self::MODE_TEST === $payment->get_mode() ? 'test' : 'live' ), |
93
|
|
|
'originKey' => $this->config->origin_key, |
94
|
|
|
'paymentMethodsResponse' => $payment_methods->get_original_object(), |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Filters the Adyen checkout configuration. |
99
|
|
|
* |
100
|
|
|
* @param object $configuration Adyen checkout configuration. |
101
|
|
|
* @since 1.2.0 |
102
|
|
|
*/ |
103
|
|
|
$configuration = apply_filters( 'pronamic_pay_adyen_checkout_configuration', $configuration ); |
104
|
|
|
|
105
|
|
|
wp_localize_script( |
106
|
|
|
'pronamic-pay-adyen-checkout', |
107
|
|
|
'pronamicPayAdyenCheckout', |
108
|
|
|
array( |
109
|
|
|
'configuration' => $configuration, |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
|
113
|
|
|
// Add checkout head action. |
114
|
|
|
add_action( 'pronamic_pay_adyen_checkout_head', array( $this, 'checkout_head' ) ); |
115
|
|
|
|
116
|
|
|
// No cache. |
117
|
|
|
Core_Util::no_cache(); |
118
|
|
|
|
119
|
|
|
require __DIR__ . '/../views/checkout-drop-in.php'; |
120
|
|
|
|
121
|
|
|
exit; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Checkout head. |
126
|
|
|
* |
127
|
|
|
* @return void |
128
|
|
|
*/ |
129
|
|
|
public function checkout_head() { |
130
|
|
|
wp_print_styles( 'pronamic-pay-redirect' ); |
131
|
|
|
|
132
|
|
|
wp_print_scripts( 'pronamic-pay-adyen-checkout' ); |
133
|
|
|
|
134
|
|
|
wp_print_styles( 'pronamic-pay-adyen-checkout' ); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.