Overview
  • Namespace
  • Class

Namespaces

  • Klarna
    • XMLRPC
      • Exception

Interfaces

  • Klarna\XMLRPC\Exception\KlarnaException
 1 <?php
 2 /**
 3  * Copyright 2016 Klarna AB.
 4  *
 5  * Licensed under the Apache License, Version 2.0 (the "License");
 6  * you may not use this file except in compliance with the License.
 7  * You may obtain a copy of the License at
 8  *
 9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 namespace Klarna\XMLRPC;
18 
19 /**
20  * Currency Constants class.
21  */
22 class Currency
23 {
24     /**
25      * Currency constant for Swedish Crowns (SEK).
26      *
27      * @var int
28      */
29     const SEK = 0;
30 
31     /**
32      * Currency constant for Norwegian Crowns (NOK).
33      *
34      * @var int
35      */
36     const NOK = 1;
37 
38     /**
39      * Currency constant for Euro.
40      *
41      * @var int
42      */
43     const EUR = 2;
44 
45     /**
46      * Currency constant for Danish Crowns (DKK).
47      *
48      * @var int
49      */
50     const DKK = 3;
51 
52     /**
53      * Converts a currency code, e.g. 'eur' to the Currency constant.
54      *
55      * @param string $val currency code
56      *
57      * @return int|null
58      */
59     public static function fromCode($val)
60     {
61         switch (strtolower($val)) {
62             case 'dkk':
63                 return self::DKK;
64             case 'eur':
65             case 'euro':
66                 return self::EUR;
67             case 'nok':
68                 return self::NOK;
69             case 'sek':
70                 return self::SEK;
71             default:
72                 return;
73         }
74     }
75 
76     /**
77      * Converts a Currency constant to the respective language code.
78      *
79      * @param int $val Currency constant
80      *
81      * @return string|null
82      */
83     public static function getCode($val)
84     {
85         switch ($val) {
86             case self::DKK:
87                 return 'dkk';
88             case self::EUR:
89                 return 'eur';
90             case self::NOK:
91                 return 'nok';
92             case self::SEK:
93                 return 'sek';
94             default:
95                 return;
96         }
97     }
98 }
99 
API documentation generated by ApiGen