GPWebpayNet.Sdk 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GPWebpayNet.Sdk --version 1.2.0                
NuGet\Install-Package GPWebpayNet.Sdk -Version 1.2.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="GPWebpayNet.Sdk" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GPWebpayNet.Sdk --version 1.2.0                
#r "nuget: GPWebpayNet.Sdk, 1.2.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 GPWebpayNet.Sdk as a Cake Addin
#addin nuget:?package=GPWebpayNet.Sdk&version=1.2.0

// Install GPWebpayNet.Sdk as a Cake Tool
#tool nuget:?package=GPWebpayNet.Sdk&version=1.2.0                

GPWebpayNet

GPWebpayNet is a helper library for communication with GP webpay payment gateway and providing payments via HTTP. It follows documentation that can be found here.

GP webpay does not provide any SDK to be able to integrate their services in a simple way. They provide sample code in .NET3.5 (really, in 2017), Java and PHP. But only for evaluation that your process of signing payment request generates valid digest. Thats all. Another proble is that these examples are quite outdated - today, there is .NetCore2 that has different assemblies for working with ceritficates.

Version

  • Version 1.2.0 - 2018-03-16

Getting Started/Installing

Install-Package GPWebpayNet.Sdk -Version 1.2.0

.NET Framework Support

This SDK supports:

  • Full .NET Framework 4.6.1
  • .netstandart 1.6
  • .netstandart 2.0

Use Cases

You can use is together with WebAPI and SPA of with ASP MVC. It is up to you.

The base GP webpay process (simplified) is as follows:

  1. Generate payment request
  2. Send it via GET or POST go payment gateway
  3. Process GET request from GP webpay

The process with API and SPA is as follows:

  1. SPA send order request to API
  2. API generates payment request for GET (url) and sends it back to SPA
  3. SPA use url and redirects to it
  4. GP webpay send request to API
  5. API process request and redirect to SPA with corresponding result

The process with MVC is as follows:

  1. Send request to MVC
  2. MVC generates payment request for GET/POST and redirects to GP webpay
  3. GP webpay send request to MVC
  4. MVC process request and redirect to SPA with corresponding result

Project Structure

GPWebpayNet.Example

It contains examples how to use this SDK. For more details you can check GPWebpayNet.SDK.Spec too.

GPWebpayNet.SDK

The main project. The main project class is GPWebpayNet.Sdk.Services.ClientService that provides methods needed for payment process. Other classes are used by this class. Whole project is designed to be used with some IoC framework so classes are decoupled.

GPWebpayNet.Example

It contains SDK unit tests.

Usage Samples

Get Redirect URL for Payment Request
public string GetRedirectUrl()
{
    var loggerFactory = new LoggerFactory()
        .AddConsole();

    const string url = Constants.GPWebpayUrlTest;
    const string privateCertificateFile = "certs/client.pfx";
    const string privateCertificateFilePassword = "test";
    const string publicCertificateFile = "certs/server_pub.pem";
    const string publicCertificateFilePassword = null;
    var doc = new XmlDocument();
    doc.AppendChild(doc.CreateElement("Info"));

    var request = new PaymentRequest
    {
        MerchantNumber = "235235",
        OrderNumber = 2412,
        Amount = new decimal(64.6546),
        Currency = CurrencyCodeEnum.Eur,
        DepositFlag = 1,
        MerOrderNumber = "MerOrderNumber",
        Url = "https://www.example.org",
        Description = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
        MD = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
        PaymentMethod = PaymentMethodEnum.Mps,
        DisabledPaymentMethod = PaymentMethodEnum.Crd,
        PaymentMethods = new[] {PaymentMethodEnum.Mcm, PaymentMethodEnum.NotSet},
        Email = "user@example.org",
        ReferenceNumber = "77987",
        AddInfo = doc.DocumentElement,
        Lang = "CZ"
    };

    var encodingLogger = loggerFactory.CreateLogger<EncodingService>();
    var clientServiceLogger = loggerFactory.CreateLogger<ClientService>();
    var clientService = new ClientService(new EncodingService(encodingLogger),
        new PaymentRequestTransformer(), new PaymentResponseTransformer(), clientServiceLogger);

    return clientService.GenerateGPWebPayRedirectUrl(
        url,
        request,
        privateCertificateFile,
        privateCertificateFilePassword,
        publicCertificateFile, 
        publicCertificateFilePassword);
}
Process Incomming GP webpay request
public void ProcessIncommingGPWPRequest()
{
    var loggerFactory = new LoggerFactory()
        .AddConsole();
            
    // Args from Request object
    var queryArgs = new QueryCollection(new Dictionary<string, StringValues>()
    {
        {"OPERATION", new StringValues("Operation")},
        {"ORDERNUMBER", new StringValues("12332")},
        {"PRCODE", new StringValues("0")},
        {"SRCODE", new StringValues("0")},
        {"RESULTTEXT", new StringValues("ResultText")},
        {"USERPARAM1", new StringValues("UserParam1")},
        {"DIGEST", new StringValues("Digest")},
        {"DIGEST1", new StringValues("Digest1")},
    });
            
    const string merchantNumber = "25236236";
    const string publicCertificateFile = "certs/server_pub.pem";
    const string publicCertificateFilePassword = null;
        
            
    var encodingLogger = loggerFactory.CreateLogger<EncodingService>();
    var clientServiceLogger = loggerFactory.CreateLogger<ClientService>();
    var clientService = new ClientService(new EncodingService(encodingLogger),
        new PaymentRequestTransformer(), new PaymentResponseTransformer(), clientServiceLogger);
    
    // Service will creates PaymentResponse from incomming args and validate response digest with 
    // public certificate provided by GPWP and then check if "PRCODE" and "SRCODE" values have correct or error values
    // ReSharper disable once UnusedVariable
    var paymentResponse = clientService.ProcessGPWebPayResponse(queryArgs, merchantNumber, publicCertificateFile, password);
}

Contributing

Pull requests, bug reports, and feature requests are welcome.

Authors

  • Marek Polak - Initial work - marazt

License

© 2017-2018 Marek Polak. This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments

  • Enjoy it!
  • If you want, you can support this project too.

TODO Paypal Donate

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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.6 is compatible.  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 tizen30 was computed.  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.4.3 1,121 10/3/2020
1.4.1 5,933 7/17/2020
1.3.3 904 10/18/2018
1.3.2 764 10/12/2018
1.3.1 780 10/8/2018
1.3.0 809 9/21/2018
1.2.0 1,029 3/16/2018
1.1.0 985 3/1/2018
1.0.0 992 2/24/2018

Extension of the IEncodingService and IClientService to support certificate instance too (Not only certificate path and its password).