Passed
Push — develop ( 8b98d9...426279 )
by Reüel
06:39
created

Methods::transform_gateway_method()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
1
<?php
2
/**
3
 * Methods
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Payments
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Sisow;
12
13
use Pronamic\WordPress\Pay\Core\PaymentMethods;
14
15
/**
16
 * Title: iDEAL Sisow payment methods
17
 * Description:
18
 * Copyright: 2005-2019 Pronamic
19
 * Company: Pronamic
20
 *
21
 * @author  Remco Tolsma
22
 * @version 2.1.0
23
 * @since   1.0.0
24
 */
25
class Methods {
26
	/**
27
	 * Indicator for 'AfterPay' payment.
28
	 *
29
	 * @var string
30
	 * @since 2.1.0
31
	 */
32
	const AFTERPAY = 'afterpay';
33
34
	/**
35
	 * Indicator for 'Belfius' payment
36
	 *
37
	 * @var string
38
	 */
39
	const BELFIUS = 'belfius';
40
41
	/**
42
	 * Indicator for 'Billink' payment
43
	 *
44
	 * @var string
45
	 */
46
	const BILLINK = 'billink';
47
48
	/**
49
	 * Indicator for 'iDEAL' payment
50
	 *
51
	 * @var string
52
	 */
53
	const IDEAL = 'ideal';
54
55
	/**
56
	 * Indicator for 'iDEAL QR' payment
57
	 *
58
	 * @var string
59
	 */
60
	const IDEALQR = 'idealqr';
61
62
	/**
63
	 * Indicator for 'bunq' payment
64
	 *
65
	 * @var string
66
	 * @since unreleased
67
	 */
68
	const BUNQ = 'bunq';
69
70
	/**
71
	 * Indicator for 'Capayable' payment.
72
	 *
73
	 * @var string
74
	 * @since 2.1.0
75
	 */
76
	const CAPAYABLE = 'capayable';
77
78
	/**
79
	 * Indicator for 'Creditcard' payment
80
	 *
81
	 * @var string
82
	 * @since 1.1.2
83
	 */
84
	const CREDIT_CARD = 'creditcard';
85
86
	/**
87
	 * Indicator for 'Achteraf betalen' payment
88
	 *
89
	 * @var string
90
	 */
91
	const ECARE = 'ecare';
92
93
	/**
94
	 * Indicator for 'Digitale acceptgiro' payment
95
	 *
96
	 * @var string
97
	 */
98
	const EBILL = 'ebill';
99
100
	/**
101
	 * Indicator for 'Focum' payment.
102
	 *
103
	 * @var string
104
	 * @since 2.1.0
105
	 */
106
	const FOCUM = 'focum';
107
108
	/**
109
	 * Indicator for 'Giropay' payment
110
	 *
111
	 * @var string
112
	 */
113
	const GIROPAY = 'giropay';
114
115
	/**
116
	 * Indicator for 'Klarna Factuur' payment.
117
	 *
118
	 * @var string
119
	 * @since 2.1.0
120
	 */
121
	const KLARNA = 'klarna';
122
123
	/**
124
	 * Indicator for 'Bank/giro betaling' payment
125
	 *
126
	 * @var string
127
	 */
128
	const OVERBOEKING = 'overboeking';
129
130
	/**
131
	 * Indicator for 'SofortBanking/DIRECTebanking' payment
132
	 *
133
	 * @var string
134
	 */
135
	const SOFORT = 'sofort';
136
137
	/**
138
	 * Indicator for 'Bancontact/MisterCash' payment
139
	 *
140
	 * @var string
141
	 */
142
	const MISTER_CASH = 'mistercash';
143
144
	/**
145
	 * Indicator for 'PayPal Express Checkout' payment
146
	 *
147
	 * @var string
148
	 */
149
	const PAYPAL_EXPRESS_CHECKOUT = 'paypalec';
150
151
	/**
152
	 * Indicator for 'Webshop Giftcard' payment
153
	 *
154
	 * @var string
155
	 */
156
	const WEBSHOP_GIFTCARD = 'webshop';
157
158
	/**
159
	 * Indicator for 'Fijn Cadeaukaart' payment
160
	 *
161
	 * @var string
162
	 */
163
	const FIJNCADEAU = 'fijncadeau';
164
165
	/**
166
	 * Indicator for 'Podium Cadeaukaart' payment
167
	 *
168
	 * @var string
169
	 */
170
	const PODIUM_CADEAUKAART = 'podium';
171
172
	/**
173
	 * Payments methods map.
174
	 *
175
	 * @var array
176
	 */
177
	private static $map = array(
178
		PaymentMethods::AFTERPAY         => self::AFTERPAY,
179
		PaymentMethods::BANCONTACT       => self::MISTER_CASH,
180
		PaymentMethods::BANK_TRANSFER    => self::OVERBOEKING,
181
		PaymentMethods::BELFIUS          => self::BELFIUS,
182
		PaymentMethods::BILLINK          => self::BILLINK,
183
		PaymentMethods::BUNQ             => self::BUNQ,
184
		PaymentMethods::IN3              => self::CAPAYABLE,
185
		PaymentMethods::CREDIT_CARD      => self::CREDIT_CARD,
186
		PaymentMethods::FOCUM            => self::FOCUM,
187
		PaymentMethods::GIROPAY          => self::GIROPAY,
188
		PaymentMethods::IDEAL            => self::IDEAL,
189
		PaymentMethods::IDEALQR          => self::IDEALQR,
190
		PaymentMethods::KLARNA_PAY_LATER => self::KLARNA,
191
		PaymentMethods::MISTER_CASH      => self::MISTER_CASH,
192
		PaymentMethods::PAYPAL           => self::PAYPAL_EXPRESS_CHECKOUT,
193
		PaymentMethods::SOFORT           => self::SOFORT,
194
	);
195
196
	/**
197
	 * Transform WordPress payment method to Sisow method.
198
	 *
199
	 * @param mixed       $payment_method Payment method.
200
	 * @param string|null $default        Value to return if method could not be transformed.
201
	 * @return string|null
202
	 */
203
	public static function transform( $payment_method, $default = null ) {
204
		if ( ! is_scalar( $payment_method ) ) {
205
			return null;
206
		}
207
208
		if ( isset( self::$map[ $payment_method ] ) ) {
209
			return self::$map[ $payment_method ];
210
		}
211
212
		return $default;
213
	}
214
215
	/**
216
	 * Transform Sisow method to WordPress payment method.
217
	 *
218
	 * @since unreleased
219
	 *
220
	 * @param string $method Sisow method.
221
	 *
222
	 * @return string
223
	 */
224
	public static function transform_gateway_method( $method ) {
225
		if ( ! is_scalar( $method ) ) {
1 ignored issue
show
introduced by
The condition is_scalar($method) is always true.
Loading history...
226
			return null;
227
		}
228
229
		$payment_method = array_search( $method, self::$map, true );
230
231
		if ( ! $payment_method ) {
232
			return null;
233
		}
234
235
		return $payment_method;
236
	}
237
}
238