-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Get Part Payment CampaignCode info (#306)
* Add Get Part Payment CampaignCode info * Add MonthlyAmount for GetPartPaymentCampaignCodeInfo * Add comment about utility property
- Loading branch information
1 parent
3a48378
commit daebefc
Showing
5 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/Svea.WebPay.SDK.Tests/Checkout/PartPaymentCampaignTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Svea.WebPay.SDK.CheckoutApi; | ||
using Svea.WebPay.SDK.Json; | ||
using Svea.WebPay.SDK.Tests.Helpers; | ||
using Svea.WebPay.SDK.Tests.Helpers.DataSamples; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Svea.WebPay.SDK.Tests.Checkout | ||
{ | ||
public class PartPaymentCampaignTests : TestBase | ||
{ | ||
|
||
[Fact] | ||
public async Task ShouldReturnPartPaymentCampaigns() | ||
{ | ||
// Arrange | ||
var expectedOrder = JsonSerializer.Deserialize<List<CampaignCodeInfo>>(UtilityDataSamples.GetPartPaymentCampaigns, JsonSerialization.Settings); | ||
var sveaClient = SveaClient(CreateHandlerMock(UtilityDataSamples.GetPartPaymentCampaigns)); | ||
|
||
// Act | ||
var actualPartPaymentCampaigns = await sveaClient.Checkout.Utility.GetPartPaymentCampaigns(true); | ||
|
||
// Assert | ||
Assert.Equal(expectedOrder.Count, actualPartPaymentCampaigns.Count); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Svea.WebPay.SDK.Tests/Helpers/DataSamples/UtilityDataSamples.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Svea.WebPay.SDK.Tests.Helpers.DataSamples | ||
{ | ||
public static class UtilityDataSamples | ||
{ | ||
public static string GetPartPaymentCampaigns = @"[ | ||
{ | ||
""CampaignCode"": 25, | ||
""Description"": ""sample string 26"", | ||
""PaymentPlanType"": 0, | ||
""ContractLengthInMonths"": 27, | ||
""MonthlyAnnuityFactor"": 28.0, | ||
""InitialFee"": 29.0, | ||
""NotificationFee"": 30.0, | ||
""InterestRatePercent"": 31.0, | ||
""NumberOfInterestFreeMonths"": 32, | ||
""NumberOfPaymentFreeMonths"": 33, | ||
""FromAmount"": 34.0, | ||
""ToAmount"": 35.0, | ||
""MonthlyAmount"": 188.00 | ||
}, | ||
{ | ||
""CampaignCode"": 25, | ||
""Description"": ""sample string 26"", | ||
""PaymentPlanType"": 0, | ||
""ContractLengthInMonths"": 27, | ||
""MonthlyAnnuityFactor"": 28.0, | ||
""InitialFee"": 29.0, | ||
""NotificationFee"": 30.0, | ||
""InterestRatePercent"": 31.0, | ||
""NumberOfInterestFreeMonths"": 32, | ||
""NumberOfPaymentFreeMonths"": 33, | ||
""FromAmount"": 34.00, | ||
""ToAmount"": 35.00, | ||
""MonthlyAmount"": 188.00 | ||
} | ||
]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Svea.WebPay.SDK/CheckoutApi/Utility/CheckoutUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Svea.WebPay.SDK.CheckoutApi.Utility | ||
{ | ||
public class CheckoutUtility | ||
{ | ||
private readonly SveaHttpClient _sveaHttpClient; | ||
|
||
public CheckoutUtility(SveaHttpClient sveaHttpClient) | ||
{ | ||
_sveaHttpClient = sveaHttpClient; | ||
} | ||
|
||
/// <summary> | ||
/// This request returns a list of available B2C/B2B part payment campaigns. | ||
/// </summary> | ||
/// <param name="isCompany">Required parameter indicating if it is for the company or private person</param> | ||
/// <param name="amount">Is used to calculate a monthly amount. Setting the parameter amount will also filter out campaigns that do not meet the amount requirement.</param> | ||
/// <param name="configureAwait"></param> | ||
/// <returns>A list of campaigns.</returns> | ||
/// <remarks>For example, this method can be used so "Part payment widget" can be displayed in Product pages. | ||
/// MonthlyAmount from Response is the value used in the widget.</remarks> | ||
public async Task<List<CampaignCodeInfo>> GetPartPaymentCampaigns(bool isCompany, long? amount = null, bool configureAwait = false) | ||
{ | ||
var url = $"/api/util/GetAvailablePartPaymentCampaigns?isCompany={isCompany}" + (amount.HasValue ? $"&amount={amount}" : ""); | ||
var uri = new Uri(url, UriKind.Relative); | ||
var data = await _sveaHttpClient.HttpGet<List<CampaignCodeInfo>>(uri, configureAwait); | ||
return data; | ||
} | ||
} | ||
} |