1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zaporylie\Vipps\Resource\Payment; |
4
|
|
|
|
5
|
|
|
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy; |
6
|
|
|
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy; |
7
|
|
|
use JMS\Serializer\SerializerBuilder; |
8
|
|
|
use zaporylie\Vipps\Resource\AuthorizedResourceBase; |
9
|
|
|
use zaporylie\Vipps\Resource\RequestIdFactory; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PaymentResourceBase |
13
|
|
|
* |
14
|
|
|
* @package Vipps\Resource\Payment |
15
|
|
|
*/ |
16
|
|
|
abstract class PaymentResourceBase extends AuthorizedResourceBase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function __construct(\zaporylie\Vipps\VippsInterface $vipps, $subscription_key) |
23
|
|
|
{ |
24
|
|
|
parent::__construct($vipps, $subscription_key); |
25
|
|
|
|
26
|
|
|
// Adjust serializer. |
27
|
|
|
$this->serializer = SerializerBuilder::create() |
28
|
|
|
->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy())) |
29
|
|
|
->build(); |
30
|
|
|
|
31
|
|
|
// Content type for all requests must be set. |
32
|
|
|
$this->headers['Content-Type'] = 'application/json'; |
33
|
|
|
|
34
|
|
|
// Client ID must be set in X-App-Id header. |
35
|
|
|
$this->headers['X-App-Id'] = $this->app->getClient()->getClientId(); |
36
|
|
|
|
37
|
|
|
// By default RequestID is different for each Resource object. |
38
|
|
|
$this->headers['X-Request-Id'] = RequestIdFactory::generate(); |
39
|
|
|
|
40
|
|
|
// Timestamp is equal to current DateTime. |
41
|
|
|
$this->headers['X-TimeStamp'] = (new \DateTime())->format(\DateTime::ISO8601); |
42
|
|
|
|
43
|
|
|
// Autodiscover X-Source-Address from env. |
44
|
|
|
$this->headers['X-Source-Address'] = getenv('HTTP_CLIENT_IP') |
45
|
|
|
?:getenv('HTTP_X_FORWARDED_FOR') |
46
|
|
|
?:getenv('HTTP_X_FORWARDED') |
47
|
|
|
?:getenv('HTTP_FORWARDED_FOR') |
48
|
|
|
?:getenv('HTTP_FORWARDED') |
49
|
|
|
?:getenv('REMOTE_ADDR') |
50
|
|
|
?:gethostname(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|