Answer the question
In order to leave comments, you need to log in
Yandex.Checkout generating the script ya_merchant_receip?
Good afternoon! We have Yandex.Cash under 54-FZ.
There is a form in the bark, there are fields sum and customerContact
<form class="needs-validation" action="https://money.yandex.ru/eshop.xml" method="post" onsubmit="formatReceipt(this);return false;">
<input required="" name="shopId" value="<TMPL_var shopId>" type="hidden">
<input required="" name="scid" value="<TMPL_var scid>" type="hidden">
<input required="" name="sum" value="" size="43"><br />
<input required="" name="paymentType" value="AC" type="hidden">
<input required="" name="customerContact" value="" placeholder="Укажите телефон +7NNNxxxXXxx или электронный адрес для получения чека" size="43"><br>
<input name="ym_merchant_receipt" value='{"customerContact": "","taxSystem": 3, "items":[{"quantity": 1, "price": {"amount": 1.00}, "tax": 1,"text": "Услуга предоставления доступа в интернет"}]}' type="hidden"/>
<button type="submit" class="btn btn-outline-success">Произвести оплату</button>
</form>
var validateContact = function(value) {
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/,
phoneReg = /^\+7[0-9]{10,11}/;
isEmail = value.match(emailReg);
isPhone = value.match(phoneReg);
return (isEmail || isPhone);
}
var formatReceipt = function (form) {
var customerContactValue = form.customerContact.value,
receipt = form.ym_merchant_receipt.value,
receiptObject = JSON.parse(receipt);
if(validateContact(customerContactValue)) {
receiptObject.customerContact = customerContactValue;
form.ym_merchant_receipt.value = JSON.stringify(receiptObject);
form.submit();
} else {
alert('Неверно введен данные. Ограничения: только цифры (+792100000000) или адрес электронной почты.')
return false;
}
};
Answer the question
In order to leave comments, you need to log in
Do not take it for rudeness, but you need to leave with such questions on a freelance exchange.
Basically, here is the working code:
var validateContact = function(value) {
var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/,
phoneReg = /^\+7[0-9]{10,11}/;
isEmail = value.match(emailReg);
isPhone = value.match(phoneReg);
return (isEmail || isPhone);
}
var formatReceipt = function (form) {
var customerContactValue = form.customerContact.value,
receipt = form.ym_merchant_receipt.value,
sum = form.sum.value, // ВОТ ЭТОТ КУСОК ДОБАВИЛСЯ
receiptObject = JSON.parse(receipt);
if(validateContact(customerContactValue)) {
receiptObject.customerContact = customerContactValue;
form.ym_merchant_receipt.value = JSON.stringify(receiptObject);
form.submit();
} else {
alert('Неверно введен данные. Ограничения: только цифры (+792100000000) или адрес электронной почты.')
return false;
}
};
This moment
sum = form.sum.value, // THIS PIECE IS ADDEDabsolutely did not solve the problem, the script still does not work!!! The entered amount from the form is not substituted into the required line and is not transmitted by the script. We are waiting for improvements. Help is greatly needed. Freelance yes. But I was already there and I didn’t see more inadequate ones out of the 10 proposed, no one helped, and the amounts are bent like for a spaceship!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question