hello! I am trying to update my database after paypal has received the payment from customer. The problem is that I don't really know to do it. This is what I am doing now
-- here is my model
class SubmitDoc(models.Model):
Student = 'stu'
Professional = 'Pro'
Status_CHOICES = (
(Student, 'Stu'),
(Professional, 'Pro'),
)
firstName = models.CharField(max_length =100)
lastName = models.CharField(max_length =100)
email = models.EmailField()
Stud_status = models.CharField(
max_length=3,
choices=Status_CHOICES,
default=Student,
)
uploadDoc = models.FileField(upload_to='documents/%Y/%m/%d/')
comment = models.TextField()
created_on = models.DateTimeField(auto_now_add=True, editable=False)
paid = models.BooleanField(default=False)
finished_read = models.BooleanField(default=False)
read_by = models.CharField(max_length = 100, default="none")
This is my view function to handle the forms that are submitted
def newSubmit(request):
save= False
form = SubmitDocForm(request.POST, request.FILES)
com =0
compteur=0
message ="bon"
solution = ""
counted=0
stud = False
amount_stu = 0.02
amount_pro = 0.03
if form.is_valid():
submitDoc = SubmitDoc()
submitDoc.firstName = form.cleaned_data['firstName']
submitDoc.lastName = form.cleaned_data['lastName']
submitDoc.email = form.cleaned_data['email']
submitDoc.Stud_status = form.cleaned_data['Stud_status']
submitDoc.uploadDoc = form.cleaned_data['uploadDoc']
# submitDoc.like = form.cleaned_data["like"]
submitDoc.comment = form.cleaned_data['comment']
submitDoc.save()
save = True
# data = request.FILES["uploadDoc"]
pathy = submitDoc.uploadDoc.path
solution= get_docx_text(pathy)
counted = len(solution.split())
type_of_doc = form.cleaned_data['Stud_status']
if form.cleaned_data['Stud_status'] == "on":
stud = True
totals = round(counted*0.02, 2)
else:
stud = False
totals = round(counted *0.03, 2)
else:
form = SubmitDocForm()
return render(request, 'francais/saved.html', locals())
My problem is that I would like to update the database, the " paid = models.BooleanField(default=False)" field to true after the payment is received from paypal.
Here is how I redirect the user to paypal for payment:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="francaisvitefaite@gmail.com">
<input type="hidden" name="item_name" value="Proofreading">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="amount" value={{totals}}>
<input type="hidden" name="custom" value="paid">
<input id="id_cancel_return" name="cancel_return" type="hidden" value="http://www.example.com/order/21/">
<input id="id_return_url" name="return" type="hidden" value="http://www.example.com/thank-you">
<input type="submit" class="w3-btn w3-white w3-border w3-border-red w3-round-large" value ="Pay with Paypal" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
Please help me to change the paid field to "True".
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/211bcb0e-23aa-470f-9874-7d9c281398ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment