我正在用 Python 设计一个网站(使用 Django),我需要通过它来卖东西。
有人可以帮助我提供源代码以集成 paypal-pro(直接付款)或 paypal-standard(快速结帐)吗?
我正在用 Python 设计一个网站(使用 Django),我需要通过它来卖东西。
有人可以帮助我提供源代码以集成 paypal-pro(直接付款)或 paypal-standard(快速结帐)吗?
You might want to try django-paypal, there's even a tutorial right there on the front page.
PayPal API 生成一个按钮,该按钮将通过paypal.standard.ipn
.
对于 API 集成,您必须遵循以下给定步骤:
安装django-paypal
:
pip install django-paypal
更新settings.py文件:
INSTALLED_APPS = [
'paypal.standard.ipn',
]
PAYPAL_RECEIVER_EMAIL = 'XXXXX'
PAYPAL_TEST = True
写收件人的电子邮件地址。PAYPAL_TEST = True
表示您想要测试 API 付款。您可以为原始支付 API 写“False”。
运行命令:
python manage.py migrate
在urls.py中:
url(r'^paypal/', include('paypal.standard.ipn.urls')),
url(r'^payment_process/$', api_views.payment_process, name='payment_process' ),
url(r'^payment_done/$', TemplateView.as_view(template_name= "pets/payment_done.html"), name='payment_done'),
url(r'^payment_canceled/$', TemplateView.as_view(template_name= "pets/payment_canceled.html"), name='payment_canceled'),*
在view.py中:
from django.conf import settings
from django.urls import reverse
from django.shortcuts import render, get_object_or_404
from paypal.standard.forms import PayPalPaymentsForm
def payment_process(request):
host = request.get_host()
paypal_dict = {
'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': '100',
'item_name': 'Item_Name_xyz',
'invoice': 'Test Payment Invoice',
'currency_code': 'USD',
'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')),
'return_url': 'http://{}{}'.format(host, reverse('payment_done')),
'cancel_return': 'http://{}{}'.format(host, reverse('payment_canceled')),
}
form = PayPalPaymentsForm(initial=paypal_dict)
return render(request, 'pets/payment_process.html', {'form': form})
在payment_process.html中:
{{ form.render }}
对于调用 API,您需要/payment_process/
. 它将在 HTML 上生成一个按钮,该按钮调用 PayPal API 进行交易。进一步的流程将在 PayPal 端、登录或卡支付上完成。
你看过pypaypal吗?您可以创建一个连接到 PayPal 的视图并提交您的付款命令。
最好使用所有者的“本机”文档:docs paypal
本教程指导如何通过沙箱接受 Paypal 应用程序付款ClientId
,SecretKey
无需任何第三方库。
您还可以将支付跟踪 ID 作为列表custom_id
的purchase_units
字典对象发送到create_order.request_body
功能。
如下所示:
create_order.request_body (
{
"intent": "CAPTURE",
"purchase_units": [
{
"custom_id": "YOUR_TRACKING_ID",
"amount": {
"currency_code": "USD",
"value": course.price,
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": course.price
}
},
},
}
]
}
)