Skip to content

Commit

Permalink
feat: added live stripe account id property
Browse files Browse the repository at this point in the history
  • Loading branch information
tiller1010 committed Dec 23, 2023
1 parent 93c17ae commit 46b66ff
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 62 deletions.
8 changes: 8 additions & 0 deletions app/getConnectedStripeAccountID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports.getConnectedStripeAccountID = (user) => {
const isLive = process.env.STRIPE_PUBLIC_KEY.match(/^pk_live_.*$/);
if (isLive) {
return user.connectedStripeAccountID_Live;
}
return user.connectedStripeAccountID;
};

17 changes: 10 additions & 7 deletions database/methods/premium-video-chat-listings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mongo = require('mongodb');
const createSearchService = require('../../app/search.js');
const { findUserByID } = require('./users.js');
const stripe = require('stripe')(process.env.STRIPE_SECRET || '');
const { getConnectedStripeAccountID } = require('../../app/getConnectedStripeAccountID.js');

function randomFilename() {
var text = "";
Expand All @@ -26,9 +27,10 @@ async function getRecentPremiumVideoChatListings(_){
let purchasablePremiumVideoChatListings = [];
for(listing of premiumVideoChatListings){
const user = await findUserByID(listing.userID);
if(user){
if(user.connectedStripeAccountID){
const account = await stripe.accounts.retrieve(user.connectedStripeAccountID);
if (user) {
const connectedStripeAccountID = getConnectedStripeAccountID(user);
if (connectedStripeAccountID) {
const account = await stripe.accounts.retrieve(connectedStripeAccountID);
if(account.charges_enabled && account.payouts_enabled){
purchasablePremiumVideoChatListings.push(listing);
}
Expand Down Expand Up @@ -56,8 +58,9 @@ async function searchPremiumVideoChatListings(_, { topic, languageOfTopic }){
for(listing of listings){
const user = await findUserByID(listing.userID);
if (user) {
if(user.connectedStripeAccountID){
const account = await stripe.accounts.retrieve(user.connectedStripeAccountID);
const connectedStripeAccountID = getConnectedStripeAccountID(user);
if (connectedStripeAccountID) {
const account = await stripe.accounts.retrieve(connectedStripeAccountID);
if(account.charges_enabled && account.payouts_enabled){
purchasablePremiumVideoChatListings.push(listing);
}
Expand Down Expand Up @@ -142,7 +145,7 @@ async function removePremiumVideoChatListing(_, { userID }){
await db.collection('premium_video_chat_listings').deleteOne({ _id: new mongo.ObjectID(originalUser.premiumVideoChatListing._id) });
return true;
}

return false;
}

Expand All @@ -153,4 +156,4 @@ module.exports = {
addPremiumVideoChatListingThumbnailTest,
updatePremiumVideoChatListing,
removePremiumVideoChatListing
};
};
9 changes: 8 additions & 1 deletion database/methods/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ async function verifyUser(_, {userID, verificationStatus}){

async function addStripeAccountIDToUser(userID, connectedStripeAccountID){
const db = getDB();
await db.collection('users').updateOne({ _id: new mongo.ObjectID(userID) }, { $set: { connectedStripeAccountID } });
const isLive = process.env.STRIPE_PUBLIC_KEY.match(/^pk_live_.*$/);
let connectedStripeAccountIDKey = 'connectedStripeAccountID';
if (isLive) {
connectedStripeAccountIDKey = 'connectedStripeAccountID_Live';
}
const updateQueryObject = {};
updateQueryObject[connectedStripeAccountIDKey] = connectedStripeAccountID;
await db.collection('users').updateOne({ _id: new mongo.ObjectID(userID) }, { $set: updateQueryObject });
const user = await findUserByID(userID);
return user;
}
Expand Down
1 change: 1 addition & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type User {
products: [Product!]
premiumVideoChatListing: PremiumVideoChatListing
connectedStripeAccountID: String
connectedStripeAccountID_Live: String
verifiedEmail: Boolean
}

Expand Down
8 changes: 5 additions & 3 deletions js/components/AccountProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PremiumVideoChatListingForm from './PremiumVideoChatListingForm.js';
import RemoveConfirmationModal from './RemoveConfirmationModal.js';
import TopicLink from './TopicLink.js';
import decipher from '../decipher.js';
import { getConnectedStripeAccountID } from '../getConnectedStripeAccountID.js';

class AccountProfile extends React.Component {
constructor(props){
Expand Down Expand Up @@ -168,6 +169,7 @@ class AccountProfile extends React.Component {
const authenticatedUserIsAdmin = authenticatedUser ? authenticatedUser.isAdmin : false;
const authenticatedUserIsVerified = authenticatedUser ? authenticatedUser.verified : false;
const products = this.state.user.products || [];
const connectedStripeAccountID = getConnectedStripeAccountID(authenticatedUser);

document.addEventListener('cssmodal:hide', () => {
this.setState({
Expand Down Expand Up @@ -256,19 +258,19 @@ class AccountProfile extends React.Component {
<>
<PremiumVideoChatListingForm user={authenticatedUser}/>
<p>
{authenticatedUser.connectedStripeAccountID ?
{connectedStripeAccountID ?
<>
{this.state.stripeAccountPending ?
<>
<p><b>!! Your Connected Stripe Account still needs to be completed, or is pending verification. !!</b></p>
<p>Your video chat listing will not be purchasable until your connected Stripe account is completed and verified.</p>
<a href={`/manage-stripe-account/${authenticatedUser.connectedStripeAccountID}`} className="button" style={{ display: 'block', margin: 'auto' }}>
<a href={`/manage-stripe-account/${connectedStripeAccountID}`} className="button" style={{ display: 'block', margin: 'auto' }}>
Complete Stripe Account
<FontAwesomeIcon icon={faUser}/>
</a>
</>
:
<a href={`/manage-stripe-account/${authenticatedUser.connectedStripeAccountID}`} className="button" style={{ display: 'block', margin: 'auto' }}>
<a href={`/manage-stripe-account/${connectedStripeAccountID}`} className="button" style={{ display: 'block', margin: 'auto' }}>
Manage Stripe Account
<FontAwesomeIcon icon={faUser}/>
</a>
Expand Down
2 changes: 1 addition & 1 deletion js/components/ForgotPasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/LessonSearchForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
10 changes: 6 additions & 4 deletions js/components/PremiumVideoChatListing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand All @@ -67,6 +67,7 @@ var stripe_js_1 = require("@stripe/stripe-js");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var graphQLFetch_js_1 = require("../graphQLFetch.js");
var getConnectedStripeAccountID_js_1 = require("../getConnectedStripeAccountID.js");
var PremiumVideoChatListing = /** @class */ (function (_super) {
__extends(PremiumVideoChatListing, _super);
function PremiumVideoChatListing(props) {
Expand Down Expand Up @@ -300,7 +301,7 @@ var PremiumVideoChatListing = /** @class */ (function (_super) {
};
PremiumVideoChatListing.prototype.handleBuyNow = function (e) {
return __awaiter(this, void 0, void 0, function () {
var _a, premiumVideoChatListing, authenticatedUserID, timeSlots, query, newTimeSlots_1, data, productUser, stripe_1;
var _a, premiumVideoChatListing, authenticatedUserID, timeSlots, query, newTimeSlots_1, data, productUser, connectedStripeAccountID, stripe_1;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
Expand Down Expand Up @@ -349,7 +350,8 @@ var PremiumVideoChatListing = /** @class */ (function (_super) {
.then(function (response) { return response.json(); })];
case 2:
productUser = _b.sent();
if (!productUser.connectedStripeAccountID) return [3 /*break*/, 4];
connectedStripeAccountID = (0, getConnectedStripeAccountID_js_1.getConnectedStripeAccountID)(productUser);
if (!connectedStripeAccountID) return [3 /*break*/, 4];
return [4 /*yield*/, (0, stripe_js_1.loadStripe)(process.env.STRIPE_PUBLIC_KEY || '')];
case 3:
stripe_1 = _b.sent();
Expand All @@ -358,7 +360,7 @@ var PremiumVideoChatListing = /** @class */ (function (_super) {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
priceID: data.createProduct.priceID,
connectedStripeAccountID: productUser.connectedStripeAccountID,
connectedStripeAccountID: connectedStripeAccountID,
})
})
.then(function (response) {
Expand Down
7 changes: 5 additions & 2 deletions js/components/PremiumVideoChatListing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadStripe } from '@stripe/stripe-js';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faPlus, faLongArrowAltRight, faClock, faFlag } from '@fortawesome/free-solid-svg-icons';
import graphQLFetch from '../graphQLFetch.js';
import { getConnectedStripeAccountID } from '../getConnectedStripeAccountID.js';

interface PremiumVideoChatListingObject {
_id: string
Expand Down Expand Up @@ -311,7 +312,9 @@ export default class PremiumVideoChatListing extends React.Component<PremiumVide
const productUser = await fetch(`/user/${premiumVideoChatListing.userID}`)
.then((response) => response.json());

if(productUser.connectedStripeAccountID){
const connectedStripeAccountID = getConnectedStripeAccountID(productUser);

if (connectedStripeAccountID) {

const stripe = await loadStripe(process.env.STRIPE_PUBLIC_KEY || '');

Expand All @@ -320,7 +323,7 @@ export default class PremiumVideoChatListing extends React.Component<PremiumVide
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
priceID: data.createProduct.priceID,
connectedStripeAccountID: productUser.connectedStripeAccountID,
connectedStripeAccountID,
})
})
.then(function(response) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/PremiumVideoChatListingFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/PremiumVideoChatListingForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
10 changes: 6 additions & 4 deletions js/components/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand All @@ -55,6 +55,7 @@ var React = require("react");
var stripe_js_1 = require("@stripe/stripe-js");
var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
var getConnectedStripeAccountID_js_1 = require("../getConnectedStripeAccountID.js");
var Product = /** @class */ (function (_super) {
__extends(Product, _super);
function Product(props) {
Expand Down Expand Up @@ -99,7 +100,7 @@ var Product = /** @class */ (function (_super) {
};
Product.prototype.handleCompletePurchase = function (e) {
return __awaiter(this, void 0, void 0, function () {
var product, productUser, stripe_1;
var product, productUser, connectedStripeAccountID, stripe_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Expand All @@ -115,7 +116,8 @@ var Product = /** @class */ (function (_super) {
.then(function (response) { return response.json(); })];
case 1:
productUser = _a.sent();
if (!productUser.connectedStripeAccountID) return [3 /*break*/, 3];
connectedStripeAccountID = (0, getConnectedStripeAccountID_js_1.getConnectedStripeAccountID)(productUser);
if (!connectedStripeAccountID) return [3 /*break*/, 3];
return [4 /*yield*/, (0, stripe_js_1.loadStripe)(process.env.STRIPE_PUBLIC_KEY || '')];
case 2:
stripe_1 = _a.sent();
Expand All @@ -124,7 +126,7 @@ var Product = /** @class */ (function (_super) {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
priceID: product.priceID,
connectedStripeAccountID: productUser.connectedStripeAccountID,
connectedStripeAccountID: connectedStripeAccountID,
})
})
.then(function (response) {
Expand Down
7 changes: 5 additions & 2 deletions js/components/Product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { loadStripe } from '@stripe/stripe-js';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faLongArrowAltRight } from '@fortawesome/free-solid-svg-icons';
import { getConnectedStripeAccountID } from '../getConnectedStripeAccountID.js';

interface ProductObject {
userID: string;
Expand Down Expand Up @@ -62,7 +63,9 @@ export default class Product extends React.Component<ProductProps, ProductState>
const productUser = await fetch(`/user/${product.productObject.userID}`)
.then((response) => response.json());

if(productUser.connectedStripeAccountID){
const connectedStripeAccountID = getConnectedStripeAccountID(productUser);

if (connectedStripeAccountID) {

const stripe = await loadStripe(process.env.STRIPE_PUBLIC_KEY || '');

Expand All @@ -71,7 +74,7 @@ export default class Product extends React.Component<ProductProps, ProductState>
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
priceID: product.priceID,
connectedStripeAccountID: productUser.connectedStripeAccountID,
connectedStripeAccountID,
})
})
.then(function(response) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/ProfileEditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/UserFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/VideoChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
2 changes: 1 addition & 1 deletion js/components/VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
Expand Down
14 changes: 14 additions & 0 deletions js/getConnectedStripeAccountID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConnectedStripeAccountID = void 0;
var getConnectedStripeAccountID = function (user) {
if (!user) {
return;
}
var isLive = process.env.STRIPE_PUBLIC_KEY.match(/^pk_live_.*$/);
if (isLive) {
return user.connectedStripeAccountID_Live;
}
return user.connectedStripeAccountID;
};
exports.getConnectedStripeAccountID = getConnectedStripeAccountID;
16 changes: 16 additions & 0 deletions js/getConnectedStripeAccountID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
interface User {
connectedStripeAccountID: string;
connectedStripeAccountID_Live: string;
}

export const getConnectedStripeAccountID = (user: User) => {
if (!user) {
return;
}
const isLive = process.env.STRIPE_PUBLIC_KEY.match(/^pk_live_.*$/);
if (isLive) {
return user.connectedStripeAccountID_Live;
}
return user.connectedStripeAccountID;
};

Loading

0 comments on commit 46b66ff

Please sign in to comment.