Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:A616567126 GPT WEB JAVA Payment Gateway Integration

From Leeroopedia
Knowledge Sources
Domains Payments, API_Integration, Security
Last Updated 2026-10-13 00:00 GMT

Overview

Pattern that integrates with external payment gateways (YiPay, WeChat Pay v3) by creating signed orders, redirecting users to gateway checkout, and processing authenticated callbacks to verify payment success.

Description

Payment gateway integration enables an application to accept payments through third-party payment processors. The flow involves three phases: order creation (construct signed payment parameters), gateway redirect (user completes payment externally), and callback verification (gateway notifies the application of payment status).

This repository integrates with two payment gateways:

  • YiPay: A generic third-party payment aggregator (WeChat, QQ, Alipay). Uses MD5 signature of sorted parameters.
  • WeChat Pay v3: Direct WeChat Native payment. Uses RSA-SHA256 signatures and AES-256-GCM encrypted callbacks.

Each gateway has different signing algorithms, callback formats, and verification methods, requiring gateway-specific handling code.

Usage

Use this principle when:

  • Accepting payments through external payment processors
  • Needing multi-gateway support (YiPay, WeChat Pay)
  • Handling asynchronous payment callbacks securely

Theoretical Basis

Three-Phase Payment Flow:

# Abstract algorithm (NOT real implementation)
def create_order(product, user, pay_type):
    order = save_to_db(product, user, price)
    params = {
        "pid": MERCHANT_ID,
        "out_trade_no": order.id,
        "money": order.price,
        "notify_url": callback_url,
        ...
    }
    params["sign"] = md5_sign(sort_and_concat(params) + SECRET_KEY)
    return params  # Client redirects to gateway with these params

def handle_callback(callback_data):
    order = get_order(callback_data.out_trade_no)
    if verify_signature(callback_data) and amounts_match:
        order.state = SUCCESS
        top_up_credits(order)
    return "success"  # Gateway expects acknowledgment

Signature Methods:

  • YiPay: MD5 of sorted key=value pairs concatenated with & and appended secret key
  • WeChat Pay v3: RSA-SHA256 signature of HTTP method + URL + timestamp + nonce_str + body

Callback Verification:

  • YiPay: Simple callback with trade_status, verified by matching PID and amount
  • WeChat Pay v3: AES-256-GCM decryption of ciphertext field using wxV3Secret

Practical Guide

The repository implements this in OrderServiceImpl and WxPayUtil:

  1. createYiOrder() — creates order, constructs CreateOrderRes with MD5 sign via createSign()
  2. yiCallBack() — verifies PID and amount, updates order state, calls okOrder() to top up credits
  3. wxCallBack() — decrypts AES/GCM ciphertext, extracts trade_state, generates card pin, sends WeChat kefu message
  4. WxPayUtil.getToken() — builds RSA-SHA256 signature for WeChat Pay v3 API requests
  5. WxPayUtil.buildNativePayJson() — constructs Native pay JSON with amount in cents

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment