Issues (46)

src/Methods.php (1 issue)

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 Credit card
132
	 *
133
	 * @var string
134
	 */
135
	const CREDITCARD = 'CREDITCARD';
136
137
	/**
138
	 * Gateway Pay after delivery
139
	 *
140
	 * @var string
141
	 */
142
	const PAYAFTER = 'PAYAFTER';
143
144
	/**
145
	 * Gateway PayPal
146
	 *
147
	 * @var string
148
	 */
149
	const PAYPAL = 'PAYPAL';
150
151
	/**
152
	 * Gateway Visa
153
	 *
154
	 * @var string
155
	 */
156
	const VISA = 'VISA';
157
158
	/**
159
	 * Gateway Santander
160
	 *
161
	 * @var string
162
	 */
163
	const SANTANDER = 'SANTANDER';
164
165
	/**
166
	 * Payments methods map.
167
	 *
168
	 * @var array<string, string>
169
	 */
170
	private static $map = array(
171
		PaymentMethods::ALIPAY        => self::ALIPAY,
172
		PaymentMethods::BANCONTACT    => self::BANCONTACT,
173
		PaymentMethods::BANK_TRANSFER => self::BANK_TRANSFER,
174
		PaymentMethods::BELFIUS       => self::BELFIUS,
175
		PaymentMethods::CREDIT_CARD   => self::CREDITCARD,
176
		PaymentMethods::DIRECT_DEBIT  => self::DIRECT_DEBIT,
177
		PaymentMethods::GIROPAY       => self::GIROPAY,
178
		PaymentMethods::IDEAL         => self::IDEAL,
179
		PaymentMethods::IDEALQR       => self::IDEALQR,
180
		PaymentMethods::IN3           => self::IN3,
181
		PaymentMethods::KBC           => self::KBC,
182
		PaymentMethods::PAYPAL        => self::PAYPAL,
183
		PaymentMethods::SANTANDER     => self::SANTANDER,
184
		PaymentMethods::SOFORT        => self::SOFORT,
185
	);
186
187
	/**
188
	 * Transform WordPress payment method to MultiSafepay method.
189
	 *
190
	 * @param string|null $payment_method Payment method.
191
	 * @param string|null $default        Default payment method.
192
	 * @return string|null
193
	 */
194
	public static function transform( $payment_method, $default = null ) {
195
		if ( ! \is_scalar( $payment_method ) ) {
196
			return null;
197
		}
198
199
		if ( isset( self::$map[ $payment_method ] ) ) {
200
			return self::$map[ $payment_method ];
201
		}
202
203
		return $default;
204
	}
205
206
	/**
207
	 * Transform MultiSafepay method to WordPress payment method.
208
	 *
209
	 * @param string $method MultiSafepay method.
210
	 * @return string|null
211
	 */
212
	public static function transform_gateway_method( $method ) {
213
		if ( ! \is_scalar( $method ) ) {
0 ignored issues
show
The condition is_scalar($method) is always true.
Loading history...
214
			return null;
215
		}
216
217
		$payment_method = \array_search( $method, self::$map, true );
218
219
		if ( ! \is_string( $payment_method ) ) {
220
			return null;
221
		}
222
223
		return $payment_method;
224
	}
225
226
	/**
227
	 * Get cards.
228
	 *
229
	 * @return array<string, string>
230
	 */
231
	public static function get_cards() {
232
		return array(
233
			self::AMEX       => _x( 'American Express', 'Payment method name', 'pronamic_ideal' ),
234
			self::MAESTRO    => _x( 'Maestro', 'Payment method name', 'pronamic_ideal' ),
235
			self::MASTERCARD => _x( 'Mastercard', 'Payment method name', 'pronamic_ideal' ),
236
			self::VISA       => _x( 'Visa', 'Payment method name', 'pronamic_ideal' ),
237
		);
238
	}
239
}
240