Skip to content

Commit

Permalink
Merge pull request #13 from dynamicweb/ssm/20967-dibs_fixes_inline_an…
Browse files Browse the repository at this point in the history
…d_others

Various fixes
  • Loading branch information
StanislavSmetaninSSM authored Nov 7, 2024
2 parents baa15e2 + b56f0ba commit 618ac33
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 27 deletions.
17 changes: 11 additions & 6 deletions src/DibsEasyCheckout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,17 @@ private void UpdateOrderInfo(string paymentId, Order order)
else
{
order.TransactionStatus = "Succeeded";

bool updateReference = order.Id.StartsWith("CART", StringComparison.Ordinal);
SetOrderComplete(order, paymentId);

if (AutoCapture)
if (updateReference)
{
string url = GetApprovetUrl(GetBaseUrl(order));
service.UpdatePaymentReference(paymentId, url);
}

if (AutoCapture)
{
try
{
LogEvent(order, "Start autocapture request.");
Expand Down Expand Up @@ -425,13 +430,13 @@ public OrderCaptureInfo Capture(Order order)
LogEvent(order, "Start autocapture request.");
ChargePayment(order, order.TransactionNumber, amount);

double capturedAmount = amount / 100d;

if (order.Price.PricePIP == amount)
{
LogEvent(order, "Capture successful", DebuggingInfoType.CaptureResult);
}
LogEvent(order, string.Format("Message=\"{0}\" Amount=\"{1:f2}\"", "Capture successful", capturedAmount), DebuggingInfoType.CaptureResult);
else
{
LogEvent(order, String.Format("Message=\"{0}\" Amount=\"{1:f2}\"", "Split capture(final)", amount / 100f), DebuggingInfoType.CaptureResult);
LogEvent(order, string.Format("Message=\"{0}\" Amount=\"{1:f2}\"", "Split capture (final)", capturedAmount), DebuggingInfoType.CaptureResult);
order.CaptureInfo.Message = "Split capture successful";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>10.6.4</VersionPrefix>
<VersionPrefix>10.6.5</VersionPrefix>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>Nets Easy Checkout</Title>
<Description>Nets Easy Checkout</Description>
Expand All @@ -21,6 +21,7 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageIcon>dibs-logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<None Remove="Updates\checkouthandler_error.cshtml" />
Expand All @@ -38,4 +39,10 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Update="dibs-logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>
13 changes: 13 additions & 0 deletions src/Models/UpdatePaymentReferenceRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.Serialization;

namespace Dynamicweb.Ecommerce.CheckoutHandlers.DibsEasyCheckout.Models;

[DataContract]
internal sealed class UpdatePaymentReferenceRequest
{
[DataMember(Name = "reference")]
public string Reference { get; set; }

[DataMember(Name = "checkoutUrl")]
public string CheckoutUrl { get; set; }
}
5 changes: 5 additions & 0 deletions src/Service/ApiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ internal enum ApiCommand
/// </summary>
CapturePayment,

/// <summary>
/// Updates the specified payment object with a new reference string and a checkoutUrl
/// PUT /payments/{paymentId}/referenceinformation
/// </summary>
UpdatePaymentReference,

/// <summary>
/// POST /charges/{operatorId}/refunds
Expand Down
3 changes: 3 additions & 0 deletions src/Service/DibsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ApiCommand.CancelPayment or
ApiCommand.CapturePayment or
ApiCommand.CreatePayment or
ApiCommand.RefundPayment => client.PostAsync(apiCommand, GetContent()),
//PUT
ApiCommand.UpdatePaymentReference => client.PutAsync(apiCommand, GetContent()),
//GET
ApiCommand.GetPayment => client.GetAsync(apiCommand),
_ => throw new NotSupportedException($"Unknown operation was used. The operation code: {configuration.CommandType}.")
Expand Down Expand Up @@ -107,6 +109,7 @@ private static string GetCommandLink(string baseAddress, ApiCommand command, str
ApiCommand.GetPayment => GetCommandLink($"payments/{operatorId}"),
ApiCommand.CancelPayment => GetCommandLink($"payments/{operatorId}/cancels"),
ApiCommand.CapturePayment => GetCommandLink($"payments/{operatorId}/charges"),
ApiCommand.UpdatePaymentReference => GetCommandLink($"payments/{operatorId}/referenceinformation"),
ApiCommand.RefundPayment => GetCommandLink($"charges/{operatorId}/refunds"),
_ => throw new NotSupportedException($"The api command is not supported. Command: {command}")
};
Expand Down
28 changes: 18 additions & 10 deletions src/Service/DibsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ public RefundPaymentResponse RefundPayment(string paymentId, long amount)
return Converter.Deserialize<RefundPaymentResponse>(response);
}

public void CancelPayment(string paymentId, long amount)
public void CancelPayment(string paymentId, long amount) => DibsRequest.SendRequest(Order, ApiUrl, SecretKey, new()
{
string response = DibsRequest.SendRequest(Order, ApiUrl, SecretKey, new()
CommandType = ApiCommand.CancelPayment,
OperatorId = paymentId,
Data = new CancelPaymentRequest
{
CommandType = ApiCommand.CancelPayment,
OperatorId = paymentId,
Data = new CancelPaymentRequest
{
Amount = amount
}
});
}
Amount = amount
}
});

public void UpdatePaymentReference(string paymentId, string checkoutUrl) => DibsRequest.SendRequest(Order, ApiUrl, SecretKey, new()
{
CommandType = ApiCommand.UpdatePaymentReference,
OperatorId = paymentId,
Data = new UpdatePaymentReferenceRequest
{
Reference = Order.Id,
CheckoutUrl = checkoutUrl
}
});
}
2 changes: 1 addition & 1 deletion src/Updates/DibsUpdateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override IEnumerable<Update> GetUpdates()
return new List<Update>()
{
new FileUpdate("39da8029-91d8-4a10-a5e3-e4cc38330188", this, "/Files/Templates/eCom7/CheckoutHandler/DibsEasy/Error/checkouthandler_error.cshtml", () => GetResourceStream("checkouthandler_error.cshtml")),
new FileUpdate("2d813363-d092-47ef-b9f1-12aca0034508", this, "/Files/Templates/eCom7/CheckoutHandler/DibsEasy/Form/EmbededDibs.cshtml", () => GetResourceStream("EmbededDibs.cshtml")),
new FileUpdate("e0fc296d-b6b4-40b9-8ec1-ec0458504f10", this, "/Files/Templates/eCom7/CheckoutHandler/DibsEasy/Form/EmbededDibs.cshtml", () => GetResourceStream("EmbededDibs.cshtml")),
new FileUpdate("8ac8cb90-18bb-40b0-a392-0acccc6df1ea", this, "/Files/Templates/eCom7/CheckoutHandler/DibsEasy/Form/HostedPaymentDibs.cshtml", () => GetResourceStream("HostedPaymentDibs.cshtml"))
};
}
Expand Down
10 changes: 1 addition & 9 deletions src/Updates/EmbededDibs.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
<label>Order ID: <b>@GetString("Ecom:Order.ID")</b></label> <br />
<label>Amount: <b>@GetString("Ecom:Order.Price.PriceWithVATFormatted")</b></label> <br />
</p>

<div id="dibs-complete-checkout"> </div>

<script src="@GetString("DibsEasy.checkoutSrc")"></script>



<script type="text/javascript" script-src="self">
var key = "@GetString("DibsEasy.checkoutKey")";
var paymentId = "@GetString("DibsEasy.paymentId")";
Expand All @@ -37,8 +33,4 @@
}
});
}
</script>



<div>@TemplateTags()</div>
</script>
Binary file added src/dibs-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 618ac33

Please sign in to comment.