import React, { useState, useEffect } from "react"; import ReactGA from 'react-ga4'; import theme from "../theme.jsx"; import { useTheme } from "@mui/styles"; import countries from "../components/Countries.jsx"; import { Box, Paper, Typography, Divider, Button, Grid, Card, List, ListItemText, ListItem, Dialog, DialogTitle, DialogContent, TextField, InputAdornment, IconButton, Checkbox, Tooltip, } from "@mui/material"; import { useNavigate, Link } from "react-router-dom"; import { Autocomplete } from "@mui/material"; import { toast } from "react-toastify" import { Cached as CachedIcon, ContentCopy as ContentCopyIcon, Draw as DrawIcon, Close as CloseIcon, } from "@mui/icons-material"; //import { useAlert import { typecost, typecost_single, } from "../views/HandlePaymentNew.jsx"; import BillingStats from "../components/BillingStats.jsx"; const Billing = (props) => { const { globalUrl, userdata, serverside, billingInfo, stripeKey, selectedOrganization, handleGetOrg, } = props; //const alert = useAlert(); let navigate = useNavigate(); const [selectedDealModalOpen, setSelectedDealModalOpen] = React.useState(false); const [dealList, setDealList] = React.useState([]); const [dealName, setDealName] = React.useState(""); const [dealAddress, setDealAddress] = React.useState(""); const [dealType, setDealType] = React.useState("MSSP"); const [dealCountry, setDealCountry] = React.useState("United States"); const [dealCurrency, setDealCurrency] = React.useState("USD"); const [dealStatus, setDealStatus] = React.useState("initiated"); const [dealValue, setDealValue] = React.useState(""); const [dealDiscount, setDealDiscount] = React.useState(""); const [dealerror, setDealerror] = React.useState(""); const stripe = typeof window === 'undefined' || window.location === undefined ? "" : props.stripeKey === undefined ? "" : window.Stripe ? window.Stripe(props.stripeKey) : "" const products = [ { code: "", label: "MSSP", phone: "" }, { code: "", label: "Enterprise", phone: "" }, { code: "", label: "Consultancy", phone: "" }, { code: "", label: "Support", phone: "" }, ]; const handleGetDeals = (orgId) => { console.log("Get deals!"); if (orgId.length === 0) { toast( "Organization ID not defined (get deals). Please contact us on https://shuffler.io if this persists logout." ); return; } const url = `${globalUrl}/api/v1/orgs/${orgId}/deals`; fetch(url, { method: "GET", credentials: "include", headers: { "Content-Type": "application/json", }, }) .then((response) => { if (response.status !== 200) { console.log("Bad status code in get deals: ", response.status); } return response.json(); }) .then((responseJson) => { console.log("Got deals: ", responseJson); if (responseJson.success === false) { toast("Failed loading deals. Contact support if this persists"); } else { setDealList(responseJson); } }) .catch((error) => { console.log("Error getting org deals: ", error); toast( "Failed getting deals for your org. Contact support if this persists." ); }); }; useEffect(() => { if (isCloud && selectedOrganization.partner_info !== undefined && selectedOrganization.partner_info.reseller === true) { handleGetDeals(selectedOrganization.id); } }, []) const paperStyle = { padding: 20, height: "100%", minHeight: 280, maxWidth: 400, width: "100%", backgroundColor: theme.palette.surfaceColor, borderRadius: theme.palette.borderRadius, border: "1px solid rgba(255,255,255,0.3)", marginRight: 10, } const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"; billingInfo.subscription = { "active": true, "name": "Pay as you go", "price": typecost_single, "currency": "USD", "currency_text": "$", "interval": "app run / month", "description": "Pay as you go", "features": [ "Includes 10.000 app run/month for free. ", "Pay for what you use with no minimum commitment and cancel anytime.", ], "limit": 10000, } const handleStripeRedirect = () => { //var priceItem = "price_1MRNF1DzMUgUjxHSfFTUb2Xh" if (stripe == "") { console.log("Stripe not loaded") return } var priceItem = "price_1MROFrDzMUgUjxHShcSxgHO1" const successUrl = `${window.location.origin}/admin?admin_tab=billing&payment=success` const failUrl = `${window.location.origin}/admin?admin_tab=billing&payment=failure` var checkoutObject = { lineItems: [ { price: priceItem, quantity: 1 }, ], mode: "subscription", billingAddressCollection: "auto", successUrl: successUrl, cancelUrl: failUrl, clientReferenceId: props.userdata.active_org.id, } //submitType: "donate", stripe.redirectToCheckout(checkoutObject) .then(function (result) { console.log("SUCCESS STRIPE?: ", result) ReactGA.event({ category: "pricing", action: "add_card_success", label: "", }) }) .catch(function(error) { console.error("STRIPE ERROR: ", error) ReactGA.event({ category: "pricing", action: "add_card_error", label: "", }) }); } const cancelSubscriptions = (subscription_id) => { const orgId = selectedOrganization.id; const data = { subscription_id: subscription_id, action: "cancel", org_id: selectedOrganization.id, }; const url = globalUrl + `/api/v1/orgs/${orgId}/cancel`; fetch(url, { mode: "cors", method: "POST", body: JSON.stringify(data), credentials: "include", crossDomain: true, withCredentials: true, headers: { "Content-Type": "application/json; charset=utf-8", }, }) .then(function (response) { if (response.status !== 200) { console.log("Error in response"); } if (handleGetOrg != undefined) { handleGetOrg(selectedOrganization.id); } return response.json(); }) .then(function (responseJson) { if (responseJson.success !== undefined && responseJson.success) { toast("Successfully stopped subscription!"); } else { toast("Failed stopping subscription. Please contact us."); } }) .catch(function (error) { console.log("Error: ", error); toast("Failed stopping subscription. Please contact us."); }); }; const sendSignatureRequest = (subscription) => { const url = `${globalUrl}/api/v1/orgs/${selectedOrganization.id}`; fetch(url, { body: JSON.stringify({ org_id: selectedOrganization.id, subscription: subscription, }), mode: "cors", method: "POST", credentials: "include", crossDomain: true, withCredentials: true, headers: { "Content-Type": "application/json; charset=utf-8", }, }) .then((response) => { if (response.status !== 200) { console.log("Error in response"); } return response.json(); }) .then((responseJson) => { console.log("Response from signature request: ", responseJson); }) .catch((error) => { console.log("Error: ", error); }) } const SubscriptionObject = (props) => { const { globalUrl, index, userdata, serverside, billingInfo, stripeKey, selectedOrganization, handleGetOrg, subscription, highlight, } = props; const [signatureOpen, setSignatureOpen] = React.useState(false); const [tosChecked, setTosChecked] = React.useState(subscription.eula_signed) var top_text = "Base Cloud Access" if (subscription.limit === undefined && subscription.level === undefined || subscription.level === null || subscription.level === 0) { subscription.name = "Enterprise" subscription.currency_text = "$" subscription.price = subscription.level*180 subscription.limit = subscription.level*100000 subscription.interval = subscription.recurrence subscription.features = [ "Includes " + subscription.limit + " app runs/month. ", "Multi-Tenancy and Region-Selection", "And all other features from /pricing", ] } var newPaperstyle = JSON.parse(JSON.stringify(paperStyle)) if (subscription.name === "Enterprise" && subscription.active === true) { top_text = "Current Plan" newPaperstyle.border = "1px solid #f85a3e" } var showSupport = false if (subscription.name.includes("default")) { top_text = "Custom Contract" newPaperstyle.border = "1px solid #f85a3e" showSupport = true } if (subscription.name.includes("App Run Units")) { top_text = "Cloud Access" showSupport = true } if (subscription.name.includes("Open Source")) { top_text = "Open Source" showSupport = true } if (subscription.name.includes("Scale")) { top_text = "Scale access" } if (highlight === true) { // Add an "Upgrade now" button newPaperstyle.border = "1px solid #f85a3e" } return ( { e.preventDefault(); setSignatureOpen(false); setTosChecked(false) }} > Read and Accept the EULA { setTosChecked(e.target.checked) }} inputProps={{ 'aria-label': 'primary checkbox' }} /> { setTosChecked(!tosChecked) }}> Accept By clicking the “accept” button, you are signing the document, electronically agreeing that it has the same legal validity and effects as a handwritten signature, and that you have the competent authority to represent and sign on behalf an entity. Need support or have questions? Contact us at support@shuffler.io.
{top_text} {isCloud && highlight === true ? { setSignatureOpen(true) }} > : null}
{subscription.name} {subscription.currency_text !== undefined ?
{subscription.currency_text}{subscription.price} / {subscription.interval}
: null} Features
    {subscription.features !== undefined && subscription.features !== null ? subscription.features.map((feature, index) => { var parsedFeature = feature if (feature.includes("Documentation: ")) { parsedFeature = Documentation to get started } if (feature.includes("Worker License: ")) { const fieldId = "webhook_uri_field_"+index parsedFeature = Use the {feature.split("Worker License: ")[0]} Worker {}} InputProps={{ endAdornment: { var copyText = document.getElementById(fieldId); if (copyText !== undefined && copyText !== null) { console.log("NAVIGATOR: ", navigator); const clipboard = navigator.clipboard; if (clipboard === undefined) { toast("Can only copy over HTTPS (port 3443)"); return; } navigator.clipboard.writeText(copyText.value); copyText.select(); copyText.setSelectionRange( 0, 99999 ); /* For mobile devices */ /* Copy the text inside the text field */ document.execCommand("copy"); toast("Copied Webhook URL"); } else { console.log("Couldn't find webhook URI field: ", copyText); } }} edge="end" > }} fullWidth /> } return (
  • {parsedFeature}
  • ) }) : null}
{(highlight === true && (subscription.name === "Pay as you go" && subscription.limit <= 10000) || subscription.name === "Open Source") ? {subscription.name.includes("Scale") ? "" : "You are not subscribed to any plan and are using the free plan with max 10,000 app runs per month. Upgrade to deactivate this limit." } {/*isCloud ? : null*/} : null} {showSupport ? : null }
) } const addDealModal = ( { setSelectedDealModalOpen(false); }} PaperProps={{ style: { backgroundColor: theme.palette.surfaceColor, color: "white", minWidth: "800px", minHeight: "320px", }, }} > Register new deal
{ setDealName(e.target.value); }} /> { setDealAddress(e.target.value); }} />
{ setDealValue(e.target.value); }} /> option.label} onChange={(event, newValue) => { setDealCountry(newValue.label); }} renderOption={(props, option) => ( img": { mr: 2, flexShrink: 0 } }} {...props} > {option.label} ({option.code}) +{option.phone} )} renderInput={(params) => ( )} /> { setDealType(newValue); }} getOptionLabel={(option) => option.label} renderOption={(props, option) => ( img": { mr: 2, flexShrink: 0 } }} {...props} > {option.label} )} renderInput={(params) => ( )} />
{dealerror.length > 0 ? ( error registering: {dealerror} ) : null}
); const submitDeal = (dealName, dealAddress, dealCountry, dealValue) => { if (dealerror.length > 0) { setDealerror(""); } const orgId = selectedOrganization.id; const data = { reseller_org: orgId, name: dealName, address: dealAddress, country: dealCountry, value: dealValue, }; const url = `${globalUrl}/api/v1/orgs/${orgId}/deals`; fetch(url, { mode: "cors", method: "POST", body: JSON.stringify(data), credentials: "include", crossDomain: true, withCredentials: true, headers: { "Content-Type": "application/json; charset=utf-8", }, }) .then(function (response) { if (response.status !== 200) { console.log("Error in response"); } return response.json(); }) .then(function (responseJson) { if (responseJson.success === true) { setSelectedDealModalOpen(false); toast( "Added new deal! We will be in touch shortly with an update." ); setDealName(""); setDealAddress(""); setDealValue(""); setDealCountry("United States"); setDealType("MSSP"); } else { setDealerror(responseJson.reason); } }) .catch(function (error) { //console.log("Error: ", error); setDealerror(error.toString()); toast("Failed adding deal reg: ", error); }); }; const isChildOrg = userdata.active_org.creator_org !== "" && userdata.active_org.creator_org !== undefined && userdata.active_org.creator_org !== null return (
{addDealModal} Billing {isCloud ? "We use Stripe to manage subscriptions and do not store any of your billing information. You can manage your subscription and billing information below." : "Shuffle is an Open Source automation platform, and no license is required to use it. You may however activate Cloud Sync, get our Scale license, get help with Kubernetes, or talk to Shuffle's Support team to get automation help." } {userdata.support === true ?
For sales: Create  New Cloud Contract  or  New Onprem Contract   -   Google Drive Link   -   Sales Process
: null } {isChildOrg ? Billing is handled by your parent organisation. Reach out to support@shuffler.io if you have questions about this. : null}
{isCloud && billingInfo.subscription !== undefined && billingInfo.subscription !== null ? isChildOrg ? null : : !isCloud ? : null} {isCloud && selectedOrganization.subscriptions !== undefined && selectedOrganization.subscriptions !== null && selectedOrganization.subscriptions.length > 0 && !isChildOrg ? selectedOrganization.subscriptions .reverse() .map((sub, index) => { return ( ) }) : null} {/* Quantity: {sub.level}
Recurrence: {sub.recurrence}
{sub.active ? (
Started:{" "} {new Date(sub.startdate * 1000).toISOString()}
) : (
Cancelled:{" "} {new Date( sub.cancellationdate * 1000 ).toISOString()}
Status: Deactivated
)} */}
{isCloud && selectedOrganization.partner_info !== undefined && selectedOrganization.partner_info.reseller === true ? (
Reseller dashboard {dealList.length === 0 ? ( No deals registered yet. Click "Add deal" to register one ) : ( dealList.map((deal, index) => { var bgColor = "#27292d"; if (index % 2 === 0) { bgColor = "#1f2023"; } return ( ); }) )}
) : null}
Utilization & Stats
) } export default Billing;