PaymentMethodType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 43
c 5
b 0
f 0
dl 0
loc 183
ccs 10
cts 11
cp 0.9091
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A to_wp() 0 8 2
A transform() 0 10 3
1
<?php
2
/**
3
 * Payment method type
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 Pronamic\WordPress\Pay\Core\PaymentMethods;
14
15
/**
16
 * Payment method type
17
 *
18
 * @link https://docs.adyen.com/developers/classic-integration/directory-lookup#DirectoryLookup-Step2:Displaylocalpaymentmethods
19
 *
20
 * @author  Remco Tolsma
21
 * @version 1.0.5
22
 * @since   1.0.0
23
 */
24
class PaymentMethodType {
25
	/**
26
	 * Constant for the 'scheme' payment method type.
27
	 *
28
	 * @link https://docs.adyen.com/developers/development-resources/test-cards/test-card-numbers
29
	 *
30
	 * @var string
31
	 */
32
	const SCHEME = 'scheme';
33
34
	/**
35
	 * Constant for the 'afterpay_default' payment method type.
36
	 *
37
	 * @var string
38
	 */
39
	const AFTERPAY = 'afterpay_default';
40
41
	/**
42
	 * Constant for the 'alipay' payment method type.
43
	 *
44
	 * @var string
45
	 */
46
	const ALIPAY = 'alipay';
47
48
	/**
49
	 * Constant for the 'applepay' payment method type.
50
	 *
51
	 * @var string
52
	 */
53
	const APPLE_PAY = 'applepay';
54
55
	/**
56
	 * Constant for the 'bcmc' payment method type.
57
	 *
58
	 * @var string
59
	 */
60
	const BANCONTACT = 'bcmc';
61
62
	/**
63
	 * Constant for the 'sepadirectdebit' payment method type.
64
	 *
65
	 * @var string
66
	 */
67
	const DIRECT_DEBIT = 'sepadirectdebit';
68
69
	/**
70
	 * Constant for the 'directEbanking' payment method type.
71
	 *
72
	 * @var string
73
	 */
74
	const DIRECT_EBANKING = 'directEbanking';
75
76
	/**
77
	 * Constant for the 'dotpay' payment method type.
78
	 *
79
	 * @var string
80
	 */
81
	const DOTPAY = 'dotpay';
82
83
	/**
84
	 * Constant for the 'eps' payment method type.
85
	 *
86
	 * @var string
87
	 */
88
	const EPS = 'eps';
89
90
	/**
91
	 * Constant for the 'GiroPay' payment method type.
92
	 *
93
	 * @var string
94
	 */
95
	const GIROPAY = 'giropay';
96
97
	/**
98
	 * Constant for the 'paywithgoogle' payment method type.
99
	 *
100
	 * @var string
101
	 */
102
	const GOOGLE_PAY = 'paywithgoogle';
103
104
	/**
105
	 * Constant for the 'ideal' payment method type.
106
	 *
107
	 * @var string
108
	 */
109
	const IDEAL = 'ideal';
110
111
	/**
112
	 * Constant for the 'klarna' payment method type.
113
	 *
114
	 * @var string
115
	 */
116
	const KLARNA = 'klarna';
117
118
	/**
119
	 * Constant for the 'maestro' payment method type.
120
	 *
121
	 * @var string
122
	 */
123
	const MAESTRO = 'maestro';
124
125
	/**
126
	 * Constant for the 'Multibanco' payment method type.
127
	 *
128
	 * @var string
129
	 */
130
	const MULTIBANCO = 'multibanco';
131
132
	/**
133
	 * Constant for the 'PayPal' payment method type.
134
	 *
135
	 * @var string
136
	 */
137
	const PAYPAL = 'paypal';
138
139
	/**
140
	 * Constant for the 'SEPA Direct Debit' payment method type.
141
	 *
142
	 * @var string
143
	 */
144
	const SEPA_DIRECT_DEBIT = 'sepadirectdebit';
145
146
	/**
147
	 * Constant for the 'UnionPay' payment method type.
148
	 *
149
	 * @var string
150
	 */
151
	const UNIONPAY = 'unionpay';
152
153
	/**
154
	 * Map payment methods to brand codes.
155
	 *
156
	 * @var array<string, string>
157
	 */
158
	private static $map = array(
159
		PaymentMethods::AFTERPAY         => self::AFTERPAY,
160
		PaymentMethods::ALIPAY           => self::ALIPAY,
161
		PaymentMethods::APPLE_PAY        => self::APPLE_PAY,
162
		PaymentMethods::BANCONTACT       => self::BANCONTACT,
163
		PaymentMethods::CREDIT_CARD      => self::SCHEME,
164
		PaymentMethods::DIRECT_DEBIT     => self::SEPA_DIRECT_DEBIT,
165
		PaymentMethods::EPS              => self::EPS,
166
		PaymentMethods::GIROPAY          => self::GIROPAY,
167
		PaymentMethods::GOOGLE_PAY       => self::GOOGLE_PAY,
168
		PaymentMethods::IDEAL            => self::IDEAL,
169
		PaymentMethods::KLARNA_PAY_LATER => self::KLARNA,
170
		PaymentMethods::MAESTRO          => self::MAESTRO,
171
		PaymentMethods::PAYPAL           => self::PAYPAL,
172
		PaymentMethods::SOFORT           => self::DIRECT_EBANKING,
173
	);
174
175
	/**
176
	 * Transform WordPress payment method to Adyen brand code.
177
	 *
178
	 * @param string|null $payment_method Payment method.
179
	 * @return string|null
180
	 */
181 12
	public static function transform( $payment_method ) {
182 12
		if ( null === $payment_method ) {
183 1
			return null;
184
		}
185
186 11
		if ( array_key_exists( $payment_method, self::$map ) ) {
187 11
			return self::$map[ $payment_method ];
188
		}
189
190
		return null;
191
	}
192
193
	/**
194
	 * Transform Adyen method to WordPress payment method.
195
	 *
196
	 * @param string $adyen_type Adyen method type.
197
	 * @return string|null
198
	 */
199 12
	public static function to_wp( $adyen_type ) {
200 12
		$result = array_search( $adyen_type, self::$map, true );
201
202 12
		if ( false === $result ) {
203 1
			return null;
204
		}
205
206 11
		return $result;
207
	}
208
}
209