Failed Conditions
Push — develop ( 0669ed...0eccc5 )
by Reüel
05:00
created

src/Methods.php (2 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay;
4
5
use Pronamic\WordPress\Pay\Core\PaymentMethods;
6
7
/**
8
 * Title: MultiSafepay connect payment methods
9
 * Description:
10
 * Copyright: 2005-2021 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.2
15
 * @since   1.2.0
16
 */
17
class Methods {
18
	/**
19
	 * Gateway Alipay
20
	 *
21
	 * @var string
22
	 */
23
	const ALIPAY = 'ALIPAY';
24
25
	/**
26
	 * Gateway American Express
27
	 *
28
	 * @var string
29
	 */
30
	const AMEX = 'AMEX';
31
32
	/**
33
	 * Gateway Bank Transfer
34
	 *
35
	 * @var string
36
	 */
37
	const BANK_TRANSFER = 'BANKTRANS';
38
39
	/**
40
	 * Gateway Belfius
41
	 *
42
	 * @var string
43
	 */
44
	const BELFIUS = 'BELFIUS';
45
46
	/**
47
	 * Gateway Direct Debit
48
	 *
49
	 * @var string
50
	 */
51
	const DIRECT_DEBIT = 'DIRDEB';
52
53
	/**
54
	 * Gateway SOFORT Banking
55
	 *
56
	 * @var string
57
	 */
58
	const SOFORT = 'DIRECTBANK';
59
60
	/**
61
	 * Gateway DotPay
62
	 *
63
	 * @var string
64
	 */
65
	const DOTPAY = 'DOTPAY';
66
67
	/**
68
	 * Gateway Giropay
69
	 *
70
	 * @var string
71
	 */
72
	const GIROPAY = 'GIROPAY';
73
74
	/**
75
	 * Gateway iDEAL QR
76
	 *
77
	 * @var string
78
	 */
79
	const IDEALQR = 'IDEALQR';
80
81
	/**
82
	 * Gateway iDEAL
83
	 *
84
	 * @var string
85
	 */
86
	const IDEAL = 'IDEAL';
87
88
	/**
89
	 * Gateway ING
90
	 *
91
	 * @var string
92
	 */
93
	const ING = 'ING';
94
95
	/**
96
	 * Gateway IN3
97
	 *
98
	 * @var string
99
	 */
100
	const IN3 = 'IN3';
101
102
	/**
103
	 * Gateway KBC
104
	 *
105
	 * @var string
106
	 */
107
	const KBC = 'KBC';
108
109
	/**
110
	 * Gateway Maestro
111
	 *
112
	 * @var string
113
	 */
114
	const MAESTRO = 'MAESTRO';
115
116
	/**
117
	 * Gateway Mastercard
118
	 *
119
	 * @var string
120
	 */
121
	const MASTERCARD = 'MASTERCARD';
122
123
	/**
124
	 * Gateway Bancontact
125
	 *
126
	 * @var string
127
	 */
128
	const BANCONTACT = 'MISTERCASH';
129
130
	/**
131
	 * Gateway Pay after delivery
132
	 *
133
	 * @var string
134
	 */
135
	const PAYAFTER = 'PAYAFTER';
136
137
	/**
138
	 * Gateway PayPal
139
	 *
140
	 * @var string
141
	 */
142
	const PAYPAL = 'PAYPAL';
143
144
	/**
145
	 * Gateway Visa
146
	 *
147
	 * @var string
148
	 */
149
	const VISA = 'VISA';
150
151
	/**
152
	 * Gateway Santander
153
	 *
154
	 * @var string
155
	 */
156
	const SANTANDER = 'SANTANDER';
157
158
	/**
159
	 * Payments methods map.
160
	 *
161
	 * @var array
162
	 */
163
	private static $map = array(
164
		PaymentMethods::ALIPAY        => self::ALIPAY,
165
		PaymentMethods::BANCONTACT    => self::BANCONTACT,
166
		PaymentMethods::BANK_TRANSFER => self::BANK_TRANSFER,
167
		PaymentMethods::BELFIUS       => self::BELFIUS,
168
		PaymentMethods::DIRECT_DEBIT  => self::DIRECT_DEBIT,
169
		PaymentMethods::GIROPAY       => self::GIROPAY,
170
		PaymentMethods::IDEAL         => self::IDEAL,
171
		PaymentMethods::IDEALQR       => self::IDEALQR,
172
		PaymentMethods::IN3           => self::IN3,
173
		PaymentMethods::KBC           => self::KBC,
174
		PaymentMethods::PAYPAL        => self::PAYPAL,
175
		PaymentMethods::SANTANDER     => self::SANTANDER,
176
		PaymentMethods::SOFORT        => self::SOFORT,
177
	);
178
179
	/**
180
	 * Transform WordPress payment method to MultiSafepay method.
181
	 *
182
	 * @since unreleased
183
	 *
184
	 * @param string $payment_method Payment method.
185
	 * @param mixed  $default        Default payment method.
186
	 *
187
	 * @return string
188
	 */
189
	public static function transform( $payment_method, $default = null ) {
190
		if ( ! is_scalar( $payment_method ) ) {
0 ignored issues
show
The condition is_scalar($payment_method) is always true.
Loading history...
191
			return null;
192
		}
193
194
		if ( isset( self::$map[ $payment_method ] ) ) {
195
			return self::$map[ $payment_method ];
196
		}
197
198
		return $default;
199
	}
200
201
	/**
202
	 * Transform MultiSafepay method to WordPress payment method.
203
	 *
204
	 * @since unreleased
205
	 *
206
	 * @param string $method Mollie method.
207
	 *
208
	 * @return string
209
	 */
210
	public static function transform_gateway_method( $method ) {
211
		if ( ! is_scalar( $method ) ) {
0 ignored issues
show
The condition is_scalar($method) is always true.
Loading history...
212
			return null;
213
		}
214
215
		$payment_method = array_search( $method, self::$map, true );
216
217
		if ( ! $payment_method ) {
218
			return null;
219
		}
220
221
		return $payment_method;
222
	}
223
}
224