Passed
Push — master ( 1afe3e...d4d981 )
by
unknown
08:48
created

PurchaseRequest::setCancelUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Empatix\OmnipaySwedbank\Messages;
4
5
use Empatix\OmnipaySwedbank\Gateway;
6
use Omnipay\Common\Message\AbstractRequest;
7
use Empatix\OmnipaySwedbank\Messages\Response;
8
9
class PurchaseRequest extends AbstractRequest
10
{
11
    protected $resource = '/psp/creditcard/payments';
12
    protected $productionEndpoint = 'https://api.payex.com';
13
    protected $testEndpoint = 'https://api.externalintegration.payex.com';
14
15
    public function setPassword($value)
16
    {
17
        $this->setParameter('password', $value);
18
    }
19
20
    public function getPassword()
21
    {
22
        return $this->getParameter('password');
23
    }
24
25
    public function setLanguage($value)
26
    {
27
        $this->setParameter('language', $value);
28
    }
29
30
    public function getLanguage()
31
    {
32
        return $this->getParameter('language');
33
    }
34
35
    public function setMetaData($value)
36
    {
37
        $this->setParameter('metadata', $value);
38
    }
39
40
    public function getMetaData()
41
    {
42
        return $this->getParameter('metadata');
43
    }
44
45
    public function setAfterUrl($value)
46
    {
47
        $this->setParameter('afterUrl', $value);
48
    }
49
50
    public function getAfterUrl()
51
    {
52
        return $this->getParameter('afterUrl');
53
    }
54
55
    public function getMerchantId()
56
    {
57
        return $this->getParameter('merchantId');
58
    }
59
60
    public function setVatAmount($value)
61
    {
62
        $this->setParameter('vatAmount', $value);
63
    }
64
65
    public function getVatAmount()
66
    {
67
        return $this->getParameter('vatAmount');
68
    }
69
70
    public function setUserAgent($value)
71
    {
72
        $this->setParameter('userAgent', $value);
73
    }
74
75
    public function getUserAgent()
76
    {
77
        return $this->getParameter('userAgent');
78
    }
79
80
    public function setPayeeId($value)
81
    {
82
        $this->setParameter('payeeId', $value);
83
    }
84
85
    public function getPayeeId()
86
    {
87
        return $this->getParameter('payeeId');
88
    }
89
90
    public function setPayeeReference($value)
91
    {
92
        $this->setParameter('payeeReference', $value);
93
    }
94
95
    public function getPayeeReference()
96
    {
97
        return $this->getParameter('payeeReference');
98
    }
99
100
    public function sendData($data)
101
    {
102
        $result = $this->httpClient->request(
103
            'POST',
104
            $this->getEndpoint() . $this->resource,
105
            [
106
                'Authorization' => 'Bearer ' . $this->getPassword(),
107
                'Content-Type' => 'application/json; charset=utf-8',
108
                'Accept' => 'application/problem+json; q=1.0, application/json; q=0.9',
109
            ],
110
            json_encode($data)
111
        );
112
113
        return $this->response = new Response(
114
            $this,
115
            json_decode($result->getBody()->getContents(), true)
116
        );
117
    }
118
119
    public function getData()
120
    {
121
        return [
122
            'payment' => [
123
                'operation' => 'Purchase',
124
                'intent' => 'AutoCapture',
125
                'currency' => $this->getCurrency(),
126
                'prices' => [
127
                    [
128
                        'type' => 'CreditCard',
129
                        'vatAmount' => $this->getVatAmount(),
130
                        'amount' => $this->getAmountInteger(),
131
                    ]
132
                ],
133
                'language' =>  $this->getLanguage(),
134
                'userAgent' => $this->getUserAgent(),
135
                'description' => $this->getDescription(),
136
                'urls' => [
137
                    'cancelUrl' => $this->getCancelUrl(),
138
                    'completeUrl' => $this->getReturnUrl(),
139
                    'callbackUrl' => $this->getNotifyUrl(),
140
                ],
141
                'payeeInfo' => [
142
                    'payeeId' => $this->getPayeeId(),
143
                    'payeeReference' => $this->getPayeeReference(),
144
                ],
145
                'metadata' => $this->getMetaData(),
146
            ],
147
        ];
148
    }
149
150
    protected function getEndpoint()
151
    {
152
        return $this->getTestMode() ? $this->testEndpoint : $this->productionEndpoint;
153
    }
154
}
155