added fav event in calendar events and added stripe connect onboarding
This commit is contained in:
@@ -85,9 +85,9 @@ class EventEditAPIView(APIView):
|
||||
data=serializer.data,
|
||||
)
|
||||
|
||||
def put(self, request, pk, format=None):
|
||||
def patch(self, request, pk, format=None):
|
||||
event = self.get_object(pk)
|
||||
serializer = CreateEventSerializer(event, data=request.data)
|
||||
serializer = CreateEventSerializer(event, data=request.data, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return ApiResponse.success(
|
||||
@@ -780,8 +780,14 @@ class PrincipalEventsInteractionView(APIView):
|
||||
interactions = EventPrincipalInteraction.objects.filter(
|
||||
principal=principal
|
||||
).prefetch_related("event")
|
||||
favorite_events = Favorites.objects.filter(
|
||||
principal=principal
|
||||
).prefetch_related("event")
|
||||
|
||||
event_ids = set(interaction.event.id for interaction in interactions) | set(
|
||||
favorite.event.id for favorite in favorite_events
|
||||
)
|
||||
|
||||
event_ids = [interaction.event_id for interaction in interactions]
|
||||
events = Event.objects.filter(id__in=event_ids).order_by("-start_date")
|
||||
events = list(
|
||||
events
|
||||
|
||||
@@ -58,3 +58,16 @@ class TransactionAdmin(admin.ModelAdmin):
|
||||
)
|
||||
list_filter = ("transaction_type", "transaction_status")
|
||||
search_fields = ["order_id"]
|
||||
|
||||
|
||||
@admin.register(models.StripeConnectAccount)
|
||||
class StripeConnectAccountAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"id",
|
||||
"principal",
|
||||
"stripe_connect_id",
|
||||
"charges_enabled",
|
||||
"transfers_enabled",
|
||||
"details_submitted",
|
||||
)
|
||||
search_fields = ("principal__name", "stripe_connect_id")
|
||||
|
||||
@@ -13,4 +13,6 @@ urlpatterns = [
|
||||
),
|
||||
path("get-wallet/", views.GetWallet.as_view(), name="get_wallet"),
|
||||
path("get-transaction/", views.TransactionView.as_view(), name="transactions"),
|
||||
|
||||
path("create-stripe-connect/", views.CreateStripeConnectAccount.as_view(), name="stripe_connect"),
|
||||
]
|
||||
|
||||
@@ -270,3 +270,55 @@ class TestWebhookAPIWithdraw(APIView):
|
||||
"message": "Webhook received, but payment failed",
|
||||
}
|
||||
return ApiResponse.success(**intent_response)
|
||||
|
||||
|
||||
class CreateStripeConnectAccount(APIView):
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def post(self, request):
|
||||
stripe.api_key = settings.STRIPE_SECRET_KEY
|
||||
|
||||
# country_code = request.data.get("country_code")
|
||||
try:
|
||||
account = stripe.Account.create(
|
||||
country="GB",
|
||||
email=request.user.email,
|
||||
type="express",
|
||||
capabilities={
|
||||
"card_payments": {"requested": True},
|
||||
"transfers": {"requested": True},
|
||||
},
|
||||
business_type="individual",
|
||||
business_profile={
|
||||
"name": request.user.first_name,
|
||||
"support_email": request.user.email,
|
||||
},
|
||||
tos_acceptance={"service_agreement": "recipient"},
|
||||
)
|
||||
except Exception as e:
|
||||
exception_response = {
|
||||
"status": status.HTTP_400_BAD_REQUEST,
|
||||
"message": constants.FAILURE,
|
||||
"errors": str(e),
|
||||
}
|
||||
return ApiResponse.error(**exception_response)
|
||||
|
||||
link = stripe.AccountLink.create(
|
||||
account=account.id,
|
||||
refresh_url=request.build_absolute_uri("/subscriptions/success/"),
|
||||
return_url=request.build_absolute_uri("/subscriptions/cancel/"),
|
||||
type="account_onboarding",
|
||||
)
|
||||
|
||||
models.StripeConnectAccount.objects.create(
|
||||
principal=request.user,
|
||||
stripe_connect_id=account.id,
|
||||
)
|
||||
|
||||
intent_response = {
|
||||
"data": link.url,
|
||||
"status": status.HTTP_200_OK,
|
||||
"message": "Link Sent",
|
||||
}
|
||||
return ApiResponse.success(**intent_response)
|
||||
|
||||
71
manage_wallets/migrations/0006_stripeconnectaccount.py
Normal file
71
manage_wallets/migrations/0006_stripeconnectaccount.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# Generated by Django 5.0.2 on 2024-03-21 08:04
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
(
|
||||
"manage_wallets",
|
||||
"0005_transaction_coin_alter_transaction_payment_method_and_more",
|
||||
),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="StripeConnectAccount",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("active", models.BooleanField(default=True)),
|
||||
("deleted", models.BooleanField(default=False)),
|
||||
("created_on", models.DateTimeField(auto_now_add=True)),
|
||||
("modified_on", models.DateTimeField(auto_now=True)),
|
||||
("stripe_connect_id", models.CharField(max_length=255, unique=True)),
|
||||
("charges_enabled", models.BooleanField(default=False)),
|
||||
("transfers_enabled", models.BooleanField(default=False)),
|
||||
("details_submitted", models.BooleanField(default=False)),
|
||||
(
|
||||
"created_by",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="%(class)s_created",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"modified_by",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="%(class)s_modified",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
(
|
||||
"principal",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"db_table": "stripe_connect",
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -88,3 +88,17 @@ class Transaction(BaseModel):
|
||||
|
||||
def __str__(self):
|
||||
return f"principal: {self.principal}, type: {self.transaction_type}, status: {self.transaction_status}, amount: {self.amount}"
|
||||
|
||||
|
||||
class StripeConnectAccount(BaseModel):
|
||||
principal = models.ForeignKey(IAmPrincipal, on_delete=models.CASCADE)
|
||||
stripe_connect_id = models.CharField(max_length=255, unique=True)
|
||||
charges_enabled = models.BooleanField(default=False)
|
||||
transfers_enabled = models.BooleanField(default=False)
|
||||
details_submitted = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "stripe_connect"
|
||||
|
||||
def __str__(self):
|
||||
return f"principal: {self.principal}, type: {self.stripe_connect_id}"
|
||||
|
||||
Reference in New Issue
Block a user