Skip to content

Commit

Permalink
Merge pull request #34 from yandex-money/release/v1.2.0
Browse files Browse the repository at this point in the history
Добавлена поддержка отправки второго чека
  • Loading branch information
pavel52rus authored Oct 23, 2019
2 parents aef51e5 + 0372f01 commit 0315ea1
Show file tree
Hide file tree
Showing 81 changed files with 6,149 additions and 647 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v1.2.0 от 23.10.2019
* Добавлена поддержка отправки второго чека

### v1.1.7 от 04.09.2019
* Исправлена ошибка выбора способов оплаты p2p
* Исправлен баг с записью логов по СББОЛ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class=""><?php echo _JSHOP_YM_KASSA_PASSWORD_LABEL; ?></label></div>
</div>
</div>
<?php foreach (\YandexCheckout\Model\PaymentMethodType::getEnabledValues() as $value) : ?>
<?php if ($value != \YandexCheckout\Model\PaymentMethodType::B2B_SBERBANK): ?>
<?php if (!in_array($value, $offPaymentMethods)): ?>
<div class="row with-select">
<div class="span11 offset1">
<div class="span8 offset2">
Expand Down Expand Up @@ -330,21 +330,62 @@ class=""><?php echo $tax; ?>%</label></div>
</div>
</div>

<div class="taxesArea row">
<div class="span11 offset1">
<div class="span8 offset2">
<?= _JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_LABEL ?>
<label>
<input style="vertical-align:middle;margin:-2px 3px 0 0;cursor: pointer" name="pm_params[send_second_receipt]" <?= $params['send_second_receipt'] ? "checked" : "" ?> type="radio" value="1">
<?= _JSHOP_YM_ENABLE ?>
</label>

<label>
<input style="vertical-align:middle;margin:-2px 3px 0 0;cursor: pointer" name="pm_params[send_second_receipt]" <?= $params['send_second_receipt'] ? "" : "checked" ?> type="radio" value="0">
<?= _JSHOP_YM_DISABLE ?>
</label>
</div>
<div class="secondReceiptArea row offset2">
<div class="span8">
<?= _JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_INFO ?>
</div>
<table style="max-width: 700px" class="table table-hover">
<tbody>
<tr>
<td style="border: none">
<?=_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_STATUS_LABEL?>
</td>
<td style="border: none">
<?php
print JHTML::_('select.genericlist', $orders->getAllOrderStatus(),
'pm_params[kassa_second_receipt_status]',
'', 'status_id', 'name',
$params['kassa_second_receipt_status']);
?>
</td>
</tr>
</tbody>
</table>
<p class="help-block">
<?= _JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_HELP_BLOCK ?>
</p>
</div>
</div>
</div>
<div class="row">
<div class="span11 offset1" style="padding-top: 10px;">
<div class="form-group">
<div class="span2"><label class=""><?= _JSHOP_YM_NOTIFICATION_URL_LABEL ?></label></div>
<div class="span8">
<input class="form-control span8 disabled" value="<?php echo escapeValue($notify_url); ?>" disabled><br>
<p class="help-block"><?php echo _JSHOP_YM_NOTIFICATION_URL_HELP_TEXT; ?></p>
<input class="form-control span8 disabled" value="<?= escapeValue($notify_url) ?>" disabled><br>
<p class="help-block"><?= _JSHOP_YM_NOTIFICATION_URL_HELP_TEXT ?></p>
</div>
</div>
</div>
</div>

<div class="row">
<div class="span11 offset1">
<h4><?php echo _JSHOP_YM_COMMON_HEAD; ?></h4>
<h4><?= _JSHOP_YM_COMMON_HEAD ?></h4>
</div>
</div>
<div class="row">
Expand All @@ -355,10 +396,10 @@ class=""><?php echo $tax; ?>%</label></div>
</div>
<div class="span8">
<?php
print JHTML::_('select.genericlist', $orders->getAllOrderStatus(),
'pm_params[kassa_transaction_end_status]',
'class="inputbox transaction-end-status" size="1" data-type="kassa"', 'status_id', 'name',
$params['kassa_transaction_end_status']);
print JHTML::_('select.genericlist', $orders->getAllOrderStatus(),
'pm_params[kassa_transaction_end_status]',
'class="inputbox transaction-end-status" size="1" data-type="kassa"', 'status_id', 'name',
$params['kassa_transaction_end_status']);
?>
</div>
</div>
Expand Down Expand Up @@ -388,9 +429,9 @@ class=""><?php echo $tax; ?>%</label></div>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div style="overflow:scroll;" class="modal-body">
<div style="padding:10px;">
<pre id="logs-list" style="overflow:scroll;"></pre>
<pre id="logs-list"></pre>
</div>
</div>
<div class="modal-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ function yandex_validate_mode(paymode) {
}
});
}

function toggleShowSecondReceipt(isShow)
{
jQuery(function($) {
if (isShow == 1) {
$(".secondReceiptArea").show();
} else {
$(".secondReceiptArea").hide();
}
});
}

function taxes_validate_mode(paymode) {
jQuery(function($) {
if (paymode == 1) {
Expand Down Expand Up @@ -107,6 +119,15 @@ function yaKassaEnableHoldModeChangeHandler() {
});
}
});

jQuery(function ($) {
toggleShowSecondReceipt($("input[name='pm_params[send_second_receipt]']:checked").val());

$("input[name='pm_params[send_second_receipt]']").on('change', function (e) {
toggleShowSecondReceipt($(this).val());
})
});

jQuery('.transaction-end-status').change(function () {
var id = this.dataset.type;
if (document.getElementById(id).checked) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
define('_JSHOP_YM_KASSA_PAYMODE_HEAD', 'Check the preferable scenario of selecting the payment method');
define('_JSHOP_YM_KASSA_PAYMODE_LABEL', 'Select payment method');
define('_JSHOP_YM_KASSA_SEND_RECEIPT_LABEL', 'Transmit details for receipts to Yandex.Checkout (Federal Law 54-FZ)');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_LABEL', 'Второй чек:');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_STATUS_LABEL', 'Формировать второй чек при переходе заказа в статус');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_INFO', 'Два чека нужно формировать, если покупатель вносит предоплату и потом получает товар или услугу. Первый чек — когда деньги поступают вам на счёт, второй — при отгрузке товаров или выполнении услуг.');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_HELP_BLOCK', 'Если в заказе будут позиции с признаками «Полная предоплата» — второй чек отправится автоматически, когда заказ перейдёт в выбранный статус.');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_HISTORY', 'Отправлен второй чек. Сумма %s рублей.');
define('_JSHOP_YM_KASSA_PAYMODE_KASSA', 'On Yandex.Checkout\'s site');
define('_JSHOP_YM_KASSA_PAYMODE_SHOP', 'On the store\'s site');
define('_JSHOP_YM_KASSA_PAYMODE_LINK', '<a href=\'https://tech.yandex.ru/money/doc/payment-solution/payment-form/payment-form-docpage/\' target=\'_blank\'>More about payment scenarios</a>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
define('_JSHOP_YM_KASSA_PAYMODE_HEAD', 'Настройка сценария оплаты');
define('_JSHOP_YM_KASSA_PAYMODE_LABEL', 'Выбор способа оплаты');
define('_JSHOP_YM_KASSA_SEND_RECEIPT_LABEL', 'Отправлять в Яндекс.Кассу данные для чеков (54-ФЗ)');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_LABEL', 'Второй чек:');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_STATUS_LABEL', 'Формировать второй чек при переходе заказа в статус');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_INFO', 'Два чека нужно формировать, если покупатель вносит предоплату и потом получает товар или услугу. Первый чек — когда деньги поступают вам на счёт, второй — при отгрузке товаров или выполнении услуг.');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_HELP_BLOCK', 'Если в заказе будут позиции с признаками «Полная предоплата» — второй чек отправится автоматически, когда заказ перейдёт в выбранный статус.');
define('_JSHOP_YM_KASSA_SEND_SECOND_RECEIPT_HISTORY', 'Отправлен второй чек. Сумма %s рублей.');
define('_JSHOP_YM_DESCRIPTION_TITLE', 'Описание платежа');
define('_JSHOP_YM_DESCRIPTION_DEFAULT_PLACEHOLDER', 'Оплата заказа №%order_id%');
define('_JSHOP_YM_DESCRIPTION_HELP', 'Это описание транзакции, которое пользователь увидит при оплате, а вы — в личном кабинете Яндекс.Кассы. Например, «Оплата заказа №72».<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@
require_once JPATH_ROOT.'/components/com_jshopping/payments/pm_yandex_money_sbbol/SbbolException.php';

if (!defined(_JSHOP_YM_VERSION)) {
define('_JSHOP_YM_VERSION', '1.1.7');
define('_JSHOP_YM_VERSION', '1.2.0');
}


class KassaPaymentMethod
{
private $module;
private $client;
private $shopId;
private $password;
private $defaultTaxRateId;
private $taxRates;
private $sendReceipt;
private $descriptionTemplate;
private $isEnableHoldMode;
private $pmconfigs;
private $defaultPaymentMode;
private $defaultPaymentSubject;
Expand All @@ -52,8 +48,6 @@ public function __construct($module, $pmConfig)
{
$this->pmconfigs = $pmConfig;
$this->module = $module;
$this->shopId = $pmConfig['shop_id'];
$this->password = $pmConfig['shop_password'];
$this->descriptionTemplate = !empty($pmConfig['ya_kassa_description_template'])
? $pmConfig['ya_kassa_description_template']
: _JSHOP_YM_DESCRIPTION_DEFAULT_PLACEHOLDER;
Expand Down Expand Up @@ -87,19 +81,16 @@ public function __construct($module, $pmConfig)
$this->taxRates[$taxRateId] = $value;
}
}

$this->sendReceipt = isset($pmConfig['ya_kassa_send_check']) && $pmConfig['ya_kassa_send_check'] == '1';
$this->isEnableHoldMode = isset($pmConfig['ya_kassa_enable_hold_mode']) && $pmConfig['ya_kassa_enable_hold_mode'] == '1';
}

public function getShopId()
{
return $this->shopId;
return $this->pmconfigs['shop_id'];
}

public function getPassword()
{
return $this->password;
return $this->pmconfigs['shop_password'];
}

/**
Expand All @@ -109,6 +100,7 @@ public function getPassword()
*
* @return null|\YandexCheckout\Request\Payments\CreatePaymentResponse
*
* @throws \Exception
* @since version
*/
public function createPayment($order, $cart, $returnUrl)
Expand Down Expand Up @@ -149,7 +141,7 @@ public function createPayment($order, $cart, $returnUrl)
$builder->setConfirmation($confirmation);

$receipt = null;
if (count($cart->products) && $this->sendReceipt) {
if (count($cart->products) && $this->isSendReceipt()) {
$this->factoryReceipt($builder, $cart->products, $order);
}

Expand All @@ -174,6 +166,13 @@ public function createPayment($order, $cart, $returnUrl)
}


/**
* @param $order
* @param $cart
* @param $returnUrl
* @return \YandexCheckout\Request\Payments\CreatePaymentResponse|null
* @throws \SbbolException
*/
public function createSbbolPayment($order, $cart, $returnUrl)
{
try {
Expand Down Expand Up @@ -361,8 +360,12 @@ public function getClient()
{
if ($this->client === null) {
$this->client = new Client();
$this->client->setAuth($this->shopId, $this->password);
$this->client->setAuth($this->getShopId(), $this->getPassword());
$this->client->setLogger($this->module);
$userAgent = $this->client->getApiClient()->getUserAgent();
$userAgent->setCms('Joomla', \JPlatform::getLongVersion());
$userAgent->setFramework('Joomshopping', \JSFactory::getConfig()->getVersion());
$userAgent->setModule('Y.CMS Joomshopping ', _JSHOP_YM_VERSION);
}

return $this->client;
Expand Down Expand Up @@ -408,7 +411,7 @@ private function createDescription($order)
*/
public function isEnableHoldMode()
{
return $this->isEnableHoldMode;
return isset($this->pmconfigs['ya_kassa_enable_hold_mode']) && $this->pmconfigs['ya_kassa_enable_hold_mode'] == '1';
}

/**
Expand All @@ -430,6 +433,19 @@ private function getCaptureValue($paymentMethod)
*/
public function isSendReceipt()
{
return $this->sendReceipt;
return isset($this->pmconfigs['ya_kassa_send_check']) && $this->pmconfigs['ya_kassa_send_check'] == '1';
}

/**
* @return bool
*/
public function isSendSecondReceipt()
{
return isset($this->pmconfigs['send_second_receipt']) && $this->pmconfigs['send_second_receipt'] == '1';
}

public function getSecondReceiptStatus()
{
return (int)$this->pmconfigs['kassa_second_receipt_status'];
}
}
Loading

0 comments on commit 0315ea1

Please sign in to comment.