LinePayOnlineAPIv3 1.0.0

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

// Install LinePayOnlineAPIv3 as a Cake Tool
#tool nuget:?package=LinePayOnlineAPIv3&version=1.0.0

LINE Pay Online API v3 C# SDK

非官方的 LINE Pay Online API v3 For C# SDK 官方詳細文件 點擊這裡

nuget 套件

nuget套件位置:LinePayOnlineAPIv3 nuget 指令:Install-Package LinePayOnlineAPIv3 -Version 1.0.0 dotnet CLI:dotnet add package LinePayOnlineAPIv3 --version 1.0.0

開始 Getting Started

建立 Sandbox 點擊這裡,註冊成功後會獲取一組 ChannelId、ChannelSecret <br>

環境 Environment

Sandbox:https://sandbox-api-pay.line.me Production:https://api-pay.line.me

如何使用 SDK

呼叫端建立 LinePayClient

var baseAddress = "https://sandbox-api-pay.line.me";
var channelId = "{ your ChannelId }";
var channelSecret = "{ your channelSecret }";
var client = new LinePayClient(baseAddress,channelId);

建立訂單交易相關資料

private Reserve GetReserveData()
{
    Reserve reserve = new Reserve
    {
        Amount = 100,
        Currency = "TWD",
        OrderId = Guid.NewGuid().ToString()
    };

    List<Products> products = new List<Products>()
    {
        new Products()
        {
            Id = Guid.NewGuid().ToString(),
            Name = "銅鑼燒",
            Quantity = 2,
            Price = 50
        }
    };

    reserve.Packages.Add
    (
        new Packages { Id = Guid.NewGuid().ToString(), Amount = 100, Products = products }
    );

    reserve.RedirectUrls.ConfirmUrl = "https://{ your Domain }/api/LinePay/confirm";
    reserve.RedirectUrls.CancelUrl = "https://{ your Domain }/api/LinePay/cancel";

    return reserve;
}

呼叫 Api

[Route("reserve")]
public async Task<IActionResult> Reserve()
{
    var reserveData = GetReserveData();
    var nonce = Guid.NewGuid().ToString(); //時間戳記 or UUID 1~4
    var requestUrl = "/v3/payments/request";
    var requestJson = JsonConverterFacade.SerializeObject(reserveData, client.SerializerSettings);
    var signature = client.GetSignature((channelSecret + requestUrl + requestJson + nonce), channelSecret);
  
    var result = await client.ReserveAsync(reserveData, nonce, signature);

    return Ok(result);
}

備註說明

  • 因為 v3 版本要求每隻 api 都需要提供簽章,而簽章製作的官方說明如下

Hmac Signature

  • Algorithm : HMAC-SHA256

  • Key : Channel Secret (LINE Pay商家中心提供"Channel Id"和"Channel SecretKey")

  • HTTP Method

    • GET : Channel Secret + URI + Query String + nonce
    • POST : Channel Secret + URI + Request Body + nonce
  • HTTP Method : GET

    • Signature = Base64(HMAC-SHA256(Your ChannelSecret, (Your ChannelSecret + URI + Query String + nonce))) Query String : 不包含 " 問號(?)" 的Query String(例如:Name1=Value1&Name2=Value2...)
  • HTTP Method : POST

    • Signature = Base64(HMAC-SHA256(Your ChannelSecret, (Your ChannelSecret + URI + RequestBody + nonce)))
  • 我有提供 client.GetSignature(message,key);

    • message
    • Post:(channelSecret + Url + requestJson + nonce)
    • Get:(channelSecret + Url + queryString + nonce)
    • key:channelSecret
var signature = client.GetSignature((channelSecret + url + queryString + nonce), channelSecret); //Get
var signature = client.GetSignature((channelSecret + url + requestJson + nonce), channelSecret); //Post

專案範例

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0 1,834 9/12/2020