Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
paysysteminner.php
1
<?php
2
3
namespace
Bitrix\Sale\Internals
;
4
5
use
Bitrix\Main\InvalidOperationException
;
6
use Bitrix\Main\Entity\EntityError;
7
use Bitrix\Main\Entity\Result;
8
use
Bitrix\Sale\Provider
;
9
use
Bitrix\Sale\Payment
;
10
use
Bitrix\Sale\Order
;
11
use
Bitrix\Main\Localization\Loc
;
12
use
Bitrix\Sale\PaySystem
;
13
14
Loc::loadMessages
(__FILE__);
15
16
class
PaySystemInner
17
{
18
const
OPERATION_DEBIT
= 0;
//from account
19
const
OPERATION_CREDIT
= 1;
//to account
20
const
OPERATION_RETURN
= 2;
//to account (return)
21
22
const
ACTION_FILE_TEXT
=
'INNER_BUDGET'
;
23
const
CACHE_ID
=
"BITRIX_SALE_INNER_BUDGET_ID"
;
24
const
TTL
= 31536000;
25
31
public
static
function
getId
($useCache =
true
)
32
{
33
$id = 0;
34
$cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
35
$ttl = $useCache ?
self::TTL
: 0;
36
37
if
($cacheManager->read($ttl, self::CACHE_ID))
38
$id = $cacheManager->get(self::CACHE_ID);
39
40
if
(intval($id) <= 0)
41
{
42
$dbRes = PaySystem\Manager::getList(array(
43
'filter'
=> array(
'ACTION_FILE'
=> self::ACTION_FILE_TEXT),
44
'select'
=> array(
'PAY_SYSTEM_ID'
)
45
)
46
);
47
48
if
($res = $dbRes->fetch())
49
{
50
$id = $res[
'PAY_SYSTEM_ID'
];
51
$cacheManager->set(self::CACHE_ID, $id);
52
}
53
}
54
55
return
intval($id);
56
}
57
65
public
static
function
createOperation
(
Order
&$order,
Payment
&$payment, $operation)
66
{
67
$result =
new
Result
();
68
$paymentSum = $payment->
getSum
();
69
70
if
($operation == self::OPERATION_DEBIT)
71
{
72
$userBudget =
UserBudgetPool::getUserBudgetByOrder
($order);
73
74
if
($userBudget >= $paymentSum)
75
{
76
UserBudgetPool::addPoolItem
($order, ( $paymentSum * -1 ),
UserBudgetPool::BUDGET_TYPE_ORDER_PAY
, $payment);
77
// $payment->setField('PAID', 'Y');
78
}
79
else
80
{
81
$result->addError(
new
EntityError
(
Loc::getMessage
(
'ORDER_PS_INNER_ERROR_INSUFFICIENT_MONEY'
)));
82
}
83
}
84
elseif($operation == self::OPERATION_CREDIT)
85
{
86
UserBudgetPool::addPoolItem
($order, ( $paymentSum ),
UserBudgetPool::BUDGET_TYPE_ORDER_UNPAY
, $payment);
87
88
// $payment->setField('PAID', 'N');
89
}
90
elseif($operation == self::OPERATION_RETURN)
91
{
92
$sumPaid = $order->getSumPaid();
93
$sumTrans =
UserBudgetPool::getUserBudgetTransForOrder
($order);
94
$finalSumPaid = $paymentSum + $sumTrans;
95
96
if
($finalSumPaid > 0)
97
{
98
$paymentSum = $paymentSum - $finalSumPaid;
99
}
100
101
// Internals\UserBudgetPool::addPoolItem($order->getUserId(), ( $paymentSum ), UserBudgetPool::BUDGET_TYPE_CANCEL_RETURN, $order, $payment);
102
// $payment->setField('PAID', 'N');
103
$payment->setField(
'IS_RETURN'
,
'Y'
);
104
}
105
else
106
{
107
throw
new
InvalidOperationException
(
'Wrong operation type!'
);
108
}
109
110
return
$result;
111
}
112
116
public
static
function
add
()
117
{
118
$id =
self::getId
(
false
);
119
120
if
($id > 0)
121
return
$id;
122
123
$result = 0;
124
125
$res = PaySystemTable::add(array(
126
'NAME'
=>
Loc::getMessage
(
'ORDER_PS_INNER_NAME'
),
127
'DESCRIPTION'
=>
Loc::getMessage
(
'ORDER_PS_INNER_DESCRIPTION'
),
128
'SORT'
=> 10,
129
'LID'
=>
''
,
130
'CURRENCY'
=>
''
131
));
132
133
if
($res->isSuccess())
134
{
135
$cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
136
$cacheManager->set(self::CACHE_ID, $res->getId());
137
138
$res = PaySystem\Manager::add(array(
139
'PAY_SYSTEM_ID'
=> $res->getId(),
140
'PERSON_TYPE_ID'
=> 0,
141
'NAME'
=>
Loc::getMessage
(
'ORDER_PS_INNER_NAME'
),
142
'ACTION_FILE'
=> self::ACTION_FILE_TEXT
143
)
144
);
145
146
if
($res->isSuccess())
147
$result = $res->getId();
148
}
149
150
return
$result;
151
}
152
}
Bitrix\Main\InvalidOperationException
Definition
exception.php:170
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\ORM\EntityError
Definition
entityerror.php:12
Bitrix\Rest\OAuth\Provider
Definition
provider.php:11
Bitrix\Sale\Helpers\Order
Definition
order.php:10
Bitrix\Sale\Internals\PaySystemInner
Definition
paysysteminner.php:17
Bitrix\Sale\Internals\PaySystemInner\add
static add()
Definition
paysysteminner.php:116
Bitrix\Sale\Internals\PaySystemInner\CACHE_ID
const CACHE_ID
Definition
paysysteminner.php:23
Bitrix\Sale\Internals\PaySystemInner\getId
static getId($useCache=true)
Definition
paysysteminner.php:31
Bitrix\Sale\Internals\PaySystemInner\TTL
const TTL
Definition
paysysteminner.php:24
Bitrix\Sale\Internals\PaySystemInner\OPERATION_RETURN
const OPERATION_RETURN
Definition
paysysteminner.php:20
Bitrix\Sale\Internals\PaySystemInner\OPERATION_CREDIT
const OPERATION_CREDIT
Definition
paysysteminner.php:19
Bitrix\Sale\Internals\PaySystemInner\ACTION_FILE_TEXT
const ACTION_FILE_TEXT
Definition
paysysteminner.php:22
Bitrix\Sale\Internals\PaySystemInner\createOperation
static createOperation(Order &$order, Payment &$payment, $operation)
Definition
paysysteminner.php:65
Bitrix\Sale\Internals\PaySystemInner\OPERATION_DEBIT
const OPERATION_DEBIT
Definition
paysysteminner.php:18
Bitrix\Sale\Internals\UserBudgetPool\BUDGET_TYPE_ORDER_PAY
const BUDGET_TYPE_ORDER_PAY
Definition
userbudgetpool.php:29
Bitrix\Sale\Internals\UserBudgetPool\getUserBudgetByOrder
static getUserBudgetByOrder(Sale\Order $order)
Definition
userbudgetpool.php:293
Bitrix\Sale\Internals\UserBudgetPool\getUserBudgetTransForOrder
static getUserBudgetTransForOrder(Sale\Order $order)
Definition
userbudgetpool.php:244
Bitrix\Sale\Internals\UserBudgetPool\BUDGET_TYPE_ORDER_UNPAY
const BUDGET_TYPE_ORDER_UNPAY
Definition
userbudgetpool.php:24
Bitrix\Sale\Internals\UserBudgetPool\addPoolItem
static addPoolItem(Sale\Order $order, $value, $type, Sale\Payment $payment=null)
Definition
userbudgetpool.php:183
Bitrix\Sale\Payment
Definition
payment.php:19
Bitrix\Sale\Payment\getSum
getSum()
Definition
payment.php:890
Bitrix\Sale\Internals
Definition
accountnumber.php:3
Bitrix\Sale\PaySystem
Definition
applepay.php:3
modules
sale
lib
internals
paysysteminner.php
Создано системой
1.10.0