Skip to content

Commit 67f2c49

Browse files
author
Ivan Tagil
authored
Merge pull request #17 from Itonomy/feature/CMP-70_paypal-tests
CMP-70 - PayPal Tests
2 parents 4ad90ae + 1269e3b commit 67f2c49

20 files changed

+468
-152
lines changed

Api/Service/PaymentServiceInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
namespace CM\Payments\Api\Service;
1010

1111
use CM\Payments\Client\Api\CMPaymentInterface;
12+
use CM\Payments\Exception\EmptyPaymentIdException;
13+
use Magento\Framework\Exception\NoSuchEntityException;
1214

1315
interface PaymentServiceInterface
1416
{
1517
/**
1618
* @param string $orderId
17-
*
1819
* @return CMPaymentInterface
20+
* @throws NoSuchEntityException
21+
* @throws EmptyPaymentIdException
1922
*/
2023
public function create(string $orderId): CMPaymentInterface;
2124
}

Client/Api/CMPaymentInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public function getId(): string;
2222
*/
2323
public function getStatus(): string;
2424

25+
/**
26+
* @return ?string
27+
*/
28+
public function getRedirectUrl(): ?string;
29+
2530
/**
2631
* @return CMPaymentUrl[]
2732
*/

Client/Api/PaymentInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace CM\Payments\Client\Api;
10+
11+
use CM\Payments\Client\Model\Response\PaymentCreate;
12+
use CM\Payments\Client\Request\PaymentCreateRequest;
13+
use GuzzleHttp\Exception\RequestException;
14+
15+
interface PaymentInterface
16+
{
17+
/**
18+
* @param PaymentCreateRequest $paymentCreateRequest
19+
* @return PaymentCreate
20+
* @throws RequestException
21+
*/
22+
public function create(PaymentCreateRequest $paymentCreateRequest): PaymentCreate;
23+
}

Client/Model/CMPayment.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,39 @@ class CMPayment implements CMPaymentInterface
1616
* @var string
1717
*/
1818
private $id;
19+
1920
/**
2021
* @var string
2122
*/
2223
private $status;
24+
25+
/**
26+
* @var ?string
27+
*/
28+
private $redirectUrl;
29+
2330
/**
24-
* @var CMPaymentInterface[]
31+
* @var CMPaymentUrl[]
2532
*/
2633
private $urls;
2734

2835
/**
29-
* CMPayment constructor.
36+
* CMPayment constructor
37+
*
3038
* @param string $id
3139
* @param string $status
32-
* @param CMPaymentInterface[] $urls
40+
* @param ?string $redirectUrl
41+
* @param CMPaymentUrl[] $urls
3342
*/
34-
public function __construct(string $id, string $status, array $urls = [])
35-
{
43+
public function __construct(
44+
string $id,
45+
string $status,
46+
?string $redirectUrl,
47+
array $urls = []
48+
) {
3649
$this->id = $id;
3750
$this->status = $status;
51+
$this->redirectUrl = $redirectUrl;
3852
$this->urls = $urls;
3953
}
4054

@@ -54,6 +68,14 @@ public function getStatus(): string
5468
return $this->status;
5569
}
5670

71+
/**
72+
* @return ?string
73+
*/
74+
public function getRedirectUrl(): ?string
75+
{
76+
return $this->redirectUrl;
77+
}
78+
5779
/**
5880
* @return CMPaymentUrl[]
5981
*/

Client/Model/CMPaymentUrl.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ class CMPaymentUrl
3434
private $order;
3535

3636
/**
37-
* CMPaymentUrl constructor.
37+
* CMPaymentUrl constructor
38+
*
3839
* @param string $purpose
3940
* @param string $method
4041
* @param string $url
4142
* @param string $order
4243
*/
43-
public function __construct(string $purpose, string $method, string $url, string $order)
44-
{
44+
public function __construct(
45+
string $purpose,
46+
string $method,
47+
string $url,
48+
string $order
49+
) {
4550
$this->purpose = $purpose;
4651
$this->method = $method;
4752
$this->url = $url;

Client/Model/Response/OrderCreate.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See LICENSE.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace CM\Payments\Client\Model\Response;
810

911
class OrderCreate
@@ -12,21 +14,25 @@ class OrderCreate
1214
* @var string|null
1315
*/
1416
private $url;
17+
1518
/**
1619
* @var string|null
1720
*/
1821
private $orderKey;
22+
1923
/**
2024
* @var string|null
2125
*/
2226
private $expiresOn;
2327

2428
/**
25-
* CMOrder constructor.
29+
* OrderCreate constructor
30+
*
2631
* @param array $orderCreate
2732
*/
28-
public function __construct(array $orderCreate)
29-
{
33+
public function __construct(
34+
array $orderCreate
35+
) {
3036
$this->url = $orderCreate['url'] ?? null;
3137
$this->orderKey = $orderCreate['order_key'] ?? null;
3238
$this->expiresOn = $orderCreate['expires_on'] ?? null;

Client/Model/Response/OrderDetail.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,60 @@ class OrderDetail implements OrderDetailInterface
1818
* string
1919
*/
2020
private $orderReference;
21+
2122
/**
2223
* string
2324
*/
2425
private $description;
26+
2527
/**
2628
* int
2729
*/
2830
private $amount;
31+
2932
/**
3033
* string
3134
*/
3235
private $email;
36+
3337
/**
3438
* string
3539
*/
3640
private $language;
41+
3742
/**
3843
* string
3944
*/
4045
private $country;
46+
4147
/**
4248
* string
4349
*/
4450
private $profile;
51+
4552
/**
4653
* string
4754
*/
4855
private $timestamp;
56+
4957
/**
5058
* string
5159
*/
5260
private $expires_on;
61+
5362
/**
5463
* array
5564
*/
5665
private $consideredSafe;
66+
5767
/**
5868
* @var Payment[]
5969
*/
6070
private $payments;
6171

6272
/**
63-
* OrderDetail constructor.
73+
* OrderDetail constructor
74+
*
6475
* @param array $orderDetail
6576
*/
6677
public function __construct(
@@ -69,9 +80,7 @@ public function __construct(
6980
$this->orderReference = $orderDetail['order_reference'];
7081
$this->description = $orderDetail['description'];
7182
$this->amount = $orderDetail['amount'];
72-
;
7383
$this->email = $orderDetail['email'];
74-
;
7584
$this->language = $orderDetail['language'];
7685
$this->country = $orderDetail['country'];
7786
$this->profile = $orderDetail['profile'];
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace CM\Payments\Client\Model\Response;
10+
11+
use CM\Payments\Client\Model\CMPaymentUrl;
12+
13+
class PaymentCreate
14+
{
15+
/**
16+
* @var string|null
17+
*/
18+
private $id;
19+
20+
/**
21+
* @var string|null
22+
*/
23+
private $status;
24+
25+
/**
26+
* @var CMPaymentUrl[]
27+
*/
28+
private $urls;
29+
30+
/**
31+
* PaymentCreate constructor
32+
*
33+
* @param array $paymentCreate
34+
*/
35+
public function __construct(
36+
array $paymentCreate
37+
) {
38+
$this->id = $paymentCreate['id'] ?? null;
39+
$this->status = $paymentCreate['status'] ?? null;
40+
if (!empty($paymentCreate['urls'])) {
41+
foreach ($paymentCreate['urls'] as $url) {
42+
$this->urls[] = new CMPaymentUrl(
43+
(string)$url['purpose'],
44+
(string)$url['method'],
45+
(string)$url['url'],
46+
(string)$url['order']
47+
);
48+
}
49+
} else {
50+
$this->urls = [];
51+
}
52+
}
53+
54+
/**
55+
* @return string|null
56+
*/
57+
public function getId(): ?string
58+
{
59+
return $this->id;
60+
}
61+
62+
/**
63+
* @return string|null
64+
*/
65+
public function getStatus(): ?string
66+
{
67+
return $this->status;
68+
}
69+
70+
/**
71+
* @return CMPaymentUrl[]
72+
*/
73+
public function getUrls(): array
74+
{
75+
return $this->urls;
76+
}
77+
78+
/**
79+
* @return string|null
80+
*/
81+
public function getRedirectUrl(): ?string
82+
{
83+
/** @var CMPaymentUrl $paymentUrl */
84+
foreach ($this->urls as $paymentUrl) {
85+
if ($paymentUrl->getPurpose() === CMPaymentUrl::PURPOSE_REDIRECT) {
86+
return $paymentUrl->getUrl();
87+
}
88+
}
89+
90+
return null;
91+
}
92+
}

Client/Payment.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © CM.com. All rights reserved.
4+
* See LICENSE.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace CM\Payments\Client;
10+
11+
use CM\Payments\Client\Api\ApiClientInterface;
12+
use CM\Payments\Client\Api\PaymentInterface;
13+
use CM\Payments\Client\Model\Response\PaymentCreate;
14+
use CM\Payments\Client\Request\PaymentCreateRequest;
15+
16+
class Payment implements PaymentInterface
17+
{
18+
/**
19+
* ApiClientInterface
20+
*/
21+
private $apiClient;
22+
23+
/**
24+
* Payment constructor
25+
*
26+
* @param ApiClientInterface $apiClient
27+
*/
28+
public function __construct(
29+
ApiClientInterface $apiClient
30+
) {
31+
$this->apiClient = $apiClient;
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function create(PaymentCreateRequest $paymentCreateRequest): PaymentCreate
38+
{
39+
$response = $this->apiClient->execute(
40+
$paymentCreateRequest
41+
);
42+
43+
return new PaymentCreate($response);
44+
}
45+
}

0 commit comments

Comments
 (0)