mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init stripe utils
This commit is contained in:
parent
412651e817
commit
416c3a4afc
8 changed files with 315 additions and 41 deletions
19
apps/api/poetry.lock
generated
19
apps/api/poetry.lock
generated
|
|
@ -3513,6 +3513,21 @@ anyio = ">=3.4.0,<5"
|
|||
[package.extras]
|
||||
full = ["httpx (>=0.22.0)", "itsdangerous", "jinja2", "python-multipart (>=0.0.7)", "pyyaml"]
|
||||
|
||||
[[package]]
|
||||
name = "stripe"
|
||||
version = "11.1.1"
|
||||
description = "Python bindings for the Stripe API"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
files = [
|
||||
{file = "stripe-11.1.1-py2.py3-none-any.whl", hash = "sha256:e79e02238d0ec7c89a64986af941dcae41e4857489b7cc83497acce9def356e5"},
|
||||
{file = "stripe-11.1.1.tar.gz", hash = "sha256:0bbdfe54a09728fc54db6bb099b2f440ffc111d07d9674b0f04bfd0d3c1cbdcf"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
requests = {version = ">=2.20", markers = "python_version >= \"3.0\""}
|
||||
typing-extensions = {version = ">=4.5.0", markers = "python_version >= \"3.7\""}
|
||||
|
||||
[[package]]
|
||||
name = "sympy"
|
||||
version = "1.13.3"
|
||||
|
|
@ -4281,4 +4296,8 @@ type = ["pytest-mypy"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.12"
|
||||
<<<<<<< HEAD
|
||||
content-hash = "f833ec3787697499d05e2aafb89bcb275b0d7468a6a4a33eb20cd139a21880d8"
|
||||
=======
|
||||
content-hash = "5d2f7ddfb277f39999b7798b9659c5bd2c2751ad667dbcab76a9d83fd6bdfa33"
|
||||
>>>>>>> 59f348e (feat: init stripe utils)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ chromadb = "^0.5.13"
|
|||
alembic = "^1.13.2"
|
||||
alembic-postgresql-enum = "^1.2.0"
|
||||
sqlalchemy-utils = "^0.41.2"
|
||||
stripe = "^11.1.1"
|
||||
|
||||
[build-system]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ from src.services.orgs.orgs import rbac_check
|
|||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from src.services.payments.stripe import archive_stripe_product, create_stripe_product, update_stripe_product
|
||||
|
||||
async def create_payments_product(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
|
|
@ -40,6 +42,11 @@ async def create_payments_product(
|
|||
new_product.creation_date = datetime.now()
|
||||
new_product.update_date = datetime.now()
|
||||
|
||||
# Create product in Stripe
|
||||
stripe_product = await create_stripe_product(request, org_id, new_product, current_user, db_session)
|
||||
new_product.provider_product_id = stripe_product.id
|
||||
|
||||
# Save to DB
|
||||
db_session.add(new_product)
|
||||
db_session.commit()
|
||||
db_session.refresh(new_product)
|
||||
|
|
@ -103,6 +110,9 @@ async def update_payments_product(
|
|||
db_session.commit()
|
||||
db_session.refresh(product)
|
||||
|
||||
# Update product in Stripe
|
||||
await update_stripe_product(request, org_id, product.provider_product_id, product, current_user, db_session)
|
||||
|
||||
return PaymentsProductRead.model_validate(product)
|
||||
|
||||
async def delete_payments_product(
|
||||
|
|
@ -127,6 +137,9 @@ async def delete_payments_product(
|
|||
if not product:
|
||||
raise HTTPException(status_code=404, detail="Payments product not found")
|
||||
|
||||
# Archive product in Stripe
|
||||
await archive_stripe_product(request, org_id, product.provider_product_id, current_user, db_session)
|
||||
|
||||
# Delete product
|
||||
db_session.delete(product)
|
||||
db_session.commit()
|
||||
|
|
@ -147,7 +160,7 @@ async def list_payments_products(
|
|||
await rbac_check(request, org.org_uuid, current_user, "read", db_session)
|
||||
|
||||
# Get payments products ordered by id
|
||||
statement = select(PaymentsProduct).where(PaymentsProduct.org_id == org_id).order_by(PaymentsProduct.id.desc())
|
||||
statement = select(PaymentsProduct).where(PaymentsProduct.org_id == org_id).order_by(PaymentsProduct.id.desc()) # type: ignore
|
||||
products = db_session.exec(statement).all()
|
||||
|
||||
return [PaymentsProductRead.model_validate(product) for product in products]
|
||||
|
|
|
|||
150
apps/api/src/services/payments/stripe.py
Normal file
150
apps/api/src/services/payments/stripe.py
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
from email.policy import default
|
||||
from fastapi import HTTPException, Request
|
||||
from sqlmodel import Session
|
||||
import stripe
|
||||
from src.db.payments.payments_products import PaymentProductTypeEnum, PaymentsProduct, PaymentsProductCreate
|
||||
from src.db.users import AnonymousUser, PublicUser
|
||||
from src.services.payments.payments import get_payments_config
|
||||
|
||||
|
||||
async def get_stripe_credentials(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
configs = await get_payments_config(request, org_id, current_user, db_session)
|
||||
|
||||
if len(configs) == 0:
|
||||
raise HTTPException(status_code=404, detail="Payments config not found")
|
||||
if len(configs) > 1:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Organization has multiple payments configs"
|
||||
)
|
||||
config = configs[0]
|
||||
if config.provider != "stripe":
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Payments config is not a Stripe config"
|
||||
)
|
||||
|
||||
# Get provider config
|
||||
credentials = config.provider_config
|
||||
|
||||
return credentials
|
||||
|
||||
async def create_stripe_product(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
product_data: PaymentsProduct,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
creds = await get_stripe_credentials(request, org_id, current_user, db_session)
|
||||
|
||||
# Set the Stripe API key using the credentials
|
||||
stripe.api_key = creds.get('stripe_secret_key')
|
||||
|
||||
## Create product
|
||||
|
||||
# Interval or one time
|
||||
if product_data.product_type == PaymentProductTypeEnum.SUBSCRIPTION:
|
||||
interval = "month"
|
||||
else:
|
||||
interval = None
|
||||
|
||||
# Prepare default_price_data
|
||||
default_price_data = {
|
||||
"currency": product_data.currency,
|
||||
"unit_amount": int(product_data.amount * 100) # Convert to cents
|
||||
}
|
||||
|
||||
if interval:
|
||||
default_price_data["recurring"] = {"interval": interval}
|
||||
|
||||
product = stripe.Product.create(
|
||||
name=product_data.name,
|
||||
description=product_data.description or "",
|
||||
marketing_features=[{"name": benefit.strip()} for benefit in product_data.benefits.split(",") if benefit.strip()],
|
||||
default_price_data=default_price_data # type: ignore
|
||||
)
|
||||
|
||||
return product
|
||||
|
||||
async def archive_stripe_product(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
product_id: str,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
creds = await get_stripe_credentials(request, org_id, current_user, db_session)
|
||||
|
||||
# Set the Stripe API key using the credentials
|
||||
stripe.api_key = creds.get('stripe_secret_key')
|
||||
|
||||
try:
|
||||
# Archive the product in Stripe
|
||||
archived_product = stripe.Product.modify(product_id, active=False)
|
||||
|
||||
return archived_product
|
||||
except stripe.StripeError as e:
|
||||
print(f"Error archiving Stripe product: {str(e)}")
|
||||
raise HTTPException(status_code=400, detail=f"Error archiving Stripe product: {str(e)}")
|
||||
|
||||
async def update_stripe_product(
|
||||
request: Request,
|
||||
org_id: int,
|
||||
product_id: str,
|
||||
product_data: PaymentsProduct,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
creds = await get_stripe_credentials(request, org_id, current_user, db_session)
|
||||
|
||||
# Set the Stripe API key using the credentials
|
||||
stripe.api_key = creds.get('stripe_secret_key')
|
||||
|
||||
try:
|
||||
|
||||
# Always create a new price
|
||||
new_price_data = {
|
||||
"currency": product_data.currency,
|
||||
"unit_amount": int(product_data.amount * 100), # Convert to cents
|
||||
"product": product_id,
|
||||
}
|
||||
|
||||
if product_data.product_type == PaymentProductTypeEnum.SUBSCRIPTION:
|
||||
new_price_data["recurring"] = {"interval": "month"}
|
||||
|
||||
new_price = stripe.Price.create(**new_price_data)
|
||||
|
||||
# Prepare the update data
|
||||
update_data = {
|
||||
"name": product_data.name,
|
||||
"description": product_data.description or "",
|
||||
"metadata": {"benefits": product_data.benefits},
|
||||
"marketing_features": [{"name": benefit.strip()} for benefit in product_data.benefits.split(",") if benefit.strip()],
|
||||
"default_price": new_price.id
|
||||
}
|
||||
|
||||
# Update the product in Stripe
|
||||
updated_product = stripe.Product.modify(product_id, **update_data)
|
||||
|
||||
|
||||
# Archive all existing prices for the product
|
||||
existing_prices = stripe.Price.list(product=product_id, active=True)
|
||||
for price in existing_prices:
|
||||
if price.id != new_price.id:
|
||||
stripe.Price.modify(price.id, active=False)
|
||||
|
||||
# Set the new price as the default price for the product
|
||||
updated_product = stripe.Product.modify(product_id, default_price=new_price.id)
|
||||
|
||||
return updated_product
|
||||
except stripe.StripeError as e:
|
||||
raise HTTPException(status_code=400, detail=f"Error updating Stripe product: {str(e)}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
import React, { useState } from 'react';
|
||||
'use client';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useOrg } from '@components/Contexts/OrgContext';
|
||||
import { SiStripe } from '@icons-pack/react-simple-icons'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext';
|
||||
import { getPaymentConfigs, createPaymentConfig, updatePaymentConfig } from '@services/payments/payments';
|
||||
import { getPaymentConfigs, createPaymentConfig, updatePaymentConfig, deletePaymentConfig } from '@services/payments/payments';
|
||||
import FormLayout, { ButtonBlack, Input, Textarea, FormField, FormLabelAndMessage, Flex } from '@components/StyledElements/Form/Form';
|
||||
import { Check, Edit } from 'lucide-react';
|
||||
import { Check, Edit, Trash2 } from 'lucide-react';
|
||||
import toast from 'react-hot-toast';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import Modal from '@components/StyledElements/Modal/Modal';
|
||||
import ConfirmationModal from '@components/StyledElements/ConfirmationModal/ConfirmationModal';
|
||||
import { Button } from '@components/ui/button';
|
||||
|
||||
const PaymentsConfigurationPage: React.FC = () => {
|
||||
const org = useOrg() as any;
|
||||
|
|
@ -37,6 +40,17 @@ const PaymentsConfigurationPage: React.FC = () => {
|
|||
setIsModalOpen(true);
|
||||
};
|
||||
|
||||
const deleteConfig = async () => {
|
||||
try {
|
||||
await deletePaymentConfig(org.id, stripeConfig.id, access_token);
|
||||
toast.success('Stripe configuration deleted successfully');
|
||||
mutate([`/payments/${org.id}/config`, access_token]);
|
||||
} catch (error) {
|
||||
console.error('Error deleting Stripe configuration:', error);
|
||||
toast.error('Failed to delete Stripe configuration');
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
|
|
@ -52,23 +66,44 @@ const PaymentsConfigurationPage: React.FC = () => {
|
|||
<h1 className="font-bold text-xl text-gray-800">Payments Configuration</h1>
|
||||
<h2 className="text-gray-500 text-md">Manage your organization payments configuration</h2>
|
||||
</div>
|
||||
<div className="flex flex-col py-4 px-6 rounded-lg light-shadow">
|
||||
<div className="flex flex-col rounded-lg light-shadow">
|
||||
{stripeConfig ? (
|
||||
<div className="flex items-center justify-between bg-white ">
|
||||
<div className="flex items-center justify-between bg-gradient-to-r from-indigo-500 to-purple-600 p-6 rounded-lg shadow-md">
|
||||
<div className="flex items-center space-x-3">
|
||||
<Check className="text-green-500" size={24} />
|
||||
<span className="text-lg font-semibold">Stripe is enabled</span>
|
||||
<SiStripe className="text-white" size={32} />
|
||||
<span className="text-xl font-semibold text-white">Stripe is enabled</span>
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
onClick={editConfig}
|
||||
className="flex items-center space-x-2 px-4 py-2 bg-white text-purple-700 text-sm rounded-full hover:bg-gray-100 transition duration-300"
|
||||
>
|
||||
<Edit size={16} />
|
||||
<span>Edit Configuration</span>
|
||||
</Button>
|
||||
<ConfirmationModal
|
||||
confirmationButtonText="Delete Configuration"
|
||||
confirmationMessage="Are you sure you want to delete the Stripe configuration? This action cannot be undone."
|
||||
dialogTitle="Delete Stripe Configuration"
|
||||
dialogTrigger={
|
||||
<Button className="flex items-center space-x-2 bg-red-500 text-white text-sm rounded-full hover:bg-red-600 transition duration-300">
|
||||
<Trash2 size={16} />
|
||||
<span>Delete Configuration</span>
|
||||
</Button>
|
||||
}
|
||||
functionToExecute={deleteConfig}
|
||||
status="warning"
|
||||
/>
|
||||
</div>
|
||||
<ButtonBlack onClick={editConfig} className="flex items-center space-x-2 bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition duration-300">
|
||||
<Edit size={16} />
|
||||
<span>Edit Configuration</span>
|
||||
</ButtonBlack>
|
||||
</div>
|
||||
) : (
|
||||
<ButtonBlack onClick={enableStripe} className="flex items-center space-x-2 bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition duration-300">
|
||||
<SiStripe size={16} />
|
||||
<span>Enable Stripe</span>
|
||||
</ButtonBlack>
|
||||
<Button
|
||||
onClick={enableStripe}
|
||||
className="flex items-center justify-center space-x-2 bg-gradient-to-r p-3 from-indigo-500 to-purple-600 text-white px-6 rounded-lg hover:from-indigo-600 hover:to-purple-700 transition duration-300 shadow-md"
|
||||
>
|
||||
<SiStripe size={24} />
|
||||
<span className="text-lg font-semibold">Enable Stripe</span>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -94,14 +129,36 @@ interface EditStripeConfigModalProps {
|
|||
}
|
||||
|
||||
const EditStripeConfigModal: React.FC<EditStripeConfigModalProps> = ({ orgId, configId, accessToken, isOpen, onClose }) => {
|
||||
const [stripeKey, setStripeKey] = useState('');
|
||||
const [stripePublishableKey, setStripePublishableKey] = useState('');
|
||||
const [stripeSecretKey, setStripeSecretKey] = useState('');
|
||||
const [stripeWebhookSecret, setStripeWebhookSecret] = useState('');
|
||||
|
||||
// Add this useEffect hook to fetch and set the existing configuration
|
||||
useEffect(() => {
|
||||
const fetchConfig = async () => {
|
||||
try {
|
||||
const config = await getPaymentConfigs(orgId, accessToken);
|
||||
const stripeConfig = config.find((c: any) => c.id === configId);
|
||||
if (stripeConfig && stripeConfig.provider_config) {
|
||||
setStripePublishableKey(stripeConfig.provider_config.stripe_publishable_key || '');
|
||||
setStripeSecretKey(stripeConfig.provider_config.stripe_secret_key || '');
|
||||
setStripeWebhookSecret(stripeConfig.provider_config.stripe_webhook_secret || '');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching Stripe configuration:', error);
|
||||
toast.error('Failed to load existing configuration');
|
||||
}
|
||||
};
|
||||
|
||||
if (isOpen) {
|
||||
fetchConfig();
|
||||
}
|
||||
}, [isOpen, orgId, configId, accessToken]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const stripe_config = {
|
||||
stripe_key: stripeKey,
|
||||
stripe_publishable_key: stripePublishableKey,
|
||||
stripe_secret_key: stripeSecretKey,
|
||||
stripe_webhook_secret: stripeWebhookSecret,
|
||||
};
|
||||
|
|
@ -123,16 +180,31 @@ const EditStripeConfigModal: React.FC<EditStripeConfigModalProps> = ({ orgId, co
|
|||
dialogContent={
|
||||
<FormLayout onSubmit={handleSubmit}>
|
||||
<FormField name="stripe-key">
|
||||
<FormLabelAndMessage label="Stripe Key" />
|
||||
<Input type="password" value={stripeKey} onChange={(e) => setStripeKey(e.target.value)} />
|
||||
<FormLabelAndMessage label="Stripe Publishable Key" />
|
||||
<Input
|
||||
type="text"
|
||||
value={stripePublishableKey}
|
||||
onChange={(e) => setStripePublishableKey(e.target.value)}
|
||||
placeholder="pk_test_..."
|
||||
/>
|
||||
</FormField>
|
||||
<FormField name="stripe-secret-key">
|
||||
<FormLabelAndMessage label="Stripe Secret Key" />
|
||||
<Input type="password" value={stripeSecretKey} onChange={(e) => setStripeSecretKey(e.target.value)} />
|
||||
<Input
|
||||
type="password"
|
||||
value={stripeSecretKey}
|
||||
onChange={(e) => setStripeSecretKey(e.target.value)}
|
||||
placeholder="sk_test_..."
|
||||
/>
|
||||
</FormField>
|
||||
<FormField name="stripe-webhook-secret">
|
||||
<FormLabelAndMessage label="Stripe Webhook Secret" />
|
||||
<Input type="password" value={stripeWebhookSecret} onChange={(e) => setStripeWebhookSecret(e.target.value)} />
|
||||
<Input
|
||||
type="password"
|
||||
value={stripeWebhookSecret}
|
||||
onChange={(e) => setStripeWebhookSecret(e.target.value)}
|
||||
placeholder="whsec_..."
|
||||
/>
|
||||
</FormField>
|
||||
<Flex css={{ marginTop: 25, justifyContent: 'flex-end' }}>
|
||||
<ButtonBlack type="submit" className="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition duration-300">
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import currencyCodes from 'currency-codes';
|
|||
import { useOrg } from '@components/Contexts/OrgContext';
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext';
|
||||
import useSWR, { mutate } from 'swr';
|
||||
import { getProducts, deleteProduct, updateProduct } from '@services/payments/products';
|
||||
import { getProducts, updateProduct, archiveProduct } from '@services/payments/products';
|
||||
import CreateProductForm from '@components/Dashboard/Payments/SubComponents/CreateProductForm';
|
||||
import { Plus, Trash2, Pencil, Info, RefreshCcw, SquareCheck, ChevronDown, ChevronUp } from 'lucide-react';
|
||||
import { Plus, Trash2, Pencil, Info, RefreshCcw, SquareCheck, ChevronDown, ChevronUp, Archive } from 'lucide-react';
|
||||
import Modal from '@components/StyledElements/Modal/Modal';
|
||||
import ConfirmationModal from '@components/StyledElements/ConfirmationModal/ConfirmationModal';
|
||||
import toast from 'react-hot-toast';
|
||||
|
|
@ -18,6 +18,7 @@ import { Formik, Form, Field, ErrorMessage } from 'formik';
|
|||
import * as Yup from 'yup';
|
||||
import { Label } from '@components/ui/label';
|
||||
import { Badge } from '@components/ui/badge';
|
||||
import { getPaymentConfigs } from '@services/payments/payments';
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string().required('Name is required'),
|
||||
|
|
@ -33,19 +34,32 @@ function PaymentsProductPage() {
|
|||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||
const [editingProductId, setEditingProductId] = useState<string | null>(null);
|
||||
const [expandedProducts, setExpandedProducts] = useState<{ [key: string]: boolean }>({});
|
||||
const [isStripeEnabled, setIsStripeEnabled] = useState(false);
|
||||
|
||||
const { data: products, error } = useSWR(
|
||||
() => org && session ? [`/payments/${org.id}/products`, session.data?.tokens?.access_token] : null,
|
||||
([url, token]) => getProducts(org.id, token)
|
||||
);
|
||||
|
||||
const handleDeleteProduct = async (productId: string) => {
|
||||
const { data: paymentConfigs, error: paymentConfigError } = useSWR(
|
||||
() => org && session ? [`/payments/${org.id}/config`, session.data?.tokens?.access_token] : null,
|
||||
([url, token]) => getPaymentConfigs(org.id, token)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (paymentConfigs) {
|
||||
const stripeConfig = paymentConfigs.find((config: any) => config.provider === 'stripe');
|
||||
setIsStripeEnabled(!!stripeConfig);
|
||||
}
|
||||
}, [paymentConfigs]);
|
||||
|
||||
const handleArchiveProduct = async (productId: string) => {
|
||||
try {
|
||||
await deleteProduct(org.id, productId, session.data?.tokens?.access_token);
|
||||
await archiveProduct(org.id, productId, session.data?.tokens?.access_token);
|
||||
mutate([`/payments/${org.id}/products`, session.data?.tokens?.access_token]);
|
||||
toast.success('Product deleted successfully');
|
||||
toast.success('Product archived successfully');
|
||||
} catch (error) {
|
||||
toast.error('Failed to delete product');
|
||||
toast.error('Failed to archive product');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,30 +100,31 @@ function PaymentsProductPage() {
|
|||
) : (
|
||||
<div className="flex flex-col h-full">
|
||||
<div className="flex justify-between items-start mb-2">
|
||||
<div className="flex space-x-2 items-center">
|
||||
<div className="flex flex-col space-y-1 items-start">
|
||||
<Badge className='w-fit flex items-center space-x-2' variant="outline">
|
||||
{product.product_type === 'subscription' ? <RefreshCcw size={12} /> : <SquareCheck size={12} />}
|
||||
<span className='text-sm'>{product.product_type}</span>
|
||||
<span className='text-sm'>{product.product_type === 'subscription' ? 'Subscription' : 'One-time payment'}</span>
|
||||
</Badge>
|
||||
<h3 className="font-bold text-lg">{product.name}</h3>
|
||||
</div>
|
||||
<div className="flex space-x-2">
|
||||
<button
|
||||
onClick={() => setEditingProductId(product.id)}
|
||||
className="text-blue-500 hover:text-blue-700"
|
||||
className={`text-blue-500 hover:text-blue-700 ${isStripeEnabled ? '' : 'opacity-50 cursor-not-allowed'}`}
|
||||
disabled={!isStripeEnabled}
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</button>
|
||||
<ConfirmationModal
|
||||
confirmationButtonText="Delete Product"
|
||||
confirmationMessage="Are you sure you want to delete this product?"
|
||||
dialogTitle={`Delete ${product.name}?`}
|
||||
confirmationButtonText="Archive Product"
|
||||
confirmationMessage="Are you sure you want to archive this product?"
|
||||
dialogTitle={`Archive ${product.name}?`}
|
||||
dialogTrigger={
|
||||
<button className="text-red-500 hover:text-red-700">
|
||||
<Trash2 size={16} />
|
||||
<Archive size={16} />
|
||||
</button>
|
||||
}
|
||||
functionToExecute={() => handleDeleteProduct(product.id)}
|
||||
functionToExecute={() => handleArchiveProduct(product.id)}
|
||||
status="warning"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -164,10 +179,14 @@ function PaymentsProductPage() {
|
|||
<p>No products available. Create a new product to get started.</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-center items-center py-10">
|
||||
<button
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
className="mb-4 flex items-center space-x-2 px-3 py-1.5 rounded-lg bg-gradient-to-bl text-white font-medium from-gray-700 to-gray-900 border border-gray-600 shadow-gray-900/20 nice-shadow hover:from-gray-600 hover:to-gray-800 transition duration-300"
|
||||
className={`mb-4 flex items-center space-x-2 px-3 py-1.5 rounded-lg bg-gradient-to-bl text-white font-medium from-gray-700 to-gray-900 border border-gray-600 shadow-gray-900/20 nice-shadow transition duration-300 ${
|
||||
isStripeEnabled ? 'hover:from-gray-600 hover:to-gray-800' : 'opacity-50 cursor-not-allowed'
|
||||
}`}
|
||||
disabled={!isStripeEnabled}
|
||||
>
|
||||
<Plus size={18} />
|
||||
<span className="text-sm font-bold">Create New Product</span>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export async function createPaymentConfig(orgId: number, data: any, access_token
|
|||
|
||||
export async function updatePaymentConfig(orgId: number, id: string, data: any, access_token: string) {
|
||||
const result = await fetch(
|
||||
`${getAPIUrl()}payments/${orgId}/config`,
|
||||
`${getAPIUrl()}payments/${orgId}/config?id=${id}`,
|
||||
RequestBodyWithAuthHeader('PUT', data, null, access_token)
|
||||
);
|
||||
const res = await errorHandling(result);
|
||||
|
|
@ -30,7 +30,7 @@ export async function updatePaymentConfig(orgId: number, id: string, data: any,
|
|||
|
||||
export async function deletePaymentConfig(orgId: number, id: string, access_token: string) {
|
||||
const result = await fetch(
|
||||
`${getAPIUrl()}payments/${orgId}/config/${id}`,
|
||||
`${getAPIUrl()}payments/${orgId}/config?id=${id}`,
|
||||
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
|
||||
);
|
||||
const res = await errorHandling(result);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export async function updateProduct(orgId: number, productId: string, data: any,
|
|||
return res;
|
||||
}
|
||||
|
||||
export async function deleteProduct(orgId: number, productId: string, access_token: string) {
|
||||
export async function archiveProduct(orgId: number, productId: string, access_token: string) {
|
||||
const result = await fetch(
|
||||
`${getAPIUrl()}payments/${orgId}/products/${productId}`,
|
||||
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue