Skip to content

Commit 41653a5

Browse files
committed
Merge branch 'carlosc' into Sprint2
Merging paypal userPlan changes
2 parents b6505a7 + 24a6b17 commit 41653a5

File tree

8 files changed

+93
-7
lines changed

8 files changed

+93
-7
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.1.7 on 2019-04-11 23:30
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('datame', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='userplan',
15+
name='isPayed',
16+
field=models.BooleanField(default=False),
17+
),
18+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1.7 on 2019-04-12 03:23
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('datame', '0002_userplan_ispayed'),
10+
('datame', '0002_auto_20190411_2237'),
11+
]
12+
13+
operations = [
14+
]

mysite/datame/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class UserPlan(models.Model):
5151
type = models.CharField('Type', max_length = 4, choices = TYPE_CHOICES)
5252
startDate = models.DateTimeField(null = True)
5353
expirationDate = models.DateTimeField(null = True)
54+
isPayed = models.BooleanField(default= False)
5455

5556
def __str__(self):
5657
res = 'User Plan from ' + self.dataScientist.name

mysite/datame/populate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def populate(request):
3434
photo='https://media.istockphoto.com/photos/portrait-of-a-german-businessman-with-beard-picture-id480286744',
3535
address='C/Cristo del Amor Number 21',phone='955766587')
3636

37-
userPlan1 = UserPlan.objects.create(type='PRO',dataScientist=dataScientist1,startDate=datetime.datetime(2019,1,1,0,0,0,0,pytz.UTC),expirationDate=datetime.datetime(2020,1,1,0,0,0,0,pytz.UTC))
37+
userPlan1 = UserPlan.objects.create(type='PRO',dataScientist=dataScientist1,startDate=datetime.datetime(2019,1,1,0,0,0,0,pytz.UTC),expirationDate=datetime.datetime(2020,1,1,0,0,0,0,pytz.UTC),isPayed=True)
3838

3939
company01 = Company.objects.create(user = company1, name = 'Endesa', description = 'Endesa, fundada como «Empresa Nacional de Electricidad Sociedad Anónima» y cuyo nombre legal es Endesa, S.A., es una empresa española que opera en los sectores eléctrico y gasístico.',nif = '44060644A', logo = 'https://graffica.info/wp-content/uploads/2016/01/Captura-de-pantalla-2016-01-28-a-las-19.00.55.png')
4040
company02 = Company.objects.create(user = company2, name = 'Everis', description = 'Somos everis an NTT DATA Company, nos dedicamos a la consultoría y outsourcing abarcando todos los sectores del ámbito económico, llegando a facturar en el último ejercicio fiscal cerca de 1.173 millones de euros.',nif = '45070745B', logo = 'https://worldfootballsummit.com/wp-content/uploads/2018/08/logo-vector-everis.jpg')

mysite/datame/userplan.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def get(self, request, format=None):
2626
# List userplan as administrator
2727
assert logged_user.is_staff
2828
dataScientist = DataScientist.objects.all().get(pk=request.GET.get('dataScientistId'))
29-
userPlanHistory = list(UserPlan.objects.filter(dataScientist=dataScientist).values())
29+
userPlanHistory = list(UserPlan.objects.filter(dataScientist=dataScientist)
30+
.filter(isPayed=True).values())
3031
response.update({
3132
'userId': str(logged_user.id),
3233
'dataScientistId': str(dataScientist.id),
@@ -55,7 +56,8 @@ def get(self, request, format=None):
5556
except:
5657
return JsonResponse({"message": "Sorry, there was a problem retrieving the Data Scientist"})
5758
try:
58-
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist).order_by('-expirationDate')
59+
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist)\
60+
.filter(isPayed=True).order_by('-expirationDate')
5961
response['dataScientistId'] = dataScientist.id
6062
currentUserPlan = None
6163
if 0 < userPlanHistory.count():
@@ -83,7 +85,7 @@ def post(self, request, format=None):
8385
dataScientist = DataScientist.objects.all().get(user=logged_user)
8486
except:
8587
return JsonResponse({"message": "Only data scientists can update their user plan."})
86-
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist).order_by('-expirationDate')
88+
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist).filter(isPayed=True).order_by('-expirationDate')
8789
currentUserPlan = None
8890
if 0 < userPlanHistory.count():
8991
currentUserPlan = userPlanHistory.first()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1.7 on 2019-04-11 16:16
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('pagos', '0002_auto_20190411_0800'),
10+
('pagos', '0002_userplanpaypalbill'),
11+
]
12+
13+
operations = [
14+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 2.1.7 on 2019-04-12 03:23
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('pagos', '0003_merge_20190411_1816'),
10+
('pagos', '0004_merge_20190411_2213'),
11+
]
12+
13+
operations = [
14+
]

mysite/pagos/views.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _generar_pago_paypal(self, offer):
7676
if link.method == "REDIRECT":
7777
url_pago = link.href
7878
else:
79-
raise Exception(pago.error)
79+
raise Exception(pago_paypal.error)
8080

8181
return url_pago, pago_paypal
8282

@@ -156,33 +156,37 @@ def get(self, request,paymentId,token_paypal,payerID,format=None):
156156

157157
class PaypalUserPlanPaymentView(APIView):
158158
def get(self, request, format=None):
159+
print("is the paypal_userPlan_payment_getting_to_back?==========")
159160
if request.method == "GET":
160161
try:
161162
response = {}
162163
try:
163164
dataScientist_user = User.objects.all().get(pk = request.user.id)
164165
dataScientist = DataScientist.objects.all().get(user=dataScientist_user)
165166
except:
167+
traceback.print_exc()
166168
response['DeveloperErrorMessage'] = 'Pagos.views.PaypalUserPlanPaymentView: Logged data scientist could not be retrieved.'
167169
response['UserCodeErrorMessage'] = 'None.'
168170
return JsonResponse(response, safe=False)
169171

170172
try:
171173
userPlan_pk = request.GET['userplan_pk']
172174
except:
175+
traceback.print_exc()
173176
response['DeveloperErrorMessage'] = 'Pagos.views.PaypalUserPlanPaymentView: No userPlan_pk was received.'
174177
response['UserCodeErrorMessage'] = 'None.'
175178
return JsonResponse(response, safe=False)
176179

177180
try:
178181
userplan = UserPlan.objects.get(pk=userPlan_pk)
179182
assert userplan.dataScientist == dataScientist
180-
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist).order_by('-expirationDate')
183+
userPlanHistory = UserPlan.objects.filter(dataScientist=dataScientist).order_by('-expirationDate').order_by('-pk')
181184
assert 0 < userPlanHistory.count()
182185
userplanPaymentPending = userPlanHistory.first()
183186

184187
assert userplan == userplanPaymentPending
185188
except:
189+
traceback.print_exc()
186190
response['DeveloperErrorMessage'] = 'Pagos.views.PaypalUserPlanPaymentView: An error ocurred retrieving the user plan to pay.'
187191
response['UserCodeErrorMessage'] = 'None.'
188192
return JsonResponse(response, safe=False)
@@ -274,15 +278,34 @@ def get(self, request, format=None):
274278
payment_id = request.GET.get('paymentId')
275279
payer_id = request.GET.get('PayerID')
276280
except:
281+
traceback.print_exc()
277282
raise HttpResponseBadRequest
278283

279284
# Execute payment with the payer ID from the create payment call (following redirect)
280285
payment = Payment.find(str(payment_id))
281286

282287
if payment.execute({"payer_id": str(payer_id)}):
283288
print("Payment[%s] execute successfully" % (payment.id))
289+
try:
290+
userPlan_pk = payment.transactions[0]['item_list']['items'][0]['sku']
291+
print("The id of the user_plan is " + str(userPlan_pk))
292+
userPlan = UserPlan.objects.get(pk=userPlan_pk)
293+
userPlan.isPayed = True
294+
print("The said userplan" + str(userPlan.id))
295+
userPlan.save()
296+
print("The said userplan" + str(userPlan.isPayed))
297+
except:
298+
traceback.print_exc()
299+
response[
300+
'DeveloperErrorMessage'] = 'Pagos.views.PaypalUserPlanPaymentView: No userPlan_pk was received.'
301+
response['UserCodeErrorMessage'] = 'None.'
302+
return JsonResponse(response, safe=False)
303+
response['DeveloperErrorMessage'] = 'Pagos.views.PaypalUserPlanPaymentView: Everything went perfect with payment!.'
304+
response['MessageCode'] = 'You have paid successfuly'
284305
else:
285306
print(payment.error)
307+
response['DeveloperErrorMessage'] = 'ERRROOOOR!'
308+
response['MessageCode'] = 'ERRROOOOR!'
286309

287310

288-
#TODO class CancelPaypalUserPlanPayment(APIView):
311+
return JsonResponse(response, safe=False)

0 commit comments

Comments
 (0)