BinancePayConnector is a .NET library that simplifies integration with the Binance Pay API for merchants, platforms, and service providers. It supports C2B flows like order creation, refunds, payouts, and webhook event handling — all in a strongly typed, modular, and extensible architecture.
$ dotnet add package BinancePayConnectorBinancePayConnector is a .NET library that simplifies integration with the Binance Pay API for merchants, platforms, and service providers. It supports C2B flows like order creation, refunds, payouts, and webhook event handling — all in a strongly typed, modular, and extensible architecture.
[!IMPORTANT] This project is not affiliated with or endorsed by Binance.
IServiceCollectionSend<T> APIInstall via NuGet:
dotnet add package BinancePayConnector
or
dotnet add package BinancePayConnectorSlim
You can use BinancePayConnector in one of the following ways:
var binancePay = new BinancePay("your-api-key", "your-api-secret");
var response = await binancePay.Order.CreateOrder(
new OrderIdentification(
new Env(TerminalType.App),
BinancePayId.Generate32().Value
),
new OrderDetailsCrypto(
"Description",
0.001m,
Assets.Usdt
),
[
new Goods(
GoodsType.VirtualGoods,
GoodsCategory.Others,
ReferenceGoodsId: BinancePayId.Generate32().Value,
GoodsName: "Name")
]
);
var binancePay = new BinancePaySlim("your-api-key", "your-api-secret");
var response = await binancePay.Send(
request: new CreateOrderRequest(
Env: new Env(
TerminalType: TerminalType.App
),
MerchantTradeNo: BinancePayId.Generate32().Value,
OrderAmount: 0.001m,
Currency: Assets.Usdt,
Description: "Description",
GoodsDetails:
[
new Goods(
GoodsType: GoodsType.VirtualGoods,
GoodsCategory: GoodsCategory.Others,
ReferenceGoodsId: BinancePayId.Generate32().Value,
GoodsName: "Name"
)
],
OrderExpireTime: DateTimeOffset.UtcNow.AddMinutes(5).ToUnixTimeMilliseconds(),
WebhookUrl: "https://96b4-188-163-49-145.ngrok-free.app/api/binancepay/webhooks/order"
)
);
builder.Services.AddBinancePay("your-api-key", "your-api-secret");
or
builder.Services.AddBinancePaySlim("your-api-key", "your-api-secret");
Then inject IBinancePay anywhere:
public class OrderController(IBinancePay binancePay) : ControllerBase
{
public async Task<IActionResult> CreateOrder()
{
var result = await binancePay.Order.CreateOrder(...);
return Ok(result.Body);
}
}
🔸 Step 1: Configuration in appsettings.json
{
"BinancePay": {
"ApiKey": "your-api-key",
"ApiSecret": "your-api-secret"
}
}
🔸 Step 2: Register via DI
builder.Services.AddBinancePay(builder.Configuration);
or
builder.Services.AddBinancePaySlim(builder.Configuration);
Configure webhook receiver (Only 1 and 2 usage):
var binancePay = new BinancePay(apiKey, apiSecret)
{
WebhookConfig = new BinancePayWebhookConfig
{
BaseUri = "http://localhost:4421"
}
};
Configure endpoint handling:
binancePay.OnUpdateInvoke(request =>
{
if (request.BizType is BizType.Order) return;
var orderNotification = DeserializeJson<OrderNotification>(request.Data);
PrintOrderNotification(request, orderNotification);
});
binancePay.OnUpdateInvoke(request =>
{
if (request.BizType is not BizType.Order) return;
var orderNotification = DeserializeJson<OrderNotification>(request.Data);
PrintOrderNotification(request, orderNotification);
}, "api/binancepay/webhooks/order");
binancePay.OnUpdateInvoke(request =>
{
if (request.BizType is not BizType.Balance) return ResponseType.Failure;
var balanceReportNotification = DeserializeJson<BalanceReportNotification>(request.Data);
PrintBalanceNotification(request, balanceReportNotification);
return ResponseType.Success;
}, "api/binancepay/webhooks/direct-debit");
[ApiController]
[Route("api/webhooks")]
public class WebhookController(IBinancePay binancePay) : ControllerBase
{
[HttpPost("order")]
public async Task<IActionResult> OrderWebHook(WebHookRequest webhook, CancellationToken ct)
{
if (webhook.BizType == BizType.Order)
{
var order = await binancePay.Order.GetOrderByPrepayId(webhook.BizIdStr, ct);
}
return Ok(new WebHookResponse(RequestStatus.Success));
}
}
If you find BinancePayConnector helpful, consider supporting its development:
PRs are welcome! Please open an issue first to discuss major changes.
I think do it by base virtual methods like "MapTo" in Result models for mapping to typed model
string PrepayId → BinancePayId PrepayIdstring QrCodeLink → Uri QrCodeLinkstring Id → BinancePayId Idlong UnixTimestamp → DateTime Time