Notifications Testing 1

This commit is contained in:
rizwanisready
2024-05-05 01:03:11 +05:30
parent 9cd8bdcce6
commit 492a3d4f82

View File

@@ -25,6 +25,40 @@ import logging
logger = logging.getLogger(__name__)
class NotificationService:
def __init__(self):
self.client = OneSignalClient(
app_id=settings.ONE_SIGNAL_APP_ID, rest_api_key=settings.ONE_SIGNAL_API_KEY
)
def send_notification(self, title, message, player_id):
notification_payload = {
"headings": {"en": title},
"contents": {"en": message},
"include_player_ids": [player_id],
}
response = self.client.send_notification(notification_payload)
return response
def payment_success_notification(self, principal, subscription, amount):
print("payment_success_notification: ", principal.player_id)
title = "Payment Successful"
message = f"Your payment for {subscription} of ${amount} was successfully processed. Your subscription is valid till {subscription.end_date}"
self.send_notification(title, message, principal.player_id)
def referral_received_notification(self, principal, amount, email):
print("referral_received_notification: ", principal.player_id)
title = "Congratulations! You got a referral G-Token."
message = f"Your referral {email} has subscribed to GoodTimesApp. You have received {amount} (£)"
self.send_notification(title, message, principal.player_id)
def payment_failed_notification(self, principal, subscription, amount):
print("payment_failed_notification: ", principal.player_id)
title = "Payment Failed!"
message = f"Your payment for {subscription} of ${amount} was failed."
self.send_notification(title, message, principal.player_id)
class WebhookService:
def __init__(self, webhook_data):
self.webhook_data = webhook_data
@@ -66,7 +100,7 @@ class WebhookService:
class ReferralRewardService:
def __init__(self, principal, principal_subscription, subscription):
# self.notification_service = NotificationService()
self.notification_service = NotificationService()
self.principal = principal
self.principal_subscription = principal_subscription
self.subscription = subscription
@@ -102,9 +136,9 @@ class ReferralRewardService:
value=amount,
)
self._credit_transaction(referral_record.referrer_principal, amount)
# self.notification_service.referral_received_notification(
# referral_record.referrer_principal, amount, self.principal.email
# )
self.notification_service.referral_received_notification(
referral_record.referrer_principal, amount, self.principal.email
)
def _credit_transaction(self, referrer_principal, amount):
print("_credit_transaction: ", referrer_principal)
@@ -185,7 +219,7 @@ class SubscriptionService:
class PaymentProcessingService:
def __init__(self, webhook_data):
self.webhook_service = WebhookService(webhook_data)
# self.notification_service = NotificationService()
self.notification_service = NotificationService()
# Retrieve objects
self.principal = self.webhook_service.get_principal()
self.transaction = self.webhook_service.get_transaction()
@@ -221,43 +255,12 @@ class PaymentProcessingService:
print("Above Third Part...!!!!!!!!!!!")
referral_service.credit_referral_reward_if_applicable()
print("Third Part Done....!!!!!")
# self.notification_service.payment_success_notification(
# self.principal, self.subscription, self.transaction.amount
# )
self.notification_service.payment_success_notification(
self.principal, self.subscription, self.transaction.amount
)
def handle_failure(self):
self.subscription_service.update_transaction_failure(self.transaction)
# self.notification_service.payment_failed_notification(
# self.principal, self.subscription, self.transaction.amount
# )
class NotificationService:
def __init__(self):
self.client = OneSignalClient(
app_id=settings.ONE_SIGNAL_APP_ID, rest_api_key=settings.ONE_SIGNAL_API_KEY
)
def send_notification(self, title, message, player_id):
notification_payload = {
"headings": {"en": title},
"contents": {"en": message},
"include_player_ids": player_id,
}
response = self.client.send_notification(notification_payload)
return response
def payment_success_notification(self, principal, subscription, amount):
title = "Payment Successful"
message = f"Your payment for {subscription} of ${amount} was successfully processed. Your subscription is valid till {subscription.end_date}"
self.send_notification(title, message, principal.player_id)
def referral_received_notification(self, principal, amount, email):
title = "Congratulations! You got a referral G-Token."
message = f"Your referral {email} has subscribed to GoodTimesApp. You have received {amount} (£)"
self.send_notification(title, message, principal.player_id)
def payment_failed_notification(self, principal, subscription, amount):
title = "Payment Failed!"
message = f"Your payment for {subscription} of ${amount} was failed."
self.send_notification(title, message, principal.player_id)