Exemplo n.º 1
0
def webhook(request):
        product.num_available = product.num_available - item.quantity
        product.save()

        html = render_to_string('order_confirmation.html', {'order': order})
        send_mail('Order confirmation', 'Your order is successful!', '*****@*****.**', ['*****@*****.**', order.email], fail_silently=False, html_message=html)
        subject = 'Order confirmation'
        from_email = '*****@*****.**'
        to = ['*****@*****.**', order.email]
        text_content = 'Your order is successful!'
        html_content = render_to_string('order_confirmation.html', {'order': order})

        pdf = render_to_pdf('order_pdf.html', {'order': order})

        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")

        if pdf:
            name = 'order_%s.pdf' % order.id
            msg.attach(name, pdf, 'application/pdf')

        msg.send()

        #html = render_to_string('order_confirmation.html', {'order': order})
        #send_mail('Order confirmation', 'Your order is successful!', '*****@*****.**', ['*****@*****.**', order.email], fail_silently=False, html_message=html)

        return HttpResponse(status=200) 
Exemplo n.º 2
0
def validate_payment(request):
    data = json.loads(request.body)
    razorpay_payment_id = data['razorpay_payment_id']
    razorpay_order_id = data['razorpay_order_id']
    razorpay_signature = data['razorpay_signature']

    client = razorpay.Client(auth=(settings.RAZORPAY_API_KEY_PUBLISHABLE,
                                   settings.RAZORPAY_API_KEY_HIDDEN))

    params_dict = {
        'razorpay_payment_id': razorpay_payment_id,
        'razorpay_order_id': razorpay_order_id,
        'razorpay_signature': razorpay_signature
    }

    res = client.utility.verify_payment_signature(params_dict)

    print(res)

    if not res:
        order = Order.objects.get(payment_intent=razorpay_order_id)
        order.paid = True
        order.save()

        for item in order.items.all():
            product = item.product
            product.num_available = product.num_available - item.quantity
            product.save()

        subject = 'Order confirmation'
        from_email = '*****@*****.**'
        to = ['*****@*****.**', order.email]
        text_content = 'Your order is successful!'
        html_content = render_to_string('order_confirmation.html',
                                        {'order': order})

        pdf = render_to_pdf('order_pdf.html', {'order': order})

        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")

        if pdf:
            name = 'order_%s.pdf' % order.id
            msg.attach(name, pdf, 'application/pdf')

        msg.send()

    return JsonResponse({'success': True})
Exemplo n.º 3
0
def send_order_confirmation(order):
    # Send html page(order confirmation) as mail
    subject = 'Order confirmation'
    from_email = '*****@*****.**'
    to = ['*****@*****.**', order.email]
    text_content = 'Your order has been confirmed!'
    html_content = render_to_string('order_confirmation.html', {'order': order})
    pdf = render_to_pdf({'order': order})
    # Add data to message variable
    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, "text/html")
    # Attach Invoice (pdf)
    if pdf:
        name = f'order_{order.id}.pdf'
        msg.attach(name, pdf, 'application/pdf')
    msg.send()
Exemplo n.º 4
0
def send_order_confirmation(order):
    subject = 'Order Confirmation'
    from_email = '*****@*****.**'
    to = ['*****@*****.**', order.email]
    text_content = 'Your order is successful'
    html_content = render_to_string('order_confirmation.html',
                                    {'order': order})

    pdf = render_to_pdf('order_pdf.html', {'order': order})
    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, 'text/html')

    if pdf:
        name = 'order_%s.pdf' % order.id
        msg.attach(name, pdf, 'application/pdf')
    msg.send()
Exemplo n.º 5
0
def send_order_confirmation(order):
    subject = 'Order confirmation'
    from_email = '*****@*****.**'
    to = ['*****@*****.**', order.email]
    text_content = 'Your order is successful!'
    html_content = render_to_string('order_confirmation.html', {'order': order})

    pdf = render_to_pdf('order_pdf.html', {'order': order})

    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, "text/html")

    if pdf:
        name = 'order_%s.pdf' % order.id
        msg.attach(name, pdf, 'application/pdf')

    msg.send()
Exemplo n.º 6
0
def send_order_confirmation(order):
    subject = 'Order confirmation'
    from_email = '*****@*****.**'
    to = [order.email]
    text_content = 'Your order has been placed successfully!'
    html_content = render_to_string('order_confirmation.html', {'order': order})

    pdf = render_to_pdf('order_pdf.html', {'order': order})

    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, "text/html")

    if pdf:
        name = 'order_%s.pdf' % order.id
        msg.attach(name, pdf, 'application/pdf')
    
    msg.send()
Exemplo n.º 7
0
def send_order_confirmation(order):
    subject = 'Confirmacion de Order'
    from_email = '*****@*****.**'
    to = ['*****@*****.**', order.email]
    text_content = "Su orden ha sido exitosa!"
    html_content = render_to_string('order_confirmation.html', {'order': order})

    pdf = render_to_pdf('order_pdf.html', {'order': order})

    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, "text/html")

    if pdf:
        name = 'order_%s.pdf' % order.id
        msg.attach(name, pdf, 'application/pdf')

    msg.send()
Exemplo n.º 8
0
def webhook(request):
    payload = request.body
    event = None

    stripe.api_key = settings.STRIPE_API_KEY_HIDDEN

    try:
        event = stripe.Event.construct_from(json.loads(payload),
                                            stripe.api_key)
    except ValueError as e:
        return HttpResponse(status=400)

    if event.type == 'payment_intent.succeeded':
        payment_intent = event.data.object

        order = Order.objects.get(payment_intent=payment_intent.id)
        order.paid = True
        order.save()

        for item in order.items.all():
            product = item.product
            product.num_available = product.num_available - item.quantity
            product.save()

        subject = 'Order confirmation'
        from_email = '*****@*****.**'
        to = ['*****@*****.**', order.email]
        text_content = 'Your order has been sent!'
        html_content = render_to_string('order_confirmation.html',
                                        {'order': order})

        pdf = render_to_pdf('order_pdf.html', {'order': order})

        msg = EmailMultiAlternatives(subject, text_content, from_email, to)
        msg.attach_alternative(html_content, "text/html")

        if pdf:
            name = 'order_%s.pdf' % order.id
            msg.attach(name, pdf, 'application/pdf')

        msg.send()

        #html = render_to_string('order_confirmation.html', {'order': order})
        #send_mail('Order confirmation', 'Your order has been sent!', '*****@*****.**', ['*****@*****.**', order.email], fail_silently=False, html_message=html)

    return HttpResponse(status=200)
Exemplo n.º 9
0
def send_order_confirmation(order):
    """
    Send the order's confirmation to the customer
    Parameters:
        -order: [Dictionary] Order's information 
    """
    subject = 'Order confirmation'
    from_email = '*****@*****.**'
    to = ['*****@*****.**', order.email]
    text_content = 'Your order is successful!'
    html_content = render_to_string('order_confirmation.html', {'order': order})

    pdf = render_to_pdf('order_pdf.html', {'order': order})

    msg = EmailMultiAlternatives(subject, text_content, from_email, to)
    msg.attach_alternative(html_content, "text/html")

    if pdf:
        name = 'order_%s.pdf' % order.id
        msg.attach(name, pdf, 'application/pdf')

    msg.send()