Implementing WeChat Pay Order Inquiry with ASP.NET Core and API V3

Official Documentation Reference

Order Status Inquiry Implementation

The WeChat Pay API provides two methods for order lookup: querying by merchant-generated identifiers or WeChat-generated transaction IDs. This implementation utilizes the merchant-specific approach.

To query payment status, the request must include proper authentication headers following WeChat's API specifications. Signature generation detail are documented in previous articles: "ASP.NET Core WeChat Pay Integration (Part 1: Unified Order API V3)" and "Resolving Signature Encryption Errrors in ASP.NET Core WeChat Pay (Part 2)".

Response Model Definition

public class WeChatOrderStatusResponse
{
    /// <summary>
    /// Merchant-specific order identifier (alphanumeric, unique per merchant)
    /// </summary>
    public string merchantOrderNumber { get; set; }

    /// <summary>
    /// WeChat-assigned transaction identifier
    /// </summary>
    public string wechatTransactionId { get; set; }

    /// <summary>
    /// Payment type enumeration:
    /// JSAPI - Official Account payments
    /// NATIVE - QR code payments
    /// APP - Mobile app payments
    /// MICROPAY - Barcode payments
    /// MWEB - Mini-program payments
    /// FACEPAY - Facial recognition payments
    /// </summary>
    public string paymentType { get; set; }

    /// <summary>
    /// Transaction status enumeration:
    /// SUCCESS - Completed
    /// REFUND - Refunded
    /// NOTPAY - Unpaid
    /// CLOSED - Closed
    /// REVOKED - Revoked (barcode payments)
    /// USERPAYING - Processing (barcode payments)
    /// PAYERROR - Failed
    /// ACCEPT - Awaiting processing
    /// </summary>
    public string transactionStatus { get; set; }

    /// <summary>
    /// Human-readable status description
    /// </summary>
    public string statusDescription { get; set; }

    /// <summary>
    /// Payer information
    /// </summary>
    public PayerInformation payer { get; set; }
}

/// <summary>
/// Payer details model
/// </summary>
public class PayerInformation
{
    /// <summary>
    /// Unique user identifier for the connected merchant
    /// </summary>
    public string userIdentifier { get; set; }
}

API Request Implementation

var apiEndpoint = $"https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{transactionId}?mchid={PaymentConstants.merchantId}";
using var httpClient = new HttpClient(new SecureHandler());
var response = await httpClient.GetAsync(apiEndpoint);
Logger.Log("Order status inquiry initiated");
var responseBody = await response.Content.ReadAsStringAsync();
var orderStatus = responseBody.DeserializeJson<WeChatOrderStatusResponse>();

JSON Deserialization Utility

/// <summary>
/// Converts JSON string to strongly-typed object
/// </summary>
/// <typeparam name="T">Target type</typeparam>
/// <param name="jsonInput">Input JSON string</param>
/// <returns>Deserialized object</returns>
public static T DeserializeJson<T>(this string jsonInput)
{
    return string.IsNullOrEmpty(jsonInput) ? default(T) : JsonConvert.DeserializeObject<T>(jsonInput);
}

Tags: ASP.NET Core WeChat Pay API V3 JSON Deserialization

Posted on Fri, 16 Oct 2026 16:24:42 +0000 by Jorge