Как передать общую сумму товара в платежный шлюз
я создаю сайт электронной коммерции на django. после того, как пользователь нажимает кнопку checkout, появляется html форма выставления счета, которая всплывает и предлагает пользователю ввести адрес, email и т.д.
Я также передал данные, такие как email, и он работал нормально. но когда я пытаюсь ввести сумму, он не проходит
как мне передать сумму в платежный шлюз?
форма Html
мой js скрипт
document.addEventListener("DOMContentLoaded", (event) => {
// Add an event listener for when the user clicks the submit button to pay
document.getElementById("submit").addEventListener("click", (e) => {
e.preventDefault();
const PBFKey = "xxxxxxxxxxxxxxxxxxxxxxxxxx"; // paste in the public key from your dashboard here
const txRef = ''+Math.floor((Math.random() * 1000000000) + 1); //Generate a random id for the transaction reference
const email = document.getElementById('email').value;
var fullname= document.getElementById('fullName').value;
var address1= document.getElementById('custAdd').value;
var address2= document.getElementById('custAdd2').value;
var country= document.getElementById('country').value;
var state= document.getElementById('state').value;
var address1= document.getElementById('postCode').value;
const amount= document.getElementById('{{cart.get_total_price}}').value;
// getpaidSetup is Rave's inline script function. it holds the payment data to pass to Rave.
getpaidSetup({
PBFPubKey: PBFKey,
customer_email: email,
amount:amount*100,
currency: "USD", // Select the currency. leaving it empty defaults to NGN
txref: txRef, // Pass your UNIQUE TRANSACTION REFERENCE HERE.
onclose: function() {},
callback: function(response) {
flw_ref = response.tx.flwRef;// collect flwRef returned and pass to a server page to complete status check.
console.log("This is the response returned after a charge", response);
if(response.tx.chargeResponse =='00' || response.tx.chargeResponse == '0') {
// redirect to a success page
} else {
// redirect to a failure page.
}
}
});
});
});
просмотров
@login_required
def CartView(request):
cart = Cart(request)
total = str(cart.get_total_price())
total = total.replace('.', '')
total = int(total)
return render(request, 'payment/payment_form.html',)
Вы не передаете эти переменные total
и cart
в контекст шаблона
Измените это
return render(request, 'payment/payment_form.html',)
to
return render(request, 'payment/payment_form.html', {'total': total, 'cart': cart})