Skip to content

Commit

Permalink
pricing and stock working
Browse files Browse the repository at this point in the history
  • Loading branch information
itsMikeLowrey committed Jun 23, 2023
1 parent f42a576 commit b152ebe
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 30 deletions.
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
to = "/index.html"
status = 200
[functions]
included_files = ["./src/assets/serviceList.txt", "/src/assets/serviceList.txt" ]
included_files = ["./src/assets/serviceList.txt", "/src/assets/serviceList.txt", "./src/assets/serviceList.json", "/src/assets/serviceList.json"]
37 changes: 37 additions & 0 deletions netlify/functions/get1ServiceStock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const mongoDBPassword = process.env.mongoDBPassword
const mongoServerLocation = process.env.mongoServerLocation
const { MongoClient, ServerApiVersion } = require('mongodb')
const Joi = require("joi")
const uri = "mongodb+srv://main:" + mongoDBPassword + "@"+ mongoServerLocation + "/?retryWrites=true&w=majority"
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 })
const phoneInfoCollection = client.db("real").collection("phonesInfo")
exports.handler = async (event) => {
const phoneMap = []
try {
const phoneInfo = await phoneInfoCollection.find().toArray()
for (const phone of phoneInfo) {
const tempObject = {
sim1: ['all'],
sim2: ['all']
}
if (phone.sim1.phoneNumber.length > 5) {
tempObject.sim1 = phone.sim1.usedServices
}
if (phone.sim2.phoneNumber.length > 5) {
tempObject.sim2 = phone.sim2.usedServices
}
phoneMap.push(tempObject)
}
return {
statusCode: 200,
body: JSON.stringify(phoneMap)
}
}
catch (error) {
console.log(error)
return {
statusCode: 500,
body: ''
}
}
}
13 changes: 6 additions & 7 deletions netlify/functions/submitOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const axios = require("axios")
const Joi = require("joi")
const fs = require('fs')
const path = require("path")
const pathWordlist = path.resolve("./src/assets/serviceList.txt")
const serviceList = fs.readFileSync(pathWordlist, 'utf8').toString().split("\n")

const pathServiceList = path.resolve("./src/assets/serviceList.json")
const serviceList = JSON.parse(fs.readFileSync(pathServiceList, 'utf8'))
exports.handler = async (event, context) => {
try {
const params = event.body
Expand Down Expand Up @@ -129,8 +128,8 @@ async function process1Service(parsed) {
await serviceSchema.validateAsync(parsed.purchaseInfo.service)

let serviceCorrect = false
for (let element of serviceList) {
if (element.replace(/[^a-zA-Z ]/g, "") === parsed.purchaseInfo.service.replace(/[^a-zA-Z ]/g, "")) {
for (let element of Object.keys(serviceList)) {
if (element === parsed.purchaseInfo.service) {
serviceCorrect = true
break
}
Expand All @@ -142,7 +141,7 @@ async function process1Service(parsed) {
const response = await axios.post(
storeAddress,
{
'amount': '2',
'amount': serviceList[parsed.purchaseInfo.service].price,
'speedPolicy': 'MediumSpeed',
'checkout': {
'paymentMethods': [
Expand All @@ -155,7 +154,7 @@ async function process1Service(parsed) {
numberArray: numberArray,
purchase: {
serviceType: '1service',
service: parsed.purchaseInfo.service.replace(/[^a-zA-Z ]/g, "")
service: parsed.purchaseInfo.service
},
timestamp: Date.now()
}
Expand Down
47 changes: 47 additions & 0 deletions src/assets/serviceList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"Twitter": {
"price": 1.50
},
"Google Voice": {
"price": 1.50
},
"Signal": {
"price": 1.50
},
"Apple": {
"price": 1.50
},
"Telegram": {
"price": 3.00
},
"Instagram": {
"price": 1.50
},
"Paypal": {
"price": 1.50
},
"Tinder": {
"price": 1.50
},
"Bumble": {
"price": 1.50
},
"Hinge": {
"price": 1.50
},
"Uber": {
"price": 1.50
},
"Tik Tok": {
"price": 1.50
},
"Uber Eats": {
"price": 1.50
},
"Grubhub": {
"price": 1.50
},
"DoorDash": {
"price": 1.50
}
}
15 changes: 0 additions & 15 deletions src/assets/serviceList.txt

This file was deleted.

60 changes: 54 additions & 6 deletions src/views/checkout1service.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup>
import { ref, computed } from 'vue'
import { ref, computed, onMounted } from 'vue'
import axios from 'axios'
import { getRandomInt, numberArrayToWordArray } from '@/assets/misc.js'
import checkoutPassphrase from "@/components/checkoutPassphrase.vue"
import services from '@/assets/serviceList.txt?raw'
const serviceOptions = services.split(/\r?\n/)
import serviceList from '@/assets/serviceList.json'
const stockArray = ref([])
const step = ref(0)
const selected = ref('')
const numberArray = ref([])
Expand All @@ -21,6 +21,41 @@ async function getPassphrase() {
const serviceInfo = computed(() => {
return { serviceType: '1service', service: selected.value}
})
async function getStock() {
const results = await axios.get('/.netlify/functions/get1ServiceStock')
stockArray.value = results.data
}
const servicePriceandStock = computed(() => {
let clone = JSON.parse(JSON.stringify(serviceList))
for (const item in clone) {
clone[item].stock = 0
}
for (const service in serviceList) {
for (const phone of stockArray.value) {
const usedServices = phone.sim1
const usedServices1 = phone.sim2
if (!usedServices.includes(service) && !usedServices.includes('all')) {
clone[service].stock +=1
}
if (!usedServices1.includes(service) && !usedServices1.includes('all')) {
clone[service].stock += 1
}
}
}
return clone
})
const serviceOptions = computed(() => {
const availableservices = []
const servicesArray = servicePriceandStock.value
for (const service in servicesArray) {
if(servicesArray[service].stock > 0)
availableservices.push(service)
}
return availableservices
})
onMounted(() => {
getStock()
})
</script>

<template>
Expand All @@ -32,12 +67,25 @@ const serviceInfo = computed(() => {
</div> -->
<div class="relative z-10">
<div class="flex flex-wrap items-center -m-8">
<div class="w-full md:w-1/2 p-8"><img src="https://res.cloudinary.com/dylevfpbl/image/upload/v1686249628/landingpage/image_4.png" alt=""></div>
<div class="w-full md:w-1/2 p-8">
<img v-if='step === 1' src="https://res.cloudinary.com/dylevfpbl/image/upload/v1686249628/landingpage/image_4.png" alt="">
<div class="md:max-w-md mx-auto text-center" v-if='step === 0'>
<h3 class="font-heading text-5xl text-white font-black tracking-tight mb-5">Supply and Pricing</h3>
<ul style="height: 40vh;" class="overflow-auto bg-gray-800 rounded-xl">
<li class="flex items-center px-3 py-5" v-for="(value, name, index) in servicePriceandStock">
<p class="text-gray-100 font-bold text-xl">{{name}}: ${{ value.price.toLocaleString("en", { useGrouping: false, minimumFractionDigits: 2 }) }} , stock: {{ value.stock }}</p>
</li>
<!-- <li class="flex items-center mb-4">
<svg class="mr-2.5" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.16699 10.8333L7.50033 14.1667L15.8337 5.83333" stroke="#3B82F6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg><p class="font-bold text-gray-100 text-xl">Access to Early Features First</p>
</li> -->
</ul>
</div>
</div>

<div class="w-full md:w-1/2 p-8 order-first md:order-last">
<div class="md:max-w-md mx-auto text-center" v-if='step === 0'>
<span class="inline-block mb-6 text-lg text-blue-500 font-bold uppercase tracking-widest">Purchase 1 Service Phone Rental</span>
<h2 class="font-heading text-6xl text-white font-black tracking-tight">$2/service</h2>
<h2 class="font-heading text-5xl md:text-6xl text-white font-black tracking-tight">$2/service</h2>
<p class="mb-8 mt-2 text-lg text-gray-700 font-bold">Verify One Service with 1 Day Access</p>
<ul class="text-left"><li class="flex items-center mb-4">
<svg class="mr-2.5" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.16699 10.8333L7.50033 14.1667L15.8337 5.83333" stroke="#3B82F6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg><p class="text-gray-100 font-bold text-xl">You Have 1 day to verify 1 service</p>
Expand Down
2 changes: 1 addition & 1 deletion src/views/landingpage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const messageArray = ref([])
<div class="w-full md:w-1/3 p-4">
<div class="flex flex-col justify-between p-8 h-full bg-gray-900 rounded-3xl">
<div class="flex-initial mb-6"><span class="inline-block mb-6 text-sm text-blue-500 font-bold uppercase tracking-widest">1 day and 1 Service</span>
<h2 class="font-heading text-4xl text-white font-black tracking-tight">$2/service</h2>
<h2 class="font-heading text-4xl text-white font-black tracking-tight">Starting at $1.50 a Service</h2>
<p class="mb-8 text-sm text-gray-700 font-bold">Verify One Service with 1 Day Access</p>
<ul><li class="flex items-center mb-4">
<svg class="mr-2.5" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.16699 10.8333L7.50033 14.1667L15.8337 5.83333" stroke="#3B82F6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg><p class="text-gray-100 font-bold">You Have 1 day to verify 1 service</p>
Expand Down

0 comments on commit b152ebe

Please sign in to comment.