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.支付交互流程 当然具体的参数配置可以参考官 ...
随机推荐
- Cordova开发App使用USB进行真机调试
在使用cordova开发app时,不像浏览器中可以直接使用浏览器的开发者工具进行调试.为了看到app的显示效果, 一种是使用模拟器进行展示,一种是使用真机进行展示. 模拟器:可以使用Android s ...
- 算法之Python实现 - 001 : 换钱的最少货币数
[题目]给定数组arr,arr中所有的值都为正数且不重复.每个值代表一种面值的货币,每种面值的货币可以使用任意张,再给定一个整数aim代表要找的钱数,求组成aim的最少货币数. [代码1]:时间与额外 ...
- SuRF: Practical Range Query Filtering with Fast Succinct Tries 阅读笔记
SuRF(Succinct Range Filter)是一种快速而紧凑的过滤器,同时支持点查询和范围查询(包括开区间查询.闭区间查询.范围计数),可以在RocksDB中用SuRF来替换Bloom过滤器 ...
- jsp Servlet 文件上传
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 阿里巴巴 Weex
原文链接:https://blog.csdn.net/zz901214/article/details/79168707/ 分享嘉宾:侑夕 阿里巴巴高级前端工程师(上张帅哥的图镇楼,看完,更有动力学习 ...
- bootstrap日期选择
<input type="text" class="form-control datepicker" style="padding: 0.375 ...
- python的可变对象与不可变对象
a = 1print(id(a))def fun(a): a = 2 print(a,id(a))fun(a)print(a,id(a)) # 1#为什么这里的a的值没有改变#因为在函数里变量赋值(内 ...
- C#移除URL上指定的参数
/// <summary> /// 移除URL上指定的参数,不区分参数大小写 /// </summary> public static ...
- 软件工程Ⅱ:Git的安装与使用
作业要求来自于https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 1.下载安装配置用户名和邮箱. (1) 安装Git软件. (2) ...
- 微信小程序超出两行省略号
display: -webkit-box; overflow: hidden; text-overflow: ellipsis; word-wrap: break-word; white-space: ...