GPWebpayNet.Sdk 1.0.0

GPWebpayNet is a helper library for communication with GP webpay(https://www.gpwebpay.cz/) payment gateway via HTTP.

There is a newer version of this package available.
See the version list below for details.
Install-Package GPWebpayNet.Sdk -Version 1.0.0
dotnet add package GPWebpayNet.Sdk --version 1.0.0
<PackageReference Include="GPWebpayNet.Sdk" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GPWebpayNet.Sdk --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

Versions

Version 1.0.0.0 - 2018-02-27

  • Initial version

Getting Started/Installing

Install-Package GPWebpayNet.Sdk -Version 1.0.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/test.pfx";
    const string privateCertificateFilePassword = "test";
    const string publicCertificateFile = "certs/test.pfx";
    const string publicCertificateFilePassword = "test";
    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 publicCertificateFile = "certs/test.pfx";
    const string password = "test";
        
            
    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, 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.

Donate

TODO Paypal Donate

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.

Versions

Version 1.0.0.0 - 2018-02-27

  • Initial version

Getting Started/Installing

Install-Package GPWebpayNet.Sdk -Version 1.0.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/test.pfx";
    const string privateCertificateFilePassword = "test";
    const string publicCertificateFile = "certs/test.pfx";
    const string publicCertificateFilePassword = "test";
    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 publicCertificateFile = "certs/test.pfx";
    const string password = "test";
        
            
    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, 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.

Donate

TODO Paypal Donate

Release Notes

First version

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.3 205 10/18/2018
1.3.2 144 10/12/2018
1.3.1 154 10/8/2018
1.3.0 168 9/21/2018
1.2.0 251 3/16/2018
1.1.0 236 3/1/2018
1.0.0 243 2/24/2018
Show less