Payment from variable amount

Ive created a code to calculate a total cost amount depending on dropdown options. This payment amount is variable depending on the option amounts. How do I now send this total amount to Wix Pay. I also need to connect name address and contact numbers etc. Any help would be greatly appreciated. Perhaps an example code

You can pass a value to the createMyPayment function like this:

//Front end
export function myButton_click(event, $w) {
    .then( (payment) => {
    } );

//Back end
export function createMyPayment(value) {
  return wixPay.createPayment({
  items: [{
  name: "Product Name",
  price: value
  amount: value


Thank you Marcia, I will try this later. Upon customers clicking to pay I’m hoping to move to another page to enable them to add their contact details and create a members login.

I’m afraid I’ve had no joy with this. It’s coming up with an error on a bracket. Also replace the myButton with an actual button number… Can I pass the total amount to a dataset, then call upon this value to use in wixpay?

There are two things that need to be changed.

  1. You need to replace “value” and “myButton” with the names you are using. Those are just placeholders that I used. It looks like you’re using the name “charge” which is what you will need to use for the value. You need to replace myButton with the name in the properties panel.

  2. The createMyPayment function needs to be placed in a jsw file in the backend.

There is more information here:

Your code in the image above won’t work as you are missing the Wix Pay import at the top along with the pages onReady function for starters.

Have you already read the existing Wix pages about Wix Pay?

Also, have a read of these pages about using Wix Pay too.

If you look at the code examples for the createPayment function in the Wix Pay API, you will be able to see an example already that gets users info too.

1 Like

Thank you for your help however I must be doing something completely wrong. So I decided to paste one of your examples in and even this comes up with errors!

Thank you for your help however I must be doing something completely wrong. So I decided to paste one of your examples in and even this comes up with errors!

Well of course it will do as you have simply just copied the code and pasted it straight into the site code tab.

The parts where it says backend code should be placed in a jsw file in your backend whilst the client side code should be placed on the page that you are using it on.

I would suggest that you read up about using backend files, as stated in the already linked pages in previous post.

live done so much reading and understanding to a small degree of the working however still not having success. I’ve pasted below photos.

I do have a good knowledge of computers and indeed was a CNC code writer. This Wix coding has beaten me, the explanations aren’t clear unfortunately. I’ve spent too long on this section of the website for simply requesting payment. How much will it cost for someone to write something for me please or can a clear explanation of the errors occurred be given. Thank you in advance.

If you are still wanting somebody else to do it for you, then you can look at hiring somebody from the Wix Arena, we can’t give you a price as it will be up to the person you might choose.

However, as for the issue you have got, it is the code on your 25 hour page that is still wrong.

You need the import lines to be at the top and not added in the middle of your code.
Then you should have an onReady function for your page and then the rest of the code.

You can have code for your page before the page onReady function, however note that this will be running before the page is ready.

If you look at this well laid out tutorial it will walk you through the process of using Wix Pay to create a payment and what code to put on your page (client-side/frontend) and what code to put in the backend jsw file/s

You can also look at this tutorial here which will give you an already made up page in your own Wix Editor with the page all setup and the code all added, you can even watch the video which will talk you through it too.

Thank you for your reply, I have tried moving the import to the top and inserting the onready function. It then says I need the export at the top too! So also tried that without luck. It states the “charge” isn’t defined This charge comes from button9 and inserted into group2. Button19 is the tester button to trigger of payment.

Would it be the function calculate block wrapped in onReady places at the bottom and everything else above it? On the example I can’t see them using the onReady function.

Hey Man, Luckily I’m on the same boat as yours as I was also trying to create similar gateway for my client but this error is coming again and again… Don’t know where I am missing something?
Thanks .

I’m not sure if we’ve encountered a weakness or loophole in their system. I’ve shuffled and reconstructed quite a few times to their advice and examples however still nothing but errors. I’m thinking to try just doing the calculation then moving to a next page to insert the wixpax coding. That way calculation coding and wipay coding won’t be mixed in together. And the onReady function will operate correctly. I’m still awaiting a reply back again, let me know please if you have any luck

1 Like

Move everything out of the onReady. It goes after.

@code-queen same problem, “charge” is coming up as not defined, I’ve attached photo. Hope there’s a solution to what I’m doing wrong.


Looking at your small page screenshot, you would be better off doing the price calculation seperately and then simply just taking the total price for the payment.

You can use Nayeli’s own example here to calculate items on your page.

Also, see here for a basic video example of calculating fields using code from Andreas Kviby, although please take note that Andreas is not connected with Wix anymore so please do not try to contact him as you will not get a reply.
Code for example above.

// For full API documentation, including code examples, visit

let nrOfPeople = 0;
let nrOfTotalTickets = 0;

let totalSum = 0;

$w.onReady(function () {

export function addButton_click(event) {
 nrOfPeople = Number($w("#nrOfPeople").value);
 let ticketPrice = Number($w("#ticketTypeDropdown").value);
 let nrOfTickets = Number($w("#nrOfTickets").value);
 if (nrOfTotalTickets < nrOfPeople) {
  // Add
  totalSum += ticketPrice*nrOfTickets;
  nrOfTotalTickets = nrOfTotalTickets + nrOfTickets;
  $w("#totalSumLabel").text = totalSum.toString();
 } else {
  $w("#messageText").text = "You have all the tickets your family needs!";

You can also have a look at these examples from Vorbly that are for calculations too.

1 Like