Stripe Checkout

I wan to use Stripe Checkout on my Wix site. I’m using these instructions: Payments | Stripe Documentation

I paste the first piece of code into an iFrame, which works. I don’t know what the “your-server-side-code” is supposed to be.

There is a second piece of code, but it’s only in other formats. I don’t know which one to use, where to put it in my Wix site, or how to link the 2 pieces of code.

I just need to be able to accept payments through Stripe for a predetermined amount. If this is not the best way, could someone please let me know what is?

I’m about to thrown my PC out of the window if I can’t solve this! I’ve looked over forums for the past 2 days and can’t find a simple explanation…

Any help would be greatly appreciated!

Thanks

https://www.futurecoding.net/stripe-integration-tool

Thanks for this, it’s very useful, but once I finish all the steps, all payments are declined. Even using the test keys and card details from stripe :confused:

OK, I’ve done this 4 times now. Followed EXACTLY what the tutorial shows. Still not working. Please help!!!

Code I am using:

Page:

import wixWindow from “wix-window”;
$w.onReady( function () {
$w(“#booknow”).onClick((event, $w) => {
var amm = $w(“#amount”).text.replace
var data = {
amount: $w(“#amount”).text,
itemName: $w(“#title”).text,
description: $w(“#desc”).text
}
wixWindow.openLightbox(“Payment”, data)
});
});

Lightbox:

import {
createToken,
encodeCard
} from “public/stripeAPI.js”;
import {
charge
} from “backend/stripeProxy”;
import wixWindow from “wix-window”;
import wixData from “wix-data”;
var pmtdata;
$w.onReady(function () {
$w(“#button2”).onClick((event, $w) => {
payNow();
});
pmtdata = wixWindow.lightbox.getContext();
changeState(pmtdata.amount, pmtdata.description);
$w(“#button2”).label = "Pay " + pmtdata.amount + “$”;
});
var payment;

function payNow() {
var accepted = false;
createToken(encodeCard(createCard())).then((token) => {
charge(token, payment).then((chargeResponse) => {
if (chargeResponse.id !== undefined) {
$w(“#info”).show();
$w(“#info”).text = “Payment Successful!”;
accepted = true;
var item = {
“amount”: pmtdata.amount,
“productName”: pmtdata.itemName,
“productDesc”: pmtdata.description,
“stripeChargeId”: chargeResponse.id
}
wixData.insert(“Payments”, item)
}
});
});
setTimeout(function () {
if (!accepted) {
$w(“#info”).show();
$w(“#info”).text = “Payment Declined. Please check your details.”;
}
}, 3200);
}

function createCard() {
return {
“name”: $w(“#cardowner”).value,
“number”: $w(“#cardnumber”).value,
“cvc”: $w(“#cvc”).value,
“exp_year”: $w(“#yyyy”).value,
“exp_month”: $w(“#mm”).value
};
}

function changeState(x, y) {
payment = {
“amount”: (x * 100),
“currency”: “GBP”,
“description”: y
}
}

Public:

import {
fetch
} from “wix-fetch”;
export async function createToken(card) {
const apiKey = “pk_test_vuwqLp8hT9Ygygz5OHVWrPKP”;
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);
}

Backend:

import {
fetch
} from “wix-fetch”;
export async function charge(token, payment) {
const cart = payment;
const apiKey = “sk_test_F08ZLWvnemwJYgDjedMrGmvv”;
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;
}

Take a look at the new Example: Stripe Payment Processing .

Have fun,

Yisrael

Hi Billy I’m looking at doing the same. Have you succeeded and if so, how?

Use paidmembersapp.com and a Stripe Payment Link - you can now just link any button in Wix to Stripe Checkout with Stripe Payment Links or, if you need custom code, we generate it for you. As far as “server-side code”, we handle that for you.