Creating subscription in Stripe using WIX code

Hi

Has anyone figured out how to allow customers to pay for subscriptions and then create those subscriptions in Stripe?

Scenario is:

  1. User selects and pays for the product which could be a monthly subscription of 30$.
  2. The monthly subscription is then created and charged in Stripe using WIX code and Stripe APIs.

I really hope that some developer guru can help me out here :slight_smile:

Best regards
Mads

See the Stripe Payment Example for details on how to process payments using the Stripe payment processor.

Thanks. I just can’t seem to figure out how to tell Stripe which product and which pricing plan to charge and subscribe the customer to.
Where can you do that?

@mikrokogebogen What you want to do will need to be done with code, and will be a challenge for beginner coders. You might want to consider checking out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.

Feel free to post any questions here.

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;
}

You may want to check out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.

@yisrael-wix Well, since my org is implementing a new payment system within the next 5 months, I am kinda not willing to pay $200+ for this code being written.

I am thinking that there has to be someone out there, that have done this and can share their input

@sebastian308 Fair enough. Perhaps one of the denizens of the forum has done something like this before and is willing to help out.