AsiaPayPaymentSDK 1.0.1

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

AsiaPayPaymentSDK

NuGet .NET Version License

AsiaPayPaymentSDK is a .NET 8 SDK designed to simplify payment processing using the AsiaPay API.
It provides seamless integration for merchants to handle transactions, refunds, and order queries.


📌 Features

Token-Based Authentication
Pre-Order Processing
Payment Token Handling
Order Queries & Refunds
QR Code Generation for Payments


🚀 Installation

Using NuGet

Run the following command in the .NET CLI:

dotnet add package AsiaPayPaymentSDK --version 1.0.0

Or using Package Manager Console (PMC):

Install-Package AsiaPayPaymentSDK -Version 1.0.0

🔥 Quick Start

1️⃣ Initialize AsiaPayService

using AsiaPayPaymentSDK.AsiaPay;

var httpClient = new HttpClient();
var paymentService = new AsiaPayService(
    httpClient, 
    PaymentConstants.ServerUrl,
    PaymentConstants.CheckH5MidPageUrl, 
    PaymentConstants.AppSecret,
    PaymentConstants.XAppKey, 
    PaymentConstants.AppId, 
    PaymentConstants.MerchCode, 
    PaymentConstants.PrivateKey
);

2️⃣ Create an Order in AsiaPay

var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds().ToString();
var nonceStr = Guid.NewGuid().ToString("N").ToLower();

var request = new AsiaPayPreOrderRequest
{
    Timestamp = timestamp,
    NonceStr = nonceStr,
    BizContent = new BizContentPreOrderRequest
    {
        NotifyUrl = "https://pshtiwan.free.beeceptor.com",
        RedirectUrl = "https://pshtiwan.free.beeceptor.com",
        AppId = PaymentConstants.AppId,
        MerchCode = PaymentConstants.MerchCode,
        MerchOrderId = Guid.NewGuid().ToString("N"),
        Title = "Tested By pshtiwan",
        TotalAmount = "500",
        TransCurrency = "IQD",
        TimeoutExpress = "5m"
    }
};

var createResponse = await paymentService.PreOrderAsync(request);

if (createResponse?.BizContent?.PrepayId == null)
{
    Console.WriteLine("Failed to create order.");
    return;
}

Console.WriteLine($"Order Created: {createResponse.BizContent.PrepayId}");

3️⃣ Generate Payment URL & QR Code

var generateQr = await paymentService.GetApplyPayTokenAsync(
    createResponse.BizContent.PrepayId, timestamp, nonceStr
);

string paymentUrl = $"https://pay.com?tradeType=PWA&appId={PaymentConstants.AppId}&merchCode={PaymentConstants.MerchCode}&prepayId={createResponse.BizContent.PrepayId}&payToken={generateQr.BizContent?.PayToken}";

Console.WriteLine($"Payment URL: {paymentUrl}");

Console.WriteLine("_________________________");

// Generate QR Code
Console.WriteLine("QrCode:data:image/png;base64," + paymentService.GenerateQrCodeBase64(paymentUrl));

Console.WriteLine("_________________________");

// Generate H5 Checkout URL
Console.WriteLine("OpenApp:" + paymentService.GenerateH5CheckoutUrl(createResponse.BizContent.PrepayId));

4️⃣ Query an Order

var queryOrder = await paymentService.QueryOrderAsync("52da1851e46c4017a7637f0249b007fe");
Console.WriteLine($"Order Details: {queryOrder}");

5️⃣ Process Refund

var refund = await paymentService.RefundOrderAsync("f8bfc6d157c74b32b99c1c434be51b3a");
Console.WriteLine($"Refund Response: {refund}");

🌎 Connect With Me

📧 Email: pshitiwan.eng@gmail.com
💼 LinkedIn: Pshitiwan Hassan
🐙 GitHub: pshtiwan-hassan

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
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.