-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
103 lines (83 loc) · 4.16 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from event_core import settings
import requests
from django.core.mail import EmailMultiAlternatives
from celery import shared_task
from django.core.mail import send_mail
def google_authorization_code(self,callback_url, client_id):
url = f'https://accounts.google.com/o/oauth2/v2/auth?redirect_uri={callback_url}&prompt=consent&response_type=token&client_id={client_id}&scope=profile%20email'
response = requests.post(url=url)
return response
@shared_task(bind=True)
def send_checkout_email(self, receiver_email_address, event_name):
subject, from_email, to = "Knock Knock, Tickets from PassMaster Here!", "[email protected]", receiver_email_address
text_content = f"Hello {receiver_email_address}, "
html_content = f"<p>This is your confirmation ticket mail for <strong>{event_name}</strong></p>"
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False)
return "Ticket mail sent"
@shared_task(bind=True)
def send_ticket_sale_mail(organizer_name,organizer_mail,event_name,ticket_name):
subject, from_email, to = "Your Event Tickets Welfare from PassMaster Here!", "[email protected]", organizer_mail
text_content = f"Hello {organizer_name}, "
html_content = f"<p>Your {ticket_name} ticket sale for<strong>{event_name}</strong>.</p>\n<p>We are few tickets away from being sold out!!,</p>\n<p>You've got this!, {organizer_name}</p>"
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False)
return "Ticket sale mail sent"
@shared_task(bind=True)
def send_tickets_sold_out(organizer_name, organizer_mail, event_name, ticket_name):
subject, from_email, to = "Your Event Tickets Welfare from PassMaster Here!", "[email protected]", organizer_mail
text_content = f"Hurray {organizer_name}!!!, "
html_content = f"<p>Your {ticket_name} ticket sale for<strong>{event_name}</strong>has been sold out.</p>\n<p>You want to more tickets sold? Create a new ticket.</p>\n<p>You've got this!, {organizer_name}</p>"
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=False)
return "Sold out tickets mail sent"
def charged_ticket_price(price):
price += price * 9/100
return price
def remove_charge_from_earnings(earning):
earning -= earning * 9/100
return earning
headers= {"Authorization":f"Bearer {settings.PAYSTACK_SECRET_KEY}"}
def paystack_charge(email, amount):
url = "https://api.paystack.co/transaction/initialize"
data = {"email": email,
"amount": amount,
}
response = requests.post(url=url, headers=headers, data=data)
return response.json()
def verify_bank_details(account_number, bank_code):
url =f"https://api.paystack.co/bank/resolve?account_number={account_number}&bank_code={bank_code}"
response = requests.get(url=url, headers=headers)
return response.json()
def create_tranfer_recipient(full_name, account_number, bank_code):
"This is to confirm and create a receiver"
url = "https://api.paystack.co/transferrecipient"
data = {
"type":"nuban",
"name":full_name,
"account_number":account_number,
"bank_code": bank_code,
"currency":"NGN"
}
response = requests.post(url=url, headers=headers, data=data)
return response.json()
def tranfer_earnings(amount, recipient_code, unique_reference, reason):
"""For the withdraw earning endpoint/ Send Money to Event Organiser"""
url ="https://api.paystack.co/transfer"
data= { "source": "balance",
"amount": amount,
"reference": unique_reference,
"recipient": recipient_code,
"reason": reason
}
response =requests.post(url=url, headers=headers, data=data, verify=False)
return response.json()
def list_banks():
url ="https://api.paystack.co/bank?country=nigeria"
response = requests.get(url=url, headers=headers)
if response.status_code == 200:
return response.json()['data']
return response.json()