Hello, all! Would any of you be able to help me figure out how to calculate the total Stripe will charge based on the following selections users make on the payment form? Here's what the payment form looks like:
Here's the code I'm using (which obviously isn't working . . .
Hi Juanita,
Looking at your code, it seems that `changeState` is currently setting the value of the variable `payment`.
It does not update the view - which sounds like what you are trying to do.
Try adding this line at the end of `changeState`
$w('#total').value = total
Here's my code:
import {
createToken, encodeCard
}
from "public/stripeAPI.js";
import {
charge
}
from 'backend/stripeProxy';
var payment;
export function payNow() {
createToken(encodeCard(createCard()))
.then((token) => {
console.log("Card token: " + token);
charge(token, payment)
.then((chargeResponse) => {
console.log("Charge ID: " + chargeResponse.id);
});
});
}
function createCard() {
return {
"name": $w("#cname").value,
"number": $w("#card").value,
"cvc": $w("#cvc").value,
"exp_year": $w("#yr").value,
"exp_month": $w("#mon").value
};
}
function changeState() {
let pricePerPage = 1000; //10 USD PER EXTRA PAGE
let base = Number($w("#baseTypeDropdown").value);
let amount = Number($w("#amount").value);
let total = (amount * pricePerPage) + base;
let description = ($w("#baseTypeDropdown").label);
$w("#total").value = total / 100;
payment = {
"amount": total,
"currency": "USD",
"description": $w("#baseTypeDropdown").value,
"receipt_email": $w("#email").value
};
}
export function button58_onclick() {
payNow();
}
export function amount_change() {
changeState();
}
export function total() {
changeState();
}
export function email_onchange() {
changeState();
}
export function baseTypeDropdown_change() {
changeState();
}
can you send the code not as a pic
Thanks, Tom! That worked! What I need to do now tho, is to force the label of the #basePriceDropdown field to appear a the 'description' in Stripe, AND inside my database in the 'category' field. Right now, the 'value' of the #basePriceDropdown field is what shows up. I've tried using the Wix API Reference code to resolve the issue, but I can't figure it out!
Can you tell from the code below, what I'm doing wrong?
Anyone? Please????