An Unofficial Alipay API for Python

Related tags

E-commercealipay
Overview

An Unofficial Alipay API for Python

Overview

An Unofficial Alipay API for Python, It Contain these API:

  • Generate direct payment url
  • Generate partner trade payment url
  • Generate standard mixed payment url
  • Generate batch trans pay url
  • Generate send goods confirm url
  • Generate forex trade url
  • Generate QR code url
  • Verify notify
  • Single Trade Query
  • Generate Refund With Pwd URL

official document: https://b.alipay.com/order/techService.htm

Install

pip install alipay

Usage

Initialization

>>> from alipay import Alipay
>>> alipay = Alipay(pid='your_alipay_pid', key='your_alipay_key', seller_email='your_seller_mail')

Or you can use seller_id instead of seller_email:

>>> alipay = Alipay(pid='your_alipay_pid', key='your_alipay_key', seller_id='your_seller_id')

Generate direct payment url

生成即时到账支付链接

Introduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373124

>>> alipay.create_direct_pay_by_user_url(out_trade_no='your_order_id', subject='your_order_subject', total_fee='100.0', return_url='your_order
_return_url', notify_url='your_order_notify_url')
'https://mapi.alipay.com/gateway.do?seller_email=.....'

Generate partner trade payment url

生成担保交易支付链接

Introduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373121

>>> params = {
... 'out_trade_no': 'your_order_id',
... 'subject': 'your_order_subject',
... 'logistics_type': 'DIRECT',
... 'logistics_fee': '0',
... 'logistics_payment': 'SELLER_PAY',
... 'price': '10.00',
... 'quantity': '12',
... 'return_url': 'your_order_return_url',
... 'notify_url': 'your_order_notify_url'
... }
>>> alipay.create_partner_trade_by_buyer_url(**params)
'https://mapi.alipay.com/gateway.do?seller_email=.....'

Generate standard mixed payment url

生成标准双接口支付链接

Introduction: https://b.alipay.com/order/productDetail.htm?productId=2012111300373136

>>> alipay.trade_create_by_buyer_url(**params)
'https://mapi.alipay.com/gateway.do?seller_email=.....'

Generate batch trans pay url

生成批量付款链接

Introduction: https://b.alipay.com/order/productDetail.htm?productId=2012111200373121

>>> params = {
... 'batch_list': (), #批量付款用户列表
... 'account_name': 'seller_account_name', #卖家支付宝名称
... 'batch_no': 'batch_id', #转账流水号,须唯一
... 'notify_url': 'your_batch_notify_url' #异步通知地址
... }
>>> alipay.create_batch_trans_notify_url(**params)
'https://mapi.alipay.com/gateway.do?seller_email=xxx&detail_data=....'

Note: batch_list 为批量付款用户列表,具体格式如下例子:(如涉及中文请使用unicode字符)

>>> batch_list = ({'account': '[email protected]', #支付宝账号
...                'name': u'测试', #支付宝用户姓名
...                'fee': '100', #转账金额
...                'note': 'test'},
...               {'account': '[email protected]', #支付宝账号
...                'name': u'测试', #支付宝用户姓名
...                'fee': '100', #转账金额
...                'note': 'test'}) #转账原因

Generate send goods confirm url

生成确认发货链接

Introduction: https://cshall.alipay.com/support/help_detail.htm?help_id=491097

>>> params = {
... 'trade_no': 'your_alipay_trade_id',
... 'logistics_name': 'your_logicstic_name',
... 'transport_type': 'EXPRESS',
... 'invocie_no': 'your_invocie_no'
... }
>>> alipay.send_goods_confirm_by_platform(**params)
'https://mapi.alipay.com/gateway.do?sign=.....&trade_no=...'

Generate forex trade url

  • Create website payment for foreigners (With QR code)
  • Create mobile payment for foreigners

Introduction: http://global.alipay.com/ospay/home.htm

>>> params = {
... 'out_trade_no': 'your_order_id',
... 'subject': 'your_order_subject',
... 'logistics_type': 'DIRECT',
... 'logistics_fee': '0',
... 'logistics_payment': 'SELLER_PAY',
... 'price': '10.00',
... 'quantity': '12',
... 'return_url': 'your_order_return_url',
... 'notify_url': 'your_order_notify_url'
... }
>>> # Create website payment for foreigners
>>> alipay.create_forex_trade_url(**params)
'https://mapi.alipay.com/gateway.do?service=create_forex_trade......'
>>> # Create mobile payment for foreigners
>>> alipay.create_forex_trade_wap_url(**params)
'https://mapi.alipay.com/gateway.do?service=create_forex_trade_wap......'

Generate QR code url

生成创建 QR 码链接

Introduction: https://b.alipay.com/order/productDetail.htm?productId=2012120700377303

>>> alipay.add_alipay_qrcode_url(**params)
'https://mapi.alipay.com/gateway.do?seller_id=.......'

Note: 如果你的 biz_data 中有 Unicode 字符,在 dumps 的时候需要把 ensure_ascii 设置为 False,即 json.dumps(d, ensure_ascii=False) 否则会遇到错误

Verify notify

verify notify from alipay server, example in Pyramid Application

def alipy_notify(request):
    alipay = request.registry['alipay']
    if alipay.verify_notify(**request.params):
        # this is a valid notify, code business logic here
    else:
        # this is a invalid notify

Single Trade Query

单笔交易查询

文档:http://wenku.baidu.com/link?url=WLjyz-H6AlfDLIU7kR4LcVNQgxSTMxX61fW0tDCE8yZbqXflCd0CVFsZaIKbRFDvVLaFlq0Q3wcJ935A7Kw-mRSs0iA4wQu8cLaCe5B8FIq

import re
xml = alipay.single_trade_query(out_trade_no="10000005")
res = re.findall('<trade_status>(\S+)</trade_status>', xml) # use RE to find trade_status, xml parsing is more useful, in fact.
status = None if not res else res[0]
print status # will print out TRADE_SUCCESS when trade is success

Generate Refund With Pwd URL

生成即时到账有密退款链接

Introduction: https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.XRddqH&treeId=62&articleId=104744&docType=1

>>> params = {
... 'batch_list': (), #批量退款数据集
... 'batch_no': 'batch_id', #退款批次号,须唯一
... 'notify_url': 'your_batch_notify_url' #异步通知地址
... }
>>> alipay.refund_fastpay_by_platform_pwd(**params)
'https://mapi.alipay.com/gateway.do?seller_email=xxx&detail_data=....'

Note: batch_list 为批量退款数据集,具体格式如下例子:(如涉及中文请使用unicode字符)

>>> batch_list = ({'trade_no': 'xxxxxxxx', #原付款支付宝交易号
...                'fee': '100', #退款总金额
...                'note': 'test'}, #退款原因
...               {'trade_no': 'xxxxxxxx', #原付款支付宝交易号
...                'fee': '100', #退款总金额
...                'note': 'test'}) #退款原因

Example in Pyramid Application

Include alipay either by setting your includes in your .ini, or by calling config.include('alipay').

pyramid.includes = alipay

now in your View

def some_view(request):
    alipay = request.registry['alipay']
    url = alipay.create_direct_pay_by_user_url(...)

Reference

Owner
Eric Lo
Eric Lo
A modular, high performance, headless e-commerce platform built with Python, GraphQL, Django, and React.

Saleor Commerce Customer-centric e-commerce on a modern stack A headless, GraphQL commerce platform delivering ultra-fast, dynamic, personalized shopp

Saleor Commerce 17.7k Jan 01, 2023
Foreign exchange rates, Bitcoin price index and currency conversion using ratesapi.io

forex-python Forex Python is a Free Foreign exchange rates and currency conversion. Note: Install latest forex-python==1.1 to avoid RatesNotAvailableE

MicroPyramid 540 Jan 05, 2023
A modular, high performance, headless e-commerce platform built with Python, GraphQL, Django, and React.

Saleor Commerce Customer-centric e-commerce on a modern stack A headless, GraphQL-first e-commerce platform delivering ultra-fast, dynamic, personaliz

Mirumee Labs 17.7k Dec 31, 2022
Portfolio and E-commerce site built on Python-Django and Stripe checkout

StripeMe Introduction Stripe Me is an e-commerce and portfolio website offering communication services, including web-development, graphic design and

3 Jul 05, 2022
Domain-driven e-commerce for Django

Domain-driven e-commerce for Django Oscar is an e-commerce framework for Django designed for building domain-driven sites. It is structured such that

Oscar 5.6k Dec 30, 2022
Currency Conversion in Python

CurrencyConversion connect to an API to do currency conversions, save as json text or screen output exchangeratesAPI.py -h Exchange Rates via 'api.cur

soup-works 1 Jan 29, 2022
Django_E-commerce - an open-source ecommerce platform built on the Django Web Framework.

Django E-commerce Django-ecommerce is an open-source ecommerce platform built on the Django Web Framework. Demo Homepage Cartpage Orderpage Features I

Biswajit Paloi 6 Nov 06, 2022
A web application to search for input products across several supermarkets' e-commerce to return price, detail of products running on Python.

Price Checker A web application to search for input products across several supermarkets' e-commerce to return price, detail of products. Requirements

3 Jun 28, 2022
imager is a modern ecommerce & social network platform that helps users to find the most matching products

imager is a modern ecommerce & social network platform that helps users to find the most matching products. Users can follow their favourite brands and to be aware of friends' actions. If you have se

Sardor 1 Jan 11, 2022
A Django based shop system

django-SHOP Django-SHOP aims to be a the easy, fun and fast e-commerce counterpart to django-CMS. Here you can find the full documentation for django-

Awesto 2.9k Jan 02, 2023
A Django e-commerce website

BRIKKHO.com E-commerce website created with Django Run It: Clone the project or download as zip: $ git clone https://github.com/FahadulShadhin/brikkho

Shadhin 1 Dec 17, 2021
Ecommerce app using Django, Rest API and ElasticSearch

e-commerce-app Ecommerce app using Django, Rest API, Docker and ElasticSearch Sort pipfile pipfile-sort Runserver with Werkzeug (django-extensions) .

Nhat Tai NGUYEN 1 Jan 31, 2022
An eBay-like e-commerce auction site that will allow users to post auction listings, place bids on listings, comment on those listings, and add listings to a watchlist.

e-commerce-auction-site This repository is my solution to Commerce project of CS50’s Web Programming with Python and JavaScript course by Harvard. 🚀

3 Sep 03, 2022
Fully functional ecommerce website with user and guest checkout capabilities and Paypal payment integration.

ecommerce_website Fully functional ecommerce website with user and guest checkout capabilities and Paypal payment integration. pip install django pyth

2 Jan 05, 2022
Storefront - An E-commerce StoreFront Application Built With Python

An E-commerce StoreFront Application A very robust storefront project. This is a

Fachii Felix Zasha 1 Apr 04, 2022
An Unofficial Alipay API for Python

An Unofficial Alipay API for Python Overview An Unofficial Alipay API for Python, It Contain these API: Generate direct payment url Generate partner t

Eric Lo 321 Dec 24, 2022
PVE with tcaledger app for payments and simulation of payment requests

tcaledger PVE with tcaledger app for payments and simulation of payment requests. The purpose of this API is to empower users to accept cryptocurrenci

3 Jan 29, 2022
Re-write of floppshop e-commerce site

Floppshop V2 Python: 3.9.5 FastAPI: 0.68 Tortoise-orm: 0.17.8 pytest: 5.2 PostgreSQL: 13.4 Setup Srak jak nie wiesz jak Clone repository $ git clone

jakub-figat 3 Nov 30, 2022
A Django app to accept payments from various payment processors via Pluggable backends.

Django-Merchant Django-Merchant is a django application that enables you to use multiple payment processors from a single API. Gateways Following gate

Agiliq 997 Dec 24, 2022
Ecommerce for Mezzanine

Created by Stephen McDonald Overview Cartridge is a shopping cart application built using the Django framework. It is BSD licensed, and designed to pr

Stephen McDonald 680 Jan 03, 2023