Skip to content

eWAYPayment/eway-rapid-netstandard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eway Rapid .NET Standard Library

Latest version on NuGet

https://img.shields.io/nuget/v/Eway.Rapid.Standard.Abstractions?color=blue&label=Eway.Rapid.Standard.Abstractions&logo=Eway.Rapid.Standard.Abstractions&logoColor=blue

Latest version on NuGet

Latest version on NuGet

A .NET standard library to integrate with Eway's Rapid Payment API.

Sign up with Eway at:

For testing, get a free Eway Partner account: https://www.eway.com.au/developers

Contents

Package Description

Rapid's .NET Standard implementation is broken down into three packages:

Eway.Rapid.Standard.Extensions.DependencyInjection:

This package should be used when the host application is using the ASP.NET CORE framework.
It provides dependency injection for the RapidClient, and inherts functionality from the Eway.Rapid.Standard package.

Eway.Rapid.Standard:

This package should be used when the host application is not using the ASP.NET CORE framework, or a custom DI framework is preferred (or DI is not used in the application). It provides a implementation for the HTTP Client, and handles API calls on your behalf. The package inherits functionality from the Eway.Rapid.Standard.Abstractions package.

Eway.Rapid.Standard.Abstractions:

This package should be used when you want full control of the Http Client, and API calls; but would like to use the pre-defined interface and protocol. The package contains data contracts, models, and Rapid endpoints. Here you may create your own custom HTTP client, and handle API calls in a custom manner.

Install

Use one of the following command to install relevant package:

Package Manager Console:

PM> Install-Package Eway.Rapid.Extensions.Standard.DependencyInjection 

OR

PM> Install-Package Eway.Rapid.Standard

.NET CLI Console:

> dotnet add package Eway.Rapid.Extensions.Standard.DependencyInjection

OR

> dotnet add package Eway.Rapid.Standard

Usage

See Eway's Rapid API Reference for more details.

ASP.NET CORE Dependency Injection Configuration:

Sample app settings entry for RapidClient's configuration.
Required nuget package: Eway.Rapid.Standard.Extensions.DependencyInjection.

{
    "RapidClient":
    {
        "RapidEndPoint": "Sandbox",
        "ApiKey": "Rapid API Key",
        "Password": "Rapid API Password"
    }
}

Invoke the dedicated extension method for RapidClient in your app's configuration section.

public void ConfigureServices(IServiceCollection services)
{
    services.AddRapidClient();
}

You're now able to inject IRapidClient into services as required.

public class HomeController : Controller
{
    IRapidClient rapidClient { get; set; }

    public HomeController(IRapidClient  rapidClient)
    {
        this.rapidClient = rapidClient;
    }
}

Custom RapidClient Configuration:

Sample configuration when not using ASP.NET CORE's default dependency injector.
Can be used with any other DI framework, or even without one.
Required nuget package: Eway.Rapid.Standard package.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Eway.Rapid;
using Eway.Rapid.Abstractions.Interfaces;
using Eway.Rapid.Abstractions.Models;
using Eway.Rapid.Abstractions.Request;

namespace ConsoleApp1
{
    class Program
    {
        static async Task Main(string[] args)
        {
            HttpClient httpClient = new HttpClient();
            RapidOptions rapidOptions = new RapidOptions
            {
                ApiKey = "Rapid API KEY",
                Password = "Rapid API Password",
                RapidEndPoint = RapidEndpoints.SANDBOX
            };
            rapidOptions.ConfigureHttpClient(httpClient);
            IRapidClient rapidClient = new RapidClient(httpClient);
        }
    }
}

Direct Connection using RapidClient:

Once you have configured the RapidClient using either the provided DI extension method, or via configuration; we can use the client as follows.
Required nuget package, either: Eway.Rapid.Standard.Extensions.DependencyInjection, or: Eway.Rapid.Standard package.

public void DirectPayment()
{
    // Create a direct connection request.
    DirectPaymentRequest transaction = new DirectPaymentRequest()
    {
        Customer = new DirectTokenCustomer()
        {
            CardDetails = new CardDetails()
            {
                Name = "John Smith",
                Number = "4444333322221111",
                ExpiryMonth = "12",
                ExpiryYear = "22",
                CVN = "123"
            }
        },
        Payment = new Payment()
        {
            TotalAmount = 1000
        },
        TransactionType = TransactionTypes.Purchase
    };

    // Use the RapidClient to process the request.
    var response = await rapidClient.CreateTransaction(transaction);

    // View the result of the direct connection response.
    Console.WriteLine(response.ResponseCode);
    Console.WriteLine(response.ResponseMessage);
    Console.WriteLine(response.TransactionID);
    Console.ReadLine();
}

Change log

Please see CHANGELOG for more information what has changed recently.

License

The MIT License (MIT). Please see License File for more information.