payOS.Net5 1.0.3

dotnet add package payOS.Net5 --version 1.0.3
NuGet\Install-Package payOS.Net5 -Version 1.0.3
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="payOS.Net5" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add payOS.Net5 --version 1.0.3
#r "nuget: payOS.Net5, 1.0.3"
#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.
// Install payOS.Net5 as a Cake Addin
#addin nuget:?package=payOS.Net5&version=1.0.3

// Install payOS.Net5 as a Cake Tool
#tool nuget:?package=payOS.Net5&version=1.0.3

The PayOS library provides convenient access to the payOS API from applications written in server .Net Core.

Documentation

See the payOS API docs for more information.

Installation

Install the package with:

    dotnet add package payOS.Net5

Usage

Initialize

You need to initialize the PayOS object with the Client ID, Api Key and Checksum Key of the payment channel you created.

  • Common C#
using Net.payOS;

IConfiguration configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

PayOS payOS = new PayOS(configuration["Environment:PAYOS_CLIENT_ID"] ?? throw new Exception("Cannot find environment"),
                    configuration["Environment:PAYOS_API_KEY"] ?? throw new Exception("Cannot find environment"),
                    configuration["Environment:PAYOS_CHECKSUM_KEY"] ?? throw new Exception("Cannot find environment"));

Methods included in the PayOS object

  • createPaymentLink

Create a payment link for the order data

Syntax:

payOS.createPaymentLink(paymentData);

Parameter data type:

namespace Net.payOS.Types;

//PaymentData Type
public record PaymentData(
    long orderCode,
    int amount,
    String description,
    List<ItemData> items,
    String cancelUrl,
    String returnUrl,
    String ?signature = null,
    String ?buyerName = null,
    String ?buyerEmail = null,
    String ?buyerPhone = null,
    String ?buyerAddress = null,
    int ?expiredAt = null
);

//ItemData Type

public record ItemData(
    String name,
    int quantity,
    int price
);

Return data type:

namespace Net.payOS.Types;

public record CreatePaymentResult(
    String bin,
    String accountNumber,
    int amount,
    String description,
    long orderCode,
    String paymentLinkId,
    String status,
    String checkoutUrl,
    String qrCode
);

Example:

using Net.payOS.Types;

long orderCode = DateTimeOffset.Now.ToUnixTimeMilliseconds();
ItemData item = new ItemData("Mì tôm hảo hảo ly", 1, 1000);
List<ItemData> items = new List<ItemData>();
items.Add(item);
PaymentData paymentData = new PaymentData(orderCode, 1000, "Thanh toan don hang", items, "https://localhost:3002/cancel", "https://localhost:3002/success");

CreatePaymentResult createPayment = await payOS.createPaymentLink(paymentData);
  • getPaymentLinkInformation

Get payment information of an order that has created a payment link.

Syntax:

payOS.getPaymentLinkInformation(id);

Parameters:

  • id: Store order code (orderCode) or payOS payment link id (paymentLinkId). Type of id is long.

Return data type:

namespace Net.payOS.Types;

public record PaymentLinkInformation(
    String id,
    long orderCode,
    int amount,
    int amountPaid,
    int amountRemaining,
    String status,
    String createdAt,
    List<Transaction> transactions,
    String? canceledAt,
    String? cancellationReason
);

Transaction type:

namespace Net.payOS.Types;

public record Transaction(
    String reference,
    int amount,
    String accountNumber,
    String description,
    String transactionDateTime,
    String? virtualAccountName,
    String? virtualAccountNumber,
    String? counterAccountBankId,
    String? counterAccountBankName,
    String? counterAccountName,
    String? counterAccountNumber
);

Example:

using Net.payOS.Types;
PaymentLinkInformation paymentLinkInformation = await _payOS.getPaymentLinkInformation(1);
  • cancelPaymentLink

Cancel the payment link of the order.

Syntax:

payOS.cancelPaymentLink(orderCode, cancellationReason);

Parameters:

  • id: Store order code (orderCode) or payOS payment link id (paymentLinkId). Type of id is long.

  • cancellationReason: Reason for canceling payment link (optional).

Return data type:

namespace Net.payOS.Types;

public record PaymentLinkInformation(
    String id,
    long orderCode,
    int amount,
    int amountPaid,
    int amountRemaining,
    String status,
    String createdAt,
    List<Transaction> transactions,
    String? canceledAt,
    String? cancellationReason
);

Example:

using Net.payOS.Types;

long orderCode = 123;
String cancellationReason = "reason";

PaymentLinkInformation cancelledPaymentLinkInfo = payOS.cancelPaymentLink(orderCode, cancellationReason);

// If you want to cancel the payment link without reason:
PaymentLinkInformation cancelledPaymentLinkInfo = payOS.cancelPaymentLink(orderCode);
  • confirmWebhook

Validate the Webhook URL of a payment channel and add or update the Webhook URL for that Payment Channel if successful.

Syntax:

payOS.confirmWebhook("https://your-webhook-url/")
  • verifyPaymentWebhookData

Verify data received via webhook after payment.

Syntax:


payOS.verifyPaymentWebhookData(body);

Return data type:

namespace Net.payOS.Types;

public record WebhookData(
    long orderCode,
    int amount,
    String description,
    String accountNumber,
    String reference,
    String transactionDateTime,
    String paymentLinkId,
    String code,
    String desc,
    String? counterAccountBankId,
    String? counterAccountBankName,
    String? counterAccountName,
    String? counterAccountNumber,
    String? virtualAccountName,
    String virtualAccountNumber
);

public record WebhookType(
    String code,
    String desc,
    WebhookDataType webhookDataType,
    String signature
);

Example:

using Net.payOS.Types;

WebhookType body = ...; //receive from PayOS

WebhookData paymentData = payOS.verifyPaymentWebhookData(body);

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
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.3 69 5/9/2024
1.0.2 114 2/17/2024
1.0.1 146 1/10/2024
1.0.0 105 12/26/2023