1
|
|
|
<?php |
2
|
|
|
|
3
|
|
View Code Duplication |
class EduSveaWebPayProductionConfig implements \Svea\WebPay\Config\ConfigurationProvider { |
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @var EDU_SveaWebPay |
7
|
|
|
*/ |
8
|
|
|
public $plugin; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* EduSveaWebPayProductionConfig constructor. |
12
|
|
|
* |
13
|
|
|
* @param EDU_SveaWebPay $_plugin |
14
|
|
|
*/ |
15
|
|
|
public function __construct( $_plugin ) { |
16
|
|
|
$this->plugin = $_plugin; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API) |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
* |
24
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
25
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
26
|
|
|
* |
27
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
28
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
29
|
|
|
*/ |
30
|
|
|
public function getUsername( $type, $country ) { |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* fetch password, used with invoice or payment plan (i.e. Svea WebService Europe API) |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
* |
38
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
39
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
40
|
|
|
* |
41
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
42
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
43
|
|
|
*/ |
44
|
|
|
public function getPassword( $type, $country ) { |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* fetch client number, used with invoice or payment plan (i.e. Svea WebService Europe API) |
49
|
|
|
* |
50
|
|
|
* @return \Svea\WebPay\Config\ClientNumber |
51
|
|
|
* |
52
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
53
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
54
|
|
|
* |
55
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
56
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
57
|
|
|
*/ |
58
|
|
|
public function getClientNumber( $type, $country ) { |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* fetch merchant id, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
* |
66
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
67
|
|
|
* @param string $country CountryCode eg. SE, NO, DK, FI, NL, DE |
68
|
|
|
*/ |
69
|
|
|
public function getMerchantId( $type, $country ) { |
|
|
|
|
70
|
|
|
return $this->plugin->get_option( 'merchant_key', '' ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* fetch secret word, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
* |
78
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
79
|
|
|
* @param string $country CountryCode eg. SE, NO, DK, FI, NL, DE |
80
|
|
|
*/ |
81
|
|
|
public function getSecret( $type, $country ) { |
|
|
|
|
82
|
|
|
return $this->plugin->get_option( 'merchant_secret', '' ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Constants for the endpoint url found in the class ConfigurationService.php |
87
|
|
|
* getEndPoint() should return an url corresponding to $type. |
88
|
|
|
* |
89
|
|
|
* @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE |
90
|
|
|
* |
91
|
|
|
* @throws Exception |
92
|
|
|
*/ |
93
|
|
|
|
94
|
|
|
public function getEndPoint( $type ) { |
|
|
|
|
95
|
|
|
switch ( strtoupper( $type ) ) { |
96
|
|
|
case "HOSTED": |
|
|
|
|
97
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_URL; |
98
|
|
|
break; |
|
|
|
|
99
|
|
|
case "INVOICE": |
|
|
|
|
100
|
|
|
case "PAYMENTPLAN": |
|
|
|
|
101
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_WS_URL; |
102
|
|
|
break; |
|
|
|
|
103
|
|
|
case "HOSTED_ADMIN": |
|
|
|
|
104
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_HOSTED_ADMIN_URL; |
105
|
|
|
break; |
|
|
|
|
106
|
|
|
case "ADMIN": |
|
|
|
|
107
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_ADMIN_URL; |
108
|
|
|
break; |
|
|
|
|
109
|
|
|
default: |
110
|
|
|
throw new Exception( 'Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED, HOSTED_ADMIN' ); |
111
|
|
|
break; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* fetch Checkout Merchant id, used for Checkout order type |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getCheckoutMerchantId() { |
|
|
|
|
121
|
|
|
// TODO: Implement getCheckoutMerchantId() method. |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* fetch Checkout Secret word, used for Checkout order type |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getCheckoutSecret() { |
|
|
|
|
130
|
|
|
// TODO: Implement getCheckoutSecret() method. |
|
|
|
|
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
View Code Duplication |
class EduSveaWebPayTestConfig implements \Svea\WebPay\Config\ConfigurationProvider { |
|
|
|
|
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @var EDU_SveaWebPay |
138
|
|
|
*/ |
139
|
|
|
public $plugin; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* EduSveaWebPayTestConfig constructor. |
143
|
|
|
* |
144
|
|
|
* @param EDU_SveaWebPay $_plugin |
145
|
|
|
*/ |
146
|
|
|
public function __construct( $_plugin ) { |
147
|
|
|
$this->plugin = $_plugin; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API) |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
* |
155
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
156
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
157
|
|
|
* |
158
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
159
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
160
|
|
|
*/ |
161
|
|
|
public function getUsername( $type, $country ) { |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* fetch password, used with invoice or payment plan (i.e. Svea WebService Europe API) |
166
|
|
|
* |
167
|
|
|
* @return string |
168
|
|
|
* |
169
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
170
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
171
|
|
|
* |
172
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
173
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
174
|
|
|
*/ |
175
|
|
|
public function getPassword( $type, $country ) { |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* fetch client number, used with invoice or payment plan (i.e. Svea WebService Europe API) |
180
|
|
|
* |
181
|
|
|
* @return \Svea\WebPay\Config\ClientNumber |
182
|
|
|
* |
183
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
184
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
185
|
|
|
* |
186
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
187
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
188
|
|
|
*/ |
189
|
|
|
public function getClientNumber( $type, $country ) { |
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* fetch merchant id, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
194
|
|
|
* |
195
|
|
|
* @return string |
196
|
|
|
* |
197
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
198
|
|
|
* @param string $country CountryCode eg. SE, NO, DK, FI, NL, DE |
199
|
|
|
*/ |
200
|
|
|
public function getMerchantId( $type, $country ) { |
|
|
|
|
201
|
|
|
return $this->plugin->get_option( 'merchant_key', '' ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* fetch secret word, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
* |
209
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
210
|
|
|
* @param string $country CountryCode eg. SE, NO, DK, FI, NL, DE |
211
|
|
|
*/ |
212
|
|
|
public function getSecret( $type, $country ) { |
|
|
|
|
213
|
|
|
return $this->plugin->get_option( 'merchant_secret', '' ); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Constants for the endpoint url found in the class ConfigurationService.php |
218
|
|
|
* getEndPoint() should return an url corresponding to $type. |
219
|
|
|
* |
220
|
|
|
* @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE |
221
|
|
|
* |
222
|
|
|
* @throws Exception |
223
|
|
|
*/ |
224
|
|
|
public function getEndPoint( $type ) { |
|
|
|
|
225
|
|
|
switch ( strtoupper( $type ) ) { |
226
|
|
|
case "HOSTED": |
|
|
|
|
227
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_URL; |
228
|
|
|
break; |
|
|
|
|
229
|
|
|
case "INVOICE": |
|
|
|
|
230
|
|
|
case "PAYMENTPLAN": |
|
|
|
|
231
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_WS_URL; |
232
|
|
|
break; |
|
|
|
|
233
|
|
|
case "HOSTED_ADMIN": |
|
|
|
|
234
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_HOSTED_ADMIN_URL; |
235
|
|
|
break; |
|
|
|
|
236
|
|
|
case "ADMIN": |
|
|
|
|
237
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_ADMIN_URL; |
238
|
|
|
break; |
|
|
|
|
239
|
|
|
default: |
240
|
|
|
throw new Exception( 'Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED, HOSTED_ADMIN' ); |
241
|
|
|
break; |
|
|
|
|
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* fetch Checkout Merchant id, used for Checkout order type |
247
|
|
|
* |
248
|
|
|
* @return string |
249
|
|
|
*/ |
250
|
|
|
public function getCheckoutMerchantId() { |
|
|
|
|
251
|
|
|
// TODO: Implement getCheckoutMerchantId() method. |
|
|
|
|
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* fetch Checkout Secret word, used for Checkout order type |
256
|
|
|
* |
257
|
|
|
* @return string |
258
|
|
|
*/ |
259
|
|
|
public function getCheckoutSecret() { |
|
|
|
|
260
|
|
|
// TODO: Implement getCheckoutSecret() method. |
|
|
|
|
261
|
|
|
} |
262
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.