1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Models\Purchase\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Common\Records\Records; |
6
|
|
|
use ByTIC\Payments\Models\BillingRecord\Traits\RecordTrait as BillingRecord; |
7
|
|
|
use ByTIC\Payments\Models\BillingRecord\Traits\RecordTrait as BillingRecordTrait; |
8
|
|
|
use ByTIC\Payments\Models\Methods\Traits\RecordTrait; |
9
|
|
|
use Exception; |
10
|
|
|
use Omnipay\Common\Message\RequestInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class MethodTrait |
14
|
|
|
* @package ByTIC\Payments\Traits |
15
|
|
|
* |
16
|
|
|
* @property int $id |
17
|
|
|
* @property string $status |
18
|
|
|
* @property string $status_notes |
19
|
|
|
* @property string $received |
20
|
|
|
* @property string $created |
21
|
|
|
* |
22
|
|
|
* @method string getConfirmURL() |
23
|
|
|
* @method string getIpnURL() |
24
|
|
|
* @method Records getManager() |
25
|
|
|
* @method update() |
26
|
|
|
* @method string getClassName() |
27
|
|
|
* @method string getStatus() |
28
|
|
|
*/ |
29
|
|
|
trait IsPurchasableModelTrait |
30
|
|
|
{ |
31
|
|
|
use IsPurchasableTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return RequestInterface |
35
|
|
|
*/ |
36
|
|
|
public function getPurchaseRequest() |
37
|
|
|
{ |
38
|
|
|
return $this->getPaymentGateway()->purchaseFromModel($this); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return bool|\ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits\GatewayTrait|null |
43
|
|
|
*/ |
44
|
|
|
public function getPaymentGateway() |
45
|
|
|
{ |
46
|
|
|
return $this->getPaymentMethod()->getGateway(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return RecordTrait |
51
|
|
|
*/ |
52
|
|
|
abstract public function getPaymentMethod(); |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $note |
56
|
|
|
*/ |
57
|
|
|
public function saveGatewayNote($note) |
58
|
|
|
{ |
59
|
|
|
$this->setGatewayNotes($note); |
60
|
|
|
$this->update(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $note |
65
|
|
|
*/ |
66
|
|
|
public function setGatewayNotes($note) |
67
|
|
|
{ |
68
|
|
|
$this->status_notes = $note; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
* @throws Exception |
74
|
|
|
*/ |
75
|
7 |
|
public function getPurchaseParametersCard() |
76
|
|
|
{ |
77
|
7 |
|
$params = null; |
|
|
|
|
78
|
7 |
|
$billing = $this->getPurchaseBillingRecord(); |
|
|
|
|
79
|
7 |
|
if (!is_object($billing)) { |
80
|
|
|
throw new Exception( |
81
|
|
|
sprintf( |
82
|
|
|
'PurchaseBillingRecord is not an object in [%s]', |
83
|
|
|
$this->getClassName() |
84
|
|
|
) |
85
|
|
|
); |
86
|
|
|
} |
87
|
7 |
|
if (!in_array(BillingRecordTrait::class, class_uses($billing))) { |
88
|
|
|
throw new Exception( |
89
|
|
|
sprintf( |
90
|
|
|
'Billing record in %s must use BillingRecordTrait %s', |
91
|
|
|
$this->getClassName(), |
92
|
|
|
BillingRecordTrait::class |
93
|
|
|
) |
94
|
|
|
); |
95
|
|
|
} |
96
|
7 |
|
$params = []; |
97
|
7 |
|
$params['firstName'] = $billing->getFirstName(); |
98
|
7 |
|
$params['lastName'] = $billing->getLastName(); |
99
|
7 |
|
$params['email'] = $billing->getEmail(); |
100
|
7 |
|
$params['phone'] = $billing->getPurchasePhone(); |
101
|
7 |
|
$params['city'] = $billing->getPurchaseCity(); |
102
|
7 |
|
$params['country'] = $billing->getPurchaseCountry(); |
103
|
|
|
|
104
|
7 |
|
return $params; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return BillingRecord|null |
109
|
|
|
*/ |
110
|
|
|
public function getPurchaseBillingRecord() |
111
|
|
|
{ |
112
|
|
|
return null; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return mixed |
117
|
|
|
*/ |
118
|
|
|
public function getConfirmStatusTitle() |
119
|
|
|
{ |
120
|
|
|
return $this->getManager()->getMessage('confirm.'.$this->getStatus()->getName()); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|