globalpayments / dotnet-sdk

GNU General Public License v2.0
43 stars 63 forks source link

HostedService.ParseResponse() method doesn't support SHA256 #80

Closed djcolonico closed 8 months ago

djcolonico commented 1 year ago

Hi, the Hosted Payment Page (HPP) documentation states that you can use a SHA256 hash to build the request security hash: https://developer.globalpay.com/hpp/card-payments#generate-hash image

When I try to process a HPP response that uses a SHA256HASH hash, the HostedService.ParseResponse() method fails with an "Incorrect hash. Please check your code and the Developers Documentation." error.

I'm using the HPP step-by-step code from: https://developer.globalpay.com/ecommerce/hosted-solution/HPP-Guide#hpp

var service = new HostedService(new GpEcomConfig
{
   MerchantId = "MerchantId",
   AccountId = "internet",
   SharedSecret = "secret",
   ServiceUrl = "https://pay.sandbox.realexpayments.com/pay"
});

Transaction response = service.ParseResponse(responseJson, true);
var orderId = response.OrderId; // GTI5Yxb0SumL_TkDMCAxQA
var responseCode = response.ResponseCode; // 00
...

Example HPP response:

{
  "MERCHANT_ID": "MerchantId",
  "ACCOUNT": "internet",
  "ORDER_ID": "order123",
  "AMOUNT": "1000",
  "CURRENCY": "GBP",
  "TIMESTAMP": "20230821064449",
  "AUTO_SETTLE_FLAG": "0",
  "HPP_CHALLENGE_REQUEST_INDICATOR": "NO_PREFERENCE",
  "HPP_ENABLE_EXEMPTION_OPTIMIZATION": false,
  "HPP_REMOVE_SHIPPING": "TRUE",
  "HPP_BILLING_COUNTRY": "826",
  "HPP_CAPTURE_ADDRESS": "TRUE",
  "HPP_VERSION": "2",
  "SHA256HASH":"1378edf43d735270a24963d07005e887a0691f19b3dfeac254d8aad3026b2106"
}

I can see in the HostedService.ParseResponse() method that only SHA1 is supported: https://github.com/globalpayments/dotnet-sdk/blob/cac98cd229c6332e3fb3c0f96617f8ed63a1b13d/src/GlobalPayments.Api/Services/HostedService.cs#L45 image

Could you please update the HostedService.ParseResponse() method to support SHA256 hashes please?

I can see that the GenerationUtils.GenerateHash() does support SHA256 hashes: https://github.com/globalpayments/dotnet-sdk/blob/cac98cd229c6332e3fb3c0f96617f8ed63a1b13d/src/GlobalPayments.Api/Utils/GenerationUtils.cs#L28

SneyderOspinaChavarria commented 9 months ago

It was fixed on the version 8.0.5 https://www.nuget.org/packages/GlobalPayments.Api/8.0.5