forked from klarna/php-xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckoutServiceRequest.php
More file actions
106 lines (96 loc) · 2.39 KB
/
CheckoutServiceRequest.php
File metadata and controls
106 lines (96 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* File containing the class to perform a checkout service call
*
* PHP version 5.3
*
* @category Payment
* @package KlarnaAPI
* @author MINT <ms.modules@klarna.com>
* @copyright 2014 Klarna AB
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
/**
* CheckoutService
*
* @category Payment
* @package KlarnaAPI
* @author MINT <ms.modules@klarna.com>
* @copyright 2014 Klarna AB
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
class CheckoutServiceRequest
{
/**
* @var ArrayAccess
*/
protected $config;
/**
* @var array
*/
protected $params;
/**
* @var string
*/
protected $uri = 'https://api.klarna.com/touchpoint/checkout/';
/**
* @var string
*/
protected $accept = 'application/vnd.klarna.touchpoint-checkout.payment-methods-v1+json';
/**
* Constructor
*
* @param ArrayAccess $config Configuration
* @param array $params Parameters used to build query.
*/
public function __construct($config, $params)
{
$this->config = $config;
$this->params = array_filter($params);
if (isset($config['checkout_service_uri'])) {
$this->uri = $config['checkout_service_uri'];
}
}
/**
* Create a checkout service response
*
* @param int $code HTTP status code
* @param string $body HTTP body
*
* @return CheckoutServiceResponse Checkout service response
*/
public function createResponse($code, $body)
{
return new CheckoutServiceResponse($this, $code, $body);
}
/**
* Get the url associated to this request
*
* @return string URL with query
*/
public function getURL()
{
return $this->uri . '?'. http_build_query($this->params);
}
/**
* Get the headers associated to this request
*
* @return array Array of headers strings
*/
public function getHeaders()
{
$digest = Klarna::digest(
Klarna::colon(
$this->config['eid'],
$this->params['currency'],
$this->config['secret']
)
);
return array(
"Accept: {$this->accept}",
"Authorization: xmlrpc-4.2 {$digest}"
);
}
}