From b2976c629bbacffd3a2aaa3357177fd38f334e28 Mon Sep 17 00:00:00 2001 From: Erdem Demir <35841628+erdemdmr@users.noreply.github.com> Date: Fri, 23 Dec 2022 13:36:46 +0300 Subject: [PATCH] Adds loyalty reward to payment request (#130) --- .../Functional/Builder/PaymentCardBuilder.cs | 22 ++++++ .../Request/CreatePaymentRequestBuilder.cs | 8 +++ Iyzipay.Tests/Functional/PaymentTest.cs | 68 +++++++++++++++++++ Iyzipay/LoyaltyReward.cs | 18 +++++ Iyzipay/Model/PaymentResource.cs | 2 +- Iyzipay/Request/CreatePaymentRequest.cs | 1 + 6 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Iyzipay/LoyaltyReward.cs diff --git a/Iyzipay.Tests/Functional/Builder/PaymentCardBuilder.cs b/Iyzipay.Tests/Functional/Builder/PaymentCardBuilder.cs index c3ae85f..fa46912 100644 --- a/Iyzipay.Tests/Functional/Builder/PaymentCardBuilder.cs +++ b/Iyzipay.Tests/Functional/Builder/PaymentCardBuilder.cs @@ -102,5 +102,27 @@ public PaymentCardBuilder BuildWithCardCredentials() _cardAlias = "card alias"; return this; } + + public PaymentCardBuilder BuildWithYKBCardCredentials() + { + _cardHolderName = "John Doe"; + _cardNumber = "5451030000000000"; + _expireYear = "2030"; + _expireMonth = "09"; + _cvc = "711"; + _cardAlias = "card alias"; + return this; + } + + public PaymentCardBuilder BuildWithDenizBankCardCredentials() + { + _cardHolderName = "John Doe"; + _cardNumber = "5549607159333771"; + _expireYear = "2030"; + _expireMonth = "09"; + _cvc = "711"; + _cardAlias = "card alias"; + return this; + } } } diff --git a/Iyzipay.Tests/Functional/Builder/Request/CreatePaymentRequestBuilder.cs b/Iyzipay.Tests/Functional/Builder/Request/CreatePaymentRequestBuilder.cs index ea1e02d..ef8d5da 100644 --- a/Iyzipay.Tests/Functional/Builder/Request/CreatePaymentRequestBuilder.cs +++ b/Iyzipay.Tests/Functional/Builder/Request/CreatePaymentRequestBuilder.cs @@ -22,6 +22,7 @@ public sealed class CreatePaymentRequestBuilder : BaseRequestBuilder private string _callbackUrl; private string _posOrderId; private string _connectorName; + private LoyaltyReward _reward; private CreatePaymentRequestBuilder() { @@ -140,6 +141,12 @@ public CreatePaymentRequestBuilder Currency(string currency) return this; } + public CreatePaymentRequestBuilder Reward(LoyaltyReward reward) + { + _reward = reward; + return this; + } + public CreatePaymentRequest Build() { CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest(); @@ -161,6 +168,7 @@ public CreatePaymentRequest Build() createPaymentRequest.PosOrderId = _posOrderId; createPaymentRequest.ConnectorName = _connectorName; createPaymentRequest.Currency = _currency; + createPaymentRequest.Reward = _reward; return createPaymentRequest; } diff --git a/Iyzipay.Tests/Functional/PaymentTest.cs b/Iyzipay.Tests/Functional/PaymentTest.cs index 4fe1d57..df6dcfa 100644 --- a/Iyzipay.Tests/Functional/PaymentTest.cs +++ b/Iyzipay.Tests/Functional/PaymentTest.cs @@ -148,5 +148,73 @@ public void Should_Retrieve_Payment() Assert.Null(payment.ErrorGroup); Assert.NotNull(payment.BasketId); } + + [Test] + public void Should_Create_Payment_With_Loyalty_Ykb_World() + { + LoyaltyReward reward = new LoyaltyReward(); + reward.RewardUsage = 1; + reward.RewardAmount = "0.1"; + + CreatePaymentRequest request = CreatePaymentRequestBuilder.Create() + .StandardListingPayment() + .Reward(reward) + .PaymentCard(PaymentCardBuilder.Create().BuildWithYKBCardCredentials().Build()) + .Build(); + + Payment payment = Payment.Create(request, _options); + + PrintResponse(payment); + + Assert.Null(payment.ConnectorName); + Assert.AreEqual(Locale.TR.ToString(), payment.Locale); + Assert.AreEqual(Status.SUCCESS.ToString(), payment.Status); + Assert.NotNull(payment.SystemTime); + Assert.Null(payment.ErrorCode); + Assert.Null(payment.ErrorMessage); + Assert.Null(payment.ErrorGroup); + Assert.NotNull(payment.PaymentId); + Assert.NotNull(payment.BasketId); + Assert.AreEqual(payment.Price, "1"); + Assert.AreEqual(payment.PaidPrice, "1.1"); + Assert.AreEqual(payment.IyziCommissionRateAmount.RemoveTrailingZeros(), "0.028875"); + Assert.AreEqual(payment.IyziCommissionFee.RemoveTrailingZeros(), "0.25"); + Assert.AreEqual(payment.MerchantCommissionRate.RemoveTrailingZeros(), "10"); + Assert.AreEqual(payment.MerchantCommissionRateAmount.RemoveTrailingZeros(), "0.1"); + } + + [Test] + public void Should_Create_Payment_With_Loyalty_Denizbank_Bonus() + { + LoyaltyReward reward = new LoyaltyReward(); + reward.RewardUsage = 1; + reward.RewardAmount = "0.1"; + + CreatePaymentRequest request = CreatePaymentRequestBuilder.Create() + .StandardListingPayment() + .Reward(reward) + .PaymentCard(PaymentCardBuilder.Create().BuildWithDenizBankCardCredentials().Build()) + .Build(); + + Payment payment = Payment.Create(request, _options); + + PrintResponse(payment); + + Assert.Null(payment.ConnectorName); + Assert.AreEqual(Locale.TR.ToString(), payment.Locale); + Assert.AreEqual(Status.SUCCESS.ToString(), payment.Status); + Assert.NotNull(payment.SystemTime); + Assert.Null(payment.ErrorCode); + Assert.Null(payment.ErrorMessage); + Assert.Null(payment.ErrorGroup); + Assert.NotNull(payment.PaymentId); + Assert.NotNull(payment.BasketId); + Assert.AreEqual(payment.Price, "1"); + Assert.AreEqual(payment.PaidPrice, "1.1"); + Assert.AreEqual(payment.IyziCommissionRateAmount.RemoveTrailingZeros(), "0.028875"); + Assert.AreEqual(payment.IyziCommissionFee.RemoveTrailingZeros(), "0.25"); + Assert.AreEqual(payment.MerchantCommissionRate.RemoveTrailingZeros(), "10"); + Assert.AreEqual(payment.MerchantCommissionRateAmount.RemoveTrailingZeros(), "0.1"); + } } } \ No newline at end of file diff --git a/Iyzipay/LoyaltyReward.cs b/Iyzipay/LoyaltyReward.cs new file mode 100644 index 0000000..7056e40 --- /dev/null +++ b/Iyzipay/LoyaltyReward.cs @@ -0,0 +1,18 @@ +using System; + +namespace Iyzipay +{ + public class LoyaltyReward : RequestStringConvertible + { + public String RewardAmount { get; set; } + public int RewardUsage { get; set; } + + public virtual String ToPKIRequestString() + { + return ToStringRequestBuilder.NewInstance() + .Append("rewardAmount", RewardAmount) + .Append("rewardUsage", RewardUsage) + .GetRequestString(); + } + } +} diff --git a/Iyzipay/Model/PaymentResource.cs b/Iyzipay/Model/PaymentResource.cs index 55145b8..f8ff0a8 100644 --- a/Iyzipay/Model/PaymentResource.cs +++ b/Iyzipay/Model/PaymentResource.cs @@ -23,7 +23,7 @@ public class PaymentResource : IyzipayResource public String CardToken { get; set; } public String CardUserKey { get; set; } public String BinNumber { get; set; } - public String LastFourDigits { get; set; } + public String LastFourDigits { get; set; } public String BasketId { get; set; } [JsonProperty(PropertyName = "itemTransactions")] public List PaymentItems { get; set; } diff --git a/Iyzipay/Request/CreatePaymentRequest.cs b/Iyzipay/Request/CreatePaymentRequest.cs index 0f0dc5b..72f2c61 100644 --- a/Iyzipay/Request/CreatePaymentRequest.cs +++ b/Iyzipay/Request/CreatePaymentRequest.cs @@ -22,6 +22,7 @@ public class CreatePaymentRequest : BaseRequest public String PosOrderId { get; set; } public String ConnectorName { get; set; } public String Currency { get; set; } + public LoyaltyReward Reward { get; set; } public override String ToPKIRequestString() {