Stripe Subscription Integration

I’ve seen all the various posts regarding this, however no one seems to have solved this…
Simply looking for a way for customers to either signup or pay for their first box and subscribe them to a membership. I’ve seen a code given by Yoav and David, and I’m just looking to tweak one of the two to incoporate a subscription instead of just charging. The ability to launch this asap is our highest priority!

Thank you for anyones help!

YOAV CODE: https://www.wix.com/code/home/forum/questions-answers/stripe-recurring-payment-integration

DAVID CODE: https://www.wix.com/code/home/forum/questions-answers/wix-code-stripe

Yoav code works on all but public page (I receive a lot of errors on this page for some reason when updating #) and again I do not know how to tweak to incorporate subscription vs. charging

Thanks

Hay gabrielagrace.music ,

I understand subscription using Stripe is tricky.

To setup payment for a subscription, you need to follow, for a start - this Build a subscriptions integration | Stripe Documentation

You need to also have a look at the subscription API

You will also need to listen on events to enable and disable the functionality on your site that is served for subscribers

Last, you need to manage (in a collection) the subscription state of your members and use code to enable and disable features of the site accordingly.

We will try and create an example (cannot promise, mainly because of what comes next…).

I can share that we are working on a paid subscription model as a feature in Wix. Using this feature, you will be able to setup plans, user groups and permissions and set which plan enables which groups and permissions on the site (which pages are enabled paid users, for instance).

6 Likes

Hi @yoav, what is expected the timeframe for the launch\release of the paid subscription model feature?

Is there anywhere that we can track the progress of this feature?

Is it intended that this would also work for recurring payments that aren’t linked to any permissions or site access i.e. for subscription based purchase of digital services?

2 Likes

I am also anxiously waiting for the subscription feature to be enabled on WIX please

1 Like

Can’t wait for this to be implemented! thanks for the heads up Yoav

1 Like

Me TOO!

1 Like

I appreciate the work you’re doing and the help, Yoav! For those of you who are wondering about a timeline for a fully-functional paid membership feature, I was contacted back in December saying this feature was in the works and I said I would be a beta tester for it before it officially releases. Unfortunately for me, I have a character flaw in that I hate waiting around for things to get done with my small business that I’m trying very hard to grow and earn some income from. That being said, I’ve jumped ship over to Wordpress because they have a plugin that handles this feature seamlessly. Since I have not been contacted even about the beta version of the Wix solution, I think I made the right move. It’s really too bad. Like everyone has been saying, it really is quite surprising this feature is not already implemented because most of their competitors don’t have a fully-operational solution either, especially since Wix so so awesome and user-friendly.

2 Likes

@Yoav
“I can share that we are working on a paid subscription model as a feature in Wix. Using this feature, you will be able to setup plans, user groups and permissions and set which plan enables which groups and permissions on the site (which pages are enabled paid users, for instance).” … Dec 14, 2017

Please, please, please ANY communication… timing… successes… possibilities… ANYTHING. This is so needed and we’ve been told this would happen for SO long now. All of us trying to run businesses have to communicate to our teams and customers to know if this is ACTUALLY going to happen or if we need to move on to another company to provide our needs. If I have to move back to Wordpress, I have to move a team of people with jobs to own this. Please communicate… and YES I have emailed and gotten fake answers.

Shannon

Shannon we’re all eager to see a fully functioning and documented ecommerce API. But while we wait, Yoav’s solution does work with Stripe:


Thanks Wix, you rock!

1 Like

Felipe, would you kindly share with us newbies how exactly you got it to work?

1 Like

Sure @ritaorlov (BTW it would be great if we could actually tag members in comments).

You need to write code in 3 places for this to work:

  1. A Javascript file in your Public Folder. This one is called stripeAPI.js
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 Publishable API Key]"; 
  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();
  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);
}
  1. A Javascript Web Module in your Backend Folder. This one is called stripeProxy.jsw
import {fetch} from 'wix-fetch';

export async function charge(token,cart) {
	
  //Go to stripe.com to create a test key and replace the one in the example
  const apiKey = "[Your Secret API 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;
}
  1. The page in your Wix Editor where you will be collecting the CC information
import {createToken, encodeCard} from "public/stripeAPI.js";
import {charge}  from 'backend/stripeProxy';

$w.onReady(function () {
	setData();
});

export function payNow() {
	createToken(encodeCard(createCard()))
		.then((token) => {
			charge(token,getCart())
				.then((chargeResponse) => {
				});
		});
}

function createCard() {
	return {
		"name": $w("#nameOnCard").value,
		"number": $w("#cardNumber").value,
		"cvc": $w("#cvc").value,
		"exp_year": $w("#expYear").value,
		"exp_month": $w("#expMonth").value
	};
}

function getCart(){
  return {
    "amount": $w('#paymentAmount').value*100,
    "currency": "USD",
    "description": "test charge"
  };
}

function setData() {
	$w("#nameOnCard").value = "Paco ElFlaco";
	$w("#cardNumber").value = 4242424242424242;
	$w("#cvc").value = 123;
	$w("#expYear").value = 18;
	$w("#expMonth").value = 12;
}

export function payButton_click(event, $w) {
	return payNow();
}

And voila! I hope this helps you get what you need. You can learn more about Stripe’s API here: Stripe API reference – curl

4 Likes

Thank you Felipe! I’ll see if I can figure out how to do what you laid out there. I really appreciate you putting this here!

Shannon

1 Like

If anyone’s still looking, it looks like this guy uses the same (or similar) code in his video Integrate Stripe with Wix Code - Part 1 - YouTube … it’s only a week old, and he says he’s got a part 2 with even more complex coding coming out soon (I hope!). The video seems straightforward, and I’m about to give it a shot, so I’ll let you all know if the video there helps make sense of the code here once I’m done!

1 Like

Annie please can you share whether you got this stripe integration working? Thanks

1 Like

@Anna the Stripe integration works like a charm. Did you try the code I wrote above? if you’re still struggling you can contact me at felipe@diaytech.com

1 Like

It worked for me, so thank you all. Esp @Felipe!

1 Like