NinePay.NetCore 1.0.0

dotnet add package NinePay.NetCore --version 1.0.0
                    
NuGet\Install-Package NinePay.NetCore -Version 1.0.0
                    
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="NinePay.NetCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NinePay.NetCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NinePay.NetCore" />
                    
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 NinePay.NetCore --version 1.0.0
                    
#r "nuget: NinePay.NetCore, 1.0.0"
                    
#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.
#addin nuget:?package=NinePay.NetCore&version=1.0.0
                    
Install NinePay.NetCore as a Cake Addin
#tool nuget:?package=NinePay.NetCore&version=1.0.0
                    
Install NinePay.NetCore as a Cake Tool

NinePay.NetCore

NinePay.NetCore là một thư viện được thiết kế để tích hợp cổng thanh toán 9Pay vào các ứng dụng .NET Core. Nó giúp đơn giản hóa quá trình tạo liên kết thanh toán, xử lý callback (ReturnURL, IPN) và xử lý phản hồi thanh toán.

Tính năng

  • Tích hợp Dependency Injection: Dễ dàng cấu hình NinePayOptionsNinePayService với Dependency Injection.
  • Dịch vụ Thanh toán Tùy chỉnh: Cho phép sử dụng các triển khai tùy chỉnh của interface INinePayService để xử lý thanh toán.
  • Xử lý Callback: Hỗ trợ tự động cấu hình các endpoints để xử lý các callback từ 9Pay (ReturnURL, IPN).
  • Tạo Liên kết Thanh toán: Cho phép tạo liên kết thanh toán cho các giao dịch 9Pay.
  • Tích hợp Processor: Hỗ trợ thêm các processor tùy chỉnh để xử lý dữ liệu trả về từ 9Pay.

Cài đặt

Để cài đặt NinePay.NetCore, sử dụng NuGet Package Manager hoặc .NET CLI:

dotnet add package NinePay.NetCore

Cấu hình và Thiết lập

1. Cấu hình NinePay trong Startup.cs hoặc Program.cs

Trong Startup.cs hoặc Program.cs của ứng dụng, đăng ký các dịch vụ của 9Pay và cấu hình các tùy chọn.

public void ConfigureServices(IServiceCollection services)
{
    services.AddNinePay(options => Configuration.GetSection("NinePay").Bind(options));
    services.AddTransient<INinePayProcessor, TestNinePayProcessor>();
}

2. Định tuyến các Endpoints của NinePay

Trong phương thức Configure, cấu hình các endpoint để xử lý các phản hồi ReturnURL và IPN từ NinePay.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.MapNinePay();
}

3. Tạo Liên kết Thanh toán

Sử dụng NinePayService để tạo một liên kết thanh toán cho giao dịch.

public class SomeClass
{
    private readonly INinePayService _NinePayService;

    public SomeClass(INinePayService NinePayService)
    {
        _NinePayService = NinePayService;
    }

    public async Task CreateLink(NinePayRequest request, string returnUrl)
    {
        var url = await _NinePayService.CreatePaymentLink(TestNinePayProcessor.TYPE, request, returnUrl);
    }
}

Tùy chỉnh Dịch vụ Thanh toán

Bạn có thể ghi đè NinePayService hoặc triển khai dịch vụ INinePayService của riêng mình và đăng ký nó trong DI container. Dưới đây là ví dụ:

public class CustomNinePayService : NinePayService
{
    // Ghi đè các phương thức xử lý yêu cầu ở đây
}

Sau đó, đăng ký dịch vụ trong DI container:

services.AddNinePay<CustomNinePayService>(options => Configuration.GetSection("NinePay").Bind(options));

Xử lý Callback từ NinePay

Thư viện tự động cấu hình hai endpoint để xử lý callback URLs từ NinePay, bao gồm ReturnURL và IPN:

  1. ReturnURL: Xử lý qua endpoint MapGet(options.ReturnURL).
  2. IPN: Xử lý qua endpoint MapPost(options.IPNURL).

Bạn có thể tùy chỉnh cách xử lý phản hồi bằng cách triển khai interface INinePayProcessor và đăng ký các processor tùy chỉnh.

Ví dụ về một processor đơn giản:

public class TestNinePayProcessor : INinePayProcessor
{
    public const string TYPE = nameof(TestNinePayProcessor);
    private readonly ILogger<TestNinePayProcessor> _logger;

    public string Type => TYPE;

    public TestNinePayProcessor(ILogger<TestNinePayProcessor> logger)
    {
        _logger = logger;
    }

    public Task ProcessReturnURL(NinePayResponse response)
    {
        _logger.LogInformation("Đang xử lý ReturnURL cho mã yêu cầu: {0}", response.RequestCode);
        return Task.CompletedTask;
    }

    public Task ProcessIPN(NinePayResponse response)
    {
        _logger.LogInformation("Đang xử lý IPN cho mã yêu cầu: {0}", response.RequestCode);
        return Task.CompletedTask;
    }
}

Đăng ký Processor Tùy chỉnh

Đăng ký processor tùy chỉnh như sau:

services.AddTransient<INinePayProcessor, TestNinePayProcessor>();

Cấu hình Ví dụ

{
  "NinePay": {
    "ApiUrl": "https://sand-payment.9pay.vn",
    "MerchantKey": "",
    "SecretKey": "",
    "ChecksumKey": ""
  }
}

Giấy phép

NinePay.NetCore là một thư viện mã nguồn mở và được cấp phép dưới Giấy phép MIT. Bạn có thể tự do sử dụng, sửa đổi và phân phối thư viện trong các dự án của mình.

Cảnh báo

  • Để đảm bảo tính bảo mật, tác giả khuyến khích bạn tham khảo/tải về và tùy chỉnh mã nguồn của thư viện này để phù hợp với yêu cầu bảo mật cao hơn cho hệ thống của bạn trong môi trường sản xuất với các giao dịch thanh toán tiền THẬT.
  • Mặc dù thư viện này đã được thiết kế để hỗ trợ tích hợp 9Pay, bạn có thể tùy chỉnh và tối ưu mã nguồn để đáp ứng các yêu cầu bảo mật cao hơn, nếu cần thiết.
  • Hướng dẫn chi tiết về quy trình tích hợp dịch vụ thanh toán 9Pay có sẵn tại đây.
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 is compatible.  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 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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.0 125 1/4/2025