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 ( f2247a...73fe3f )
by Jakub
04:00
created

Payment::getMerchantSerialNumber()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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
     * Gets merchantSerialNumber value.
36
     *
37
     * @return string
38
     */
39
    public function getMerchantSerialNumber()
40
    {
41
        if (empty($this->merchantSerialNumber)) {
42
            throw new InvalidArgumentException('Missing merchant serial number');
43
        }
44
        return $this->merchantSerialNumber;
45
    }
46
47
    /**
48
     * Payment constructor.
49
     *
50
     * Payments API needs one extra param - merchant serial number.
51
     *
52
     * @param \zaporylie\Vipps\VippsInterface $app
53
     * @param string $subscription_key
54
     * @param $merchant_serial_number
55
     */
56
    public function __construct(VippsInterface $app, $subscription_key, $merchant_serial_number)
57
    {
58
        parent::__construct($app, $subscription_key);
59
        $this->merchantSerialNumber = $merchant_serial_number;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function cancelPayment($order_id, $text)
66
    {
67
        // Build request object from data passed to method.
68
        $request = (new RequestCancelPayment())
69
            ->setMerchantInfo(
70
                (new MerchantInfo())
71
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
72
            )
73
            ->setTransaction(
74
                (new Transaction())
75
                    ->setTransactionText($text)
76
            );
77
        $resource = new CancelPayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
78
        /** @var \zaporylie\Vipps\Model\Payment\ResponseCancelPayment $response */
79
        $response = $resource->call();
80
        return $response;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 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...
87
    {
88
        // Build request object from data passed to method.
89
        $request = (new RequestCapturePayment())
90
            ->setMerchantInfo(
91
                (new MerchantInfo())
92
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
93
            )
94
            ->setTransaction(
95
                (new Transaction())
96
                    ->setTransactionText($text)
97
            );
98
        // If amount is 0 (default) all remaining founds will be captured.
99
        if ($amount !== 0) {
100
            $request->getTransaction()->setAmount($amount);
101
        }
102
        $resource = new CapturePayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
103
        /** @var \zaporylie\Vipps\Model\Payment\ResponseCapturePayment $response */
104
        $response = $resource->call();
105
        return $response;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 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...
112
    {
113
        // Get order status.
114
        // this is GET request so no need to create request object.
115
        $resource = new GetOrderStatus(
116
            $this->app,
117
            $this->getSubscriptionKey(),
118
            $this->getMerchantSerialNumber(),
119
            $order_id
120
        );
121
        /** @var \zaporylie\Vipps\Model\Payment\ResponseGetOrderStatus $response */
122
        $response = $resource->call();
123
        return $response;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129 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...
130
    {
131
        // Get payment details.
132
        // this is GET request so no need to create request object.
133
        $resource = new GetPaymentDetails(
134
            $this->app,
135
            $this->getSubscriptionKey(),
136
            $this->getMerchantSerialNumber(),
137
            $order_id
138
        );
139
        /** @var \zaporylie\Vipps\Model\Payment\ResponseGetPaymentDetails $response */
140
        $response = $resource->call();
141
        return $response;
142
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147
    public function initiatePayment($order_id, $mobile_number, $amount, $text, $callback, $refOrderID = null)
148
    {
149
        // Create Request object based on data passed to this method.
150
        $request = (new RequestInitiatePayment())
151
            ->setCustomerInfo(
152
                (new CustomerInfo())
153
                    ->setMobileNumber($mobile_number)
154
            )
155
            ->setMerchantInfo(
156
                (new MerchantInfo())
157
                    ->setCallBack($callback)
158
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
159
            )
160
            ->setTransaction(
161
                (new Transaction())
162
                    ->setTransactionText($text)
163
                    ->setAmount($amount)
164
                    ->setOrderId($order_id)
165
                    ->setRefOrderId($refOrderID)
166
            );
167
        // Pass request object along with all data required by InitiatePayment
168
        // to make a call.
169
        $resource = new InitiatePayment($this->app, $this->getSubscriptionKey(), $request);
170
        /** @var \zaporylie\Vipps\Model\Payment\ResponseInitiatePayment $response */
171
        $response = $resource->call();
172
        return $response;
173
    }
174
175
    /**
176
     * {@inheritdoc}
177
     */
178 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...
179
    {
180
        // Prepare request object based on data passed to method.
181
        $request = (new RequestRefundPayment())
182
            ->setMerchantInfo(
183
                (new MerchantInfo())
184
                    ->setMerchantSerialNumber($this->getMerchantSerialNumber())
185
            )
186
            ->setTransaction(
187
                (new Transaction())
188
                    ->setTransactionText($text)
189
            );
190
191
        // If amount is 0 all remaining founds will be refunded.
192
        if ($amount !== 0) {
193
            $request->getTransaction()->setAmount($amount);
194
        }
195
        // Create a resource.
196
        $resource = new RefundPayment($this->app, $this->getSubscriptionKey(), $order_id, $request);
197
        /** @var \zaporylie\Vipps\Model\Payment\ResponseRefundPayment $response */
198
        $response = $resource->call();
199
        return $response;
200
    }
201
}
202