我正在尝试使用Django Oscar建立一个基本的电子商务网站,我遇到了困难。问题的大部分与缺乏如何连接有意义的(想想Paypal,Stripe,Braintree)支付方法和存在我以前从未听过的模糊不清的例子有关。
无论哪种方式,我都在尝试使用django-oscar-paypal
并遵循其文档。 Paypal Express部分似乎可以工作,按钮显示出来,类似于检查和处理。
但是,如果我选择以常规方式进行结账(希望用卡付款),我会转到下一页(括号中的信息是我的)
以下模板的产品:
{% 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 %}
当我点击&#34;继续&#34;时,我会看到类似预订页面的内容,付款方式为空。当我点击&#34;更改&#34;在它上面,它会带我回到屏幕截图上的页面。
我的问题是如何获得信用卡才能使用此设置?是否有更好的方法完全做这件事?我对Django有点熟悉,但这个看似简单的任务似乎需要大量的知识和/或大量的重新发明轮子。后者必须是这种情况,因为没有任何文档或教程,但许多网站据称使用Django-Oscar。
感谢任何帮助或建议。
答案 0 :(得分:1)
从django-paypal仓库中查看sandbox代码,尤其是 templates 文件夹, settings.py 和 urls.py 。我按照说明进行操作,并在 settings.py 和 urls.py 中添加了必要的贝宝密钥,但是由于有较不详尽的文档记录,因此无法复制模板。< / p>
对我来说,只需至少添加与沙箱相同的模板,即可使用有效的贝宝按钮替换正在查看的屏幕。特别是,sandbox/templates/checkout/payment_details.html
似乎是代替您看到的此提醒消息的结果-请注意,模板同时具有Express和Flow选项,因此请仅使用您的网站设置使用的内容。
答案 1 :(得分:1)
将以下代码添加到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'}}¤cy=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>