Skip to content

Commit d345063

Browse files
MartinMystikJonasf3l1x
authored andcommitted
Rucurring payments + payment data fixes
1 parent 54b139b commit d345063

8 files changed

Lines changed: 474 additions & 149 deletions

File tree

src/Entity/AbstractPayment.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Contributte\Comgate\Entity;
4+
5+
use Contributte\Comgate\Entity\Codes\CountryCode;
6+
7+
class AbstractPayment extends AbstractEntity
8+
{
9+
10+
/** @var int */
11+
protected $price;
12+
13+
/** @var string ISO 4217 */
14+
protected $curr;
15+
16+
/** @var string */
17+
protected $label;
18+
19+
/** @var string */
20+
protected $refId;
21+
22+
/** @var string */
23+
protected $email;
24+
25+
/** @var string */
26+
protected $country = CountryCode::ALL;
27+
28+
/** @var string */
29+
protected $account;
30+
31+
/** @var string */
32+
protected $name;
33+
34+
public function getPrice(): int
35+
{
36+
return $this->price;
37+
}
38+
39+
public function getCurr(): string
40+
{
41+
return $this->curr;
42+
}
43+
44+
public function getLabel(): string
45+
{
46+
return $this->label;
47+
}
48+
49+
public function getRefId(): string
50+
{
51+
return $this->refId;
52+
}
53+
54+
public function getEmail(): string
55+
{
56+
return $this->email;
57+
}
58+
59+
public function getCountry(): string
60+
{
61+
return $this->country;
62+
}
63+
64+
public function getAccount(): string
65+
{
66+
return $this->account;
67+
}
68+
69+
public function setAccount(string $account): void
70+
{
71+
$this->account = $account;
72+
}
73+
74+
public function getName(): string
75+
{
76+
return $this->name;
77+
}
78+
79+
public function setName(string $name): void
80+
{
81+
$this->name = $name;
82+
}
83+
84+
/**
85+
* @return mixed[]
86+
*/
87+
public function toArray(): array
88+
{
89+
return [
90+
'price' => $this->price,
91+
'curr' => $this->curr,
92+
'label' => $this->label,
93+
'refId' => $this->refId,
94+
'email' => $this->email,
95+
'country' => $this->country,
96+
'account' => $this->account,
97+
'name' => $this->name,
98+
];
99+
}
100+
101+
}

src/Entity/Codes/PaymentMethodCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ final class PaymentMethodCode
5050

5151
public const PART_TWISTO = 'PART_TWISTO';
5252
public const PART_SKIPPAY = 'PART_SKIPPAY';
53+
5354
}

src/Entity/Payment.php

Lines changed: 12 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,29 @@
88
use Contributte\Comgate\Entity\Codes\LangCode;
99
use Contributte\Comgate\Entity\Codes\PaymentMethodCode;
1010

11-
class Payment extends AbstractEntity
11+
class Payment extends AbstractPayment
1212
{
1313

14-
/** @var int */
15-
private $price;
16-
17-
/** @var string ISO 4217 */
18-
private $curr;
19-
20-
/** @var string */
21-
private $label;
22-
23-
/** @var string */
24-
private $refId;
25-
26-
/** @var string */
27-
private $email;
28-
2914
/** @var string */
3015
private $method = PaymentMethodCode::ALL;
3116

32-
/** @var string */
33-
private $country = CountryCode::ALL;
34-
35-
/** @var string */
36-
private $payerId;
37-
38-
/** @var string */
39-
private $account;
40-
41-
/** @var string */
42-
private $phone;
43-
44-
/** @var string */
45-
private $name;
46-
4717
/** @var string ISO 639-1 */
4818
private $lang = LangCode::CS;
4919

5020
/** @var bool */
51-
private $prepareOnly;
21+
private $prepareOnly = true;
5222

5323
/** @var bool */
54-
private $preauth;
24+
private $preauth = false;
5525

5626
/** @var bool */
57-
private $initRecurring;
27+
private $initRecurring = false;
5828

5929
/** @var bool */
60-
private $verification;
30+
private $verification = false;
6131

6232
/** @var bool */
63-
private $embedded;
64-
65-
/** @var bool */
66-
private $eetReport;
67-
68-
/** @var mixed[] */
69-
private $eetData;
33+
private $embedded = false;
7034

7135
final private function __construct()
7236
{
@@ -91,86 +55,15 @@ public static function of(
9155
$p->method = $method;
9256
$p->country = $country;
9357
$p->lang = $lang;
94-
$p->prepareOnly = true;
9558

9659
return $p;
9760
}
9861

99-
public function getPrice(): int
100-
{
101-
return $this->price;
102-
}
103-
104-
public function getCurr(): string
105-
{
106-
return $this->curr;
107-
}
108-
109-
public function getLabel(): string
110-
{
111-
return $this->label;
112-
}
113-
114-
public function getRefId(): string
115-
{
116-
return $this->refId;
117-
}
118-
119-
public function getEmail(): string
120-
{
121-
return $this->email;
122-
}
123-
12462
public function getMethod(): string
12563
{
12664
return $this->method;
12765
}
12866

129-
public function getCountry(): string
130-
{
131-
return $this->country;
132-
}
133-
134-
public function getPayerId(): string
135-
{
136-
return $this->payerId;
137-
}
138-
139-
public function setPayerId(string $payerId): void
140-
{
141-
$this->payerId = $payerId;
142-
}
143-
144-
public function getAccount(): string
145-
{
146-
return $this->account;
147-
}
148-
149-
public function setAccount(string $account): void
150-
{
151-
$this->account = $account;
152-
}
153-
154-
public function getPhone(): string
155-
{
156-
return $this->phone;
157-
}
158-
159-
public function setPhone(string $phone): void
160-
{
161-
$this->phone = $phone;
162-
}
163-
164-
public function getName(): string
165-
{
166-
return $this->name;
167-
}
168-
169-
public function setName(string $name): void
170-
{
171-
$this->name = $name;
172-
}
173-
17467
public function getLang(): string
17568
{
17669
return $this->lang;
@@ -231,49 +124,20 @@ public function setEmbedded(bool $embedded): void
231124
$this->embedded = $embedded;
232125
}
233126

234-
public function isEetReport(): bool
235-
{
236-
return $this->eetReport;
237-
}
238-
239-
public function setEetReport(bool $eetReport): void
240-
{
241-
$this->eetReport = $eetReport;
242-
}
243-
244-
/**
245-
* @return mixed[]
246-
*/
247-
public function getEetData(): array
248-
{
249-
return $this->eetData;
250-
}
251-
252-
/**
253-
* @param mixed[] $eetData
254-
*/
255-
public function setEetData(array $eetData): void
256-
{
257-
$this->eetData = $eetData;
258-
}
259-
260127
/**
261128
* @return mixed[]
262129
*/
263130
public function toArray(): array
264131
{
265-
return [
266-
'price' => $this->price,
267-
'curr' => $this->curr,
268-
'label' => $this->label,
269-
'refId' => $this->refId,
132+
return array_merge(parent::toArray(), [
270133
'method' => $this->method,
271-
'email' => $this->email,
272-
'prepareOnly' => $this->prepareOnly ? 'true' : 'false',
273-
'country' => $this->country,
274134
'lang' => $this->lang,
135+
'prepareOnly' => $this->prepareOnly ? 'true' : 'false',
136+
'preauth' => $this->preauth ? 'true' : 'false',
137+
'initRecurring' => $this->initRecurring ? 'true' : 'false',
138+
'verification' => $this->verification ? 'true' : 'false',
275139
'embedded' => $this->embedded ? 'true' : 'false',
276-
];
140+
]);
277141
}
278142

279143
}

src/Entity/RecurringPayment.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Contributte\Comgate\Entity;
4+
5+
use Brick\Math\RoundingMode;
6+
use Brick\Money\Money;
7+
use Contributte\Comgate\Entity\Codes\CountryCode;
8+
9+
class RecurringPayment extends AbstractPayment
10+
{
11+
12+
/** @var string */
13+
private $initRecurringId;
14+
15+
final private function __construct()
16+
{
17+
}
18+
19+
public static function of(
20+
string $initRecurringId,
21+
Money $money,
22+
string $label,
23+
string $refId,
24+
string $email,
25+
string $country = CountryCode::ALL,
26+
): self
27+
{
28+
$p = new static();
29+
$p->initRecurringId = $initRecurringId;
30+
$p->price = $money->multipliedBy(100, RoundingMode::UNNECESSARY)->getAmount()->toInt();
31+
$p->curr = $money->getCurrency()->getCurrencyCode();
32+
$p->label = $label;
33+
$p->refId = $refId;
34+
$p->email = $email;
35+
$p->country = $country;
36+
37+
return $p;
38+
}
39+
40+
public function getInitRecurringId(): int
41+
{
42+
return $this->price;
43+
}
44+
45+
/**
46+
* @return mixed[]
47+
*/
48+
public function toArray(): array
49+
{
50+
return array_merge(parent::toArray(), [
51+
'prepareOnly' => 'true',
52+
'initRecurringId' => $this->initRecurringId,
53+
]);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)