VietQR.Deeplink.Client 1.0.6

dotnet add package VietQR.Deeplink.Client --version 1.0.6
                    
NuGet\Install-Package VietQR.Deeplink.Client -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VietQR.Deeplink.Client" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VietQR.Deeplink.Client" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="VietQR.Deeplink.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add VietQR.Deeplink.Client --version 1.0.6
                    
#r "nuget: VietQR.Deeplink.Client, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package VietQR.Deeplink.Client@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=VietQR.Deeplink.Client&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=VietQR.Deeplink.Client&version=1.0.6
                    
Install as a Cake Tool

VietQR.Deeplink.Client

NuGet NuGet Downloads .NET License

Thư viện client C# (.NET) kết nối dịch vụ VietQR Deeplink để lấy link mở ứng dụng ngân hàng khi thanh toán bằng mã VietQR, hỗ trợ Dependency Injection trong ASP.NET Core và phương thức mở rộng cho VietQR.Core.


⚡ Tính năng

  • Mở rộng VietQR.Core: Tạo mã thanh toán và lấy link mở app ngân hàng nhanh chóng chỉ với 1 dòng lệnh.
  • Tra cứu danh sách App tự động: Cung cấp hàm GetSupportedAppsAsync() và API công khai để lấy danh sách 43+ ngân hàng & ví điện tử (kèm logo, mã BIN, cờ SupportsAutofill).
  • Truyền mã linh hoạt: Chấp nhận AppCode ("MB"), ShortName ("MBBank"), mã BIN 6 số ("970422") hoặc Alias (không phân biệt hoa thường).
  • Dependency Injection: Đăng ký qua services.AddVietQrDeeplink() trong ASP.NET Core hoặc Generic Host.
  • Tự động nhận diện Endpoint: Tự động cập nhật domain máy chủ Deeplink qua Discovery Endpoint (có in-memory cache).
  • Hỗ trợ đa nền tảng .NET: Chạy tốt trên .NET 6.0, .NET 8.0, .NET 9.0, .NET 10.0.

📦 Cài đặt

dotnet add package VietQR.Core
dotnet add package VietQR.Deeplink.Client

🚀 Hướng dẫn sử dụng

1. Đăng ký dịch vụ trong Program.cs

using VietQR.Deeplink.Client;

// Cách 1: Sử dụng cấu hình mặc định (Zero-config, chạy ngay không cần tham số)
builder.Services.AddVietQrDeeplink();

// Cách 2: Tùy biến domain máy chủ hoặc timeout nếu tự host
builder.Services.AddVietQrDeeplink(options =>
{
    options.BaseUrl = "https://deeplink.example.com";
    options.TimeoutSeconds = 10;
});

Cấu hình mẫu trong appsettings.json (tùy chọn, không bắt buộc):

{
    "Deeplink": {
        "BaseUrl": "https://deeplink.example.com",
        "TimeoutSeconds": 10
    }
}
using VietQR.Core;
using VietQR.Deeplink.Client;

public class CheckoutController : ControllerBase
{
    private readonly IVietQrDeeplinkClient _deeplinkClient;

    public CheckoutController(IVietQrDeeplinkClient deeplinkClient)
    {
        _deeplinkClient = deeplinkClient;
    }

    [HttpPost("pay")]
    public async Task<IActionResult> CreatePayment(CancellationToken ct)
    {
        // 1. Tạo chuỗi QR thanh toán chuẩn Napas247 bằng VietQR.Core
        var qr = new VietQr()
            .SetBeneficiaryOrganization("970422", "113366668888", VietQrServiceType.Account)
            .SetTransactionAmount("50000")
            .SetAdditionalData(purpose: "Thanh toan don hang #1024");

        // 2. Lấy link ngắn hạn mở app ngân hàng
        // Tham số thứ 2 chấp nhận: Mã App ("MB"), Tên ngắn ("MBBank") hoặc Mã BIN 6 số ("970422")
        var intent = await qr.ToDeeplinkUrlAsync(_deeplinkClient, "MB", ct);

        if (intent == null)
        {
            return BadRequest("Không thể tạo link mở app ngân hàng.");
        }

        // intent.Url: "https://deeplink.example.com/p/x8K2mN9..."
        // intent.ExpiresInSeconds: 60
        return Ok(new { paymentUrl = intent.Url, expiresIn = intent.ExpiresInSeconds });
    }
}

🔍 Làm sao để biết Ngân hàng / Ví điện tử nào được hỗ trợ?

Bạn có 2 cách để lấy hoặc kiểm tra danh sách các ứng dụng được hỗ trợ mở Deeplink:

Cách 1: Lấy bằng code C# qua SDK (GetSupportedAppsAsync)

Dùng hàm _deeplinkClient.GetSupportedAppsAsync() để lấy danh sách động từ máy chủ (rất tiện để trả về cho Frontend/Mobile dựng màn hình chọn App thanh toán):

[HttpGet("supported-apps")]
public async Task<IActionResult> GetSupportedApps(CancellationToken ct)
{
    IReadOnlyList<DeeplinkBankAppInfo> apps = await _deeplinkClient.GetSupportedAppsAsync(ct);

    // Ví dụ lọc ra các ngân hàng hỗ trợ tự động điền thông tin chuyển khoản (Autofill)
    var autofillApps = apps.Where(a => a.SupportsAutofill).ToList();

    return Ok(apps);
}

Mỗi phần tử DeeplinkBankAppInfo trả về gồm:

  • AppCode: Mã truyền vào hàm tạo link (VD: "MB", "VCB", "TPB", "MOMO").
  • Bin: Mã BIN 6 số chuẩn NAPAS (VD: "970422").
  • ShortName: Tên viết tắt ngân hàng (VD: "MBBank", "Vietcombank").
  • AppName: Tên ứng dụng hiển thị (VD: "MB Bank", "VCB Digibank").
  • Logo: URL ảnh icon ứng dụng ngân hàng sắc nét.
  • SupportsAutofill: true nếu mở thẳng màn hình chuyển khoản và tự điền STK/Số tiền/Nội dung; false nếu chỉ mở ứng dụng.

Kết quả JSON mẫu khi trả về cho Frontend:

{
    "code": "00",
    "desc": "success",
    "data": [
        {
            "appCode": "MB",
            "bin": "970422",
            "shortName": "MBBank",
            "appName": "MB Bank",
            "logo": "https://deeplink.example.com/icons/mb.png",
            "supportsAutofill": true,
            "supportsIos": true,
            "supportsAndroid": true
        },
        {
            "appCode": "VCB",
            "bin": "970436",
            "shortName": "Vietcombank",
            "appName": "VCB Digibank",
            "logo": "https://deeplink.example.com/icons/vcb.png",
            "supportsAutofill": false,
            "supportsIos": true,
            "supportsAndroid": true
        }
    ]
}

Cách 2: Gọi trực tiếp qua HTTP REST API

GET https://vietqr.hiendev.io.vn/api/v1/vietqr-core/deeplink/apps

Hệ thống sẽ trả về danh mục ngân hàng kèm logo, mã BIN và cờ supportsAutofill (true nếu hỗ trợ tự điền dữ liệu, false nếu chỉ mở ứng dụng).

Lưu ý về cơ chế Deeplink:

  • Nhóm 1 (supportsAutofill = true): Mở app + tự động điền sẵn STK, số tiền, nội dung vào màn hình chuyển khoản (Hiện có 7 app: BIDV, MB, OCB, TPBank, CAKE, MoMo, ZaloPay).
  • Nhóm 2 (supportsAutofill = false): Vẫn là Deeplink mở thẳng ứng dụng ngân hàng trên thiết bị (dẫn vào app hoặc màn hình quét mã QR/chuyển tiền), không tự điền sẵn dữ liệu.

💡 Mẹo truyền mã: Khi gọi ToDeeplinkUrlAsync(_deeplinkClient, appCode) hoặc CreateIntentAsync(appCode, qrContent), bạn có thể truyền linh hoạt bất kỳ định danh nào: mã appCode (VD: "MB"), tên viết tắt shortName (VD: "MBBank"), mã BIN 6 số chuẩn NAPAS (VD: "970422"), hoặc bí danh aliases mà không phân biệt chữ hoa/thường.


📄 Giấy phép

Phát hành theo giấy phép MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 82 11/3/2026
1.0.5 91 11/2/2026
1.0.4 99 11/1/2026
1.0.3 99 11/1/2026
1.0.2 122 11/1/2026

feat(api): Tối ưu giao diện test Deeplink playground và cập nhật tài liệu client (252ad03)