Skip to content

Commit b64c904

Browse files
authored
Update UmkaOnline.php
1 parent 0d2af98 commit b64c904

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

armax.umkaonline/lib/UmkaOnline.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
use Bitrix\Sale\Cashbox\AdvancePaymentCheck;
2424
use Bitrix\Sale\Cashbox\AdvanceReturnCashCheck;
2525
use Bitrix\Sale\Cashbox\AdvanceReturnCheck;
26+
use Bitrix\Sale\Cashbox\PrepaymentCheck;
27+
use Bitrix\Sale\Cashbox\PrepaymentReturnCheck;
28+
use Bitrix\Sale\Cashbox\PrepaymentReturnCashCheck;
29+
use Bitrix\Sale\Cashbox\FullPrepaymentCheck;
30+
use Bitrix\Sale\Cashbox\FullPrepaymentReturnCheck;
31+
use Bitrix\Sale\Cashbox\FullPrepaymentReturnCashCheck;
2632
use Bitrix\Sale\Cashbox\CreditCheck;
2733
use Bitrix\Sale\Cashbox\CreditReturnCheck;
2834
use Bitrix\Sale\Cashbox\CreditPaymentCheck;
@@ -78,7 +84,6 @@ public function buildCheckQuery(Check $check)
7884

7985
/** @var Main\Type\DateTime $dateTime */
8086
$dateTime = $data['date_create'];
81-
$phone = $this->normalizePhone($data['client_phone']);
8287

8388
$serviceEmail = $this->getValueFromSettings('SERVICE', 'EMAIL');
8489
if (!$serviceEmail)
@@ -93,10 +98,7 @@ public function buildCheckQuery(Check $check)
9398
'callback_url' => $this->getCallbackUrl(),
9499
),
95100
'receipt' => array(
96-
'client' => array(
97-
'email' => $data['client_email'] ?: '',
98-
'phone' => $phone,
99-
),
101+
'client' => array(),
100102
'company' => array(
101103
'email' => $serviceEmail,
102104
'sno' => $this->getValueFromSettings('TAX', 'SNO'),
@@ -109,6 +111,36 @@ public function buildCheckQuery(Check $check)
109111
)
110112
);
111113

114+
$email = $data['client_email'] ?: '';
115+
116+
$phone = \NormalizePhone($data['client_phone']);
117+
if (is_string($phone))
118+
{
119+
if ($phone[0] === '7')
120+
$phone = substr($phone, 1);
121+
}
122+
else
123+
{
124+
$phone = '';
125+
}
126+
127+
$clientInfo = $this->getValueFromSettings('CLIENT', 'INFO');
128+
if ($clientInfo === 'PHONE')
129+
{
130+
$result['receipt']['client'] = ['phone' => $phone];
131+
}
132+
elseif ($clientInfo === 'EMAIL')
133+
{
134+
$result['receipt']['client'] = ['email' => $email];
135+
}
136+
else
137+
{
138+
$result['receipt']['client'] = [
139+
'email' => $email,
140+
'phone' => $phone,
141+
];
142+
}
143+
112144
$paymentTypeMap = $this->getPaymentTypeMap();
113145
foreach ($data['payments'] as $payment)
114146
{
@@ -119,9 +151,9 @@ public function buildCheckQuery(Check $check)
119151
}
120152

121153
$checkTypeMap = $this->getCheckTypeMap();
154+
$paymentObjectMap = $this->getPaymentObjectMap();
122155
foreach ($data['items'] as $i => $item)
123156
{
124-
125157
$vat = $this->getValueFromSettings('VAT', $item['vat']);
126158
if ($vat === null)
127159
$vat = $this->getValueFromSettings('VAT', 'NOT_VAT');
@@ -132,16 +164,31 @@ public function buildCheckQuery(Check $check)
132164
'sum' => (float)$item['sum'],
133165
'quantity' => $item['quantity'],
134166
'payment_method' => $checkTypeMap[$check::getType()],
135-
'payment_object' => 'commodity',
167+
'payment_object' => $paymentObjectMap[$item['payment_object']],
136168
'vat' => array(
137169
'type' => $vat
138170
),
139171
);
140172
}
173+
141174
return $result;
142175
}
143176

144177

178+
/**
179+
* @return array
180+
*/
181+
private function getPaymentObjectMap()
182+
{
183+
return [
184+
Check::PAYMENT_OBJECT_COMMODITY => 'commodity',
185+
Check::PAYMENT_OBJECT_SERVICE => 'service',
186+
Check::PAYMENT_OBJECT_JOB => 'job',
187+
Check::PAYMENT_OBJECT_EXCISE => 'excise',
188+
Check::PAYMENT_OBJECT_PAYMENT => 'payment',
189+
];
190+
}
191+
145192
/**
146193
* @return array
147194
*/
@@ -177,6 +224,12 @@ protected function getCheckTypeMap()
177224
AdvancePaymentCheck::getType() => 'advance',
178225
AdvanceReturnCashCheck::getType() => 'advance',
179226
AdvanceReturnCheck::getType() => 'advance',
227+
PrepaymentCheck::getType() => 'prepayment',
228+
PrepaymentReturnCheck::getType() => 'prepayment',
229+
PrepaymentReturnCashCheck::getType() => 'prepayment',
230+
FullPrepaymentCheck::getType() => 'full_prepayment',
231+
FullPrepaymentReturnCheck::getType() => 'full_prepayment',
232+
FullPrepaymentReturnCashCheck::getType() => 'full_prepayment',
180233
CreditCheck::getType() => 'credit',
181234
CreditReturnCheck::getType() => 'credit',
182235
CreditPaymentCheck::getType() => 'credit_payment',

0 commit comments

Comments
 (0)