0% found this document useful (0 votes)
102 views

Moncash Rest Api With C#: Documentation

This document provides instructions for making payments using the MonCash REST API with C#. It discusses installing the SDK with NuGet or direct download, and making an initial call to create a payment. It then demonstrates capturing a payment using the transaction ID or order ID. The goal is to integrate the payment gateway into a site to enable taking payments using C#.

Uploaded by

Wood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Moncash Rest Api With C#: Documentation

This document provides instructions for making payments using the MonCash REST API with C#. It discusses installing the SDK with NuGet or direct download, and making an initial call to create a payment. It then demonstrates capturing a payment using the transaction ID or order ID. The goal is to integrate the payment gateway into a site to enable taking payments using C#.

Uploaded by

Wood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MonCash REST API WITH

C#

Documentation

INTRODUCTION 2

INSTALLATION WITH NUGET 2

INSTALLATION DIRECT DOWNLOAD 2

MAKING FIRST CALL 2

1
Introduction
Moncash REST API is a simple way of integrating the payment gateway into your site to
take payments. In this article we're going to look at a simple example that will use
Moncash SDK to take payments using C#.

Installation with Nuget


Nuget is the recommended way to install the SDK. Alternatively, if you prefer not to use Nuget, but want to
install our SDK, you can do so by doing a direct download https://github.com/ecelestin/ecelestin-Moncash-
sdk-csharp.

Install-Package MonCashSDK.NET -Version 1.0.0 More details here

Installation Direct Download


If you don’t want to use Nuget, you can grab the SDK zip that contains Moncash C# Rest API SDK with all its
dependencies with it.

1. Clone the repository


2. In the Solution Explorer, Right-Click on your Solution
3. Point to Add
4. Click Existing Project
5. Navigate to the directory where you cloned the SDK from Github
6. Select the Solutions file and click open
7. Finally, Add the NetMonCashSDK Prject as a Reference to your own project

Making First Call


After the installation, so that we can import all using classes into your code. For our example code, we will
include it at the top of the file that will be required by our request and response code.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetMonCashSDK.Http;
using NetMonCashSDK.Model;
using System.Net;

1. Initiating of the Api service

ApiService apiService = new ApiService("client id", "client secret", Constants.SANDB


OX);

2
2. Let’s try to create a new moncash Payment

long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;


var payment = new Payment($"{milliseconds}", 500);
PaymentCreator creator = apiService.paymentCreator(payment).Result;

if (creator.status != null && creator.status.Equals($"{(int)HttpStatusCode.Accepted}


")){
Console.WriteLine("redirect to the link below");
//creator.redirectUri() method return the payment gateway url
Console.WriteLine(creator.redirectUri());
} else if (creator.status == null) {
Console.WriteLine(creator.error);
Console.WriteLine(creator.error_description);
}else {
Console.WriteLine(creator.status);
Console.WriteLine(creator.error);
Console.WriteLine(creator.message);
Console.WriteLine(creator.path);
}

3. Capture payment using the transactionId

PaymentCapture capture = apiService.paymentCapture(new TransactionId("12874819")).Re


sult;

Assert.IsNotNull(capture.status);
Assert.AreEqual($"{(int)HttpStatusCode.OK}", capture.status);
Assert.AreEqual("successful", capture.payment.message, "Result must be successful");

if (capture.status != null && capture.status.Equals($"{(int)HttpStatusCode.OK}")){


Console.WriteLine("Transaction");
Console.WriteLine(capture.payment.message);
Console.WriteLine($"TransactionId: {capture.payment.transaction_id}");
Console.WriteLine($"Payer: {capture.payment.payer}");
Console.WriteLine($"Amount: {capture.payment.cost}");
} else {
Console.WriteLine($"{capture.error} | {capture.error_description}");
}

3
4. Capture payment using the orderId

PaymentCapture capture = apiService.paymentCapture(new OrderId("9876543210")).Result


;
Assert.IsNotNull(capture.status);
Assert.AreEqual($"{(int)HttpStatusCode.OK}", capture.status);
Assert.AreEqual("successful", capture.payment.message, "Result must be successful");
if (capture.status != null && capture.status.Equals($"{(int)HttpStatusCode.OK}")){
Console.WriteLine("Transaction");
Console.WriteLine(capture.payment.message);
Console.WriteLine($"TransactionId: {capture.payment.transaction_id}");
Console.WriteLine($"Payer: {capture.payment.payer}");
Console.WriteLine($"Amount: {capture.payment.cost}");
} else {
Console.WriteLine($"{capture.error} | {capture.error_description}");
}

You might also like