一,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})