Hi @tarrahopwood
Sorry but I have been swamped with work but I will try to help you with half of the questions you asked.
Question 2 & 3.
> saving stripe customer id in wix database
> do you know how to save the customer’s CC/billing information so that if there are any one-off purchases the CC/billing info auto loads for that individual customer with tokenization & charges them by the click of a button?
Tokens cannot be stored or used more than once. To store card or bank account information for later use, you can create Customer objects
To save a customer Id first, you need to retrieve the customer id from the api while creating a customer or charging for a subscription. To get the customer id, see the backend code below.
const response = await fetch("https://api.stripe.com/v1/customers", {
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + apiKey
},
body: encodeClient(client)
});
if (response.status >= 200 && response.status < 300) {
const ret = await response.json();
let cus = ret.id; //fetching the customer id from the api
return {"cusId": cus}; //sending it back to the page
}
Then on the page you need to use .then() to receive your customer id like below.
createCustomer(customer) //create a new customer
.then((response) => {
if(response.cusId !== undefined) {
let item = {
"customer": response.cusId, //this is your customer ID
"items[0][plan]": planId //this is your plan id
};
cusId = response.cusId; //global variable being set to the received customer id
After that you can easily store it in the database once the order is processed. See below.
async function jackpot(response) {
let toInsert = {
'image': $w("#image1").src,
'itemName': $w("#name").text,
'price': $w("#price").text,
'category': 'Subscribed',
'email': $w("#email").value,
'customerId': cusId, //customer id here
'subId': response.subId
};
await wixData.insert("Orders", toInsert);
wixLocation.to("/thank-you-page");
}
Your database should look like this then.
If you are able to do this then you will also be able to do the cancellation and update part by reading the Stripe API Stripe API reference – Subscriptions – curl