GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 1.x ( 1b1399...23f55b )
by Jakub
07:08
created

Payment::getPaymentDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace zaporylie\Vipps\Api;
4
5
use zaporylie\Vipps\Exceptions\Api\InvalidArgumentException;
6
use zaporylie\Vipps\Model\Payment\CustomerInfo;
7
use zaporylie\Vipps\Model\Payment\MerchantInfo;
8
use zaporylie\Vipps\Model\Payment\RequestCancelPayment;
9
use zaporylie\Vipps\Model\Payment\RequestCapturePayment;
10
use zaporylie\Vipps\Model\Payment\RequestInitiatePayment;
11
use zaporylie\Vipps\Model\Payment\RequestRefundPayment;
12
use zaporylie\Vipps\Model\Payment\Transaction;
13
use zaporylie\Vipps\Resource\Payment\CancelPayment;
14
use zaporylie\Vipps\Resource\Payment\CapturePayment;
15
use zaporylie\Vipps\Resource\Payment\GetOrderStatus;
16
use zaporylie\Vipps\Resource\Payment\GetPaymentDetails;
17
use zaporylie\Vipps\Resource\Payment\InitiatePayment;
18
use zaporylie\Vipps\Resource\Payment\RefundPayment;
19
use zaporylie\Vipps\VippsInterface;
20
21
/**
22
 * Class Payment
23
 *
24
 * @package Vipps\Api
25
 */
26
class Payment extends ApiBase implements PaymentInterface
27
{
28
29
    /**
30
     * @var string
31
     */
32
    protected $merchantSerialNumber;
33
34
    /**
35
     * @var string
36
     */
37
    protected $customPath;
38
39
    /**
40
     * Gets merchantSerialNumber value.
41
     *
42
     * @return string
43
     */
44
    public function getMerchantSerialNumber()
45
    {
46
        if (empty($this->merchantSerialNumber)) {
47
            throw new InvalidArgumentException('Missing merchant serial number');
48
        }
49
        return $this->merchantSerialNumber;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getCustomPath()
56
    {
57
        return $this->customPath;
58
    }
59
60
    /**
61
     * Payment constructor.
62
     *
63
     * Payments API needs one extra param - merchant serial number.
64
     *
65
     * @param \zaporylie\Vipps\VippsInterface $app
66
     * @param string $subscription_key
67
     * @param $merchant_serial_number
68
     * @param $custom_path
69
     */
70
    public function __construct(
71
        VippsInterface $app,
72
        $subscription_key,
73
        $merchant_serial_number,
74
        $custom_path = 'Ecomm'
75
    ) {
76
        parent::__construct($app, $subscription_key);
77
        $this->merchantSerialNumber = $merchant_serial_number;
78
        $this->customPath = $custom_path;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function cancelPayment($order_id, $text)
85
    {
86
        // Build request object from data passed to method.
87
        $request = (new RequestCancelPayment())
88
            ->setMerchantInfo(
89
                (new MerchantInfo())
90
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
91
            )
92
            ->setTransaction(
93
                (new Transaction())
94
                    ->setTransactionText($text)
95
            );
96
        $resource = new CancelPayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
97
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
98
        /** @var \zaporylie\Vipps\Model\Payment\ResponseCancelPayment $response */
99
        $response = $resource->call();
100
        return $response;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 View Code Duplication
    public function capturePayment($order_id, $text, $amount = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        // Build request object from data passed to method.
109
        $request = (new RequestCapturePayment())
110
            ->setMerchantInfo(
111
                (new MerchantInfo())
112
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
113
            )
114
            ->setTransaction(
115
                (new Transaction())
116
                    ->setTransactionText($text)
117
            );
118
        // If amount is 0 (default) all remaining founds will be captured.
119
        if ($amount !== 0) {
120
            $request->getTransaction()->setAmount($amount);
121
        }
122
        $resource = new CapturePayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
123
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
124
        /** @var \zaporylie\Vipps\Model\Payment\ResponseCapturePayment $response */
125
        $response = $resource->call();
126
        return $response;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 View Code Duplication
    public function getOrderStatus($order_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134
        // Get order status.
135
        // this is GET request so no need to create request object.
136
        $resource = new GetOrderStatus(
137
            $this->app,
138
            $this->getSubscriptionKey(),
139
            $this->getMerchantSerialNumber(),
140
            $order_id
141
        );
142
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
143
        /** @var \zaporylie\Vipps\Model\Payment\ResponseGetOrderStatus $response */
144
        $response = $resource->call();
145
        return $response;
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     */
151 View Code Duplication
    public function getPaymentDetails($order_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        // Get payment details.
154
        // this is GET request so no need to create request object.
155
        $resource = new GetPaymentDetails(
156
            $this->app,
157
            $this->getSubscriptionKey(),
158
            $this->getMerchantSerialNumber(),
159
            $order_id
160
        );
161
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
162
        /** @var \zaporylie\Vipps\Model\Payment\ResponseGetPaymentDetails $response */
163
        $response = $resource->call();
164
        return $response;
165
    }
166
167
    /**
168
     * {@inheritdoc}
169
     */
170
    public function initiatePayment($order_id, $mobile_number, $amount, $text, $callback, $refOrderID = null)
171
    {
172
        // Create Request object based on data passed to this method.
173
        $request = (new RequestInitiatePayment())
174
            ->setCustomerInfo(
175
                (new CustomerInfo())
176
                    ->setMobileNumber($mobile_number)
177
            )
178
            ->setMerchantInfo(
179
                (new MerchantInfo())
180
                    ->setCallBack($callback)
181
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
182
            )
183
            ->setTransaction(
184
                (new Transaction())
185
                    ->setTransactionText($text)
186
                    ->setAmount($amount)
187
                    ->setOrderId($order_id)
188
                    ->setRefOrderId($refOrderID)
189
            );
190
        // Pass request object along with all data required by InitiatePayment
191
        // to make a call.
192
        $resource = new InitiatePayment($this->app, $this->getSubscriptionKey(), $request);
193
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
194
        /** @var \zaporylie\Vipps\Model\Payment\ResponseInitiatePayment $response */
195
        $response = $resource->call();
196
        return $response;
197
    }
198
199
    /**
200
     * {@inheritdoc}
201
     */
202 View Code Duplication
    public function refundPayment($order_id, $text, $amount = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
203
    {
204
        // Prepare request object based on data passed to method.
205
        $request = (new RequestRefundPayment())
206
            ->setMerchantInfo(
207
                (new MerchantInfo())
208
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
209
            )
210
            ->setTransaction(
211
                (new Transaction())
212
                    ->setTransactionText($text)
213
            );
214
215
        // If amount is 0 all remaining founds will be refunded.
216
        if ($amount !== 0) {
217
            $request->getTransaction()->setAmount($amount);
218
        }
219
        // Create a resource.
220
        $resource = new RefundPayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
221
        $resource->setPath(str_replace('Ecomm', $this->customPath, $resource->getPath()));
222
        /** @var \zaporylie\Vipps\Model\Payment\ResponseRefundPayment $response */
223
        $response = $resource->call();
224
        return $response;
225
    }
226
}
227