случайно написал вопрос не в той теме, http://forum.jbzoo.c...v220/?p=103769
#21
Отправлено 28 March 2018 - 10:26
#22
Отправлено 28 March 2018 - 13:00
Вопрос с редиректом решил, оказалось что кнопка должна быть name=create-pay а не просто create. Не знаю почему у меня не появилась нужная кнопка, скорее всего я ее как то удалил, сайт делался год назад и тогда оплаты не надо было.
#23
Отправлено 29 March 2018 - 06:42
Народ подскажите дураку, у меня опять затуп...
Почему то возврат в callback сопровождается ошибкой в функции инициализации. Выдает ошибку Undefined Order: Variable name with order ID was not found в логах и при возврате в магазин выдает сообщение 500 Internal Server Error из проверки JDEBUG. При этом заказ создается и в логах элемента все данные есть
if (!JDEBUG) {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
jexit('500 Internal Server Error');
}
29-03-18 - 05:март --- $debug 29-03-18 - 05:март --- 0 29-03-18 - 05:март --- idempotenceKey: 29-03-18 - 05:март --- 5abc772f41c857.82540772 29-03-18 - 05:март --- pay_id: 29-03-18 - 05:март --- 224e8aef-000f-5000-a000-1ae24fc91f2b 29-03-18 - 05:март --- $pay_status: 29-03-18 - 05:март --- pending 29-03-18 - 05:март --- $pay_created_at: 29-03-18 - 05:март --- 2018-03-29T05:18:39+00:00 29-03-18 - 05:март --- $payCurrency: 29-03-18 - 05:март --- RUB 29-03-18 - 05:март --- $pay_amount: 29-03-18 - 05:март --- 2925 29-03-18 - 05:март --- $orderAmount: 29-03-18 - 05:март --- 2925 29-03-18 - 05:март --- $orderId: 29-03-18 - 05:март --- 116 29-03-18 - 05:март --- $shopId: 29-03-18 - 05:март --- скрыт 29-03-18 - 05:март --- $secret: 29-03-18 - 05:март --- скрыт 29-03-18 - 05:март --- $return_url: 29-03-18 - 05:март --- https://kozhevatkinprof.ru/index.php?option=com_zoo&controller=payment&task=paymentSuccess&orderId=116 29-03-18 - 05:март --- $pay_redirect_url: 29-03-18 - 05:март --- https://money.yandex.ru/api-pages/v2/payment-confirm/epl?orderId=224e8aef-000f-5000-a000-1ae24fc91f2b
Яндекс ответ в callback присылает в таком виде. Хоть убейте не понимаю как мне работать с этими данными в isValid как получить переменную с этими данными? Подскажите пожалуйста, уже крыша едет от этих API
{
"type": "notification",
"event": "payment.waiting_for_capture",
"object": {
"id": "21740069-000f-50be-b000-0486ffbf45b0",
"status": "waiting_for_capture",
"paid": true,
"amount": {
"value": "2.00",
"currency": "RUB"
},
"created_at": "2017-10-14T10:53:29.072Z",
"metadata": {},
"payment_method": {
"type": "yandex_money",
"id": "731714f2-c6eb-4ae0-aeb6-8162e89c1065",
"saved": false,
"account_number": "410011066000000",
"title": "Yandex.Money wallet 410011066000000"
}
}
}
Функция getRequestOrderId() не получает id через функцию getOrderId(), не могу понять что не так.
public function getRequestOrderId()
{
$ord_id = $this->getOrderId();
$this->logInfo('$RequestOrderId:');
$this->logInfo($ord_id);
return $ord_id;
}
Все запросы отсылаются по 4 раза, здесь совсем непонятно почему...
Сообщение отредактировал Rivermc: 29 March 2018 - 10:30
#24
Отправлено 07 April 2018 - 16:05
Всем добрый день. Модуль яндекс кассы почти готов, принимает оплачивает возвращает, отправляет данные для ФЗ 54 и выгружает csv о оплаченных заказах для интеграции в 1С. Есть одна неприятная проблема, функция getRedirectUrl вызывается 4 раза, что создает в яндексе 4 заказа. Где искать, как поправить? Пришлось частично переписать callback, планирую переписать что бы работал только как отдельный модуль, тогда поделюсь. Но в данный момент есть вот такая беда.
#25
Отправлено 08 April 2018 - 07:03
Надо код смотреть ;-) Присылайте в ЛС, я могу посмотреть.
#26
Отправлено 08 April 2018 - 15:19
Кодом поделюсь, сейчас там много лишнего закоменченого и т д. Вызов несколько раз функции redirecturl общая проблема мой код здесь не причем, в темах про другие системы оплаты присутствует. Где посмотреть откуда она вызывается и почему несколько раз? Очень надо исправить, иначе прям беда беда
#27
Отправлено 08 April 2018 - 16:59
Как хотите. У меня нигде столько раз не вызывалось.
#28
Отправлено 08 April 2018 - 17:32
У меня предположением - что Вы в цикле метод указали - поэтому в цикле он нес-ко раз и отправляет.
JBZoo чат /
Разработка Joomla расширений и т.д.! / Рекомендую хостинг Joomla
Joomla расширение для Яндекс Турбо и Яндекс Дзен - помощь в настройке
#29
Отправлено 08 April 2018 - 19:01
public function getRedirectUrl()
{
require_once JPATH_ROOT .'/vendor/autoload.php';
$debug = $this->isDebug();
//$orderData = $this->getOrderData();
$shopId = $this->config->get('shopid');
$secret = $this->config->get('secret');
$vat_code = $this->config->get('vat_code');
$tax_system_code = $this->config->get('tax_system_code');
$recipient = $this->config->get('recipient');
$order = $this->getOrder();
$orderId = $this->getOrderId();
$return_url = $this->_jbrouter->payment('success') . '&orderId=' . $orderId;
$payCurrency = JString::strtoupper($this->getDefaultCurrency());
$orderAmount = $this->_order->val($this->getOrderSumm(), $order->getCurrency())->convert($payCurrency);
$orderAmount = round($orderAmount->val(), 0);
$orderDesc = $this->getOrderDescription();
//$orderFileds = $order->getFields();
//$shippingName = $order->getShipping()->getName();
$shippingPrice = $order->getShippingPrice()->val();
//$this->logInfo('shippingName ' . $shippingName);
$this->logInfo('shippingPrice ' . $shippingPrice);
$shippingArray = array(
"description" => 'Доставка',
"quantity" => '1',
"amount" => array(
"value" => $shippingPrice,
"currency" => $payCurrency
),
"vat_code" => $vat_code
);
$orderItems = (array)$order->getItems();
//$this->logInfo('Items:' . implode(',', $orderItems));
$i = 0;
foreach ($orderItems as $item) {
$recipientItems = array(
"description" => $item['item_name'],
"quantity" => $item['quantity'],
"amount" => array(
"value" => $item['elements']['_value'],
"currency" => $payCurrency
),
"vat_code" => $vat_code
);
$recip[$i] = $recipientItems;
$i= $i+1;
}
$recip[] = $shippingArray;
$orderRecipientPhone = $order->getFieldElement('91dc265a-6d12-43f1-95c5-53189b161ccd')->data();
$orderRecipientPhone = preg_replace('~\D~','',$orderRecipientPhone['value']);
if ($recipient == 'phone') {
$recipientArray = array(
"phone" => $orderRecipientPhone,
"tax_system_code" => $tax_system_code,
"items" => $recip
);
}
else {
$orderRecipient = $order->getFieldElement('8fa262d6-30b0-4f1b-933f-5314d459463a')->data();
$orderRecipient = $orderRecipient['value'];
$recipientArray = array(
"email" => $orderRecipient['value'],
"tax_system_code" => $tax_system_code,
"items" => $recip
);
}
/*
$this->logInfo('recipientArray description ' . $recipientArray['items'][0]['description']);
$this->logInfo('recipientArray quantity ' . $recipientArray['items'][0]['quantity']);
$this->logInfo('recipientArray vat_code ' . $recipientArray['items'][0]['vat_code']);
$this->logInfo('recipientArray value ' . $recipientArray['items'][0]['amount']['value']);
$this->logInfo('recipientArray currency ' . $recipientArray['items'][0]['amount']['currency']);
$this->logInfo('shippingArray 1 description ' . $recipientArray['items'][1]['description']);
$this->logInfo('shippingArray 1 quantity ' . $recipientArray['items'][1]['quantity']);
$this->logInfo('shippingArray 1 vat_code ' . $recipientArray['items'][1]['vat_code']);
$this->logInfo('shippingArray 1 value ' . $recipientArray['items'][1]['amount']['value']);
$this->logInfo('shippingArray 1 currency ' . $recipientArray['items'][1]['amount']['currency']);
*/
$this->client = new Client();
$this->client->setAuth($shopId, $secret);
$idempotenceKey = uniqid('', true);
$pay = $this->client->createPayment(
array(
'amount' => array(
'value' => $orderAmount,
'currency' => $payCurrency
),
'payment_method_data' => array(
'type' => 'bank_card'
),
//'capture' => 1,
'confirmation' => array(
'type' => 'redirect',
'return_url' => $return_url
),
'metadata' => array(
'orderId' => $orderId,
'recipientPhone' => $orderRecipientPhone
),
'receipt' => $recipientArray
),
$idempotenceKey
);
$pay = json_encode($pay);
$pay = json_decode($pay, true);
$pay_id_d = $pay['id'];
$pay_status = $pay['status'];
$pay_amount = $pay['amount']['value'];
$pay_created_at = $pay['created_at'];
$pay_redirect_url = $pay['confirmation']['confirmation_url'];
$this->logInfo('//-------------------------------------------//');
//$this->logInfo('getRedirectUrl debug' . $debug);
//$this->logInfo('$recipientArrayrecip ' . $recipientArrayrecip);
//$this->logInfo('getRedirectUrl idempotenceKey:' . $idempotenceKey);
$this->logInfo('Описание заказа: ' . $orderDesc);
$this->logInfo('Статус платежа:'. $pay_status);
$this->logInfo('Дата и время создания платежа:' . $pay_created_at);
$this->logInfo('Валюта:' . $payCurrency);
$this->logInfo('Сумма платежа:' . $pay_amount);
$this->logInfo('Сумма корзины:' . $orderAmount);
$this->logInfo('Id заказа:' . $orderId);
$this->logInfo('Получатель чека: ' . $orderRecipient);
//$this->logInfo('getRedirectUrl shopId:' . $shopId);
//$this->logInfo('getRedirectUrl secret:' . $secret);
//$this->logInfo('getRedirectUrl return_url:' . $return_url);
//$this->logInfo('getRedirectUrl pay_redirect_url:' . $pay_redirect_url);
$this->logInfo('//-------------------------------------------//');
return $pay_redirect_url;
}
public function paymentCallback()
{
$j = @file_get_contents('php://input');
$data = json_decode($j, true);
$orderId = $data['object']['metadata']['orderId'];
$this->_init($orderId);
$this->app->jbevent->fire($this->order, 'basket:paymentCallback');
$this->app->jbdoc->rawOutput();
$cart = JBCart::getInstance();
/** @type JBCartElementPayment $payment */
$payment = $this->order->getPayment();
// check payment element
if (!empty($payment)) {
$payment->logInfo('Платеж существует');
$pay_id = $payment->getRequestPayId($data);
$status_pay = $payment->getStatusPay($pay_id);
$amount_pay = $payment->getAmountPay($data);
if ($status_pay == 'waiting_for_capture') {
$payment->logInfo( 'Ожидание подтверждение платежа: ' . $status_pay);
$paymentCapture = $payment->paymentCapture($pay_id, $amount_pay);
$payment->logInfo( 'Подтверждение платежа: ' . $paymentCapture);
if ($paymentCapture == 'succeeded') {
$payment->logInfo( 'Платеж подтвержден ' . $paymentCapture);
$payment->setSuccess();
$this->app->event->dispatcher->notify($this->app->event->create($this->order, 'basket:paymentSuccess'));
$payment->renderResponse();
$itemPay = $payment->getItemPay($data, $paymentCapture);
}
else {
$payment->logInfo( 'Платеж не подтвержден ' . $paymentCapture);
$this->app->event->dispatcher->notify($this->app->event->create($this->order, 'basket:paymentFail'));
$itemPay = $payment->getItemPay($data, $paymentCapture);
}
}
else if ($status_pay == 'succeeded') {
$payment->logInfo( 'Платеж уже подтвержден '. $status_pay);
}
else {
$payment->logInfo( 'Платеж отменен '. $status_pay);
$this->app->event->dispatcher->notify($this->app->event->create($this->order, 'basket:paymentFail'));
$itemPay = $payment->getItemPay($data, $paymentCapture);
}
}
else {
$payment->logInfo('Такого платежа не существует');
}
// payment is exists
if (!$this->_orderInfo->get('type')) {
$payment->logInfo('Undefined payment system');
}
// check payment type
if ($payment->getType() != $this->_orderInfo->get('type')) {
$payment->logInfo('Payment type is not correct');
}
// current status is not completed
if ($payment->getStatus() == $cart->getPaymentSuccess()) {
$payment->logInfo('Payment status is "' . $payment->getStatus()->getCode() . '" already');
}
// check sum
$realSum = $payment->getOrderSumm();
$requestSum = $payment->getRequestOrderSum();
if ($realSum->compare($requestSum, '!=', 2)) {
$payment->logInfo('Not correct amount: ' . $realSum->data(true) . ' != ' . $requestSum->data(true));
}
// check if sum was empty
if ($realSum->compare(0, '<=')) {
$payment->logInfo('Amount less or equal zero: ' . $realSum->data(true));
}
// checking of payment element
if ($payment->isValid()) {
$payment->logInfo( 'isValid good');
} else {
$payment->logInfo('No valid request');
}
}











