Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add separate view for order payment
Paweł Kowalewski18916f2eb007
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.pyindex bc3dc010f7..aa1fd3c418 100644--- a/saleor/checkout/steps.py+++ b/saleor/checkout/steps.py@@ -212,7 +212,7 @@ class SummaryStep(BaseCheckoutStep):order = self.checkout.create_order()order.create_history_entry()order.send_confirmation_email()- return redirect('order:details', token=order.token)+ return redirect('order:payment', token=order.token)return responsedef validate(self):diff --git a/saleor/checkout/templates/checkout/billing.html b/saleor/checkout/templates/checkout/billing.htmlindex c89f6cb46d..166a56b7c9 100644--- a/saleor/checkout/templates/checkout/billing.html+++ b/saleor/checkout/templates/checkout/billing.html@@ -11,7 +11,7 @@{% if not user.is_authenticated %}<p class="alert alert-info">{% trans "Already have an account?" %}- <a href="{% url "registration:login" %}">{% trans "Log in" %}</a>+ <a href="{% url "registration:login" %}?next={% url "checkout:details" step="billing-address" %}">{% trans "Log in" %}</a></p>{% endif %}{% endblock %}diff --git a/saleor/order/static/js/order_details.js b/saleor/order/static/js/order_details.jsdeleted file mode 100644index 999e6a9404..0000000000--- a/saleor/order/static/js/order_details.js+++ /dev/null@@ -1,3 +0,0 @@-$(function() {- $(".address-details").popover({placement: 'auto right'});-});diff --git a/saleor/order/templates/order/details.html b/saleor/order/templates/order/details.htmlindex c885c6512f..41b26ee58e 100644--- a/saleor/order/templates/order/details.html+++ b/saleor/order/templates/order/details.html@@ -33,53 +33,6 @@</div></div>- {% if order.user == user or not order.is_fully_paid %}- {% if not order.is_fully_paid %}- <div class="row">- <div class="col-sm-6">- <div class="panel panel-default">- <div class="panel-body">- {% if waiting_payment %}- <form method="post" action="{% url 'order:cancel-payment' token=order.token %}">- {% csrf_token %}- <legend>{% trans "Payment pending" %}</legend>- <p>{% trans "We are currently waiting for an external service to authorize your payment for this order." %}</p>- <p>{% trans "Current status" %}: <span class="label label-default">{{ waiting_payment.get_status_display }}</span></p>- <p>{% trans "Unless you are absolutely sure that the process will not complete (for example you have closed the browser window before paying), you should wait before attempting a new payment. Please be warned that if you try again and the previous transaction succeeds you might end up being charged twice." %}</p>- {{ waiting_payment_form|as_vertical_form }}- <button type="submit" class="btn btn-danger">{% trans "I understand, allow me to pay again" %}</button>- </form>- {% elif payment_form %}- <form method="post" action="{% url "order:details" token=order.token %}">- {% csrf_token %}- <legend>{% trans "Pay for your order" %}</legend>- {{ payment_form }}- <div class="form-group text-right">- {% block form_submit %}- <button type="submit" class="btn btn-primary">- {% trans "Proceed to payment" %}- </button>- {% endblock %}- </div>- </form>- {% else %}- <p>{% trans "You've authorized transaction. Order is in processing" %}</p>- {% endif %}- </div>- </div>- </div>- </div>- {% endif %}- {% if payments %}- <h3>{% trans "Payment history" %}</h3>- <ul>- {% for payment in payments %}- <li>{{ payment.created|date }}, {{ payment.created|time }} — <span class="label label-default">{{ payment.get_status_display }}</span></li>- {% endfor %}- </ul>- {% endif %}- {% endif %}-<div class="row">{% if order.user == user %}<div class="col-sm-6">@@ -151,8 +104,3 @@</div>{% endfor %}{% endblock content %}--{% block footer_scripts %}- {{ block.super }}- <script type="text/javascript" src="{% static "js/order_details.js" %}"></script>-{% endblock footer_scripts %}diff --git a/saleor/order/templates/order/payment.html b/saleor/order/templates/order/payment.htmlnew file mode 100644index 0000000000..8bd93b4cfe--- /dev/null+++ b/saleor/order/templates/order/payment.html@@ -0,0 +1,125 @@+{% extends "base.html" %}++{% load as_vertical_form from bootstrap %}+{% load gross from prices_i18n %}+{% load i18n %}+{% load staticfiles %}++{% block title %}{% trans "Pay for order" %} {{ order }} — {{ block.super }}{% endblock %}++{% block outerbreadcrumb %}+{% endblock outerbreadcrumb %}++{% block content %}+ <div class="row">+ <div class="col-sm-8">+ {% if order.user == user or not order.is_fully_paid %}+ {% if not order.is_fully_paid %}+ <div class="panel panel-primary">+ {% if waiting_payment %}+ <div class="panel-heading">+ {% trans "Payment pending" %}+ </div>+ <div class="panel-body">+ <form method="post" action="{% url 'order:cancel-payment' token=order.token %}">+ {% csrf_token %}+ <p>{% trans "We are currently waiting for an external service to authorize your payment for this order." %}</p>+ <p>{% trans "Current status" %}: <span class="label label-default">{{ waiting_payment.get_status_display }}</span></p>+ <p>{% trans "Unless you are absolutely sure that the process will not complete (for example you have closed the browser window before paying), you should wait before attempting a new payment. Please be warned that if you try again and the previous transaction succeeds you might end up being charged twice." %}</p>+ {{ waiting_payment_form|as_vertical_form }}+ <button type="submit" class="btn btn-danger">{% trans "I understand, allow me to pay again" %}</button>+ </form>+ </div>+ {% elif payment_form %}+ <div class="panel-heading">+ {% trans "Pay for your order" %} {{ order }}+ </div>+ <div class="panel-body">+ <form method="post" action="{% url "order:details" token=order.token %}">+ {% csrf_token %}+ {{ payment_form }}+ <div class="form-group text-right">+ {% block form_submit %}+ <button type="submit" class="btn btn-primary">+ {% trans "Proceed to payment" %}+ </button>+ {% endblock %}+ </div>+ </form>+ </div>+ {% else %}+ <div class="panel-body">+ <p>{% trans "You've authorized transaction. Order is in processing" %}</p>+ </div>+ {% endif %}+ </div>+ {% endif %}+ {% endif %}++ {% for group in groups %}+ <div class="panel panel-default">+ <div class="panel-heading">+ {% blocktrans with number=forloop.counter %}Shipment #{{ number }}{% endblocktrans %}+ </div>+ <table class="table">+ <thead>+ <tr>+ <th class="col-sm-6">{% trans "Name" %}</th>+ <th class="col-sm-3 text-right">{% trans "Price" %}</th>+ <th class="col-sm-3 text-right">{% trans "Subtotal" %}</th>+ </tr>+ </thead>+ <tfoot>+ <tr>+ <th colspan="2">{% trans "Total" %}</th>+ <th class="text-right">{% gross group.get_total %}</th>+ </tr>+ </tfoot>+ <tbody>+ {% for item in group %}+ <tr>+ <td>{{ item.product }}{% if item.quantity != 1 %} <em>×{{ item.quantity }}</em>{% endif %}</td>+ <td class="text-right">{% gross item.get_price_per_item %}</td>+ <td class="text-right">{% gross item.get_total %}</td>+ </tr>+ {% endfor %}+ {% if group.shipping_price.gross %}+ <tr>+ <td class="col-sm-4">+ {% trans "Shipping" %}+ </td>+ <td class="text-right">{% gross group.shipping_price %}</td>+ <td class="text-right">{% gross group.shipping_price %}</td>+ </tr>+ {% endif %}+ </tbody>+ </table>+ </div>+ {% endfor %}+ </div>++ {% if order.user == user %}+ <div class="col-sm-4">+ <div class="panel panel-default">+ <div class="panel-heading">+ {% trans "Billing address" %}+ </div>+ <div class="panel-body">+ <address>{% include "userprofile/snippets/address-details.html" with address=order.billing_address %}</address>+ </div>+ </div>++ {% if order.is_shipping_required %}+ <div class="panel panel-default">+ <div class="panel-heading">+ {% trans "Shipping address" %}+ </div>+ <div class="panel-body">+ <address>{% include "userprofile/snippets/address-details.html" with address=order.shipping_address %}</address>+ </div>+ </div>+ {% endif %}+ </div>+ {% endif %}+ </div>+{% endblock content %}diff --git a/saleor/order/urls.py b/saleor/order/urls.pyindex c88fdecba6..2da53bb77f 100644--- a/saleor/order/urls.py+++ b/saleor/order/urls.py@@ -6,6 +6,8 @@ from . import viewsurlpatterns = [url(r'^%s/$' % (TOKEN_PATTERN,), views.details, name='details'),+ url(r'^%s/payment/$' % (TOKEN_PATTERN,),+ views.payment, name='payment'),url(r'^%s/payment/(?P<variant>[-\w]+)/$' % (TOKEN_PATTERN,),views.start_payment, name='payment'),url(r'^%s/cancel-payment/$' % (TOKEN_PATTERN,), views.cancel_payment,diff --git a/saleor/order/views.py b/saleor/order/views.pyindex afdbb49dec..49c8be473d 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -17,6 +17,16 @@ logger = logging.getLogger(__name__)def details(request, token):+ orders = Order.objects.prefetch_related('groups__items')+ order = get_object_or_404(orders, token=token)+ groups = order.groups.all()+ payments = order.payments.all()+ return TemplateResponse(request, 'order/details.html',+ {'order': order, 'groups': groups,+ 'payments': payments})+++def payment(request, token):orders = Order.objects.prefetch_related('groups__items')order = get_object_or_404(orders, token=token)groups = order.groups.all()@@ -36,11 +46,12 @@ def details(request, token):payment_form = Noneif not order.is_pre_authorized():payment_form = PaymentMethodsForm(form_data)+ # FIXME: redirect if there is only one payment methodif payment_form.is_valid():payment_method = payment_form.cleaned_data['method']return redirect('order:payment', token=order.token,variant=payment_method)- return TemplateResponse(request, 'order/details.html',+ return TemplateResponse(request, 'order/payment.html',{'order': order, 'groups': groups,'payment_form': payment_form,'waiting_payment': waiting_payment,diff --git a/saleor/static/img/authorize_net-logo.png b/saleor/static/img/authorizenet-logo.pngsimilarity index 100%rename from saleor/static/img/authorize_net-logo.pngrename to saleor/static/img/authorizenet-logo.pngdiff --git a/saleor/static/img/coinbase-logo.png b/saleor/static/img/coinbase-logo.pngnew file mode 100644index 0000000000..4de162ec82Binary files /dev/null and b/saleor/static/img/coinbase-logo.png differdiff --git a/saleor/static/img/cybersource-logo.png b/saleor/static/img/cybersource-logo.pngnew file mode 100644index 0000000000..9739a5f355Binary files /dev/null and b/saleor/static/img/cybersource-logo.png differdiff --git a/saleor/static/img/dotpay-logo.png b/saleor/static/img/dotpay-logo.pngnew file mode 100644index 0000000000..bc4711a31dBinary files /dev/null and b/saleor/static/img/dotpay-logo.png differdiff --git a/saleor/static/img/sage-logo.png b/saleor/static/img/sage-logo.pngnew file mode 100644index 0000000000..7aaacdadf9Binary files /dev/null and b/saleor/static/img/sage-logo.png differdiff --git a/saleor/static/img/sofort-logo.png b/saleor/static/img/sofort-logo.pngnew file mode 100644index 0000000000..e13eb0b9a5Binary files /dev/null and b/saleor/static/img/sofort-logo.png differdiff --git a/saleor/static/img/stripe-logo.png b/saleor/static/img/stripe-logo.pngnew file mode 100644index 0000000000..9d0ad7a535Binary files /dev/null and b/saleor/static/img/stripe-logo.png differdiff --git a/saleor/static/img/wallet-logo.png b/saleor/static/img/wallet-logo.pngnew file mode 100644index 0000000000..2090a927c6Binary files /dev/null and b/saleor/static/img/wallet-logo.png differdiff --git a/saleor/static/js_src/storefront.jsx b/saleor/static/js_src/storefront.jsxindex ec033e57d3..e76482ab46 100644--- a/saleor/static/js_src/storefront.jsx+++ b/saleor/static/js_src/storefront.jsx@@ -188,7 +188,9 @@ $(".cart-item-amount").each(function(index) {var $cartTotal = $(".cart-total");var cartTotalValue = $cartTotal.text();-var cartTotal = React.render(<CartTotal value={cartTotalValue} />, $(".cart-total")[0]);+if ($cartTotal.length) {+ var cartTotal = React.render(<CartTotal value={cartTotalValue}/>, $(".cart-total")[0]);+}var cartSubtotals = [];$(".cart-item-subtotal").each(function() {diff --git a/saleor/static/scss/_app.scss b/saleor/static/scss/_app.scssindex 9f026f777c..a537244f6f 100644--- a/saleor/static/scss/_app.scss+++ b/saleor/static/scss/_app.scss@@ -134,14 +134,23 @@ $icon-font-path: "../fonts/";}#id_method {+ @include make-row;list-style: none;padding: 0;+ li {+ @include make-xs-column(6);+ @include make-sm-column(4);+ margin-bottom: $grid-gutter-width/3;+ white-space: nowrap;+ }+li:not(:first-child) {label {font-size: 0;- @each $provider in (default, authorize_net, braintree, paypal) {+ @each $provider in (default, authorizenet, braintree, coinbase, cybersource, dotpay,+ wallet, paypal, sage, sofort, stripe) {input[value=#{$provider}] {margin: 6px 110px 6px 0;