Skip to content

moyasar/moyasar-dotnet

Repository files navigation

Moyasar.Net

Build Status

Moyasar's .NET Client Library

Target Frameworks

This library targets following frameworks:

  1. .Net Standard 2.0
  2. .Net Framework 4.0

Installation

If you are using dotnet command line tools you can add the library to your project using the following command

dotnet add package moyasar

Or if you are using Nuget Package Manager

PM> Install-Package moyasar

Manual Installation

Please note that this installation method is not recommended

To Install the library manually please download the last release from the releases section and reference it in your project.

Usage

Setup

Make sure to set the API key before proceeding

MoyasarService.ApiKey = "YouKeyHere";

Payment

Make sure you always try to catch the following exceptions:

ValidationException

NetworkException

ApiException

To fetch a payment from Moyasar, use the following:

Payment.Fetch("Payment-Id");

To refund a payment, one must have a Payment instance somePayment then invoke the following:

somePayment.Refund();

To update your payment, change Description property on that payment, then invoke Update:

somePayment.Description = "Colombia, Narino Sandona, Medium Roast (Special)";
somePayment.Update();

To list or search for payments at Moyasar, do the following:

var result = Payment.List();

or

var result = Payment.List(new SearchQuery()
{
    Id = "SomeId",
    Source = "creditcard OR sadad",
    Status = "some status",
    Page = 2,
    CreatedAfter = DateTime.Now.AddDays(-5),
    CreatedBefore = DateTime.Now
});

All SearchQuery parameters are optional, use what is needed

Invoice

Use Invoice class with the same methods as Payment class, except for the following:

To create an invoice for example:

var invoice = Invoice.Create(new InvoiceInfo()
{
    Amount = 7000,
    Currency = "SAR",
    Description = "A 70 SAR invoice just because",
    ExpiredAt = DateTime.Now.AddDays(3),
    CallbackUrl = "http:https://www.example.com/invoice_callback"
});

To Cancel an Invoice:

someInvoice.Cancel();

For more details, please refer to the official documentation: https://moyasar.com/docs/api/

Testing

To run the tests use the following command

dotnet test