Skip to content

Commit 681c43e

Browse files
committed
add provider type to cashless payment, Fixes #39
1 parent 9d4bfb9 commit 681c43e

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/Models/Receipts/Payments/CardPaymentPayload.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace igorbunov\Checkbox\Models\Receipts\Payments;
44

5+
use Exception;
6+
57
class CardPaymentPayload extends PaymentParent
68
{
79
/** @var int $code */
@@ -17,6 +19,7 @@ class CardPaymentPayload extends PaymentParent
1719
public string $receipt_no;
1820
public string $acquirer_and_seller;
1921
public int $commission;
22+
public string $provider_type;
2023

2124
public function __construct(
2225
string $value,
@@ -30,7 +33,8 @@ public function __construct(
3033
string $payment_system = '',
3134
string $receipt_no = '',
3235
string $acquirer_and_seller = '',
33-
int $commission = 0
36+
int $commission = 0,
37+
string $provider_type = ''
3438
) {
3539
parent::__construct(parent::TYPE_CARD, $value, $label);
3640

@@ -44,5 +48,16 @@ public function __construct(
4448
$this->receipt_no = $receipt_no;
4549
$this->acquirer_and_seller = $acquirer_and_seller;
4650
$this->commission = $commission;
51+
52+
if (!empty($provider_type)) {
53+
if (!ProviderTypeEnum::isCorrectValue($provider_type)) {
54+
throw new Exception(
55+
'Wrong provider type: ' . $provider_type . ', allowed keys: '
56+
. implode(', ', ProviderTypeEnum::getKeys())
57+
);
58+
}
59+
60+
$this->provider_type = $provider_type;
61+
}
4762
}
4863
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace igorbunov\Checkbox\Models\Receipts\Payments;
4+
5+
class ProviderTypeEnum
6+
{
7+
public const TAPXPHONE = "TAPXPHONE";
8+
public const POSCONTROL = "POSCONTROL";
9+
public const TERMINAL = "TERMINAL";
10+
public const ANDROID_PAYLINK = "ANDROID_PAYLINK";
11+
public const DESKTOP_PAYLINK = "DESKTOP_PAYLINK";
12+
13+
/**
14+
* @return array<array-key, string>
15+
*/
16+
public static function getKeys(): array
17+
{
18+
return [
19+
self::TAPXPHONE,
20+
self::POSCONTROL,
21+
self::TERMINAL,
22+
self::ANDROID_PAYLINK,
23+
self::DESKTOP_PAYLINK
24+
];
25+
}
26+
27+
public static function isCorrectValue(string $value): bool
28+
{
29+
return in_array($value, self::getKeys());
30+
}
31+
}

0 commit comments

Comments
 (0)