Skip to content

Commit

Permalink
Adds loyalty reward to payment request (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemdmr authored Dec 23, 2022
1 parent 022dbd5 commit b2976c6
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Iyzipay.Tests/Functional/Builder/PaymentCardBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class CreatePaymentRequestBuilder : BaseRequestBuilder
private string _callbackUrl;
private string _posOrderId;
private string _connectorName;
private LoyaltyReward _reward;

private CreatePaymentRequestBuilder()
{
Expand Down Expand Up @@ -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();
Expand All @@ -161,6 +168,7 @@ public CreatePaymentRequest Build()
createPaymentRequest.PosOrderId = _posOrderId;
createPaymentRequest.ConnectorName = _connectorName;
createPaymentRequest.Currency = _currency;
createPaymentRequest.Reward = _reward;
return createPaymentRequest;
}

Expand Down
68 changes: 68 additions & 0 deletions Iyzipay.Tests/Functional/PaymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
18 changes: 18 additions & 0 deletions Iyzipay/LoyaltyReward.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
2 changes: 1 addition & 1 deletion Iyzipay/Model/PaymentResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaymentItem> PaymentItems { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Iyzipay/Request/CreatePaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit b2976c6

Please sign in to comment.