MoneySpace 1.0.0

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

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

MoneySpace SDK for .NET and .NET Core

NuGet

The MoneySpace SDK for .NET and .NET Core enables .NET developers to easily work with MoneySpace API. It supports .NET Framework 4.5+ and .NET Core.

Quickstart

To get started install the MoneySpace package from NuGet.

Initialize a MoneySpaceApi to access the operations for each API:

#!c#
    var api = MoneySpaceApi.Create("secretId", "secretKey");
    var createPaymentRequest = new CreatePaymentRequest
    {
        FirstName = "example",
        LastName = "example",
        Email = "example@test.com",
        Phone = "0888888888",
        Description = "T-shirt 001 ,pricing 100.25 baht",
        Address = "Address 111/22",
        Message = "After shipping, please share me the delivery receipt",
        Amount = 0.25, // It's important to have only 2 decimical place
        FeeType = FeeType.Include, // Use FeeType.Exclude if you want shopper to pay fees
        CustomerOrderId = "ShopDemoOrder_013", // Unique
        GatewayType = GatewayType.Card, // use GatewayType.Qrprom if you want qr code payment method, GatewayType.Qrprom can only be used with FeeType.Include
        SuccessUrl = "https://www.moneyspace.net/merchantapi/paycardsuccess",
        FailUrl = "https://www.moneyspace.net?status=fail",
        CancelUrl = "https://www.moneyspace.net?status=cancel"
    };
    var createdPayment = await api.Merchant.CreateAsync(createPaymentRequest);

.NET Core Applications

The MoneySpace.Extensions.Microsoft package makes it easy to add the MoneySpace SDK to your .NET Core applications.

Once installed register the SDK with the built-in DI container in Startup.cs:

#!c#
public void ConfigureServices(IServiceCollection services)
{
    // ...
    var conf = new MoneySpaceConfiguration("secretId", "secretKey");
    services.AddMoneySpaceSdk(conf);   
}

Then take a dependency on IMoneySpaceApi in your class constructor:

#!c#
public class PaymentController : ControllerBase
{
    private readonly IMoneySpaceApi _moneySpaceApi;

    public CheckoutController(IMoneySpaceApi moneySpaceApi)
    {
        _moneySpaceApi = moneySpaceApi ?? throw new ArgumentNullException(nameof(moneySpaceApi));
    }

    // etc.

}

To configure the SDK using .NET Core Configuration pass your application's IConfiguration:

#!c#
public class Startup
{
    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        services.AddMoneySpaceSDK(Configuration);    
    }
}

You can then configure appsettings.json file with your MoneySpace details:

#!json
{
    "MoneySpace": {
        "SecretId": "secretId",
        "SecretKey" : "secretKey"
    }
}

Available Methods

Create Payment Request

IMPORTANT It's important to have only 2 decimical place in Amount GatewayType.Qrnone can only be used with FeeType.Include CustomerOrderId need to be unique. You can generate GUID for that field

#!c#
var createPaymentRequest = new CreatePaymentRequest
{
    FirstName = "example",
    LastName = "example",
    Email = "example@test.com",
    Phone = "0888888888",
    Description = "T-shirt 001 ,pricing 100.25 baht",
    Address = "Address 111/22",
    Message = "After shipping, please share me the delivery receipt",
    Amount = 0.25, // It's important to have only 2 decimical place
    FeeType = FeeType.Include, // Use FeeType.Exclude if you want shopper to pay fees
    CustomerOrderId = "ShopDemoOrder_013",
    GatewayType = GatewayType.Card, // use GatewayType.Qrnone if you want qr code payment method, GatewayType.Qrprom can only be used with FeeType.Include
    SuccessUrl = "https://www.moneyspace.net/merchantapi/paycardsuccess",
    FailUrl = "https://www.moneyspace.net?status=fail",
    CancelUrl = "https://www.moneyspace.net?status=cancel"
};

var createdPayment = await _moneySpaceApi.Merchant.CreateAsync(createPaymentRequest);

// If error
if (!createdPayment.IsSuccess)
{
    return BadRequest(new { Error = createdPayment.Status });
}
Create Installment Request

IMPORTANT It's important to have only 2 decimical place in Amount CustomerOrderId need to be unique. You can generate GUID for that field

#!c#
var createInstallmentRequest = new CreateInstallmentRequest
{
    FirstName = "example",
    LastName = "example",
    Email = "example@test.com",
    Phone = "0888888888",
    Description = "T-shirt 001 ,pricing 100.25 baht",
    Address = "Address 111/22",
    Message = "After shipping, please share me the delivery receipt",
    Amount = 3100.01, // It's important to have only 2 decimical place
    FeeType = FeeType.Include, // Use FeeType.Exclude if you want shopper to pay fees
    CustomerOrderId = "ShopDemoOrder_013",
    SuccessUrl = "https://www.moneyspace.net/merchantapi/paycardsuccess",
    FailUrl = "https://www.moneyspace.net?status=fail",
    CancelUrl = "https://www.moneyspace.net?status=cancel",
    BankType = BankType.FCY,
    StartTerm = StartTerm.Three,
    EndTerm = EndTerm.Ten
};

var createdInstallment = await _moneySpaceApi.Merchant.CreateAsync(createInstallmentRequest);

// If error
if (!createdInstallment.IsSuccess)
{
    return BadRequest(new { Error = createdInstallment.Status });
}
Check transaction
#!c#
var checkTransactionRequest = new CheckTransactionRequest
{
    TransactionId = "transactionId",
};

var checkTransactionResponse = await _moneySpaceApi.Merchant.CheckTransactionAsync(checkTransactionRequest);

// If error
if (!checkTransactionResponse.IsSuccess)
{
    return BadRequest(new { Error = checkTransactionResponse.Status });
}
Check OrderId
#!c#
var checkOrderIdRequest = new CheckOrderIdRequest
{
    OrderId = "orderId",
};

var checkOrderIdResponse = await _moneySpaceApi.Merchant.CheckOrderIdAsync(checkOrderIdRequest);

// If error
if (!checkOrderIdResponse.IsSuccess)
{
    return BadRequest(new { Error = checkOrderIdResponse.Status });
}
#!c#
var linkPaymentResponse = await _moneySpaceApi.Merchant.GetPaymentCardLinkAsync("transactionId");
Store info
#!c#
var storeResponse = await _moneySpaceApi.Merchant.StoreAsync();
var store = storeResponse.Store.First();
WebHook Receiver

First you need to define action in controller which will bind webhook response from form data. Then we will check if response have right hash.

#!c#
public IActionResult WebHookReceiver([FromForm] WebHookResponse webHookResponse)
{
    // Verify WebHook hash for integrity
    if (!_moneySpaceApi.WebHookHelper.VerifyResponse(webHookResponse))
    {
        // WebHook parameters is not real.
        return BadRequest( new { Error = "Error when verifying the WebHook request." }  );
    }
    
    // WebHook is true and verified.
    // Do what you want.
    switch (webHookResponse.Status)
    {
        case PaymentStatus.Ok:
            
            break;
        case PaymentStatus.Pending:
            
            break;
        case PaymentStatus.Fail:
            
            break;
        case PaymentStatus.Cancel:
            
            break;
        case PaymentStatus.PaySuccess:
            
            break;
    }

    return Ok();
}

Enums

GatewayType

Payment method
Card: GatewayType.Card
Qr Code Payment: GatewayType.Qrnone

FeeType

Who pays fees
Merchant: FeeType.Include
Shopper: FeeType.Exclude

BankType

Bank Type
KTC: BankType.KTC
BAY: BankType.BAY
FCY: BankType.FCY

StartTerm

Start term
3: StartTerm.Three
4: StartTerm.Four
5: StartTerm.Five
6: StartTerm.Six
7: StartTerm.Seven
8: StartTerm.Eight
9: StartTerm.Nine
10: StartTerm.Ten

EndTerm

End term
3: EndTerm.Three
4: EndTerm.Four
6: EndTerm.Six
9: EndTerm.Nine
10: EndTerm.Ten
12: EndTerm.Twelve
18: EndTerm.Eighteen
24: EndTerm.TwentyFour
36: EndTerm.ThirtySix

Versioning

MoneySpace SDK uses Semantic Versioning. The latest stable code can be found on the master branch and will be published to NuGet.

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 net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on MoneySpace:

Package Downloads
MoneySpace.Extensions.Microsoft

Moneyspace.net SDK Extensions for Microsoft Configuration and Dependency Injection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 1,134 10/20/2021