Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
Develop

See merge request locker/api-core!384
  • Loading branch information
phuongntt-cystack committed Feb 23, 2024
2 parents 3dffa78 + fd223a6 commit 54f37aa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions locker_server/api/v1_0/sync/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def sync(self, request, *args, **kwargs):
paging_param = self.request.query_params.get("paging", "0")
page_size_param = self.check_int_param(self.request.query_params.get("size", 50))
page_param = self.check_int_param(self.request.query_params.get("page", 1))
page_param = page_param if page_param is not None else 1

# Get sync data from cache
cache_key = self.user_service.get_sync_cache_key(user_id=user.user_id, page=page_param, size=page_size_param)
Expand Down Expand Up @@ -175,6 +176,7 @@ def sync_ciphers(self, request, *args, **kwargs):
paging_param = self.request.query_params.get("paging", "0")
page_size_param = self.check_int_param(self.request.query_params.get("size", 50))
page_param = self.check_int_param(self.request.query_params.get("page", 1))
page_param = page_param if page_param is not None else 1
ciphers_filter = {
"collection_id": self.request.query_params.get("collection_id")
}
Expand Down
7 changes: 6 additions & 1 deletion locker_server/api/v1_micro_service/mobile_payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ def upgrade_plan(self, request, *args, **kwargs):
except UserDoesNotExistException:
raise ValidationError(detail={"user_id": ["User does not exist"]})

is_first_annual = self.payment_service.is_first_payment(user_id=user_id, **{
"plans": [PLAN_TYPE_PM_PREMIUM, PLAN_TYPE_PM_FAMILY],
"durations": [DURATION_YEARLY]
})
return Response(status=status.HTTP_200_OK, data={
"success": True,
"scope": new_payment.scope,
"payment_id": new_payment.payment_id
"payment_id": new_payment.payment_id,
"is_first_annual": is_first_annual,
})

@action(methods=["post"], detail=False)
Expand Down
8 changes: 7 additions & 1 deletion locker_server/api/v1_micro_service/payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ def webhook_create(self, request, *args, **kwargs):
)
else:
enterprise_billing_contacts = []
user_id = new_payment.user.user_id
is_first_annual = self.payment_service.is_first_payment(user_id=user_id, **{
"plans": [PLAN_TYPE_PM_PREMIUM, PLAN_TYPE_PM_FAMILY],
"durations": [DURATION_YEARLY]
})
return Response(status=status.HTTP_200_OK, data={
"success": True,
"user_id": new_payment.user.user_id,
"user_id": user_id,
"status": new_payment.status,
"paid": True if new_payment.status == PAYMENT_STATUS_PAID else False,
"scope": new_payment.scope,
Expand All @@ -66,6 +71,7 @@ def webhook_create(self, request, *args, **kwargs):
"customer": new_payment.get_customer_dict(),
"payment_method": new_payment.payment_method,
"payment_data": payment_data,
"is_first_annual": is_first_annual,
"cc": enterprise_billing_contacts
})

Expand Down
13 changes: 13 additions & 0 deletions locker_server/api_orm/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ def count_referral_payments(self, referral_user_ids: List[int]) -> int:
status__in=[PAYMENT_STATUS_PAID], user_id__in=referral_user_ids
).count()

def is_first_payment(self, user_id: int, **filter_params) -> bool:
exclude_total_0 = filter_params.get("exclude_total_0", True)
plans_param = filter_params.get("plans", [])
durations = filter_params.get("durations", [])
payments = PaymentORM.objects.filter(user_id=user_id)
if exclude_total_0 is True:
payments = payments.exclude(total_price=0)
if plans_param:
payments = payments.filter(plan__in=plans_param)
if durations:
payments = payments.filter(duration__in=durations)
return payments.count() == 1

# ------------------------ Create Payment resource --------------------- #
def create_payment(self, **payment_data) -> Optional[Payment]:
payment_orm = PaymentORM.create(**payment_data)
Expand Down
4 changes: 4 additions & 0 deletions locker_server/core/repositories/payment_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def check_promo_code(self, user_id: int, code: str, new_duration: str = None,
def count_referral_payments(self, referral_user_ids: List[int]) -> int:
pass

@abstractmethod
def is_first_payment(self, user_id: int, **filter_params) -> bool:
pass

# ------------------------ Create Payment resource --------------------- #
@abstractmethod
def create_payment(self, **payment_data) -> Optional[Payment]:
Expand Down
3 changes: 3 additions & 0 deletions locker_server/core/services/payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,6 @@ def create_payment(self, **payment_data) -> Payment:

def update_payment(self, payment: Payment, update_data) -> Payment:
return self.payment_repository.update_payment(payment=payment, update_data=update_data)

def is_first_payment(self, user_id: int, **filter_params) -> bool:
return self.payment_repository.is_first_payment(user_id=user_id, **filter_params)

0 comments on commit 54f37aa

Please sign in to comment.