1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class EduSveaWebPayBaseConfig implements \Svea\WebPay\Config\ConfigurationProvider { |
4
|
|
|
/** |
5
|
|
|
* @var EDU_SveaWebPay |
6
|
|
|
*/ |
7
|
|
|
public $plugin; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* EduSveaWebPayProductionConfig constructor. |
11
|
|
|
* |
12
|
|
|
* @param EDU_SveaWebPay $_plugin |
13
|
|
|
*/ |
14
|
|
|
public function __construct( $_plugin ) { |
15
|
|
|
$this->plugin = $_plugin; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* fetch username, used with invoice or payment plan (i.e. Svea WebService Europe API) |
20
|
|
|
* |
21
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
22
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
23
|
|
|
* |
24
|
|
|
* @return string |
25
|
|
|
* |
26
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
27
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
28
|
|
|
*/ |
29
|
|
|
public function getUsername( $type, $country ) { |
30
|
|
|
echo 'username'; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* fetch password, used with invoice or payment plan (i.e. Svea WebService Europe API) |
35
|
|
|
* |
36
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
37
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
38
|
|
|
* |
39
|
|
|
* @return string |
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
|
|
|
echo 'password'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* fetch client number, used with invoice or payment plan (i.e. Svea WebService Europe API) |
50
|
|
|
* |
51
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
52
|
|
|
* @param string $country iso3166 alpha-2 CountryCode, eg. SE, NO, DK, FI, NL, DE can be used if needed to match different configuration settings |
53
|
|
|
* |
54
|
|
|
* @return \Svea\WebPay\Config\ClientNumber |
55
|
|
|
* |
56
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidTypeException in case of unsupported $type |
57
|
|
|
* @throws \Svea\WebPay\HostedService\Helper\InvalidCountryException in case of unsupported $country |
58
|
|
|
*/ |
59
|
|
|
public function getClientNumber( $type, $country ) { |
60
|
|
|
echo 'client'; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* fetch merchant id, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
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
|
|
|
* @return string |
70
|
|
|
* |
71
|
|
|
*/ |
72
|
|
|
public function getMerchantId( $type, $country ) { |
73
|
|
|
$merchantId = $this->plugin->get_option( 'merchant_key', '' ); |
74
|
|
|
|
75
|
|
|
return $merchantId; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* fetch secret word, used with card or direct bank payments (i.e. Svea Hosted Web Service API) |
80
|
|
|
* |
81
|
|
|
* @param string $type Svea\WebPay\Config\ConfigurationProvider::INVOICE_TYPE, ::PAYMENTPLAN_TYPE can be used if needed to match different configuration settings |
82
|
|
|
* @param string $country CountryCode eg. SE, NO, DK, FI, NL, DE |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
* |
86
|
|
|
*/ |
87
|
|
|
public function getSecret( $type, $country ) { |
88
|
|
|
$secret = $this->plugin->get_option( 'merchant_secret', '' ); |
89
|
|
|
|
90
|
|
|
return $secret; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Constants for the endpoint url found in the class ConfigurationService.php |
95
|
|
|
* getEndPoint() should return an url corresponding to $type. |
96
|
|
|
* |
97
|
|
|
* @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
* @throws Exception |
101
|
|
|
*/ |
102
|
|
|
|
103
|
|
|
public function getEndPoint( $type ) { /* Defined in subclasses */ |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* fetch Checkout Merchant id, used for Checkout order type |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function getCheckoutMerchantId( $country = null ) { |
112
|
|
|
$merchantId = $this->plugin->get_option( 'merchant_key', '' ); |
113
|
|
|
|
114
|
|
|
return $merchantId; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* fetch Checkout Secret word, used for Checkout order type |
119
|
|
|
* |
120
|
|
|
* @return string |
121
|
|
|
*/ |
122
|
|
|
public function getCheckoutSecret( $country = null ) { |
123
|
|
|
$secret = $this->plugin->get_option( 'merchant_secret', '' ); |
124
|
|
|
|
125
|
|
|
return $secret; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getIntegrationCompany() { |
129
|
|
|
return 'MultiNet Interactive AB : EduAdmin WordPress-plugin'; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getIntegrationPlatform() { |
133
|
|
|
return 'EduAdmin WordPress'; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
View Code Duplication |
class EduSveaWebPayProductionConfig extends EduSveaWebPayBaseConfig { |
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Constants for the endpoint url found in the class ConfigurationService.php |
141
|
|
|
* getEndPoint() should return an url corresponding to $type. |
142
|
|
|
* |
143
|
|
|
* @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE |
144
|
|
|
* |
145
|
|
|
* @return string |
146
|
|
|
* @throws Exception |
147
|
|
|
*/ |
148
|
|
|
|
149
|
|
|
public function getEndPoint( $type ) { |
150
|
|
|
switch ( strtoupper( $type ) ) { |
151
|
|
|
case 'HOSTED': |
152
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_URL; |
153
|
|
|
break; |
|
|
|
|
154
|
|
|
case 'INVOICE': |
155
|
|
|
case 'PAYMENTPLAN': |
156
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_WS_URL; |
157
|
|
|
break; |
|
|
|
|
158
|
|
|
case 'HOSTED_ADMIN': |
159
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_HOSTED_ADMIN_URL; |
160
|
|
|
break; |
|
|
|
|
161
|
|
|
case 'ADMIN': |
162
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_PROD_ADMIN_URL; |
163
|
|
|
break; |
|
|
|
|
164
|
|
|
case 'CHECKOUT': |
165
|
|
|
return Svea\WebPay\Config\ConfigurationService::CHECKOUT_PROD_BASE_URL; |
166
|
|
|
break; |
|
|
|
|
167
|
|
|
default: |
168
|
|
|
throw new Exception( 'Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED, HOSTED_ADMIN, CHECKOUT' ); |
169
|
|
|
break; |
|
|
|
|
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
View Code Duplication |
class EduSveaWebPayTestConfig extends EduSveaWebPayBaseConfig { |
|
|
|
|
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Constants for the endpoint url found in the class ConfigurationService.php |
178
|
|
|
* getEndPoint() should return an url corresponding to $type. |
179
|
|
|
* |
180
|
|
|
* @param string $type one of Svea\WebPay\Config\ConfigurationProvider::HOSTED_TYPE, ::INVOICE_TYPE, ::PAYMENTPLAN_TYPE, ::HOSTED_ADMIN_TYPE, ::ADMIN_TYPE |
181
|
|
|
* |
182
|
|
|
* @return string |
183
|
|
|
* @throws Exception |
184
|
|
|
*/ |
185
|
|
|
public function getEndPoint( $type ) { |
186
|
|
|
switch ( strtoupper( $type ) ) { |
187
|
|
|
case 'HOSTED': |
188
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_URL; |
189
|
|
|
break; |
|
|
|
|
190
|
|
|
case 'INVOICE': |
191
|
|
|
case 'PAYMENTPLAN': |
192
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_WS_URL; |
193
|
|
|
break; |
|
|
|
|
194
|
|
|
case 'HOSTED_ADMIN': |
195
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_HOSTED_ADMIN_URL; |
196
|
|
|
break; |
|
|
|
|
197
|
|
|
case 'ADMIN': |
198
|
|
|
return Svea\WebPay\Config\ConfigurationService::SWP_TEST_ADMIN_URL; |
199
|
|
|
break; |
|
|
|
|
200
|
|
|
case 'CHECKOUT': |
201
|
|
|
return Svea\WebPay\Config\ConfigurationService::CHECKOUT_TEST_BASE_URL; |
202
|
|
|
break; |
|
|
|
|
203
|
|
|
default: |
204
|
|
|
throw new Exception( 'Invalid type. Accepted values: INVOICE, PAYMENTPLAN, HOSTED, HOSTED_ADMIN, CHECKOUT' ); |
205
|
|
|
break; |
|
|
|
|
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
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.