1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Model\Callback; |
6
|
|
|
|
7
|
|
|
use Kerox\Messenger\Model\Callback\Payment\PaymentCredential; |
8
|
|
|
use Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo; |
9
|
|
|
use Kerox\Messenger\Model\Common\Address; |
10
|
|
|
|
11
|
|
|
class Payment |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $payload; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Kerox\Messenger\Model\Callback\Payment\RequestedUserInfo |
20
|
|
|
*/ |
21
|
|
|
protected $requestedUserInfo; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \Kerox\Messenger\Model\Callback\Payment\PaymentCredential |
25
|
|
|
*/ |
26
|
|
|
protected $paymentCredential; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $amount; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $shippingOptionId; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Payment constructor. |
40
|
|
|
*/ |
41
|
1 |
|
public function __construct( |
42
|
|
|
string $payload, |
43
|
|
|
RequestedUserInfo $requestedUserInfo, |
44
|
|
|
PaymentCredential $paymentCredential, |
45
|
|
|
array $amount, |
46
|
|
|
string $shippingOptionId |
47
|
|
|
) { |
48
|
1 |
|
$this->payload = $payload; |
49
|
1 |
|
$this->requestedUserInfo = $requestedUserInfo; |
50
|
1 |
|
$this->paymentCredential = $paymentCredential; |
51
|
1 |
|
$this->amount = $amount; |
52
|
1 |
|
$this->shippingOptionId = $shippingOptionId; |
53
|
1 |
|
} |
54
|
|
|
|
55
|
1 |
|
public function getPayload(): string |
56
|
|
|
{ |
57
|
1 |
|
return $this->payload; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function getRequestedUserInfo(): RequestedUserInfo |
61
|
|
|
{ |
62
|
1 |
|
return $this->requestedUserInfo; |
63
|
|
|
} |
64
|
|
|
|
65
|
1 |
|
public function getShippingAddress(): Address |
66
|
|
|
{ |
67
|
1 |
|
return $this->requestedUserInfo->getShippingAddress(); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function getPaymentCredential(): PaymentCredential |
71
|
|
|
{ |
72
|
1 |
|
return $this->paymentCredential; |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
public function getCurrency(): ?string |
76
|
|
|
{ |
77
|
1 |
|
return $this->amount['currency'] ?? null; |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
public function getAmount(): ?string |
81
|
|
|
{ |
82
|
1 |
|
return $this->amount['amount'] ?? null; |
83
|
|
|
} |
84
|
|
|
|
85
|
1 |
|
public function getShippingOptionId(): string |
86
|
|
|
{ |
87
|
1 |
|
return $this->shippingOptionId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \Kerox\Messenger\Model\Callback\Payment |
92
|
|
|
*/ |
93
|
1 |
|
public static function create(array $callbackData): self |
94
|
|
|
{ |
95
|
1 |
|
$requestedUserInfo = RequestedUserInfo::create($callbackData['requested_user_info']); |
96
|
1 |
|
$paymentCredential = PaymentCredential::create($callbackData['payment_credential']); |
97
|
|
|
|
98
|
1 |
|
return new self( |
99
|
1 |
|
$callbackData['payload'], |
100
|
|
|
$requestedUserInfo, |
101
|
|
|
$paymentCredential, |
102
|
1 |
|
$callbackData['amount'], |
103
|
1 |
|
$callbackData['shipping_option_id'] |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|