A
A
Anton Mashukov2018-09-28 00:59:43
JSON
Anton Mashukov, 2018-09-28 00:59:43

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>

you need to substitute the amount that the client enters into the line "price": {"amount": here the amount}
of the java script
code below is the code in which the phone or mail transfer is already implemented, you also need to add the transfer of the amount in the script.
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; 
        }
    };

Help to pass the sum field data

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
ngicaknnxamexex, 2018-09-28
@ngicaknnxamexex

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; 
        }
    };

Replace it with the piece you indicated above.

A
Anton Mashukov, 2018-09-28
@Anton_Belgorod

This moment

sum = form.sum.value, // THIS PIECE IS ADDED
absolutely 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 question

Ask a Question

731 491 924 answers to any question