@@ -208,54 +208,54 @@ |
||
208 | 208 | |
209 | 209 | foreach ($arr as $key => $val) { |
210 | 210 | switch($key) { |
211 | - case "0": |
|
212 | - case "eid": |
|
213 | - $this->setEid($val); |
|
214 | - break; |
|
215 | - case "1": |
|
216 | - case "id": |
|
217 | - $this->setId($val); |
|
218 | - break; |
|
219 | - case "2": |
|
220 | - case "desc": |
|
221 | - case "description": |
|
222 | - $this->setDescription($val); |
|
223 | - break; |
|
224 | - case "3": |
|
225 | - case "months": |
|
226 | - $this->setMonths($val); |
|
227 | - break; |
|
228 | - case "4": |
|
229 | - case "startfee": |
|
230 | - $this->setStartFee($val); |
|
231 | - break; |
|
232 | - case "5": |
|
233 | - case "invoicefee": |
|
234 | - $this->setInvoiceFee($val); |
|
235 | - break; |
|
236 | - case "6": |
|
237 | - case "interestrate": |
|
238 | - $this->setInterestRate($val); |
|
239 | - break; |
|
240 | - case "7": |
|
241 | - case "minamount": |
|
242 | - $this->setMinAmount($val); |
|
243 | - break; |
|
244 | - case "8": |
|
245 | - case "country": |
|
246 | - $this->setCountry($val); |
|
247 | - break; |
|
248 | - case "9": |
|
249 | - case "type": |
|
250 | - $this->setType($val); |
|
251 | - break; |
|
252 | - case "10": |
|
253 | - case "expire": |
|
254 | - $this->setExpire($val); |
|
255 | - break; |
|
256 | - default: |
|
257 | - //Array index not supported. |
|
258 | - break; |
|
211 | + case "0": |
|
212 | + case "eid": |
|
213 | + $this->setEid($val); |
|
214 | + break; |
|
215 | + case "1": |
|
216 | + case "id": |
|
217 | + $this->setId($val); |
|
218 | + break; |
|
219 | + case "2": |
|
220 | + case "desc": |
|
221 | + case "description": |
|
222 | + $this->setDescription($val); |
|
223 | + break; |
|
224 | + case "3": |
|
225 | + case "months": |
|
226 | + $this->setMonths($val); |
|
227 | + break; |
|
228 | + case "4": |
|
229 | + case "startfee": |
|
230 | + $this->setStartFee($val); |
|
231 | + break; |
|
232 | + case "5": |
|
233 | + case "invoicefee": |
|
234 | + $this->setInvoiceFee($val); |
|
235 | + break; |
|
236 | + case "6": |
|
237 | + case "interestrate": |
|
238 | + $this->setInterestRate($val); |
|
239 | + break; |
|
240 | + case "7": |
|
241 | + case "minamount": |
|
242 | + $this->setMinAmount($val); |
|
243 | + break; |
|
244 | + case "8": |
|
245 | + case "country": |
|
246 | + $this->setCountry($val); |
|
247 | + break; |
|
248 | + case "9": |
|
249 | + case "type": |
|
250 | + $this->setType($val); |
|
251 | + break; |
|
252 | + case "10": |
|
253 | + case "expire": |
|
254 | + $this->setExpire($val); |
|
255 | + break; |
|
256 | + default: |
|
257 | + //Array index not supported. |
|
258 | + break; |
|
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | public static function fromCode($val) |
65 | 65 | { |
66 | 66 | switch(strtolower($val)) { |
67 | - case 'dkk': |
|
68 | - return self::DKK; |
|
69 | - case 'eur': |
|
70 | - case 'euro': |
|
71 | - return self::EUR; |
|
72 | - case 'nok': |
|
73 | - return self::NOK; |
|
74 | - case 'sek': |
|
75 | - return self::SEK; |
|
76 | - default: |
|
77 | - return null; |
|
67 | + case 'dkk': |
|
68 | + return self::DKK; |
|
69 | + case 'eur': |
|
70 | + case 'euro': |
|
71 | + return self::EUR; |
|
72 | + case 'nok': |
|
73 | + return self::NOK; |
|
74 | + case 'sek': |
|
75 | + return self::SEK; |
|
76 | + default: |
|
77 | + return null; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | public static function getCode($val) |
89 | 89 | { |
90 | 90 | switch($val) { |
91 | - case self::DKK: |
|
92 | - return 'dkk'; |
|
93 | - case self::EUR: |
|
94 | - return 'eur'; |
|
95 | - case self::NOK: |
|
96 | - return 'nok'; |
|
97 | - case self::SEK: |
|
98 | - return 'sek'; |
|
99 | - default: |
|
100 | - return null; |
|
91 | + case self::DKK: |
|
92 | + return 'dkk'; |
|
93 | + case self::EUR: |
|
94 | + return 'eur'; |
|
95 | + case self::NOK: |
|
96 | + return 'nok'; |
|
97 | + case self::SEK: |
|
98 | + return 'sek'; |
|
99 | + default: |
|
100 | + return null; |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 |
@@ -436,29 +436,29 @@ discard block |
||
436 | 436 | |
437 | 437 | $type = $pclass->getType(); |
438 | 438 | switch($type) { |
439 | - case KlarnaPClass::CAMPAIGN: |
|
440 | - case KlarnaPClass::ACCOUNT: |
|
441 | - return round( |
|
442 | - self::_aprAnnuity( |
|
443 | - $sum, $pclass->getMonths(), |
|
444 | - $pclass->getInterestRate(), |
|
445 | - $pclass->getInvoiceFee(), |
|
446 | - $minpay |
|
447 | - ), |
|
448 | - 2 |
|
449 | - ); |
|
450 | - case KlarnaPClass::SPECIAL: |
|
451 | - throw new Klarna_PClassException( |
|
452 | - 'Method is not available for SPECIAL pclasses' |
|
453 | - ); |
|
454 | - case KlarnaPClass::FIXED: |
|
455 | - throw new Klarna_PClassException( |
|
456 | - 'Method is not available for FIXED pclasses' |
|
457 | - ); |
|
458 | - default: |
|
459 | - throw new Klarna_PClassException( |
|
460 | - 'Unknown PClass type! ('.$type.')' |
|
461 | - ); |
|
439 | + case KlarnaPClass::CAMPAIGN: |
|
440 | + case KlarnaPClass::ACCOUNT: |
|
441 | + return round( |
|
442 | + self::_aprAnnuity( |
|
443 | + $sum, $pclass->getMonths(), |
|
444 | + $pclass->getInterestRate(), |
|
445 | + $pclass->getInvoiceFee(), |
|
446 | + $minpay |
|
447 | + ), |
|
448 | + 2 |
|
449 | + ); |
|
450 | + case KlarnaPClass::SPECIAL: |
|
451 | + throw new Klarna_PClassException( |
|
452 | + 'Method is not available for SPECIAL pclasses' |
|
453 | + ); |
|
454 | + case KlarnaPClass::FIXED: |
|
455 | + throw new Klarna_PClassException( |
|
456 | + 'Method is not available for FIXED pclasses' |
|
457 | + ); |
|
458 | + default: |
|
459 | + throw new Klarna_PClassException( |
|
460 | + 'Unknown PClass type! ('.$type.')' |
|
461 | + ); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | |
@@ -609,21 +609,21 @@ discard block |
||
609 | 609 | $country = KlarnaCountry::getCode($country); |
610 | 610 | |
611 | 611 | switch (strtoupper($country)) { |
612 | - case "SE": |
|
613 | - return 50.0; |
|
614 | - case "NO": |
|
615 | - return 95.0; |
|
616 | - case "FI": |
|
617 | - return 8.95; |
|
618 | - case "DK": |
|
619 | - return 89.0; |
|
620 | - case "DE": |
|
621 | - case "AT": |
|
622 | - return 6.95; |
|
623 | - case "NL": |
|
624 | - return 5.0; |
|
625 | - default: |
|
626 | - throw new KlarnaException("Invalid country {$country}"); |
|
612 | + case "SE": |
|
613 | + return 50.0; |
|
614 | + case "NO": |
|
615 | + return 95.0; |
|
616 | + case "FI": |
|
617 | + return 8.95; |
|
618 | + case "DK": |
|
619 | + return 89.0; |
|
620 | + case "DE": |
|
621 | + case "AT": |
|
622 | + return 6.95; |
|
623 | + case "NL": |
|
624 | + return 5.0; |
|
625 | + default: |
|
626 | + throw new KlarnaException("Invalid country {$country}"); |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | $multiply = 1; //Round to closest integer |
641 | 641 | $country = KlarnaCountry::getCode($country); |
642 | 642 | switch($country) { |
643 | - case "FI": |
|
644 | - case "DE": |
|
645 | - case "NL": |
|
646 | - case "AT": |
|
647 | - $multiply = 10; //Round to closest decimal |
|
648 | - break; |
|
643 | + case "FI": |
|
644 | + case "DE": |
|
645 | + case "NL": |
|
646 | + case "AT": |
|
647 | + $multiply = 10; //Round to closest decimal |
|
648 | + break; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | return floor(($value*$multiply)+0.5)/$multiply; |
@@ -142,22 +142,22 @@ discard block |
||
142 | 142 | public static function checkLanguage($country, $language) |
143 | 143 | { |
144 | 144 | switch($country) { |
145 | - case KlarnaCountry::AT: |
|
146 | - case KlarnaCountry::DE: |
|
147 | - return ($language === KlarnaLanguage::DE); |
|
148 | - case KlarnaCountry::NL: |
|
149 | - return ($language === KlarnaLanguage::NL); |
|
150 | - case KlarnaCountry::FI: |
|
151 | - return ($language === KlarnaLanguage::FI); |
|
152 | - case KlarnaCountry::DK: |
|
153 | - return ($language === KlarnaLanguage::DA); |
|
154 | - case KlarnaCountry::NO: |
|
155 | - return ($language === KlarnaLanguage::NB); |
|
156 | - case KlarnaCountry::SE: |
|
157 | - return ($language === KlarnaLanguage::SV); |
|
158 | - default: |
|
159 | - //Country not yet supported by Klarna. |
|
160 | - return false; |
|
145 | + case KlarnaCountry::AT: |
|
146 | + case KlarnaCountry::DE: |
|
147 | + return ($language === KlarnaLanguage::DE); |
|
148 | + case KlarnaCountry::NL: |
|
149 | + return ($language === KlarnaLanguage::NL); |
|
150 | + case KlarnaCountry::FI: |
|
151 | + return ($language === KlarnaLanguage::FI); |
|
152 | + case KlarnaCountry::DK: |
|
153 | + return ($language === KlarnaLanguage::DA); |
|
154 | + case KlarnaCountry::NO: |
|
155 | + return ($language === KlarnaLanguage::NB); |
|
156 | + case KlarnaCountry::SE: |
|
157 | + return ($language === KlarnaLanguage::SV); |
|
158 | + default: |
|
159 | + //Country not yet supported by Klarna. |
|
160 | + return false; |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | /** |
@@ -173,20 +173,20 @@ discard block |
||
173 | 173 | public static function checkCurrency($country, $currency) |
174 | 174 | { |
175 | 175 | switch($country) { |
176 | - case KlarnaCountry::AT: |
|
177 | - case KlarnaCountry::DE: |
|
178 | - case KlarnaCountry::NL: |
|
179 | - case KlarnaCountry::FI: |
|
180 | - return ($currency === KlarnaCurrency::EUR); |
|
181 | - case KlarnaCountry::DK: |
|
182 | - return ($currency === KlarnaCurrency::DKK); |
|
183 | - case KlarnaCountry::NO: |
|
184 | - return ($currency === KlarnaCurrency::NOK); |
|
185 | - case KlarnaCountry::SE: |
|
186 | - return ($currency === KlarnaCurrency::SEK); |
|
187 | - default: |
|
188 | - //Country not yet supported by Klarna. |
|
189 | - return false; |
|
176 | + case KlarnaCountry::AT: |
|
177 | + case KlarnaCountry::DE: |
|
178 | + case KlarnaCountry::NL: |
|
179 | + case KlarnaCountry::FI: |
|
180 | + return ($currency === KlarnaCurrency::EUR); |
|
181 | + case KlarnaCountry::DK: |
|
182 | + return ($currency === KlarnaCurrency::DKK); |
|
183 | + case KlarnaCountry::NO: |
|
184 | + return ($currency === KlarnaCurrency::NOK); |
|
185 | + case KlarnaCountry::SE: |
|
186 | + return ($currency === KlarnaCurrency::SEK); |
|
187 | + default: |
|
188 | + //Country not yet supported by Klarna. |
|
189 | + return false; |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | /** |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | public static function getLanguage($country) |
202 | 202 | { |
203 | 203 | switch($country) { |
204 | - case KlarnaCountry::AT: |
|
205 | - case KlarnaCountry::DE: |
|
206 | - return KlarnaLanguage::DE; |
|
207 | - case KlarnaCountry::NL: |
|
208 | - return KlarnaLanguage::NL; |
|
209 | - case KlarnaCountry::FI: |
|
210 | - return KlarnaLanguage::FI; |
|
211 | - case KlarnaCountry::DK: |
|
212 | - return KlarnaLanguage::DA; |
|
213 | - case KlarnaCountry::NO: |
|
214 | - return KlarnaLanguage::NB; |
|
215 | - case KlarnaCountry::SE: |
|
216 | - return KlarnaLanguage::SV; |
|
217 | - default: |
|
218 | - return KlarnaLanguage::EN; |
|
204 | + case KlarnaCountry::AT: |
|
205 | + case KlarnaCountry::DE: |
|
206 | + return KlarnaLanguage::DE; |
|
207 | + case KlarnaCountry::NL: |
|
208 | + return KlarnaLanguage::NL; |
|
209 | + case KlarnaCountry::FI: |
|
210 | + return KlarnaLanguage::FI; |
|
211 | + case KlarnaCountry::DK: |
|
212 | + return KlarnaLanguage::DA; |
|
213 | + case KlarnaCountry::NO: |
|
214 | + return KlarnaLanguage::NB; |
|
215 | + case KlarnaCountry::SE: |
|
216 | + return KlarnaLanguage::SV; |
|
217 | + default: |
|
218 | + return KlarnaLanguage::EN; |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | /** |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | public static function getCurrency($country) |
231 | 231 | { |
232 | 232 | switch($country) { |
233 | - case KlarnaCountry::AT: |
|
234 | - case KlarnaCountry::DE: |
|
235 | - case KlarnaCountry::NL: |
|
236 | - case KlarnaCountry::FI: |
|
237 | - return KlarnaCurrency::EUR; |
|
238 | - case KlarnaCountry::DK: |
|
239 | - return KlarnaCurrency::DKK; |
|
240 | - case KlarnaCountry::NO: |
|
241 | - return KlarnaCurrency::NOK; |
|
242 | - case KlarnaCountry::SE: |
|
243 | - return KlarnaCurrency::SEK; |
|
244 | - default: |
|
245 | - return false; |
|
233 | + case KlarnaCountry::AT: |
|
234 | + case KlarnaCountry::DE: |
|
235 | + case KlarnaCountry::NL: |
|
236 | + case KlarnaCountry::FI: |
|
237 | + return KlarnaCurrency::EUR; |
|
238 | + case KlarnaCountry::DK: |
|
239 | + return KlarnaCurrency::DKK; |
|
240 | + case KlarnaCountry::NO: |
|
241 | + return KlarnaCurrency::NOK; |
|
242 | + case KlarnaCountry::SE: |
|
243 | + return KlarnaCurrency::SEK; |
|
244 | + default: |
|
245 | + return false; |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | public static function get($country) |
115 | 115 | { |
116 | 116 | switch (strtoupper($country)) { |
117 | - case "DE": |
|
118 | - return KlarnaEncoding::PNO_DE; |
|
119 | - case "DK": |
|
120 | - return KlarnaEncoding::PNO_DK; |
|
121 | - case "FI": |
|
122 | - return KlarnaEncoding::PNO_FI; |
|
123 | - case "NL": |
|
124 | - return KlarnaEncoding::PNO_NL; |
|
125 | - case "NO": |
|
126 | - return KlarnaEncoding::PNO_NO; |
|
127 | - case "SE": |
|
128 | - return KlarnaEncoding::PNO_SE; |
|
129 | - case "AT": |
|
130 | - return KlarnaEncoding::PNO_AT; |
|
131 | - default: |
|
132 | - return -1; |
|
117 | + case "DE": |
|
118 | + return KlarnaEncoding::PNO_DE; |
|
119 | + case "DK": |
|
120 | + return KlarnaEncoding::PNO_DK; |
|
121 | + case "FI": |
|
122 | + return KlarnaEncoding::PNO_FI; |
|
123 | + case "NL": |
|
124 | + return KlarnaEncoding::PNO_NL; |
|
125 | + case "NO": |
|
126 | + return KlarnaEncoding::PNO_NO; |
|
127 | + case "SE": |
|
128 | + return KlarnaEncoding::PNO_SE; |
|
129 | + case "AT": |
|
130 | + return KlarnaEncoding::PNO_AT; |
|
131 | + default: |
|
132 | + return -1; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | public static function getRegexp($enc) |
145 | 145 | { |
146 | 146 | switch($enc) { |
147 | - case self::PNO_SE: |
|
148 | - /* |
|
147 | + case self::PNO_SE: |
|
148 | + /* |
|
149 | 149 | * All positions except C contain numbers 0-9. |
150 | 150 | * |
151 | 151 | * PNO: |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | * 16XXXXXX-NNNN |
162 | 162 | * |
163 | 163 | */ |
164 | - return '/^[0-9]{6,6}(([0-9]{2,2}[-\+]{1,1}[0-9]{4,4})|([-\+]'. |
|
165 | - '{1,1}[0-9]{4,4})|([0-9]{4,6}))$/'; |
|
166 | - case self::PNO_NO: |
|
167 | - /* |
|
164 | + return '/^[0-9]{6,6}(([0-9]{2,2}[-\+]{1,1}[0-9]{4,4})|([-\+]'. |
|
165 | + '{1,1}[0-9]{4,4})|([0-9]{4,6}))$/'; |
|
166 | + case self::PNO_NO: |
|
167 | + /* |
|
168 | 168 | * All positions contain numbers 0-9. |
169 | 169 | * |
170 | 170 | * Pno |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * |
179 | 179 | * NNNNNNNNK (orgno) length = 9 |
180 | 180 | */ |
181 | - return '/^[0-9]{6,6}((-[0-9]{5,5})|([0-9]{2,2}((-[0-9]'. |
|
182 | - '{5,5})|([0-9]{1,1})|([0-9]{3,3})|([0-9]{5,5))))$/'; |
|
183 | - case self::PNO_FI: |
|
184 | - /* |
|
181 | + return '/^[0-9]{6,6}((-[0-9]{5,5})|([0-9]{2,2}((-[0-9]'. |
|
182 | + '{5,5})|([0-9]{1,1})|([0-9]{3,3})|([0-9]{5,5))))$/'; |
|
183 | + case self::PNO_FI: |
|
184 | + /* |
|
185 | 185 | * Pno |
186 | 186 | * DDMMYYCIIIT |
187 | 187 | * DDMMYYIIIT |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | * NNNNNNNT |
195 | 195 | * T = 0-9, A-F, H, J, K-N, P, R-Y |
196 | 196 | */ |
197 | - return '/^[0-9]{6,6}(([A\+-]{1,1}[0-9]{3,3}[0-9A-FHJK-NPR-Y]'. |
|
198 | - '{1,1})|([0-9]{3,3}[0-9A-FHJK-NPR-Y]{1,1})|([0-9]{1,1}-{0,1}'. |
|
199 | - '[0-9A-FHJK-NPR-Y]{1,1}))$/i'; |
|
200 | - case self::PNO_DK: |
|
201 | - /* |
|
197 | + return '/^[0-9]{6,6}(([A\+-]{1,1}[0-9]{3,3}[0-9A-FHJK-NPR-Y]'. |
|
198 | + '{1,1})|([0-9]{3,3}[0-9A-FHJK-NPR-Y]{1,1})|([0-9]{1,1}-{0,1}'. |
|
199 | + '[0-9A-FHJK-NPR-Y]{1,1}))$/i'; |
|
200 | + case self::PNO_DK: |
|
201 | + /* |
|
202 | 202 | * Pno |
203 | 203 | * DDMMYYNNNG length 10 |
204 | 204 | * G = gender, odd/even for men/women. |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | * Orgno |
207 | 207 | * XXXXXXXX length 8 |
208 | 208 | */ |
209 | - return '/^[0-9]{8,8}([0-9]{2,2})?$/'; |
|
210 | - case self::PNO_NL: |
|
211 | - case self::PNO_DE: |
|
212 | - /** |
|
209 | + return '/^[0-9]{8,8}([0-9]{2,2})?$/'; |
|
210 | + case self::PNO_NL: |
|
211 | + case self::PNO_DE: |
|
212 | + /** |
|
213 | 213 | * Pno |
214 | 214 | * DDMMYYYYG length 9 |
215 | 215 | * DDMMYYYY 8 |
@@ -217,21 +217,21 @@ discard block |
||
217 | 217 | * Orgno |
218 | 218 | * XXXXXXX 7 company org nr |
219 | 219 | */ |
220 | - return '/^[0-9]{7,9}$/'; |
|
221 | - case self::EMAIL: |
|
222 | - /** |
|
220 | + return '/^[0-9]{7,9}$/'; |
|
221 | + case self::EMAIL: |
|
222 | + /** |
|
223 | 223 | * Validates an email. |
224 | 224 | */ |
225 | - return '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]'. |
|
226 | - '+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z0-9-][a-zA-Z0-9-]+)+$/'; |
|
227 | - case self::CELLNO: |
|
228 | - /** |
|
225 | + return '/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]'. |
|
226 | + '+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z0-9-][a-zA-Z0-9-]+)+$/'; |
|
227 | + case self::CELLNO: |
|
228 | + /** |
|
229 | 229 | * Validates a cellno. |
230 | 230 | * @TODO Is this encoding only for Sweden? |
231 | 231 | */ |
232 | - return '/^07[\ \-0-9]{8,13}$/'; |
|
233 | - default: |
|
234 | - throw new Klarna_UnknownEncodingException($enc); |
|
232 | + return '/^07[\ \-0-9]{8,13}$/'; |
|
233 | + default: |
|
234 | + throw new Klarna_UnknownEncodingException($enc); |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | array $options = null |
106 | 106 | ) { |
107 | 107 | switch ($method) { |
108 | - case 'GET': |
|
109 | - case 'POST': |
|
110 | - return $this->handle($method, $resource, $options, array()); |
|
111 | - default: |
|
112 | - throw new InvalidArgumentException( |
|
113 | - "{$method} is not a valid HTTP method" |
|
114 | - ); |
|
108 | + case 'GET': |
|
109 | + case 'POST': |
|
110 | + return $this->handle($method, $resource, $options, array()); |
|
111 | + default: |
|
112 | + throw new InvalidArgumentException( |
|
113 | + "{$method} is not a valid HTTP method" |
|
114 | + ); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -233,44 +233,44 @@ discard block |
||
233 | 233 | |
234 | 234 | $url = $result->getHeader('Location'); |
235 | 235 | switch ($result->getStatus()) { |
236 | - case 301: |
|
237 | - // Update location and fallthrough |
|
238 | - $resource->setLocation($url); |
|
239 | - case 302: |
|
240 | - // Don't fallthrough for other than GET |
|
241 | - if ($result->getRequest()->getMethod() !== 'GET') { |
|
242 | - break; |
|
243 | - } |
|
244 | - case 303: |
|
245 | - // Detect eternal loops |
|
246 | - if (in_array($url, $visited)) { |
|
247 | - throw new Klarna_Checkout_ConnectorException( |
|
248 | - 'Infinite redirect loop detected.', |
|
249 | - -1 |
|
236 | + case 301: |
|
237 | + // Update location and fallthrough |
|
238 | + $resource->setLocation($url); |
|
239 | + case 302: |
|
240 | + // Don't fallthrough for other than GET |
|
241 | + if ($result->getRequest()->getMethod() !== 'GET') { |
|
242 | + break; |
|
243 | + } |
|
244 | + case 303: |
|
245 | + // Detect eternal loops |
|
246 | + if (in_array($url, $visited)) { |
|
247 | + throw new Klarna_Checkout_ConnectorException( |
|
248 | + 'Infinite redirect loop detected.', |
|
249 | + -1 |
|
250 | + ); |
|
251 | + } |
|
252 | + $visited[] = $url; |
|
253 | + // Follow redirect |
|
254 | + return $this->handle( |
|
255 | + 'GET', |
|
256 | + $resource, |
|
257 | + array('url' => $url), |
|
258 | + $visited |
|
250 | 259 | ); |
251 | - } |
|
252 | - $visited[] = $url; |
|
253 | - // Follow redirect |
|
254 | - return $this->handle( |
|
255 | - 'GET', |
|
256 | - $resource, |
|
257 | - array('url' => $url), |
|
258 | - $visited |
|
259 | - ); |
|
260 | - case 201: |
|
261 | - // Update Location |
|
262 | - $resource->setLocation($url); |
|
263 | - break; |
|
264 | - case 200: |
|
265 | - // Update Data on resource |
|
266 | - $json = json_decode($result->getData(), true); |
|
267 | - if ($json === null) { |
|
268 | - throw new Klarna_Checkout_ConnectorException( |
|
269 | - 'Bad format on response content.', |
|
270 | - -2 |
|
271 | - ); |
|
272 | - } |
|
273 | - $resource->parse($json); |
|
260 | + case 201: |
|
261 | + // Update Location |
|
262 | + $resource->setLocation($url); |
|
263 | + break; |
|
264 | + case 200: |
|
265 | + // Update Data on resource |
|
266 | + $json = json_decode($result->getData(), true); |
|
267 | + if ($json === null) { |
|
268 | + throw new Klarna_Checkout_ConnectorException( |
|
269 | + 'Bad format on response content.', |
|
270 | + -2 |
|
271 | + ); |
|
272 | + } |
|
273 | + $resource->parse($json); |
|
274 | 274 | } |
275 | 275 | return $result; |
276 | 276 | } |