python之支付
一,alipay方式
1,国内的alipay支付:我在网上找了好多的教程,大多数都是属于国内内支付的,所以在这里我就不详细介绍了,
操作:https://www.cnblogs.com/xuanan/p/7892052.html
2,境外的alipay支付:
使用python内置的模块:Alipay
alipay_client =Alipay(
pid=PID,
key=商户的key,
seller_email=商家的email
)
接口的集成:
data={
'partner': PID,
'_input_charset': "utf-8",
'notify_url':异步回调接口,
'return_url':付款后返回给用户的接口,
'out_trade_no': 订单号,
'subject': subject,
'currency': "USD(货币)",
'total_fee':价钱(美元),
'body':'Alwayshoming system service.',
'app_pay':'Y'
}
电脑网页版api:
order_string=alipay_client.create_forex_trade_url(**data)
手机网页版api:
order_string=alipay_client.create_forex_trade_wap_url(**data)
二,Paypal支付
使用paypal支付有两种操作方法,
1,是将数据封装好,然后在使用requests去请求Paypal的付款接口
2,就是使用python支付模块:paypalrestsdk
按钮的集成:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> <div id="paypal_button"></div>
<script> $(document).ready(function(){
init_paypal();
});
function init_paypal(){
paypal.Button.render({ env: 'production', // Or 'sandbox',
client: {
sandbox: '*****',
production: '*****'
},
commit: true, // Show a 'Pay Now' button style: {
label: 'paypal',
size: 'medium', // small | medium | large | responsive
shape: 'rect', // pill | rect
color: 'blue', // gold | blue | silver | black
tagline: false
}, payment: function(data, actions) {
/* Set up the payment here */
var create_data = {
"order_id": order_id
};
var CREATE_URL = *****;
return paypal.request({method: 'post',
url: CREATE_URL,
data: create_data,
headers: {
'X-CSRFToken': CSRF_TOKEN
}
}).then(function(res) {
return res.paymentID;
});
}, onAuthorize: function(data, actions) {
/* * Execute the payment here */
var EXECUTE_URL = *****';
// Set up the data you need to pass to your server
var datas = {
"paymentID": data.paymentID,
"payerID": data.payerID,
"order_id":order_id
};
// Make a call to your server to execute the payment
return paypal.request({method: 'POST',
url: EXECUTE_URL,
data:datas,
headers: {
'X-CSRFToken': CSRF_TOKEN
}
}).then(function (res) {
if(res.code !== 0) {
alert(res.error.message);
} else {
window.alert(res.data);
window.location.href = *****;
}
}); },
onCancel: function(data, actions) {
/*Buyer cancelled the payment*/
window.alert('Payment Cancel');
}, onError: function(err) {
/*
* An error occurred during the transaction
*/
window.alert(*****);
}
}, '#paypal_button');
} </script> </body>
</html>
在使用paypalrestsdk集成支付接口对象
paypalrestsdk.configure({
"mode": "live", # sandbox or live
"client_id": "********",
"client_secret": "*******"})
加入付款信息:
payment = paypalrestsdk.Payment({
"intent": "***",
"payer": {
"payment_method": "paypal"},
"redirect_urls": {
"return_url": "****",
"cancel_url": "***"},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": order.price,
"currency": "USD",
"quantity": 1}]},
"amount": {
"total": order.price,
"currency": "USD"},
"description": description}]})
确认付款:
payment = paypalrestsdk.Payment.find(payment_id)
三,stripe信用卡支付
详细使用方法:https://stripe.com/docs
python进行支付:
def stripe_payment(request):
if request.is_ajax():
if request.method == 'POST':
pay_data = request.data
token = pay_data['token']
order_id = pay_data['order_id']
description = pay_data['description']
price = 价钱乘以100
try:
stripe.api_key = "sk_test_QPtlnU7Sl7skmuOZWAmqyuTO"
charge = stripe.Charge.create(
amount=price,
currency='usd',
description=description,
source=token,
)
result = 'Payment ' + charge['status']
except Exception as e:
result = e.message
return Response({'code': 0, 'data': result})
python之支付的更多相关文章
- Python支付宝在线支付API
一.蚂蚁金服开发平台申请测试账号 a. 登陆蚂蚁金服开放平台https://open.alipay.com/platform/manageHome.htm,在“开发中心”—“研发服务”下拉处选择沙箱作 ...
- 微信支付 python版
需求: 微信打开商品列表页面-> 点击商品后直接显示付款页面-> 点击付款调用微信支付 说明 微信支付需要你申请了公众号(appid, key - 用于签名), 商户号(mch_id, A ...
- 第四百零三节,python网站在线支付,支付宝接口集成与远程调试,
第四百零三节,python网站在线支付,支付宝接口集成与远程调试, windows系统安装Python虚拟环境 首先保证你的系统已经安装好了Python 安装virtualenv C:\WINDOWS ...
- python 全栈开发,Day106(结算中心(详细),立即支付)
昨日内容回顾 1. 为什么要开发路飞学城? 提供在线教育的学成率: 特色: 学,看视频,单独录制增加趣味性. 练,练习题 改,改学生代码 管,管理 测,阶段考核 线下:8次留级考试 2. 组织架构 - ...
- python 全栈开发,Day102(支付宝支付)
昨日内容回顾 1. django请求生命周期? - 当用户在浏览器中输入url时,浏览器会生成请求头和请求体发给服务端 请求头和请求体中会包含浏览器的动作(action),这个动作通常为get或者po ...
- s11 day 101 python Linux环境安装 与路飞项目支付功能
from django.conf.urls import urlfrom django.contrib import adminfrom app01 import viewsurlpatterns = ...
- Python实现支付宝在线支付
windows系统安装Python虚拟环境 首先保证你的系统已经安装好了Python 安装virtualenv C:\WINDOWS\system32>pip3 install virtuale ...
- Python支付接口汇总大全(包含微信、支付宝等)
微信接口 wzhifuSDK- 由微信支付SDK 官方PHP Demo移植而来,v3.37下载地址 weixin_pay- 是一个简单的微信支付的接口 weixin_pay- 微信支付接口(V3.3. ...
- Python实现微信小程序支付功能
由于最近自己在做小程序的支付,就在这里简单介绍一下讲一下用python做小程序支付这个流程.当然在进行开发之前还是建议读一下具体的流程,清楚支付的过程. 1.支付交互流程 当然具体的参数配置可以参考官 ...
随机推荐
- K8s快速入门
在k8s中所有的内容都抽象为资源,资源实例化之后,叫做对象.一般使用yaml格式的文件来创建符合我们预期期望的pod,这样的yaml文件我们一般称为资源清单 资源清单的格式: apiVersion: ...
- CentOS6.3上搭建expect无交互开发环境
1.背景 在面向shell编程时对于需要交互的场合则必须通过人工来干预,而对于这种方式是违反无人职守的原则:现在expect就解决了这个问题, Expect是一个免费的编程工具语言,用来实现自动和交互 ...
- python 推导式
推导式又称解析式,是Python的一种独有特性.目的是可以从一个数据序列推导出另一个数据序列,适用于python 的list ,dict 和集合 list中的推导式: _list=[i for i i ...
- appium+夜神模拟器+python安卓app爬虫初体验
环境搭建:Windows 7 64bit jdk包:jdk-8u171-windows-x64.exe(http://www.oracle.com/technetwork/java/javase/do ...
- 解题(Solution -4Sum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- 用eclipse创建动态web项目手动生成web.xml方法
建一个web项目,后来在用到web.xml文件时,才发现项目创建时没有自动创建web.xml文件. 在创建的项目上单击右键,然后单击java EE Tools下的用红线圈住的地方,然后查看你的WEB- ...
- Centos 7 Ntop 流量分析 安装
Centos 6 安装 Ntop:https://www.cnblogs.com/weijie0717/p/4886314.html 一.安装 1.添加EPEL 仓库 # yum install ep ...
- python环境搭建(linux)
python安装 # wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz # yum install openssl-devel ...
- 【python深入】map/reduce/lambda 内置函数的使用
python中的内置函数里面,有map和reduce两个方法,这两个方法可以非常好的去做一些事情,但是之前都没有用过,下面是关于这两个方法的介绍: 一.map相关 map()会根据提供的函数对指定的序 ...
- 19-03【golang】strings包
golang的strings包提供了字符串操作的一系列函数.下面做个简单介绍 函数 用法 备注 Compare(a,b sring) 比较两个字符串 Contains(s, substr stri ...