GS.*_*GS. 13 django django-paypal
我正在用Python设计一个网站(使用Django),我需要通过它销售东西.
有人可以帮助我使用源代码来集成paypal-pro(直接付款)或paypal标准(快速结账)吗?
小智 9
PayPal API生成一个Button,它将通过调用其API paypal.standard.ipn。
对于API集成,您必须遵循以下给定步骤:
安装django-paypal:
pip install django-paypal
Run Code Online (Sandbox Code Playgroud)
更新settings.py文件:
INSTALLED_APPS = [
'paypal.standard.ipn',
]
PAYPAL_RECEIVER_EMAIL = 'XXXXX'
PAYPAL_TEST = True
Run Code Online (Sandbox Code Playgroud)
写收件人的电子邮件地址。PAYPAL_TEST = True表示您需要Test API付款。您可以为原始付款API编写“ False”。
运行命令:
python manage.py migrate
Run Code Online (Sandbox Code Playgroud)
在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'),*
Run Code Online (Sandbox Code Playgroud)
在views.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})
Run Code Online (Sandbox Code Playgroud)
在payment_process.html中:
{{ form.render }}
Run Code Online (Sandbox Code Playgroud)
要调用API,您需要提供/payment_process/。它将在HTML上生成一个按钮,该按钮调用PayPal API进行交易。进一步的处理将在PayPal结束,登录或卡支付上进行。
| 归档时间: |
|
| 查看次数: |
17251 次 |
| 最近记录: |