Skip to content

Commit

Permalink
Merge pull request #40 from sveawebpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mlvochin committed Feb 24, 2021
2 parents 2d56179 + 057ad5e commit 2f742d7
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,86 @@ public void TestLowerAmountResponseFailure()
Assert.That(response.ErrorMessage, Is.EqualTo("Transaction rejected by bank."));
}

[Test]
public void TestLowerAmountConfirmCompleteFlow()
{
var customerRefNo = CreateCustomerRefNo();
var payment = MakePreparedPayment(PrepareRegularPayment(PaymentMethod.KORTCERT, customerRefNo));

LowerAmountResponse lowerAmountResponse = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
.LowerAmountConfirm(new LowerAmountConfirm(
transactionId: payment.TransactionId,
amountToLower: 111,
captureDate: DateTime.Now
))
.PrepareRequest()
.DoRequest()
.To(LowerAmount.Response);
}

[Test]
public void TestLowerAmountConfirm()
{
var customerRefNo = CreateCustomerRefNo();
var payment = MakePreparedPayment(PrepareRegularPayment(PaymentMethod.KORTCERT, customerRefNo));

var hostedActionRequest = new HostedAdmin(SveaConfig.GetDefaultConfig(), CountryCode.SE)
.LowerAmountConfirm(new LowerAmountConfirm(
transactionId: payment.TransactionId,
amountToLower: 111,
captureDate: DateTime.Parse("2021-05-29")
));

HostedAdminRequest hostedAdminRequest = hostedActionRequest.PrepareRequest();
Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/loweramountconfirm/transactionid").InnerText, Is.EqualTo(payment.TransactionId + ""));
Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/loweramountconfirm/amounttolower").InnerText, Is.EqualTo("111"));
Assert.That(hostedAdminRequest.MessageXmlDocument.SelectSingleNode("/loweramountconfirm/capturedate").InnerText, Is.EqualTo("2021-05-29"));

var hostedAdminResponse = hostedActionRequest.DoRequest<HostedAdminResponse>();
Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/statuscode").InnerText, Is.EqualTo("0"));
Assert.That(hostedAdminResponse.MessageXmlDocument.SelectSingleNode("/response/transaction/customerrefno").InnerText, Is.EqualTo(customerRefNo));
}


[Test]
public void TestLowerAmountConfirmResponse()
{
var responseXml = new XmlDocument();
responseXml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
<response>
<transaction id=""598972"">
<customerrefno>1ba66a0d653ca4cf3a5bc3eeb9ed1a2b4</customerrefno>
</transaction>
<statuscode>0</statuscode>
</response>");
LowerAmountConfirmResponse response = LowerAmountConfirm.Response(responseXml);

Assert.That(response.TransactionId, Is.EqualTo(598972));
Assert.That(response.CustomerRefNo, Is.EqualTo("1ba66a0d653ca4cf3a5bc3eeb9ed1a2b4"));
Assert.That(response.ClientOrderNumber, Is.EqualTo("1ba66a0d653ca4cf3a5bc3eeb9ed1a2b4"));
Assert.That(response.StatusCode, Is.EqualTo(0));
Assert.That(response.Accepted, Is.True);
Assert.That(response.ErrorMessage, Is.Empty);
}

[Test]
public void TestLowerAmountConfirmResponseFailure()
{
var responseXml = new XmlDocument();
responseXml.LoadXml(@"<?xml version='1.0' encoding='UTF-8'?>
<response>
<statuscode>107</statuscode>
</response>");
LowerAmountConfirmResponse response = LowerAmountConfirm.Response(responseXml);

Assert.That(response.TransactionId, Is.Null);
Assert.That(response.CustomerRefNo, Is.Null);
Assert.That(response.ClientOrderNumber, Is.Null);
Assert.That(response.StatusCode, Is.EqualTo(107));
Assert.That(response.Accepted, Is.False);
Assert.That(response.ErrorMessage, Is.EqualTo("Transaction rejected by bank."));
}

[Test]
public void TestQueryTransactionIdDirectPayment()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Xml;
using Webpay.Integration.CSharp.Hosted.Admin.Response;

namespace Webpay.Integration.CSharp.Hosted.Admin.Actions
{
public class LowerAmountConfirm
{
public readonly long AmountToLower;
public readonly long TransactionId;
public readonly DateTime CaptureDate;

public LowerAmountConfirm(long transactionId, long amountToLower, DateTime captureDate)
{
TransactionId = transactionId;
AmountToLower = amountToLower;
CaptureDate = captureDate;
}

public static LowerAmountConfirmResponse Response(XmlDocument responseXml)
{
return new LowerAmountConfirmResponse(responseXml);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public T DoRequest<T>()
var hostedAdminResponse = HostedAdminRequest.HostedAdminCall(GetEndPointBase(), PrepareRequest());
return (T)(object)hostedAdminResponse.To(LowerAmount.Response);
}
//LowerAmountConfirm
if (typeof(T) == typeof(LowerAmountConfirmResponse))
{
var hostedAdminResponse = HostedAdminRequest.HostedAdminCall(GetEndPointBase(), PrepareRequest());
return (T)(object)hostedAdminResponse.To(LowerAmountConfirm.Response);
}
//Query
if ( typeof(T) == typeof(QueryResponse) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public HostedActionRequest LowerAmount(LowerAmount lowerAmount)
return new HostedActionRequest(xml, CountryCode, MerchantId, ConfigurationProvider, "/loweramount");
}

public HostedActionRequest LowerAmountConfirm(LowerAmountConfirm lowerAmount)
{
var xml = string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?>
<loweramountconfirm>
<transactionid>{0}</transactionid>
<amounttolower>{1}</amounttolower>
<capturedate>{2}</capturedate>
</loweramountconfirm>", lowerAmount.TransactionId,
lowerAmount.AmountToLower,
lowerAmount.CaptureDate.ToString("yyyy-MM-dd"));
return new HostedActionRequest(xml, CountryCode, MerchantId, ConfigurationProvider, "/loweramountconfirm");
}

public HostedActionRequest Query(QueryByTransactionId query)
{
var xml = string.Format(@"<?xml version=""1.0"" encoding=""UTF-8""?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Webpay.Integration.CSharp.Hosted.Admin.Response
{
public class LowerAmountConfirmResponse: LowerAmountResponse
{
public LowerAmountConfirmResponse(XmlDocument response) : base(response)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Svea Ekonomi AB")]
[assembly: AssemblyProduct("Webpay.Integration.CSharp")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -35,5 +35,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Compile Include="Exception\SveaWebPayException.cs" />
<Compile Include="Exception\SveaWebPayValidationException.cs" />
<Compile Include="Hosted\Admin\Actions\Annul.cs" />
<Compile Include="Hosted\Admin\Actions\LowerAmountConfirm.cs" />
<Compile Include="Hosted\Admin\Response\CreditResponse.cs" />
<Compile Include="Hosted\Admin\Response\AnnulResponse.cs" />
<Compile Include="Hosted\Admin\Actions\CancelRecurSubscription.cs" />
Expand All @@ -84,6 +85,7 @@
<Compile Include="Hosted\Admin\Actions\GetReconciliationReport.cs" />
<Compile Include="Hosted\Admin\Response\GetReconciliationReportResponse.cs" />
<Compile Include="Hosted\Admin\Actions\Credit.cs" />
<Compile Include="Hosted\Admin\Response\LowerAmountConfirmResponse.cs" />
<Compile Include="Hosted\Admin\Response\LowerAmountResponse.cs" />
<Compile Include="Hosted\Admin\Actions\Query.cs" />
<Compile Include="Hosted\Admin\Actions\QueryByClientOrderNumber.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<iconUrl>http://cdn.svea.com/sveaekonomi/rgb_ekonomi_small.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Add EINVOICEB2B distribution type, add helper method to validate peppol-ID, calculate price per month according to new formula</releaseNotes>
<copyright>Copyright 2019</copyright>
<releaseNotes>Added LowerAmountConfirm method</releaseNotes>
<copyright>Copyright 2021</copyright>
<tags>svea webpay</tags>
</metadata>
</package>

0 comments on commit 2f742d7

Please sign in to comment.