Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Shan shanwixcode

🏠
Working from home
View GitHub Profile
View backend-process-sendgrid.js
import {mediaManager} from 'wix-media-backend';
import {bufferEncode} from './sendgrid';
export function getFileUrl(fileId) {
return mediaManager.getFileUrl(fileId);
}
export function sendMail(url, email, subject, body, filename, filetype) {
return bufferEncode(url, email, subject, body, filename, filetype);
}
View backend-sendgrid.js
import {fetch} from 'wix-fetch';
import sgMail from '@sendgrid/mail';
var api_key = 'XXXXXX';
export function bufferEncode(url, email, subject, body, filename, filetype) {
return createBuffer(url)
.then( (buf) => {
return sendEmail(buf, email, subject, body, filename, filetype);
});
View sendgrid-attachment-page.js
import {getFileUrl, sendMail} from 'backend/attachment/process';
$w.onReady(function () {
});
export function upload_click(event) {
$w("#upload").disable();
let files = $w("#uploadButton1").value;
let fileName = files[0].name;
View dataValidation.js
import wixData from 'wix-data';
let options = {
"suppressAuth": true,
"suppressHooks": true
};
export function validateEmail(email) {
var emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(emailRegex.test(email)){
View mailchimpbackend.js
const axios = require('axios'); //remember to install the axios npm
var url = 'https://{SERVER}.api.mailchimp.com/3.0/lists/{LIST ID}/members';
var api_key = '{API KEY HERE}';
export function createSub(fname, lname, email) {
return axios({
url: url,
method: 'post',
headers: {
View page.js
import {createSub} from 'backend/mailChimp';
$w.onReady(function () {
});
export function submit_click(event) {
if($w("#fName").valid && $w("#lName").valid && $w("#email").valid){
$w("#error").hide();
$w("#submit").disable();
View wixStores.js
import wixData from 'wix-data';
$w.onReady(function () {
});
export function repeater1_itemReady($item, itemData, index) {
$item("#price").text = itemData.price + ' ' + itemData.currency;
}
View backendFile.js
//stripe.jsw
import {fetch} from 'wix-fetch';
export async function subscription(token, item) {
const cart = item;
const apiKey = "SECRET_API_KEY";
const response = await fetch("https://api.stripe.com/v1/subscriptions", {
method: 'post',
headers: {
View public.js
//stripeAPI.js
import {fetch} from 'wix-fetch';
export async function createToken(card) {
const apiKey = "PUBLIC_API_KEY";
const response = await fetch("https://api.stripe.com/v1/tokens", {
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded",
View stripePage.js
import {createToken, encodeCard} from "public/stripeAPI.js";
import {subscription, createCustomer} from "backend/stripe";
import wixLocation from 'wix-location';
$w.onReady(function () {
});
var items = []; //your plan ID will go here (plan_XXXXXXXXXXXXXX)