I am having issues myself, setting up stripe.
I am creating a new website for my org, and I need to use the same stripe subscription system as we have today.
My problem is how to code this on wix.
I have 3 types of subscriptions that are currently running in stripe.
On my wix page, I want to still be able to select between theese 3 and checkout.
Also I need to be able to send multiple meta data inputs from the site, that follows the subscription into stripe.
in stripe, I have prod_xxxx ID’s for my subscription plans, and I want to be able to still use these.
I want to use either a radio button input or dropdown menu to do this.
And when I chose “checkout” I want it to open up a lightbox with the card payment options.
So far I have gotten this on my page code:
import wixWindow from “wix-window”;
$w.onReady( function () {
$w(“#betaling”).onClick((event, $w) => {
var amm = $w(“#amount”).value
var data = {
amount: $w(“#amount”).value,
name: $w(“#navn”).value,
nick: $w(“#nick”).value,
cpr: $w(“#CPR”).value,
email: $w(“#email”).value
afdeling: $w(“#dropdown1”).value,
}
wixWindow.openLightbox(“betaling”, data) }); });
The #navn should be the “customer” in stripe.
What is missing, is how I get the #amount (radiobutton) to define BOTH an amount AND the subscription ID associated with the amount.
Then I need to get the code built for the lightbox.
In the lightbox I have set up input fields for the card information:
Cardholder name, Card number, Exp month, Exp year, CVC and “Pay now” button.
My big issue now, is how do I code the lightbox?
my public “stripeAPI” is like this:
import {fetch} from ‘wix-fetch’;
export async function createToken(card) {
//Go to stripe.com to create a test key and replace the one in the example
const apiKey = “YOUR_API”;
const response = await fetch(“https://api.stripe.com/v1/tokens”, {
method: ‘post’,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
“Authorization”: "Bearer " + apiKey
},
body: card
});
if (response.status >= 200 && response.status < 300) {
const json = await response.json()
return json.id;
}
const responseText = await response.text();
console.log(responseText);
return response.status;
}
export function encodeCard(card){
let encoded = “”;
for ( let [k, v] of Object.entries(card)) {
encoded = encoded.concat(“card[”, k, “]=”, encodeURI(v), “&”);
}
return encoded.substr(0, encoded.length - 1);
}
I am aware that the API key is missing (for pasting purposes)
My backend “stripeProxy” is like this:
import {fetch} from ‘wix-fetch’;
export async function charge(token,payment) {
const cart = payment;
//Go to stripe.com to create a test key and replace th eone in the example
const apiKey = “YOUR_KEY”;
const response = await fetch(“https://api.stripe.com/v1/charges”, {
method: ‘post’,
headers: {
“Content-Type”: “application/x-www-form-urlencoded”,
“Authorization”: "Bearer " + apiKey
},
body: encodeBody(token, cart)
});
if (response.status >= 200 && response.status < 300) {
return await response.json();
}
return await response.text();
}
function encodeBody(token, cart){
let encoded = “”;
for ( let [k, v] of Object.entries(cart)) {
encoded = encoded.concat(k,“=”, encodeURI(v), “&”);
}
encoded = encoded.concat(“source=”, encodeURI(token));
return encoded;
}