When a payment is successful, we will send an automatic email to our customers including the generated PDF invoice. Edit the views.py file of the payment application and add the following imports to it:
from django.template.loader import render_to_stringfrom django.core.mail import EmailMessagefrom django.conf import settingsimport weasyprintfrom io import BytesIO
Then, in the payment_process view, add the following code after the order.save() line with the same indentation level as follows:
def payment_process(request): # ... if request.method == 'POST': # ... if result.is_success: # ... order.save() # create invoice e-mail subject = 'My Shop - Invoice no. {}'.format(order.id) message = 'Please, find attached the ...