(91) 350-9520 support@omarine.org M-F: 7 AM - 7 PM; Weekends: 9 AM - 5 PM

Lập trình Web: Python: Django: Xây dựng cửa hàng trực tuyến với Oscar-Paypal, phần 5

13. Tạo migration và di chuyển dữ liệu

python manage.py makemigrations paypal
python manage.py migrate

14. Tùy biến khuôn mẫu

Bạn tạo các thư mục:

mkdir -p templates/basket/partials/
mkdir templates/checkout/

Sau đó tạo các tệp khuôn mẫu với nội dung tương ứng như sau:


{% extends 'oscar/basket/partials/basket_content.html' %}
{% load i18n %}

{% block formactions %}
<div class="form-actions">
    {% if anon_checkout_allowed or request.user.is_authenticated %}
        {% if basket.total_excl_tax > 0 %}
            <a href="{% url 'paypal-redirect' %}">
                <img src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px;">
        {% endif %}
    {% endif %}
    <a href="{% url 'checkout:index' %}" class="pull-right btn btn-large btn-primary">{% trans "Proceed to checkout" %}</a>
{% endblock formactions %}


{% extends 'oscar/checkout/payment_details.html' %}
{% load i18n %}

{% block payment_details %}
    <div class="well">
        <div class="sub-header">
            <h3>{% trans "PayPal Express" %}</h3>
        <p>{% trans "Click on the below icon to use Express Checkout but where the shipping address and method is already chosen on the merchant site." %}</p>
        <div style="overflow:auto"><a href="{% url 'paypal-direct-payment' %}" title="{% trans "Pay with PayPal" %}"><img src="https://www.paypal.com/en_US/i/logo/PayPal_mark_37x23.gif" align="left" style="margin-right:7px;"></a>

    <div class="well">
        <div class="sub-header">
            <h3>{% trans "PayPal PayFlow Pro" %}</h3>
        <form method="post" action="{% url 'checkout:preview' %}" class="form-stacked">
            {% csrf_token %}
            <h4>{% trans "Bankcard" %}</h4>
            {% include "partials/form_fields.html" with form=bankcard_form %}
            <h4>{% trans "Billing address" %}</h4>
            {% include "partials/form_fields.html" with form=billing_address_form %}
            <div class="form-actions">
                <button type="submit" class="btn btn-large btn-primary">{% trans "Continue" %}</button>

{% endblock %}


{% extends 'oscar/checkout/preview.html' %}
{% load currency_filters %}
{% load i18n %}

{% block payment_method %}
    <div class="span6">
    <div class="sub-header">
        <h2>{% trans "Payment" %}</h2>
    <div class="well well-success">
        <p>{% blocktrans with amount=order_total.incl_tax|currency %}<strong>{{ amount }} will be debited from your bankcard.{% endblocktrans %}</p>
        <div class="alert-actions">
            <a href="{% url 'checkout:payment-details' %}" class="btn">{% trans "Change payment details" %}</a>
{% endblock %}

{% block hiddenforms %}
    {{ bankcard_form.as_p }}
    {{ billing_address_form.as_p }}
{% endblock %}

15. Cập nhật URLconf

Chúng ta đã xây dựng chương trình thanh toán cụ thể. Nó hoạt động trên mẫu URL mà cần được bổ sung. Ngoài ra, chúng ta thêm hai mẫu URL cho menu PayPal trong Dashboard:

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin

from apps.app import application
from paypal.payflow.dashboard.app import application as payflow
from paypal.express.dashboard.app import application as express_dashboard

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^i18n/', include('django.conf.urls.i18n')),

urlpatterns += i18n_patterns(
    url(r'^', application.urls),

    # PayPal Express integration...
    url(r'^checkout/paypal/', include('paypal.express.urls')),
    # Dashboard views for Payflow Pro
    url(r'^dashboard/paypal/payflow/', include(payflow.urls)),
    # Dashboard views for Express
    url(r'^dashboard/paypal/express/', include(express_dashboard.urls)),

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL,

Gửi phản hồi

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: