一,alipay方式html
1,國內的alipay支付:我在網上找了好多的教程,大多數都是屬於國內內支付的,因此在這裏我就不詳細介紹了,python
操做:https://www.cnblogs.com/xuanan/p/7892052.htmlajax
2,境外的alipay支付: api
使用python內置的模塊:Alipay app
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:ide
order_string=alipay_client.create_forex_trade_url(**data)
手機網頁版api:post
order_string=alipay_client.create_forex_trade_wap_url(**data)
二,Paypal支付url
使用paypal支付有兩種操做方法,spa
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})