Wix is not receiving response from Stripe API

Hi, we have multiple sites that have Stripe integration with code via API.
It has suddenly stopped working on more than 1 site with no or some transactions going through.
It works in Preview but not Live though.

We have obtained confirmation from Stripe that we do get Status 200 (or any other) and this gets sent to Wix but Wix refuses to accept it.

Any ideas?

Thanks

Please provide the URL of your site.

1: https://www.shropshirevegbox.co.uk/dc-checkout
2: from https://en.monpackged.fr/plans to https://en.monpackged.fr/dc-checkout
3: Davydov Consulting: https://www.davydovconsulting.com/pay

Are all of these sites still encountering the problem?

Were the sites changed in any way recently? Code? Domain names? Etc.

1 and 2 are work in progress with quite a lot of code on various pages added/changed every day. 3rd has been static for months. Domain were not changed. Strange that they suddenly all stopped accepting Stripe response.

I’m going to refer this to QA for evaluation.

Did they all stop working at the same time? When was this? Are they still not working (today)?

It happened 5-7 days ago and they are not working or working intermittently as of today.

Important - have you checked with Stripe? I’m not aware of any issues with wix-fetch, so it could very well be a Stripe issue, or some network or security issue that Stripe is having.

Yes, before posting this I checked with Stripe support and they confirmed they do send response to wix but wix is refusing to accept it.

hi Oleg, in order for us to further investigate it would help us if you could recreate the issue and post us the requests information from the dev tools network tab (including url, headers, body for both requests and responses)

It would also help for us to debug your code if you posted the " backend/stripeProxy " code over here (remove the API key)

3:

You need to fill the form

Then click button PAY.

2:

First, we choose the plan we need
Then we go to checkout page

when we make a transaction before withdrawing money for a plan, we first withdraw 0.5 euros as a check for card activity. After which we create a subscription and customer. However, when working on a live site after creation, it sends a request to stripe, but it cannot be received back, which is why the subscription and customer are not created.
However, the test amount of 0.5 euro removed. And also system does not return status 200 second time.
The first time status 200 returns after withdrawing 0.5 test euros, and the second time should be triggered when creating a subscription, but instead of the second status 200 we get an error.
A similar system works in a similar way on our other sites, only instead of a subscription, payment should be charged immediately (in addition to test)

Being on the payment page, we fill in all the fields for providing data for delivery and enter this card, etc.

1:

@info6114 could you provide me with contact information so we could set up a debug session

Here you go:

////////////////////////////////////////////////////////Therefore_can///////////////////////////
import { fetch } from ‘wix-fetch’;
import { setPaidStatus } from ‘backend/premium’;

////////////////////////////////////////////////
// A “test key” is used for this example.
// Use a “live key” for a production site.
// Go to stripe.com to get your own key.
// API keys | Stripe Documentation
const apiKey = “”; // (secret key)
// The key in use in this file is the private API key.
// The private key is used to perform all actions and
// should be kept confidential and guarded and
// therefore is only to be used in backend files.
////////////////////////////////////////////////

const stripe = require(‘stripe’)(‘’);

export async function createProduct(name) {
return await stripe.products.create({ name: name });
};
export async function createPrice(amount, product_id) {
return await stripe.prices.create({
unit_amount: amount,
currency: ‘eur’,
recurring: { interval: ‘month’ },
product: product_id,
});
};

export async function deleteSub(subID) {
return await stripe.subscriptions.del(subID)
};
export async function deleteCust(custID) {
return await stripe.customers.del(custID)
};
export async function createCustomer(desc,email,phone) {
return await stripe.customers.create({
description: desc,
email: email,
phone: phone,
});
};

export async function createSubscription(customer, price, paymentMethod,iterations) {
return await stripe.subscriptionSchedules.create({
customer: customer,
start_date: ‘now’,
end_behavior: ‘release’,
default_settings: {

        "default_payment_method": paymentMethod, 

    }, 

    phases: [{ 
        items: [{ price: price, quantity: 1 }], 
        iterations: iterations, 
    }, ], 
}); 

};
export async function charge(token, payment, userId) {

const cart = payment; 
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) 
}); 
console.log("STATUS: " + response.status); 
if (response.status >= 200 && response.status < 300) { 
    // transaction successful - get charge ID 
    const ret = await response.json(); 
    let id = await setPaidStatus(userId, ret.id); 
    return { "chargeId": ret.id }; 
} 
// transaction failed - return error type 
let res = await response.json(); 
let err = res.error.type; 
return { "error": err }; 

}
export async function createPayment(cradnumber, cardexp_month, cradexp_year, cart_cvc, cust_id) {
return await stripe.paymentMethods.create({
type: ‘card’,
card: {
number: cradnumber,
exp_month: cardexp_month,
exp_year: cradexp_year,
cvc: cart_cvc,
},
customer: cust_id
});
}
export async function attachPayment(pid, cid) {
return await stripe.paymentMethods.attach(
pid, { customer: cid }
);
};

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

export async function testCharge() {

let cart = { 
    amount: '999', 
    currency: 'usd', 
    source: 'tok_visa', 
    receipt_email: 'your@emailaddress.com' 
}; 
const response = await fetch("https://api.stripe.com/v1/charges", { 
    method: 'post', 
    headers: { 
        'Accept': 'application/json', 
        'Content-Type': "application/x-www-form-urlencoded", 
        'Authorization': "Bearer " + apiKey 
    }, 
    body: encodeBody('tok_visa', cart) 
}); 
return await response.json(); 

}
///////////////////////////////////////////////////////////////////////////////////////////VegStripeProxy///////////////////////
import {fetch} from ‘wix-fetch’;
import {setPaidStatus} from ‘backend/premium’;

////////////////////////////////////////////////
// A “test key” is used for this example.
// Use a “live key” for a production site.
// Go to stripe.com to get your own key.
// API keys | Stripe Documentation
const apiKey = “”; // (secret key)
// The key in use in this file is the private API key.
// The private key is used to perform all actions and
// should be kept confidential and guarded and
// therefore is only to be used in backend files.
////////////////////////////////////////////////

export async function charge(token, payment, userId) {

const cart = payment; 
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) 
}); 
console.log("STATUS: " + response.status); 
if (response.status >= 200 && response.status < 300) { 
	// transaction successful - get charge ID 
	const ret = await response.json(); 
	let id = await setPaidStatus(userId, ret.id); 
	return {"chargeId": ret.id}; 
} 
// transaction failed - return error type 
let res = await response.json(); 
let err = res.error.type; 
return {"error": err}; 

}

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

export async function testCharge() {

/* 
// This function performs a simple integration test 
// and is only used for testing purposes. 
// For more details, see: https://stripe.com/docs/development 

// Call this function on any page using the following snippet: 

// import statement at beginning of file 
import {testCharge} from 'backend/stripeProxy'; 

// put this in the page's onReady() function 
testCharge() 
	.then((response) => { 
		console.log(response); 
	}); 
*/ 

let cart = { 
	amount: '999', 
	currency: 'usd', 
	source: 'tok_visa', 
	receipt_email: 'your@emailaddress.com' 
}; 
const response = await fetch("https://api.stripe.com/v1/charges", { 
	method: 'post', 
	headers: { 
		'Accept': 'application/json', 
		'Content-Type': "application/x-www-form-urlencoded", 
		'Authorization': "Bearer " + apiKey 
	}, 
	body: encodeBody('tok_visa', cart) 
}); 
return await response.json(); 

}
//////////////////////////////////////////////////////////////////////////////////////ConsultingProxy/////////////////////////
import {fetch} from ‘wix-fetch’;
import {setPaidStatus} from ‘backend/premium’;

////////////////////////////////////////////////
// A “test key” is used for this example.
// Use a “live key” for a production site.
// Go to stripe.com to get your own key.
// API keys | Stripe Documentation
const apiKey = “”; // (secret key)
// The key in use in this file is the private API key.
// The private key is used to perform all actions and
// should be kept confidential and guarded and
// therefore is only to be used in backend files.
////////////////////////////////////////////////

export async function charge(token, payment, userId) {

const cart = payment; 
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) 
}); 
console.log("STATUS: " + response.status); 
if (response.status >= 200 && response.status < 300) { 
	// transaction successful - get charge ID 
	const ret = await response.json(); 
	let id = await setPaidStatus(userId, ret.id); 
	return {"chargeId": ret.id}; 
} 
// transaction failed - return error type 
let res = await response.json(); 
let err = res.error.type; 
return {"error": err}; 

}

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

export async function testCharge() {

/* 
// This function performs a simple integration test 
// and is only used for testing purposes. 
// For more details, see: https://stripe.com/docs/development 

// Call this function on any page using the following snippet: 

// import statement at beginning of file 
import {testCharge} from 'backend/stripeProxy'; 

// put this in the page's onReady() function 
testCharge() 
	.then((response) => { 
		console.log(response); 
	}); 
*/ 

let cart = { 
	amount: '999', 
	currency: 'usd', 
	source: 'tok_visa', 
	receipt_email: 'your@emailaddress.com' 
}; 
const response = await fetch("https://api.stripe.com/v1/charges", { 
	method: 'post', 
	headers: { 
		'Accept': 'application/json', 
		'Content-Type': "application/x-www-form-urlencoded", 
		'Authorization': "Bearer " + apiKey 
	}, 
	body: encodeBody('tok_visa', cart) 
}); 
return await response.json(); 

}

Hi Uriya, thanks, you can set up session in Zoom through this https://meetings.hubspot.com/info1631

We changed fetch.then to await fetch and that back to life.
Thanks everyone for the help.