1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* A lightweigt model for contacting Klarna API |
5
|
|
|
* |
6
|
|
|
* @author andre |
7
|
|
|
*/ |
8
|
|
|
class lightConnector { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Connecting method |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $method = null; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* URI part for API calls |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $uri = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Instance of shop configuration |
24
|
|
|
* @var object |
25
|
|
|
*/ |
26
|
|
|
protected $config = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Holds the klarna orderid |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $klarnaOrderId = null; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* TransactionId of an existing order |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $transactionId = null; |
39
|
|
|
|
40
|
|
|
protected $apiUrl = array('live'=>'https://api.klarna.com/','test'=>'https://api.playground.klarna.com/'); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Creates an instance of light connector |
44
|
|
|
* |
45
|
|
|
* @param type $config |
46
|
|
|
* @param type $method |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function __construct($config, $method = null) { |
49
|
|
|
parent::__construct(); |
50
|
|
|
$this->method = $method; |
|
|
|
|
51
|
|
|
$this->config = $config; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Sets method of requesting API |
56
|
|
|
* |
57
|
|
|
* @param string $method |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function setMethod($method) { |
61
|
|
|
$this->method = $method; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Sets klarna order id |
66
|
|
|
* |
67
|
|
|
* @param string $klarnaOrderId |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function setKlarnaOrderId($klarnaOrderId) { |
71
|
|
|
$this->klarnaOrderId = $klarnaOrderId; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Adds transactionId |
76
|
|
|
* |
77
|
|
|
* @param string $transactionId |
78
|
|
|
*/ |
79
|
|
|
public function setTransactionId($transactionId) { |
80
|
|
|
$this->transactionId = $transactionId; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Updates customer addresses |
85
|
|
|
* |
86
|
|
|
* @param array $billingAddress |
87
|
|
|
* @param array $shippingAddress |
|
|
|
|
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function updateCustomerAddress($billingAddress, $shippingAddress = false) { |
|
|
|
|
91
|
|
|
$aAddressParts = array(''); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Performs an API-Call |
96
|
|
|
* |
97
|
|
|
* @param array $data |
98
|
|
|
*/ |
99
|
|
|
protected function setCall($data) { |
100
|
|
|
$testdrive = $this->config->get('testDrive'); |
101
|
|
|
$url = ($testdrive) ? $this->apiUrl['test'] : $this->apiUrl['live']; |
102
|
|
|
|
103
|
|
|
$data = json_encode($data); |
104
|
|
|
$headers = array('Content-Type: application/json'); |
105
|
|
|
$curl = curl_init(); |
106
|
|
|
curl_setopt($curl, CURLOPT_URL, $url); |
107
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
108
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->method); |
109
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
110
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
111
|
|
|
$response = curl_exec($curl); |
|
|
|
|
112
|
|
|
curl_close($curl); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.