Skip to content

Commit c3a7023

Browse files
committed
Add typed properties to Resource handling
1 parent 98b4ece commit c3a7023

26 files changed

+72
-138
lines changed

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ parameters:
44
- src
55
- test
66
ignoreErrors:
7+
# Ignore Call to an undefined static method zaporylie\Vipps\Resource\HttpMethod::POST().
8+
- '#Call to an undefined static method zaporylie\\Vipps\\Resource\\HttpMethod::POST\(\)#'
9+
- '#Call to an undefined static method zaporylie\\Vipps\\Resource\\HttpMethod::PUT\(\)#'
10+
- '#Call to an undefined static method zaporylie\\Vipps\\Resource\\HttpMethod::PATCH\(\)#'
11+
- '#Call to an undefined static method zaporylie\\Vipps\\Resource\\HttpMethod::DELETE\(\)#'
12+
- '#Call to an undefined static method zaporylie\\Vipps\\Resource\\HttpMethod::GET\(\)#'
713

814
includes:
915
- phpstan-baseline.neon

src/Resource/Authorization/GetToken.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class GetToken extends ResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod;
20-
*/
21-
protected $method = HttpMethod::POST;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/accessToken/get';
21+
protected string $path = '/accessToken/get';
2722

2823
/**
2924
* GetToken constructor.
@@ -34,6 +29,7 @@ class GetToken extends ResourceBase
3429
*/
3530
public function __construct(VippsInterface $vipps, $subscription_key, $client_secret)
3631
{
32+
$this->method = HttpMethod::POST();
3733
parent::__construct($vipps, $subscription_key);
3834
// Authorization module requires client_id to be set on "client_id"
3935
// header.

src/Resource/IdempotencyKeyFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class IdempotencyKeyFactory
1515
*
1616
* @return string
1717
*/
18-
public static function generate()
18+
public static function generate(): string
1919
{
2020
return uniqid('', true);
2121
}

src/Resource/Payment/CancelPayment.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class CancelPayment extends PaymentResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod
20-
*/
21-
protected $method = HttpMethod::PUT;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/ecomm/v2/payments/{id}/cancel';
21+
protected string $path = '/ecomm/v2/payments/{id}/cancel';
2722

2823
/**
2924
* InitiatePayment constructor.
@@ -40,6 +35,7 @@ public function __construct(
4035
RequestCancelPayment $requestObject
4136
) {
4237
parent::__construct($vipps, $subscription_key);
38+
$this->method = HttpMethod::PUT();
4339
$this->body = $this
4440
->getSerializer()
4541
->serialize(

src/Resource/Payment/CapturePayment.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class CapturePayment extends PaymentResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod
20-
*/
21-
protected $method = HttpMethod::POST;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/ecomm/v2/payments/{id}/capture';
21+
protected string $path = '/ecomm/v2/payments/{id}/capture';
2722

2823
/**
2924
* InitiatePayment constructor.
@@ -39,6 +34,7 @@ public function __construct(
3934
$order_id,
4035
RequestCapturePayment $requestObject
4136
) {
37+
$this->method = HttpMethod::POST();
4238
parent::__construct($vipps, $subscription_key);
4339
$this->body = $this
4440
->getSerializer()

src/Resource/Payment/GetOrderStatus.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717
class GetOrderStatus extends PaymentResourceBase
1818
{
1919

20-
/**
21-
* @var \zaporylie\Vipps\Resource\HttpMethod
22-
*/
23-
protected $method = HttpMethod::GET;
24-
2520
/**
2621
* @var string
2722
*/
28-
protected $path = '/ecomm/v2/payments/{id}/status';
23+
protected string $path = '/ecomm/v2/payments/{id}/status';
2924

3025
/**
3126
* InitiatePayment constructor.
@@ -36,6 +31,7 @@ class GetOrderStatus extends PaymentResourceBase
3631
*/
3732
public function __construct(VippsInterface $vipps, $subscription_key, $order_id)
3833
{
34+
$this->method = HttpMethod::GET();
3935
parent::__construct($vipps, $subscription_key);
4036
$this->id = $order_id;
4137
}

src/Resource/Payment/GetPaymentDetails.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@
99
class GetPaymentDetails extends PaymentResourceBase
1010
{
1111

12-
/**
13-
* @var \zaporylie\Vipps\Resource\HttpMethod
14-
*/
15-
protected $method = HttpMethod::GET;
16-
1712
/**
1813
* @var string
1914
*/
20-
protected $path = '/ecomm/v2/payments/{id}/details';
15+
protected string $path = '/ecomm/v2/payments/{id}/details';
2116

2217
/**
2318
* InitiatePayment constructor.
@@ -28,6 +23,7 @@ class GetPaymentDetails extends PaymentResourceBase
2823
*/
2924
public function __construct(VippsInterface $vipps, $subscription_key, $order_id)
3025
{
26+
$this->method = HttpMethod::GET();
3127
parent::__construct($vipps, $subscription_key);
3228
$this->id = $order_id;
3329
}

src/Resource/Payment/InitiatePayment.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class InitiatePayment extends PaymentResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod
20-
*/
21-
protected $method = HttpMethod::POST;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/ecomm/v2/payments';
21+
protected string $path = '/ecomm/v2/payments';
2722

2823
/**
2924
* InitiatePayment constructor.
@@ -34,6 +29,7 @@ class InitiatePayment extends PaymentResourceBase
3429
*/
3530
public function __construct(VippsInterface $vipps, $subscription_key, RequestInitiatePayment $requestObject)
3631
{
32+
$this->method = HttpMethod::POST();
3733
parent::__construct($vipps, $subscription_key);
3834
$this->body = $this
3935
->getSerializer()

src/Resource/Payment/RefundPayment.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class RefundPayment extends PaymentResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod
20-
*/
21-
protected $method = HttpMethod::POST;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/ecomm/v2/payments/{id}/refund';
21+
protected string $path = '/ecomm/v2/payments/{id}/refund';
2722

2823
/**
2924
* InitiatePayment constructor.
@@ -39,6 +34,7 @@ public function __construct(
3934
$order_id,
4035
RequestRefundPayment $requestObject
4136
) {
37+
$this->method = HttpMethod::POST();
4238
parent::__construct($vipps, $subscription_key);
4339
$this->body = $this
4440
->getSerializer()

src/Resource/PaymentsInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface PaymentsInterface extends ResourceInterface
2121
* @param string $orderID
2222
* @return $this
2323
*/
24-
public function setOrderID($orderID);
24+
public function setOrderID(string $orderID): self;
2525

2626
/**
2727
* Create new payment.
@@ -36,19 +36,19 @@ public function setOrderID($orderID);
3636
* Callback absolute Url.
3737
* @param string $fallback
3838
* Fallback absolute Url.
39-
* @param null $refOrderID
39+
* @param string|null $refOrderID
4040
* (optional) Reference to previous order.
4141
* @return $this
4242
*/
43-
public function create($mobileNumber, $amount, $text, $callback, $fallback, $refOrderID = null);
43+
public function create(int $mobileNumber, int $amount, string $text, string $callback, string $fallback, string $refOrderID = null): self;
4444

4545
/**
4646
* Cancel payment.
4747
*
4848
* @param string $text
4949
* @return $this
5050
*/
51-
public function cancel($text);
51+
public function cancel(string $text): self;
5252

5353
/**
5454
* Capture payment.
@@ -59,7 +59,7 @@ public function cancel($text);
5959
* (optional) Amount in øre.
6060
* @return $this
6161
*/
62-
public function capture($text, $amount = 0);
62+
public function capture(string $text, int $amount = 0): self;
6363

6464
/**
6565
* Refund payment.
@@ -70,7 +70,7 @@ public function capture($text, $amount = 0);
7070
* (optional) Amount in øre.
7171
* @return $this
7272
*/
73-
public function refund($text, $amount = 0);
73+
public function refund(string $text, int $amount = 0): self;
7474

7575
/**
7676
* Get payment status.

src/Resource/RecurringPayment/CancelCharge.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818
class CancelCharge extends RecurringPaymentResourceBase
1919
{
2020

21-
/**
22-
* @var \zaporylie\Vipps\Resource\HttpMethod
23-
*/
24-
protected $method = HttpMethod::DELETE;
25-
2621
/**
2722
* @var string
2823
*/
29-
protected $path = '/recurring/v2/agreements/{id}/charges/{charge_id}';
24+
protected string $path = '/recurring/v2/agreements/{id}/charges/{charge_id}';
3025

3126
/**
3227
* CancelCharge constructor.
@@ -45,6 +40,7 @@ public function __construct(
4540
$this->id = $agreement_id;
4641
$this->charge_id = $charge_id;
4742
parent::__construct($vipps, $subscription_key);
43+
$this->method = HttpMethod::DELETE();
4844
}
4945

5046
/**

src/Resource/RecurringPayment/CaptureCharge.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818
class CaptureCharge extends RecurringPaymentResourceBase
1919
{
2020

21-
/**
22-
* @var \zaporylie\Vipps\Resource\HttpMethod
23-
*/
24-
protected $method = HttpMethod::POST;
25-
2621
/**
2722
* @var string
2823
*/
29-
protected $path = '/recurring/v2/agreements/{id}/charges/{charge_id}/capture';
24+
protected string $path = '/recurring/v2/agreements/{id}/charges/{charge_id}/capture';
3025

3126
/**
3227
* InitiatePayment constructor.
@@ -47,6 +42,7 @@ public function __construct(
4742
// By default RequestID is different for each Resource object.
4843
$this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate();
4944
parent::__construct($vipps, $subscription_key);
45+
$this->method = HttpMethod::POST();
5046
}
5147

5248
/**

src/Resource/RecurringPayment/CreateAgreement.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
class CreateAgreement extends RecurringPaymentResourceBase
1616
{
1717

18-
/**
19-
* @var \zaporylie\Vipps\Resource\HttpMethod
20-
*/
21-
protected $method = HttpMethod::POST;
22-
2318
/**
2419
* @var string
2520
*/
26-
protected $path = '/recurring/v2/agreements';
21+
protected string $path = '/recurring/v2/agreements';
2722

2823
/**
2924
* InitiatePayment constructor.
@@ -35,6 +30,7 @@ class CreateAgreement extends RecurringPaymentResourceBase
3530
public function __construct(VippsInterface $vipps, $subscription_key, RequestCreateAgreement $requestObject)
3631
{
3732
parent::__construct($vipps, $subscription_key);
33+
$this->method = HttpMethod::POST();
3834
$this->body = $this
3935
->getSerializer()
4036
->serialize(

src/Resource/RecurringPayment/CreateCharge.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717
class CreateCharge extends RecurringPaymentResourceBase
1818
{
1919

20-
/**
21-
* @var \zaporylie\Vipps\Resource\HttpMethod
22-
*/
23-
protected $method = HttpMethod::POST;
24-
2520
/**
2621
* @var string
2722
*/
28-
protected $path = '/recurring/v2/agreements/{id}/charges';
23+
protected string $path = '/recurring/v2/agreements/{id}/charges';
2924

3025
/**
3126
* InitiatePayment constructor.
@@ -45,6 +40,7 @@ public function __construct(
4540
// By default RequestID is different for each Resource object.
4641
$this->headers['Idempotency-Key'] = IdempotencyKeyFactory::generate();
4742
parent::__construct($vipps, $subscription_key);
43+
$this->method = HttpMethod::POST();
4844
$this->body = $this
4945
->getSerializer()
5046
->serialize(

src/Resource/RecurringPayment/GetAgreement.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@
1414
class GetAgreement extends RecurringPaymentResourceBase
1515
{
1616

17-
/**
18-
* @var \zaporylie\Vipps\Resource\HttpMethod
19-
*/
20-
protected $method = HttpMethod::GET;
21-
2217
/**
2318
* @var string
2419
*/
25-
protected $path = '/recurring/v2/agreements/{id}';
20+
protected string $path = '/recurring/v2/agreements/{id}';
2621

2722
/**
2823
* InitiatePayment constructor.

src/Resource/RecurringPayment/GetAgreements.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement;
66
use zaporylie\Vipps\Resource\HttpMethod;
7+
use zaporylie\Vipps\VippsInterface;
78

89
/**
910
* Class GetAgreements
@@ -13,15 +14,10 @@
1314
class GetAgreements extends RecurringPaymentResourceBase
1415
{
1516

16-
/**
17-
* @var \zaporylie\Vipps\Resource\HttpMethod
18-
*/
19-
protected $method = HttpMethod::GET;
20-
2117
/**
2218
* @var string
2319
*/
24-
protected $path = '/recurring/v2/agreements';
20+
protected string $path = '/recurring/v2/agreements';
2521

2622
/**
2723
* @return \zaporylie\Vipps\Model\RecurringPayment\ResponseGetAgreement[]

0 commit comments

Comments
 (0)