简体   繁体   English

在 Django-Oscar 中通过 Paypal 处理付款

[英]Processing Payments Via Paypal in Django-Oscar

I am trying to set up a basic e-commerce site using Django Oscar and am having difficulties.我正在尝试使用 Django Oscar 建立一个基本的电子商务网站,但遇到了困难。 The majority of the problem has to do with the absence of examples of how to hook up meaningful (think Paypal, Stripe, Braintree) methods of payment and presence of obscure ones of which I have never heard before.大部分问题与缺乏如何连接有意义的(想想 Paypal、Stripe、Braintree)付款方式的示例以及我以前从未听说过的晦涩的付款方式有关。

Either way, I am attempting to use django-oscar-paypal and follow its documentation.无论哪种方式,我都试图使用django-oscar-paypal并遵循其文档。 The Paypal Express part seems to work in that the button shows up and something akin to check out and processing happens. Paypal Express 部分似乎可以正常工作,因为该按钮出现并且类似于结帐和处理的事情发生了。

However, if I choose to proceed with checkout in a regular way (with hopes of paying with a card), I am taken to the following page (the message in parentheses is mine)但是,如果我选择以常规方式进行结帐(希望用卡付款),则会转到以下页面(括号中的消息是我的)

在此处输入图片说明

Which is a product of the following template:这是以下模板的产物:

{% extends "checkout/checkout.html" %}
{% load i18n %}

{% block title %}
    {% trans "Payment details" %} | {{ block.super }}
{% endblock %}

{% block checkout_nav %}
    {% include 'checkout/nav.html' with step=3 %}
{% endblock %}

{% block checkout_title %}{% trans "Enter payment details" %}{% endblock %}

{% block order_contents %}{% endblock %}
{% block shipping_address %}{% endblock %}
{% block shipping_method %}{% endblock %}
{% block payment_method %}{% endblock %}

{% block payment_details %}
    {% block payment_details_content %}
        <p>{% trans "(*** Message from ./templates/tshirt-theme/ ***) This page needs implementing within your project.  You may want to use one of Oscar's payment gateway libraries:" %}</p>
        <ul>
            <li><a href="https://github.com/django-oscar/django-oscar-paypal">django-oscar-paypal</a></li>
            <li><a href="https://github.com/django-oscar/django-oscar-datacash">django-oscar-datacash</a></li>
            <li><a href="https://github.com/django-oscar/django-oscar-gocardless">django-oscar-gocardless</a></li>
            <li><a href="https://github.com/django-oscar/django-oscar-paymentexpress">django-oscar-paymentexpress</a></li>
            <li><a href="https://github.com/django-oscar/django-oscar-accounts">django-oscar-accounts</a></li>
        </ul>
        <a id="view_preview" href="{% url 'checkout:preview' %}" class="btn btn-primary btn-lg">{% trans "Continue" %}</a>
    {% endblock payment_details_content %}
{% endblock payment_details %}

When I click "Continue", I am taken to something resembling a pre-order page on which the Payment Method is empty.当我点击“继续”时,我被带到一个类似于预购页面的页面,其中的付款方式为空。 When I click "Change" on it, it takes me back to the page on the screenshot.当我点击“更改”时,它会将我带回屏幕截图上的页面。

My question is how do I get credit cards to work with this setup?我的问题是如何让信用卡使用此设置? Is there a better way of doing this thing altogether?有没有更好的方法来做这件事? I am somewhat familiar with Django, but this seemingly simple task seems to require a lot of knowledge and/or a lot of re-inventing the wheel.我对 Django 有点熟悉,但这个看似简单的任务似乎需要很多知识和/或大量重新发明轮子。 The latter must be the case because there is no documentation or tutorials on any of this, but many sites allegedly use Django-Oscar.后者肯定是这种情况,因为没有关于这方面的任何文档或教程,但据称许多站点使用 Django-Oscar。

Any help or advice is appreciated.任何帮助或建议表示赞赏。

From the django-paypal repo view the sandbox code, in particular the templates folder, settings.py and urls.py .从 django-paypal 存储库查看沙箱代码,特别是模板文件夹settings.pyurls.py I followed the instructions and added the necessary paypal keys to settings.py as well as the urls.py but failed to copy the templates, since that was documented less carefully.我按照说明将必要的贝宝密钥添加到settings.py以及urls.py但未能复制模板,因为它的记录不太仔细。

For me simply adding at the very least the same templates as the sandbox made the screen you are viewing be replaced with working paypal buttons.对我来说,只需添加至少与沙箱相同的模板,您正在查看的屏幕就会被替换为有效的贝宝按钮。 In particular, the sandbox/templates/checkout/payment_details.html seems to be what gets rendered in place of this reminder message you are seeing — note that the template has both Express and Flow options, so use only what your site is set to use.特别是, sandbox/templates/checkout/payment_details.html似乎是代替您看到的此提醒消息而呈现的内容 - 请注意,该模板具有 Express 和 Flow 选项,因此请仅使用您的站点设置使用的内容.

Add the below code to oscar/checkout/preview.html , and also change the client ID #将以下代码添加到oscar/checkout/preview.html ,并更改客户端 ID #

<body>
<div class="col-sm-5 col-sm-offset-7">

        <!-- Set up a container element for the button -->
     <div id="paypal-button-container" ></div>

    <!-- Include the PayPal JavaScript SDK -->
    <script src="https://www.paypal.com/sdk/js?client-id={{'Askdlsfhslfkdlfkdsflskd-wkJzFrkfldfkjhdlkfrW3-5U-RW0-ZsZskflsfu_YT-85r'}}&currency=PLN&locale=pl_PL"></script>

    <script>
         // Render the PayPal button into #paypal-button-container
        paypal.Buttons({
                        style: {
                            layout: 'horizontal',
                            size: 'small',
                            color:  'blue',
                            shape:  'rect',
                            label:  'pay',
                            height: 44,
                            tagline: 'true'
                        },
                             enableStandardCardFields: false, 
            // Set up the transaction
            createOrder: function(data, actions) {
                return actions.order.create({
                    purchase_units: [{
                        amount: {
                                value: JSON.parse({{ order_total.incl_tax }}) // pass variable with amount to script
                           // <!-- value: '0.01', -->
                        }
                    }]
                });
            },

            // Finalize the transaction
            onApprove: function(data, actions) {
                return actions.order.capture().then(function(details) {
                    // Show a success message to the buyer
                    alert('Transaction completed by ' + details.payer.name.given_name + '!');
                });
            }


        }).render('#paypal-button-container');
    </script>

</div> 
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM