django虚拟pos是一个在多个在线支付平台上抽象支付流程的模块。
django-virtual-pos的Python项目详细描述
django虚拟pos
django模块抽象了几个虚拟销售点的流程 包括贝宝
这是什么?
本模块抽象了在 西班牙。
许可证
实施的付款方式
贝宝
Paypal提供贝宝支付。
比特支付
Bitpay比特币支付,从钱包到结账
桑坦德·埃拉冯
Santander Elavon是西班牙银行的付款方式之一 桑坦德。
要求和安装
要求
- Python2.7(未测试Python3,需要贡献者!)
- Django
- BeautifulSoup4
- lxml
- pycrypto
- Pytz
- Requests
类型:
$ pip install django beautifulsoup4 lxml pycrypto pytz
安装
来自Pypi
$ pip install django-virtual-pos
从主分支
主分支将始终包含此模块的工作版本。
$ pip install git+git://github.com/intelligenia/django-virtual-pos.git
设置.py
将应用程序djangovirtualpos添加到您的设置中。py:
INSTALLED_APPS=(# ..."djangovirtualpos",)
使用
请参阅manual(当前仅限西班牙语)。
所需型号
您需要使用自己的payment实现这个框架视图 模型。
此模型必须至少具有以下属性:-code: 系统提供的销售代码。-操作编号:银行操作 号码。-status:付款状态:“已付”,“待定” (pending是必需的)或“已取消”。-amount:要 充电。
以及以下方法:-联机确认:将付款标记为 支付。
集成示例
- djshop
所需视图
销售摘要视图
defpayment_summary(request,payment_id):""" Load a Payment object and show a summary of its contents to the user. """payment=get_object_or_404(Payment,id=payment_id,status="pending")replacements={"payment":payment,# ...}returnrender(request,'<sale summary template path>',replacements)
注意,这个payment summary视图应该加载一个名为 set_payment_attributes.js。
需要此文件来设置初始付款属性 银行已选择用户。
付款确认视图
@csrf_exemptdefpayment_confirmation(request,virtualpos_type):""" This view will be called by the bank. """# Directly call to confirm_payment view# Or implement the following actions# Checking if the Point of Sale existsvirtual_pos=VirtualPointOfSale.receiveConfirmation(request,virtualpos_type=virtualpos_type)ifnotvirtual_pos:# The VPOS does not exist, inform the bank with a cancel# response if neededreturnVirtualPointOfSale.staticResponseNok(virtualpos_type)# Verify if bank confirmation is indeed from the bankverified=virtual_pos.verifyConfirmation()operation_number=virtual_pos.operation.operation_numberwithtransaction.atomic():try:# Getting your payment object from operation numberpayment=Payment.objects.get(operation_number=operation_number,status="pending")exceptPayment.DoesNotExist:returnvirtual_pos.responseNok("not_exists")ifverified:# Charge the money and answer the bank confirmationtry:response=virtual_pos.charge()# Implement the online_confirm method in your payment# this method will mark this payment as paid and will# store the payment date and time.payment.online_confirm()exceptVPOSCantChargease:returnvirtual_pos.responseNok(extended_status=e)exceptExceptionase:returnvirtual_pos.responseNok("cant_charge")else:# Payment could not be verified# signature is not rightresponse=virtual_pos.responseNok("verification_error")returnresponse
支付确认视图
defpayment_ok(request,sale_code):""" Informs the user that the payment has been made successfully :param payment_code: Payment code. :param request: request. """# Load your Payment model given its codepayment=get_object_or_404(Payment,code=sale_code,status="paid")context={'pay_status':"Done","request":request}returnrender(request,'<payment_ok template>',{'context':context,'payment':payment})
付款取消视图
defpayment_cancel(request,sale_code):""" Informs the user that the payment has been canceled :param payment_code: Payment code. :param request: request. """# Load your Payment model given its codepayment=get_object_or_404(Payment,code=sale_code,status="pending")# Mark this payment as canceledpayment.cancel()context={'pay_status':"Done","request":request}returnrender(request,'<payment_canceled template>',{'context':context,'payment':payment})
退款视图
defrefund(request,tpv,payment_code,amount,description):""" :param request: :param tpv: TPV Id :param payment_code: Payment code :param amount: Refund Amount (Example 10.89). :param description: Description of refund cause. :return: """amount=Decimal(amount)try:# Checking if the Point of Sale existstpv=VirtualPointOfSale.get(id=tpv)# Checking if the Payment existspayment=Payment.objects.get(code=payment_code,state="paid")exceptPayment.DoesNotExistase:returnhttp_bad_request_response_json_error(message=u"Does not exist payment with code {0}".format(payment_code))refund_status=tpv.refund(payment_code,amount,description)ifrefund_status:message=u"Refund successful"else:message=u"Refund with erros"returnhttp_response_json_ok(message)