Giter Club home page Giter Club logo

redsystpv's Introduction

RedsysTPV

Note: It fully supports Blazor webassembly and a sample application is provided in the repository.

¡¡¡This project has been refactored by ProDInfo. Thanks for your support and your great research to update all numeric codes!!!

SHA256 signature implementation

This is a .NET Standard library based on RedsysTPV by mbuenoferrer for help you on cart and orders integrations with the Redsys payment gateway (a platform that manage online payments for several spanish banks like La Caixa, Banco Santander, BBVA, Banco Sabadell, Bankia, etc). Now it can be used on .NET Core or any other that implements netstandard 2.0.

This library is released because of the mandatory update from old SHA1 signatures to SHA256, in order to keep using the platform securely. The old SHA1 signatures will stop working on November 23th, when Redsys virtual POS will accept only signatures generated using SHA-256.

Note that only simple payments by post-redirect method is implemented, not SOAP option is covered on this project.

This code includes a sample web that implements the library. I recommend see this sample to a better understand of how to use the library.

You can find an example here: http://redsystpv.azurewebsites.net.

How to install

You can install RedsysTPV as a nuget package:

PM> Install-Package RedsysTPV.NetStandard

How to use

The payment platform works as follow:

  1. The commerce post an html form with obfuscated data and an operation signature.
  2. If request is correct, platform redirect user to the bank payment page.
  3. User types his card number on a secure bank page
  4. and the platform sends a background request to a specific commerce url to notify operation results.
  5. User is redirected to a ok/ko page of the commerce.

Create payment request

var paymentRequestService = new PaymentRequestService();

var paymentRequest = 
	new PaymentRequest(
		Ds_Merchant_ConsumerLanguage: Language.Spanish,
		Ds_Merchant_MerchantCode: "012345678",	
		Ds_Merchant_Terminal: "1",	
		Ds_Merchant_TransactionType:  TransactionType.Authorization,
                Ds_Merchant_Amount: 123,
                Ds_Merchant_Currency: Currency.EUR,
		Ds_Merchant_Order: "9999TEST0001",
		Ds_Merchant_MerchantURL: "http://www.example.com/payment-notifications"),
		Ds_Merchant_UrlOK: "http://www.example.com/payment-ok",
		Ds_Merchant_UrlKO: "http://www.example.com/payment-ko");

//Case you need to set the redsys payment methods
paymentRequest.Ds_Merchant_PayMethod = PaymentMethod.CreditCard;
 
var formData = 
	paymentRequestService.GetPaymentRequestFormData(
		paymentRequest: paymentRequest,
		merchantKey: "put_here_your_commerce_hash_key");

ViewBag.ConnectionURL = "https://sis-t.redsys.es:25443/sis/realizarPago"; // for production environment, replace with https://sis.redsys.es/sis/realizarPago

This generates a model (formData) that contains the fields required to fill this html form (example for MVC View):

@model RedsysTPV.Models.PaymentFormData
<form name="frm" action="@ViewBag.ConnectionURL" method="POST">
	<input type="hidden" name="Ds_SignatureVersion" value="@Model.Ds_SignatureVersion" />
	<input type="hidden" name="Ds_MerchantParameters" value="@Model.Ds_MerchantParameters" />
	<input type="hidden" name="Ds_Signature" value="@Model.Ds_Signature" />
	<input type="submit" value="Enviar" style="display: none;">
</form>
<script>
	document.forms[0].submit();
</script>

The form will be send automatically by the tiny javascript, and the user will see the payment page of the gateway.

Get payment response:

var paymentResponseService = new PaymentResponseService();

var merchantParameters = Convert.ToString(Request["Ds_MerchantParameters"]);
var merchantKey = ConfigurationManager.AppSettings["MerchantKey"];
var platformSignature = Convert.ToString(Request["Ds_Signature"]);

var processedPayment = paymentResponseService.GetProcessedPayment(merchantParameters, merchantKey, platformSignature);

if (processedPayment.IsValidSignature)
{
	// Signature is correct, the request come from trusted source
	if (processedPayment.IsPaymentPerformed.DefaultIfEmpty(false).Single())
	{
		// Payment accepted: success
		// Update the order on database, etc
	}
	else
	{
		// Payment rejected: fail
		// Update the order on database, etc
	}
}
else
{
	// Signature is not valid, the request come from untrusted source
}

Disclaimer

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.

License

The MIT License (MIT)

Copyright (c) 2015 Miguel Ángel Bueno

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

redsystpv's People

Contributors

crahungit avatar jlg4 avatar mabuenox avatar prodinfo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

redsystpv's Issues

Ds_Merchant_PayMethod BIZUM

Hola!

¿Cómo asigno BIZUM al Ds_Merchant_PayMethod?

Ds_Merchant_PayMethod = "z" (no es posible)

Gracias!

New system of PaymentMethods

Hi,
with recently changes from redsys they've added 1 extra parameter in the request method (DS_MERCHANT_PAYMETHODS) it's possible to modify it?

Compatible with net standard 2.0 & net standard 2.1 & netcoreapp3.1

I would like to modify the project to create nuget package that can use on different platforms:
.Net Standard 2.1
.Net Standard 2.0
Net Core 3.1
Net Framework 4.8

Actually only work on .Net Standard 2.1 and not it's incompatible with asp.net core 3.1. I neeed on some project that I work.

I can't see nothing on this repository about creation nuget package.
How contribute to this change? I Create a pull request with the change on all projects with multitargeting?

Very thanls

Support for language and other parameters?

Hello! You did a very nice job with this package, but I have encoutered with the need to alter the language of the Redsys TPV. This is done with the "Ds_Merchant_ConsumerLanguage" parameter, which is optional. Could you please add support for this parameter? It wouldn't hurt to support all of them, actually.

Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.