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 * Encoding class.
21 */
22 class Encoding
23 {
24 /**
25 * PNO/SSN encoding for Sweden.
26 *
27 * @var int
28 */
29 const PNO_SE = 2;
30
31 /**
32 * PNO/SSN encoding for Norway.
33 *
34 * @var int
35 */
36 const PNO_NO = 3;
37
38 /**
39 * PNO/SSN encoding for Finland.
40 *
41 * @var int
42 */
43 const PNO_FI = 4;
44
45 /**
46 * PNO/SSN encoding for Denmark.
47 *
48 * @var int
49 */
50 const PNO_DK = 5;
51
52 /**
53 * PNO/SSN encoding for Germany.
54 *
55 * @var int
56 */
57 const PNO_DE = 6;
58
59 /**
60 * PNO/SSN encoding for Netherlands.
61 *
62 * @var int
63 */
64 const PNO_NL = 7;
65
66 /**
67 * PNO/SSN encoding for Austria.
68 *
69 * @var int
70 */
71 const PNO_AT = 8;
72
73 /**
74 * Encoding constant for customer numbers.
75 *
76 * @see Klarna::setCustomerNo()
77 *
78 * @var int
79 */
80 const CUSTNO = 1000;
81
82 /**
83 * Encoding constant for email address.
84 *
85 * @var int
86 */
87 const EMAIL = 1001;
88
89 /**
90 * Encoding constant for cell numbers.
91 *
92 * @var int
93 */
94 const CELLNO = 1002;
95
96 /**
97 * Encoding constant for bank bic + account number.
98 *
99 * @var int
100 */
101 const BANK_BIC_ACC_NO = 1003;
102
103 /**
104 * Returns the constant for the wanted country.
105 *
106 * @param string $country country
107 *
108 * @return int
109 */
110 public static function get($country)
111 {
112 switch (strtoupper($country)) {
113 case 'DE':
114 return self::PNO_DE;
115 case 'DK':
116 return self::PNO_DK;
117 case 'FI':
118 return self::PNO_FI;
119 case 'NL':
120 return self::PNO_NL;
121 case 'NO':
122 return self::PNO_NO;
123 case 'SE':
124 return self::PNO_SE;
125 case 'AT':
126 return self::PNO_AT;
127 default:
128 return -1;
129 }
130 }
131
132 /**
133 * Checks if the specified PNO is correct according to specified
134 * encoding constant.
135 *
136 * @param string $pno PNO/SSN string.
137 * @param int $enc {@link Encoding PNO/SSN encoding} constant.
138 *
139 * @return bool True if correct.
140 */
141 public static function checkPNO($pno, $enc = null)
142 {
143 return strlen($pno) > 0;
144 }
145 }
146