top of page

Forum Posts

AdVantage Agency
Content Creator
Content Creator
Nov 26, 2020
In Tips, Tutorials, Examples
In this post I will write the code that allows you to perform an action on the elements of a repeater based on the date. In this case let's assume we want to make an advent calendar where day after day gifts are released, always keeping the gifts of the past days visible. To do this you need: -A database with a text field filled in with the date we want the item to unlock. The date must be in yyyy-mm-dd format. -A repeater connected to the dataset Here is the code: $w.onReady(function () {     showDays(); }); function showDays() { // The calendar currently spans December 1-24, 2020 and the current date  // is set to December 08, 2020 in order to demonstrate the example. // To customize the example: // - Update the dates stored in the Day field in the AdventGift database collection to the span of time  //   you want to run the calendar. // - On the first day of the calendar, comment out the code on Line 15 and uncomment the code on Line 16 //   so that the current date is set to today's date. const currentDate = new Date('2020-12-08'); // const currentDate = new Date();     $w("#giftDataset").onReady(() => {         $w("#adventRepeater").forEachItem(($item, itemData, index) => { let fixedItemDate = $item('#calendarDate').text; let dateItem = new Date(fixedItemDate); if (currentDate.getDate() > dateItem.getDate()) {                 $item('#overlayBox').hide();                 $item('#giftImage').show();                 $item('#nameDateBox').show();             } else if (currentDate.getDate() == dateItem.getDate()) {                 $item('#redNumberText').show();                 $item('#blackNumberText').hide(); let slideOptionsOut = { "duration": 1700, "delay": 1000, "direction": "left"                 }; let slideOptionsIn = { "duration": 1700, "delay": 0, "direction": "right"                 };                 $item('#overlayBox').onClick((event) => {                     $item('#overlayBox').hide("slide", slideOptionsOut).then(() => {                         $item('#giftImage').show("slide", slideOptionsIn);                         $item('#nameDateBox').show("slide", slideOptionsIn);                     });                 })             }         });     }); } You can watch my example and make it yours here: https://www.wix.com/corvid/example/advent-calendar-for-christmas
1
0
259
AdVantage Agency
Content Creator
Content Creator
Oct 09, 2020
In Coding with Velo
Stripe has updated its API because the old ones do not respect a European regulation. How do I update the code on the site, I have now integrated the old API like this: PAGE: import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; import {createToken, encodeCard} from "public/stripeAPI.js"; import {charge} from 'backend/stripePrivate'; $w.onReady(function () { // TODO: write your page related code here... }); function createCard() { return { "name": $w("#iptName").value, "number": $w("#iptCardNumber").value, "cvc": $w("#iptCVC").value, "exp_year": $w("#iptYear").value, "exp_month": $w("#iptMonth").value }; } export function payNow() { /*var euro = 1; if ($w('#checkbox1').checked){ euro = euro + 5; } */ console.log($w('#dbMembers').getCurrentItem()) console.log() let payment = { "amount": ($w('#checkbox2').value * 100), "currency": "EUR", "description": "trial" } createToken(encodeCard(createCard())) .then((token) => { charge(token, payment, wixUsers.currentUser.id) .then((response) => { if(response.chargeId) { //payment success $w('#response').text = response.chargeId; $w('#lblResponse').text = "Pagato!!!"; } else { //payment fail $w('#response').text = response.error; $w('#lblResponse').text = "Processing error (from Stripe):"; } $w('#response').show(); }); }); } export function button1_click(event) { payNow() } PUBLIC: import {fetch} from 'wix-fetch'; //////////////////////////////////////////////// // 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. // https://stripe.com/docs/keys const apiKey = "pk_test_"; // (public key) // The publishable key is just used to identify your account. // It does not provide permission to perform any function // except for creating a token, and can therefore be used // in a public file. //////////////////////////////////////////////// // This function uses the Stripe API to get a card token. // A card token is a secure representation of the card // and can only be used once. // https://stripe.com/docs/api#create_card_token export async function createToken(card) { 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; } // Builds the fetch body from the array of card details. 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); } BACKEND: import {fetch} from 'wix-fetch'; //////////////////////////////////////////////// // 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. // https://stripe.com/docs/keys const apiKey = "sk_test_"; // (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) }); if (response.status >= 200 && response.status < 300) { // transaction successful - get charge ID const ret = await response.json(); 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; } But the tripe guidelines say to change like this but I don't know how: https://stripe.com/docs/payments/payment-intents/migration Can anyone show me how to update the code?
0
0
64
AdVantage Agency
Content Creator
Content Creator
Sep 25, 2020
In Coding with Velo
What is the code to use to connect the activecampaign api to wix? I tried various methods but failed
0
0
22
AdVantage Agency
Content Creator
Content Creator
Jul 21, 2020
In Coding with Velo
what code should i use to create a kind of automation that sends 3 emails after 1 day each?
0
2
43
AdVantage Agency
Content Creator
Content Creator
Jul 12, 2020
In Coding with Velo
I have 2 menus for a restaurant, one for the afternoon and one for the evening. I would like to make sure that the lunch menu is shown every day from a certain time and that of the dinner at another time. To do this I thought of creating 2 pages with the menus inside and making an extra page that redirects the user to one of those 2 based on the time the link is opened. how can I do? What codes should I use?
0
11
471
AdVantage Agency
Content Creator
Content Creator
Jun 17, 2020
In Coding with Velo
I wrote this code, which helps assigning a random number and sending by e-mail to the user who push the button, recording everything in a database. In preview-mode everything works correctly and the database records the number generated and the user, signing that, from that user, the code was required. Instead, on the live site, the code works but the database doesn't record activities. import wixData from 'wix-data'; import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; $w.onReady(function () { }); export function button1_click(event) { let discountCode = Math.floor(Math.random() * 8999) + 1000; let User = wixUsers.currentUser.id; let toinsert = { "member": User, "codiceSconto": discountCode, "codiceInviato": true }; wixData.insert('Codicisconto', toinsert) $w('#dbCodiciSconto').save() .catch((err) => { console.log(err); }); console.log('Inserito nel database') wixUsers.emailUser('S2A6sCb', User, { variables: { codiceSconto: discountCode.toString() } }) .then(() => { console.log('mail inviata') $w('#button1').disable(); wixLocation.to(`/account/my-account`) }) } Could someone check the code to find the problem, please? If is not a code problem, which could be the real problem?
0
2
15
AdVantage Agency
Content Creator
Content Creator
Apr 25, 2020
In Coding with Velo
hi everyone, do you know any valid advanced level corvid courses? I know how to program with corvid well enough but I find it difficult to work with database code but in general with all complex codes. Can you advise me how I can learn corvid in depth and in full?
0
0
28
AdVantage Agency
Content Creator
Content Creator
Apr 07, 2020
In Coding with Velo
Hi, i wrote this code for filter a dataset 2 times, first for the user and the second for the category of a product. The category filtering work, but the user filter doesn't work ( the user is not logged in but I created a small list of users invented in a dataset, therefore the id is that of the row of the customer dataset) How can I solve it? import wixData from 'wix-data'; import wixUsers from 'wix-users'; let utente; let categoria; $w.onReady(function () { let utilizzatore = wixUsers.currentUser.id; console.log(utilizzatore) }); function filtering (category, user) { user = $w("#dbClienti").getCurrentItem(); console.log(user); var newFilter = wixData.filter() newFilter = newFilter.eq('categoria', category); newFilter = newFilter.eq('cliente', user); $w('#dbAcquisti').setFilter(newFilter); console.log(newFilter) utente = user categoria = category } export function iptDropdown_change(event) { let adjGenre; if ($w('#iptDropdown').value !== 'tutti' ) { adjGenre = $w('#iptDropdown').value; } filtering(adjGenre, utente); }
0
1
139

AdVantage Agency

Content Creator
+4
More actions
bottom of page