Advertisement
neonua666

template

May 8th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 6.01 KB | None | 0 0
  1. {% extends "base.html" %}
  2. {% load helpers %}
  3. {% load i18n %}
  4.  
  5. {% block content %}
  6.     <section class="detail-section">
  7.         <h1 class="main-title" style="margin-bottom: 10px;">{% trans "Payment" %}</h1>
  8.  
  9.         <div style="width: 250px; padding: 20px; margin: 0 auto;">
  10.             <dl class="def-list">
  11.                 <dt>{% trans "Package price net" %}:</dt>
  12.                 <dd><span id="price">0</span>{{ CURRENCY_SYMBOL }}</dd>
  13.  
  14.                 <dt>{% trans "VAT" %} (19%):</dt>
  15.                 <dd><span id="tax-price">0</span>{{ CURRENCY_SYMBOL }}</dd>
  16.  
  17.                 <dt>{% trans "e-payment fee" %}:</dt>
  18.                 <dd><span id="fee-price">0</span>{{ CURRENCY_SYMBOL }}</dd>
  19.  
  20.                 <dt>{% trans "Total price gross" %}:</dt>
  21.                 <dd><span id="total-price-gross">{{ order.get_full_price }}</span>{{ CURRENCY_SYMBOL }}</dd>
  22.             </dl>
  23.         </div>
  24.  
  25.         {% url 'order_info' order.id as order_details_url %}
  26.         <p>
  27.         {% blocktrans with order_id=order.id order_details_url=order_details_url %}
  28.             You can pay for order #{{ order_id }} now using the form below or pay for it later from <a href="{{ order_details_url }}">order list.</a>
  29.         {% endblocktrans %}
  30.         </p>
  31.  
  32.         <div class="form" style="width: 500px; margin: 0 auto;">
  33.             {{ payment_method_form.method }}
  34.         </div>
  35.         <br>
  36.  
  37. <script src="https://www.paypalobjects.com/api/checkout.js"></script>
  38.    
  39.  
  40.         <div id="payment-forms">
  41.             <div id="pay_pal"
  42.                 data-fee-price='{{ order.get_paypal_price|sub:order.get_full_price|floatformat:"2" }}'
  43.                 data-tax-price='{{ order.get_tax }}'
  44.                 data-price='{{ order.price_without_tax }}'
  45.                 data-total-price="{{ order.get_paypal_price }}"
  46.                 class="hidden centerd-block">
  47.             <span class="pay_pal_n"></span>
  48.             </div>
  49.         </div>
  50.     </section>
  51. {% endblock content %}
  52.  
  53. {% block bottom-content %}
  54.     <span class="body-groups"></span>
  55. {% endblock bottom-content %}
  56.  
  57. {% block js %}
  58.  
  59.     {# Paypal button #}
  60. <script>
  61. window.onload = function() {
  62.     // Render the PayPal button
  63.  
  64.     paypal.Button.render({
  65.  
  66.         // Set your environment
  67.  
  68.         env: '{{ env }}', // sandbox | production
  69.  
  70.         // PayPal Client IDs - replace with your own
  71.         // Create a PayPal app: https://developer.paypal.com/developer/applications/create
  72.  
  73.         client: {
  74.             '{{ env }}' : '{{ paypal_token }}'
  75.         },
  76.  
  77.         // Wait for the PayPal button to be clicked
  78.  
  79.         payment: function() {
  80.  
  81.             // Make a client-side call to the REST api to create the payment
  82.             return paypal.rest.payment.create(this.props.env, this.props.client, {
  83.                 transactions: [
  84.                     {
  85.                         amount: { total: '{{ order.get_paypal_price }}', currency: 'EUR'
  86.                     },
  87.                         "invoice_number" : "{{ order.id }}",
  88.                         "description": "Packages: {% for number in number_list %} {{ number }}{% if forloop.last %}.{% else %}, {% endif %} {% endfor%}"
  89.                     }
  90.                 ]
  91.             });
  92.         },
  93.         commit: true,
  94.  
  95.         // Wait for the payment to be authorized by the customer
  96.  
  97.         onAuthorize: function(data, actions) {
  98.  
  99.             // Execute the payment
  100.  
  101.             return actions.payment.execute().then(function() {
  102.                 data['csrfmiddlewaretoken'] = '{{ csrf_token }}';
  103.                 $.ajax({
  104.                     url: '{% url 'paypal_payment_success' order.id  %}',
  105.                     type: "POST",
  106.                     dataType: 'json',
  107.                     data: data,
  108.                     success: function (json) {
  109.                         window.location.href = json.url;
  110.                         }
  111.                     });
  112.                 document.querySelector('.pay_pal_n').innerText = 'Payment Complete! Validate payment...';
  113.             });
  114.         }
  115.     }, '.pay_pal_n');
  116. };
  117. </script>
  118. {# End Paypal button #}
  119.  
  120.     <script type="text/javascript">
  121.         jQuery(document).ready(function($) {
  122.             var activePayment = '{{ request.user.payment_method }}' === '' ? 'pay_pal': '{{ request.user.payment_method }}',
  123.                 paymentBlock = $('#payment-forms'),
  124.                 totalPriceSelector = $('#total-price-gross'),
  125.                 taxPriceSelector = $('#tax-price'),
  126.                 feePriceSelector = $('#fee-price'),
  127.                 feePriceBlock = feePriceSelector.parent(),
  128.                 feePriceBlockWithTitle = feePriceBlock.prev(),
  129.                 priceSelector = $('#price');
  130.  
  131.             $('#id_method').select2(
  132.                 'val', activePayment
  133.             ).on('change', function(el) {
  134.                 changePayment(el.val);
  135.             });
  136.  
  137.             var changePayment = function(val) {
  138.                 var paymentInfo = paymentBlock.find('#' + val),
  139.                     price = paymentInfo.data('price'),
  140.                     taxPrice = paymentInfo.data('tax-price'),
  141.                     feePrice = paymentInfo.data('fee-price'),
  142.                     totalPrice = paymentInfo.data('total-price');
  143.  
  144.                 // Swith to correct payment block
  145.                 $('#payment-forms > div').addClass('hidden');
  146.                 paymentInfo.removeClass('hidden');
  147.  
  148.                 if (feePrice !== 0) {
  149.                     feePriceBlock.show();
  150.                     feePriceBlockWithTitle.show();
  151.                 } else {
  152.                     feePriceBlock.hide();
  153.                     feePriceBlockWithTitle.hide();
  154.                 }
  155.  
  156.                 // Change price information in top block
  157.                 priceSelector.text(price);
  158.                 taxPriceSelector.text(taxPrice);
  159.                 feePriceSelector.text(feePrice);
  160.                 totalPriceSelector.text(totalPrice);
  161.             };
  162.  
  163.             // Bootstrap
  164.             changePayment(activePayment);
  165.         });
  166.     </script>
  167. {% endblock js %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement