Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quickpay fixes #13

Merged
merged 9 commits into from
Jun 4, 2024
57 changes: 53 additions & 4 deletions src/ApiService.cs
Original file line number Diff line number Diff line change
@@ -2,14 +2,63 @@

internal enum ApiService
{
/// <summary>
/// Create payment
/// POST /payments
/// </summary>
CreatePayment,

/// <summary>
/// Get payment
/// GET /payments/{operatorId}
/// </summary>
GetPayment,

/// <summary>
/// Authorize payment
/// POST /payments/{operatorId}/authorize
/// </summary>
AuthorizePayment,

/// <summary>
/// Capture payment
/// POST /payments/{operatorId}/capture
/// </summary>
CapturePayment,

/// <summary>
/// Refund payment
/// POST /payments/{operatorId}/refund
/// </summary>
RefundPayment,

/// <summary>
/// Create saved card
/// POST /cards
/// </summary>
CreateCard,

/// <summary>
/// Get saved card
/// GET /cards/{operatorId}
/// </summary>
GetCard,

/// <summary>
/// Create or update a card link
/// PUT /cards/{operatorId}/link
/// </summary>
GetCardLink,
GetCardData,
GetCardToken,

/// <summary>
/// Create card token
/// POST /cards/{operatorId}/tokens
/// </summary>
CreateCardToken,

/// <summary>
/// Delete card link
/// POST /cards/{operatorId}/cancel
/// </summary>
DeleteCard,
RefundPayment,
GetPaymentStatus
}
18 changes: 18 additions & 0 deletions src/CheckedData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow;

internal sealed class CheckedData
{
public CheckDataResult Result { get; set; }

public string Message { get; set; }

public CheckedData(CheckDataResult result)
{
Result = result;
}

public CheckedData(CheckDataResult result, string message) : this(result)
{
Message = message;
}
}
32 changes: 32 additions & 0 deletions src/CommandConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow;

internal sealed class CommandConfiguration
{
/// <summary>
/// Quick pay command. See operation urls in <see cref="QuickPayRequest"/> and <see cref="ApiService"/>
/// </summary>
public ApiService CommandType { get; set; }

/// <summary>
/// Command operator id, like /cards/{OperatorId}
/// </summary>
public string OperatorId { get; set; }

/// <summary>
/// Command operator second id, like /cards/{OperatorId}/operations/{OperatorSecondId}
/// </summary>
public string OperatorSecondId { get; set; }

/// <summary>
/// Command query parameters, like /payments/{OperatorId}/refund?{QueryParameters}
/// </summary>
public Dictionary<string, string> QueryParameters { get; set; }

/// <summary>
/// Parameters for request
/// </summary>
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>10.1.0</VersionPrefix>
<VersionPrefix>10.1.1</VersionPrefix>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>QuickPay Payment Window</Title>
<Description>The QuickPay Payment Window checkout handler is designed to work with QuickPay v10.</Description>
@@ -25,7 +25,15 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.2.2" />
<None Remove="Updates\Card.cshtml" />
<None Remove="Updates\Post.cshtml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Updates\Card.cshtml" />
<EmbeddedResource Include="Updates\Post.cshtml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dynamicweb.Ecommerce" Version="10.4.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
65 changes: 65 additions & 0 deletions src/Hash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow;

internal static class Hash
{
public static string ComputeHash(string key, IDictionary<string, string> formValues)
{
string message = GetMacString(formValues);

return ComputeHash(key, message);
}


public static string ComputeHash(string key, string message)
{
var encoding = new UTF8Encoding();
byte[] byteKey = encoding.GetBytes(key);

using (HMACSHA256 hmac = new HMACSHA256(byteKey))
{
var messageBytes = encoding.GetBytes(message);
var hashedBytes = hmac.ComputeHash(messageBytes);

return ByteArrayToHexString(hashedBytes);
}
}

private static string ByteArrayToHexString(byte[] bytes)
{
var result = new StringBuilder();
foreach (byte b in bytes)
{
result.Append(b.ToString("x2"));
}

return result.ToString();
}

private static string GetMacString(IDictionary<string, string> formValues)
{
var excludeList = new List<string> { "MAC" };
var keysSorted = formValues.Keys.ToArray();
Array.Sort(keysSorted, StringComparer.Ordinal);

var message = new StringBuilder();
foreach (string key in keysSorted)
{
if (excludeList.Contains(key))
continue;

if (message.Length > 0)
message.Append(" ");

var value = formValues[key];
message.Append(value);
}

return message.ToString();
}
}
10 changes: 10 additions & 0 deletions src/Models/CardLinkUrl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.Serialization;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.Models;

[DataContract]
internal sealed class CardLinkUrl
{
[DataMember(Name = "url")]
public string Url { get; set; }
}
11 changes: 11 additions & 0 deletions src/Models/Frontend/CallbackError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.Serialization;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.Models.Frontend;

//This is a model for ajax-interactions with our templates only
[DataContract]
internal sealed class CallbackError
{
[DataMember(Name = "errorMessage")]
public string ErrorMessage { get; set; }
}
35 changes: 35 additions & 0 deletions src/Models/Frontend/CreateCardRequestData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Runtime.Serialization;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.Models.Frontend;

//This is a model for ajax-interactions with our templates only
[DataContract]
internal sealed class CreateCardRequestData
{
[DataMember(Name = "agreementId")]
public string AgreementId { get; set; }

[DataMember(Name = "brandingId")]
public string BrandingId { get; set; }

[DataMember(Name = "languageCode")]
public string LanguageCode { get; set; }

[DataMember(Name = "paymentMethods")]
public string PaymentMethods { get; set; }

[DataMember(Name = "googleAnalyticsTrackingId")]
public string GoogleAnalyticsTrackingId { get; set; }

[DataMember(Name = "googleAnalyticsClientId")]
public string GoogleAnalyticsClientId { get; set; }

[DataMember(Name = "receiptUrl")]
public string ReceiptUrl { get; set; }

[DataMember(Name = "cancelUrl")]
public string CancelUrl { get; set; }

[DataMember(Name = "callbackUrl")]
public string СallbackUrl { get; set; }
}
13 changes: 13 additions & 0 deletions src/Models/ServiceError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.Serialization;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.QuickPayPaymentWindow.Models;

[DataContract]
internal sealed class ServiceError
{
[DataMember(Name = "message")]
public string Message { get; set; }

[DataMember(Name = "error_code")]
public int ErrorCode { get; set; }
}
Loading