explaingit

minibear2021/douyinpay

14PythonAudience · developerComplexity · 3/5Setup · hard

TLDR

Python library for integrating Douyin Pay (Chinese TikTok's payment system) into your backend. Handles API calls, signing, encryption, certificates, and payment notifications automatically.

Mindmap

mindmap
  root((douyinpay))
    What it does
      Create payment orders
      Process refunds
      Query and close orders
      Download billing records
    Payment Types
      App payments
      H5 browser payments
      JSAPI mini-program
      Native QR code
    Security
      RSA signing
      SM2 national standard
      Auto certificate management
    Advanced Features
      Profit sharing
      Wallet transfers
      Async support
      Notification parser
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add Douyin Pay checkout to a Chinese e-commerce app or mini-program so customers can pay via QR code, H5, or in-app.

USE CASE 2

Handle refunds and query order status automatically in a backend service that sells to Douyin users.

USE CASE 3

Split revenue between multiple parties after a sale, such as a marketplace paying out sellers.

USE CASE 4

Receive and securely verify payment notifications from Douyin, returning the correct status codes the platform requires.

Tech stack

PythonRSASM2Async/AwaitHTTPSDouyin Pay API

Getting it running

Difficulty · hard Time to first run · 1day+

Requires a Douyin merchant account with approved API access. You must obtain a merchant ID, certificate serial number, private key, and encryption key from the Douyin merchant platform before any code will run.

License not mentioned in the explanation.

In plain English

This is a Python library for backend developers who need to integrate with Douyin Pay, the payment system of Douyin, which is the Chinese version of TikTok. The README is written in Chinese. The library handles the API calls, signing, encryption, and certificate management that the Douyin Pay platform requires. Installing the library and creating a client requires a merchant ID, an API certificate serial number, a private key, and an encryption key, all of which are obtained from the Douyin merchant platform. Once configured, the client provides methods for creating payment orders across several payment types: app payments, H5 browser payments, JSAPI payments for mini-programs, and native QR code payments. It also supports querying and closing orders, processing refunds, downloading billing records, splitting revenue among multiple parties (profit sharing), and transferring funds directly to a user's Douyin wallet. The library supports both synchronous and asynchronous usage. Both clients share the same method names and parameters, so switching between them is straightforward. Async calls require only an added await keyword. A context manager interface is available for both modes to ensure connections are closed properly. For security, the library supports two signing algorithms: RSA and the Chinese national cryptography standard SM2. Choosing between them is a matter of passing the appropriate value in the config. The library also manages platform certificates automatically, downloading, decrypting, caching, and refreshing them without any manual steps. When Douyin sends a payment notification to your server, the included parser verifies the signature and decrypts the payload, then raises specific exception types for signature failures or decryption errors so that you can return the correct HTTP status codes as required by the platform. Error handling also covers API business errors and network failures as distinct exception classes.

Copy-paste prompts

Prompt 1
Using the douyinpay Python library, show me how to create an async client with my merchant ID, certificate serial number, private key, and encryption key, then create a native QR code payment order.
Prompt 2
Using douyinpay, write Python code to handle an incoming Douyin Pay notification webhook: verify the signature, decrypt the payload, and return the correct HTTP response. Handle signature and decryption errors separately.
Prompt 3
Show me how to use douyinpay to process a refund for an existing order and then download the billing records for the current month.
Prompt 4
Using the douyinpay library, demonstrate how to set up profit sharing after a successful payment, splitting revenue between two merchant parties.
Prompt 5
How do I switch from the synchronous douyinpay client to the async client? Show a side-by-side example of creating a payment order both ways using the SM2 signing algorithm.
Open on GitHub → Explain another repo

← minibear2021 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.