forked from YetiForceCompany/YetiForcePortal2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payments.php
71 lines (67 loc) · 2.83 KB
/
payments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* File to handle notifications from the payment system.
*
* @copyright YetiForce Sp. z o.o.
* @license YetiForce Public License 4.0 (licenses/LicenseEN.txt or yetiforce.com)
* @author Arkadiusz Adach <[email protected]>
* @author Mariusz Krzaczkowski <[email protected]>
*/
\define('ROOT_DIRECTORY', __DIR__ . DIRECTORY_SEPARATOR . '.');
\define('PUBLIC_DIRECTORY', '');
if (!file_exists(ROOT_DIRECTORY . '/vendor/autoload.php')) {
echo 'Please install dependencies via composer install.';
return;
}
require_once ROOT_DIRECTORY . '/vendor/autoload.php';
set_error_handler(['\\App\\Controller\\Base', 'exceptionErrorHandler']);
session_save_path(ROOT_DIRECTORY . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'session');
session_start();
use App\Log;
Log::init();
try {
$paymentStatusMap = [
\App\Payments\Utilities\TransactionState::STATUS_NEW => 'PLL_CREATED',
\App\Payments\Utilities\TransactionState::STATUS_PROCESSING => 'PLL_CREATED',
\App\Payments\Utilities\TransactionState::STATUS_COMPLETED => 'PLL_PAID',
\App\Payments\Utilities\TransactionState::STATUS_REJECTED => 'PLL_DENIED',
];
$request = new \App\Request($_REQUEST);
$paymentSystem = $request->getByType('paymentSystem', \App\Purifier::ALNUM);
$payments = \App\Payments::getInstance($paymentSystem);
if (!($payments instanceof \App\Payments\PaymentsSystemInterface)) {
throw new \Exception('Wrong payment type.');
}
$transactionState = $payments->requestHandlingFromPaymentsSystem($request->getAllRaw());
if (empty($paymentStatusMap[$transactionState->status])) {
Log::error($transactionState, 'Payments');
throw new \Exception('Unknown status of the transaction.');
}
if ($transactionState->crmOrderId < 1) {
Log::error($transactionState, 'Payments');
throw new \Exception('Incorrect CRM ID value.');
}
Log::info($transactionState, 'Payments');
$api = new \App\Api([
'Content-Type' => 'application/json',
'X-ENCRYPTED' => 1,
'X-API-KEY' => \App\Config::get('paymentApiKey')
], [
'auth' => [\App\Config::get('paymentServerName'), \App\Config::get('paymentServerPass')]
]);
$answerfromApi = $api->call('ReceiveFromPaymentsSystem', [
'ssingleordersid' => $transactionState->crmOrderId,
'paymentsin_status' => $paymentStatusMap[$transactionState->status],
'transaction_id' => $transactionState->transactionId,
'paymentsvalue' => $transactionState->amount,
'payments_original_value' => $transactionState->originalAmount,
'currency_id' => $transactionState->currency,
'payments_original_currency' => $transactionState->originalCurrency,
'paymentstitle' => $transactionState->description,
'payment_system' => $payments->getPicklistValue(),
], 'PUT');
echo $payments->successAnswerForPaymentSystem();
} catch (\Throwable $exception) {
header('HTTP/1.1 400 Bad request');
Log::error($exception->getMessage(), 'Payments');
}