Hi all! I’m trying to help a client’s users get access to their invoices inside of the site so they can keep track of billing. I’ve been researching quite a bit and am close, but I know I’m missing two parts. Thanks in advance for any advice!
(1 of 2)Filtering the Dataset by User
To start, in the first half of the code below, I’m not filtering the dataset properly. I’m trying to filter by the user’s email or ID. I found an example of code online that users the owner instead that I’m pasting below so you can see what I used to start the project:
import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
let user ;
var userID ;
$w . onReady ( function () {
user = wixUsers . currentUser ;
userID = user . id ;
$w ( “#dataset2” ). setFilter (
wixData . filter ()
. eq ( “_owner” , userID )
);
const millisecondsToDelay = 2000 ;
setTimeout (() => {
$w ( ‘#repeater1’ ). show ();
}, millisecondsToDelay );
});
(2 of 2) Creating Dynamic Links to the Invoice
I’m also trying to let the user pay his or her invoice by tapping a button. I’ve got a hidden text field set to display the invoice ID, which is what I’m trying to use for the variable part of the link. I’m not quite sure where I’m missing my mark, but something seems to be off with the link structure. To add context, the URL below works when I manually add the variable. The part I’m struggling with is the invoice ID variable. I hid the client’s ID so that’s why it appears incomplete:
import wixLocation from ‘wix-location’ ;
export function button2_click ( event ) {
let Invoice = $w ( “#text3” ). text ;
wixLocation . to ( https://invoices.wix.com/invoice/[CLIENT'S_ID [u]_HERE][/u] : ${ Invoice }
);
}
1). You can add filter in the dataset. Click dataset-> Settings-> Add Filter → Field “Owner” → Condition “is”

2). I’m not sure what you’re trying to acheive
Try this
Add a backed file and paste this code
import { invoices } from 'wix-billing-backend';
export async function myCreateInvoicePreviewUrlFunction(myInvoiceId) {
const retrievedInvoice = await invoices.getInvoice(myInvoiceId);
const options = {
suppressAuth: false
};
return await invoices.createInvoicePreviewUrl(retrievedInvoice.id, options);
}
Call “myCreateInvoicePreviewUrlFunction” function from frontend
import {myCreateInvoicePreviewUrlFunction} from 'backend/{backendFileName}'
import wixLocation from 'wix-location';
export async function button2_click(event){
let Invoice = $w("#text3").text;
await myCreateInvoicePreviewUrlFunction(Invoice).then((url)=>{
wixLocation.to(url)
})
}
To know more about wix invoice https://www.wix.com/velo/reference/wix-billing-backend/invoices-obj
These are newer functions that I haven’t worked with previously so I’m not sure if I’m articulating it quite right. Sorry for any confusion!
Simply put, I’m trying to set up a section of the member’s area through which they could view their invoices.
Part of the issue is that the “owner” of the invoice is the admin. We want to show the customer their invoice. That’s why I was trying to set up a custom filter. The first step would be only showing invoices on the page that have the same customer ID as the person logged in.
The second part is meant to be the code that lets the logged in user open up the invoice with the repeater button.
Does this help clarify things?
No, actually how will you create the invoices? By dashboard or by velo api?
Have you created new database collection for your member area?
The intent was to create the invoice using the dashboard and then let users access it in the section of the site.
Whenever you create an invoice you need to manually get the invoice id and update to your collection that you created.
Note: The collection item should be created by the member. You should just update the invoice id.
copy the code in my previous replies and paste it in the members page.
On repeater button click you should call the backend function that will take the member to a new window with the invoice. If you need more help you can message me personally.