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