diff --git a/Iyzipay.Samples/PaymentSample.cs b/Iyzipay.Samples/PaymentSample.cs index 9a865f8..8520fa0 100644 --- a/Iyzipay.Samples/PaymentSample.cs +++ b/Iyzipay.Samples/PaymentSample.cs @@ -13,7 +13,7 @@ public void Should_Create_Payment() CreatePaymentRequest request = new CreatePaymentRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; - request.Price = "1"; + request.Price = "1.0"; request.PaidPrice = "1.2"; request.Currency = Currency.TRY.ToString(); request.Installment = 1; @@ -300,6 +300,198 @@ public void Should_Create_Payment_With_Registered_Card() Assert.IsNull(payment.ErrorGroup); } + [Test] + public void Should_Create_Ucs_Payment_And_Register_Card() + { + CreatePaymentRequest request = new CreatePaymentRequest(); + request.Locale = Locale.TR.ToString(); + request.ConversationId = "123456789"; + request.Price = "1.0"; + request.PaidPrice = "1.2"; + request.Currency = Currency.TRY.ToString(); + request.GsmNumber = "+905350000000"; + request.Installment = 1; + request.BasketId = "B67832"; + request.PaymentChannel = PaymentChannel.WEB.ToString(); + request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); + + PaymentCard paymentCard = new PaymentCard(); + paymentCard.CardHolderName = "John Doe"; + paymentCard.CardNumber = "5528790000000008"; + paymentCard.ExpireMonth = "12"; + paymentCard.ExpireYear = "2030"; + paymentCard.Cvc = "123"; + paymentCard.RegisterConsumerCard = "false"; + request.PaymentCard = paymentCard; + + Buyer buyer = new Buyer(); + buyer.Id = "BY789"; + buyer.Name = "John"; + buyer.Surname = "Doe"; + buyer.GsmNumber = "+905350000000"; + buyer.Email = "emailbusra@email.com"; + buyer.IdentityNumber = "74300864791"; + buyer.LastLoginDate = "2015-10-05 12:43:35"; + buyer.RegistrationDate = "2013-04-21 15:12:09"; + buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + buyer.Ip = "85.34.78.112"; + buyer.City = "Istanbul"; + buyer.Country = "Turkey"; + buyer.ZipCode = "34732"; + request.Buyer = buyer; + + Address shippingAddress = new Address(); + shippingAddress.ContactName = "Jane Doe"; + shippingAddress.City = "Istanbul"; + shippingAddress.Country = "Turkey"; + shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + shippingAddress.ZipCode = "34742"; + request.ShippingAddress = shippingAddress; + + Address billingAddress = new Address(); + billingAddress.ContactName = "Jane Doe"; + billingAddress.City = "Istanbul"; + billingAddress.Country = "Turkey"; + billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + billingAddress.ZipCode = "34742"; + request.BillingAddress = billingAddress; + + List basketItems = new List(); + BasketItem firstBasketItem = new BasketItem(); + firstBasketItem.Id = "BI101"; + firstBasketItem.Name = "Binocular"; + firstBasketItem.Category1 = "Collectibles"; + firstBasketItem.Category2 = "Accessories"; + firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + firstBasketItem.Price = "0.3"; + basketItems.Add(firstBasketItem); + + BasketItem secondBasketItem = new BasketItem(); + secondBasketItem.Id = "BI102"; + secondBasketItem.Name = "Game code"; + secondBasketItem.Category1 = "Game"; + secondBasketItem.Category2 = "Online Game Items"; + secondBasketItem.ItemType = BasketItemType.VIRTUAL.ToString(); + secondBasketItem.Price = "0.5"; + basketItems.Add(secondBasketItem); + + BasketItem thirdBasketItem = new BasketItem(); + thirdBasketItem.Id = "BI103"; + thirdBasketItem.Name = "Usb"; + thirdBasketItem.Category1 = "Electronics"; + thirdBasketItem.Category2 = "Usb / Cable"; + thirdBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + thirdBasketItem.Price = "0.2"; + basketItems.Add(thirdBasketItem); + request.BasketItems = basketItems; + + Payment payment = Payment.Create(request, options); + + PrintResponse(payment); + + Assert.AreEqual(Status.SUCCESS.ToString(), payment.Status); + Assert.AreEqual(Locale.TR.ToString(), payment.Locale); + Assert.AreEqual("123456789", payment.ConversationId); + Assert.IsNotNull(payment.SystemTime); + Assert.IsNull(payment.ErrorCode); + Assert.IsNull(payment.ErrorMessage); + Assert.IsNull(payment.ErrorGroup); + } + + [Test] + public void Should_Create_Ucs_Payment_With_Registered_Card() + { + CreatePaymentRequest request = new CreatePaymentRequest(); + request.Locale = Locale.TR.ToString(); + request.ConversationId = "123456789"; + request.Price = "1"; + request.PaidPrice = "1.2"; + request.Currency = Currency.TRY.ToString(); + request.Installment = 1; + request.BasketId = "B67832"; + request.PaymentChannel = PaymentChannel.WEB.ToString(); + request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); + + PaymentCard paymentCard = new PaymentCard(); + paymentCard.CardToken = "card Token"; + paymentCard.ConsumerToken = "consumer Token"; + paymentCard.UcsToken = "ucs Token"; + request.PaymentCard = paymentCard; + + Buyer buyer = new Buyer(); + buyer.Id = "BY789"; + buyer.Name = "John"; + buyer.Surname = "Doe"; + buyer.GsmNumber = "+905350000000"; + buyer.Email = "email@email.com"; + buyer.IdentityNumber = "74300864791"; + buyer.LastLoginDate = "2015-10-05 12:43:35"; + buyer.RegistrationDate = "2013-04-21 15:12:09"; + buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + buyer.Ip = "85.34.78.112"; + buyer.City = "Istanbul"; + buyer.Country = "Turkey"; + buyer.ZipCode = "34732"; + request.Buyer = buyer; + + Address shippingAddress = new Address(); + shippingAddress.ContactName = "Jane Doe"; + shippingAddress.City = "Istanbul"; + shippingAddress.Country = "Turkey"; + shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + shippingAddress.ZipCode = "34742"; + request.ShippingAddress = shippingAddress; + + Address billingAddress = new Address(); + billingAddress.ContactName = "Jane Doe"; + billingAddress.City = "Istanbul"; + billingAddress.Country = "Turkey"; + billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + billingAddress.ZipCode = "34742"; + request.BillingAddress = billingAddress; + + List basketItems = new List(); + BasketItem firstBasketItem = new BasketItem(); + firstBasketItem.Id = "BI101"; + firstBasketItem.Name = "Binocular"; + firstBasketItem.Category1 = "Collectibles"; + firstBasketItem.Category2 = "Accessories"; + firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + firstBasketItem.Price = "0.3"; + basketItems.Add(firstBasketItem); + + BasketItem secondBasketItem = new BasketItem(); + secondBasketItem.Id = "BI102"; + secondBasketItem.Name = "Game code"; + secondBasketItem.Category1 = "Game"; + secondBasketItem.Category2 = "Online Game Items"; + secondBasketItem.ItemType = BasketItemType.VIRTUAL.ToString(); + secondBasketItem.Price = "0.5"; + basketItems.Add(secondBasketItem); + + BasketItem thirdBasketItem = new BasketItem(); + thirdBasketItem.Id = "BI103"; + thirdBasketItem.Name = "Usb"; + thirdBasketItem.Category1 = "Electronics"; + thirdBasketItem.Category2 = "Usb / Cable"; + thirdBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + thirdBasketItem.Price = "0.2"; + basketItems.Add(thirdBasketItem); + request.BasketItems = basketItems; + + Payment payment = Payment.Create(request, options); + + PrintResponse(payment); + + Assert.AreEqual(Status.SUCCESS.ToString(), payment.Status); + Assert.AreEqual(Locale.TR.ToString(), payment.Locale); + Assert.AreEqual("123456789", payment.ConversationId); + Assert.IsNotNull(payment.SystemTime); + Assert.IsNull(payment.ErrorCode); + Assert.IsNull(payment.ErrorMessage); + Assert.IsNull(payment.ErrorGroup); + } + [Test] public void Should_Retrieve_Payment_Result() { diff --git a/Iyzipay.Samples/ThreedsSample.cs b/Iyzipay.Samples/ThreedsSample.cs index 8946523..6a3a71f 100644 --- a/Iyzipay.Samples/ThreedsSample.cs +++ b/Iyzipay.Samples/ThreedsSample.cs @@ -106,6 +106,201 @@ public void Should_Initialize_Threeds() Assert.IsNotNull(threedsInitialize.HtmlContent); } + [Test] + public void Should_Initialize_Threeds_Payment_With_Ucs_Registered_Card() + { + CreatePaymentRequest request = new CreatePaymentRequest(); + request.Locale = Locale.TR.ToString(); + request.ConversationId = "123456789"; + request.Price = "1.0"; + request.PaidPrice = "1.2"; + request.Currency = Currency.TRY.ToString(); + request.Installment = 1; + request.BasketId = "B67832"; + request.PaymentChannel = PaymentChannel.WEB.ToString(); + request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); + request.CallbackUrl = "https://www.merchant.com/callback"; + + PaymentCard paymentCard = new PaymentCard(); + paymentCard.CardToken = "card Token"; + paymentCard.ConsumerToken = "consumer Token"; + paymentCard.UcsToken = "ucs Token"; + request.PaymentCard = paymentCard; + + Buyer buyer = new Buyer(); + buyer.Id = "BY789"; + buyer.Name = "John"; + buyer.Surname = "Doe"; + buyer.GsmNumber = "+905350000000"; + buyer.Email = "email@email.com"; + buyer.IdentityNumber = "74300864791"; + buyer.LastLoginDate = "2015-10-05 12:43:35"; + buyer.RegistrationDate = "2013-04-21 15:12:09"; + buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + buyer.Ip = "85.34.78.112"; + buyer.City = "Istanbul"; + buyer.Country = "Turkey"; + buyer.ZipCode = "34732"; + request.Buyer = buyer; + + Address shippingAddress = new Address(); + shippingAddress.ContactName = "Jane Doe"; + shippingAddress.City = "Istanbul"; + shippingAddress.Country = "Turkey"; + shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + shippingAddress.ZipCode = "34742"; + request.ShippingAddress = shippingAddress; + + Address billingAddress = new Address(); + billingAddress.ContactName = "Jane Doe"; + billingAddress.City = "Istanbul"; + billingAddress.Country = "Turkey"; + billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + billingAddress.ZipCode = "34742"; + request.BillingAddress = billingAddress; + + List basketItems = new List(); + BasketItem firstBasketItem = new BasketItem(); + firstBasketItem.Id = "BI101"; + firstBasketItem.Name = "Binocular"; + firstBasketItem.Category1 = "Collectibles"; + firstBasketItem.Category2 = "Accessories"; + firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + firstBasketItem.Price = "0.3"; + basketItems.Add(firstBasketItem); + + BasketItem secondBasketItem = new BasketItem(); + secondBasketItem.Id = "BI102"; + secondBasketItem.Name = "Game code"; + secondBasketItem.Category1 = "Game"; + secondBasketItem.Category2 = "Online Game Items"; + secondBasketItem.ItemType = BasketItemType.VIRTUAL.ToString(); + secondBasketItem.Price = "0.5"; + basketItems.Add(secondBasketItem); + + BasketItem thirdBasketItem = new BasketItem(); + thirdBasketItem.Id = "BI103"; + thirdBasketItem.Name = "Usb"; + thirdBasketItem.Category1 = "Electronics"; + thirdBasketItem.Category2 = "Usb / Cable"; + thirdBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + thirdBasketItem.Price = "0.2"; + basketItems.Add(thirdBasketItem); + request.BasketItems = basketItems; + + ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options); + + PrintResponse(threedsInitialize); + + Assert.AreEqual(Status.SUCCESS.ToString(), threedsInitialize.Status); + Assert.AreEqual(Locale.TR.ToString(), threedsInitialize.Locale); + Assert.AreEqual("123456789", threedsInitialize.ConversationId); + Assert.IsNotNull(threedsInitialize.SystemTime); + Assert.IsNull(threedsInitialize.ErrorCode); + Assert.IsNull(threedsInitialize.ErrorMessage); + Assert.IsNull(threedsInitialize.ErrorGroup); + Assert.IsNotNull(threedsInitialize.HtmlContent); + } + + [Test] + public void Should_Initialize_Threeds_Payment_And_Register_Card() + { + CreatePaymentRequest request = new CreatePaymentRequest(); + request.Locale = Locale.TR.ToString(); + request.ConversationId = "123456789"; + request.Price = "1.0"; + request.PaidPrice = "1.2"; + request.Currency = Currency.TRY.ToString(); + request.Installment = 1; + request.BasketId = "B67832"; + request.PaymentChannel = PaymentChannel.WEB.ToString(); + request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); + request.CallbackUrl = "https://www.merchant.com/callback"; + + PaymentCard paymentCard = new PaymentCard(); + paymentCard.CardHolderName = "John Doe"; + paymentCard.CardNumber = "5528790000000008"; + paymentCard.ExpireMonth = "12"; + paymentCard.ExpireYear = "2030"; + paymentCard.Cvc = "123"; + paymentCard.RegisterConsumerCard = "false"; + request.PaymentCard = paymentCard; + + Buyer buyer = new Buyer(); + buyer.Id = "BY789"; + buyer.Name = "John"; + buyer.Surname = "Doe"; + buyer.GsmNumber = "+905350000000"; + buyer.Email = "email@email.com"; + buyer.IdentityNumber = "74300864791"; + buyer.LastLoginDate = "2015-10-05 12:43:35"; + buyer.RegistrationDate = "2013-04-21 15:12:09"; + buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + buyer.Ip = "85.34.78.112"; + buyer.City = "Istanbul"; + buyer.Country = "Turkey"; + buyer.ZipCode = "34732"; + request.Buyer = buyer; + + Address shippingAddress = new Address(); + shippingAddress.ContactName = "Jane Doe"; + shippingAddress.City = "Istanbul"; + shippingAddress.Country = "Turkey"; + shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + shippingAddress.ZipCode = "34742"; + request.ShippingAddress = shippingAddress; + + Address billingAddress = new Address(); + billingAddress.ContactName = "Jane Doe"; + billingAddress.City = "Istanbul"; + billingAddress.Country = "Turkey"; + billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; + billingAddress.ZipCode = "34742"; + request.BillingAddress = billingAddress; + + List basketItems = new List(); + BasketItem firstBasketItem = new BasketItem(); + firstBasketItem.Id = "BI101"; + firstBasketItem.Name = "Binocular"; + firstBasketItem.Category1 = "Collectibles"; + firstBasketItem.Category2 = "Accessories"; + firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + firstBasketItem.Price = "0.3"; + basketItems.Add(firstBasketItem); + + BasketItem secondBasketItem = new BasketItem(); + secondBasketItem.Id = "BI102"; + secondBasketItem.Name = "Game code"; + secondBasketItem.Category1 = "Game"; + secondBasketItem.Category2 = "Online Game Items"; + secondBasketItem.ItemType = BasketItemType.VIRTUAL.ToString(); + secondBasketItem.Price = "0.5"; + basketItems.Add(secondBasketItem); + + BasketItem thirdBasketItem = new BasketItem(); + thirdBasketItem.Id = "BI103"; + thirdBasketItem.Name = "Usb"; + thirdBasketItem.Category1 = "Electronics"; + thirdBasketItem.Category2 = "Usb / Cable"; + thirdBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); + thirdBasketItem.Price = "0.2"; + basketItems.Add(thirdBasketItem); + request.BasketItems = basketItems; + + ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options); + + PrintResponse(threedsInitialize); + + Assert.AreEqual(Status.SUCCESS.ToString(), threedsInitialize.Status); + Assert.AreEqual(Locale.TR.ToString(), threedsInitialize.Locale); + Assert.AreEqual("123456789", threedsInitialize.ConversationId); + Assert.IsNotNull(threedsInitialize.SystemTime); + Assert.IsNull(threedsInitialize.ErrorCode); + Assert.IsNull(threedsInitialize.ErrorMessage); + Assert.IsNull(threedsInitialize.ErrorGroup); + Assert.IsNotNull(threedsInitialize.HtmlContent); + } + [Test] public void Should_Create_Threeds_Payment() { diff --git a/Iyzipay.Samples/UcsInitSample.cs b/Iyzipay.Samples/UcsInitSample.cs new file mode 100644 index 0000000..b63da57 --- /dev/null +++ b/Iyzipay.Samples/UcsInitSample.cs @@ -0,0 +1,38 @@ +using Iyzipay.Model; +using Iyzipay.Model.V2; +using Iyzipay.Request; +using NUnit.Framework; +using System; + +namespace Iyzipay.Samples +{ + public class UcsInitSample : Sample + { + [Test] + public void Should_Ucs_Initialize() + { + InitUcsRequest request = new InitUcsRequest(); + request.Locale = Locale.TR.ToString(); + request.ConversationId = "123456789"; + request.Email = "email@email.com"; + request.GsmNumber = "+905350000000"; + + UcsInit ucsInitCreate = UcsInit.Create(request, options); + + PrintResponse(ucsInitCreate); + + Assert.AreEqual(Status.SUCCESS.ToString(), ucsInitCreate.Status); + Assert.AreEqual(Locale.TR.ToString(), ucsInitCreate.Locale); + Assert.IsNotNull(ucsInitCreate.SystemTime); + Assert.AreEqual("123456789", ucsInitCreate.ConversationId); + Assert.IsNotNull(ucsInitCreate.UcsToken); + Assert.IsNotNull(ucsInitCreate.BuyerProtectedConsumer); + Assert.IsNotNull(ucsInitCreate.BuyerProtectedMerchant); + Assert.IsNotNull(ucsInitCreate.GsmNumber); + Assert.IsNotNull(ucsInitCreate.MaskedGsmNumber); + Assert.IsNotNull(ucsInitCreate.MerchantName); + Assert.IsNotNull(ucsInitCreate.Script); + Assert.IsNotNull(ucsInitCreate.ScriptType); + } + } +} \ No newline at end of file diff --git a/Iyzipay/Model/PaymentCard.cs b/Iyzipay/Model/PaymentCard.cs index 078a7a2..937ddd1 100644 --- a/Iyzipay/Model/PaymentCard.cs +++ b/Iyzipay/Model/PaymentCard.cs @@ -13,6 +13,9 @@ public class PaymentCard : RequestStringConvertible public String CardAlias { get; set; } public String CardToken { get; set; } public String CardUserKey { get; set; } + public String RegisterConsumerCard { get; set; } + public String ConsumerToken { get; set; } + public String UcsToken { get; set; } public String ToPKIRequestString() { @@ -26,6 +29,9 @@ public String ToPKIRequestString() .Append("cardAlias", CardAlias) .Append("cardToken", CardToken) .Append("cardUserKey", CardUserKey) + .Append("registerConsumerCard", RegisterConsumerCard) + .Append("consumerToken", ConsumerToken) + .Append("ucsToken", UcsToken) .GetRequestString(); } } diff --git a/Iyzipay/Model/UcsInit.cs b/Iyzipay/Model/UcsInit.cs new file mode 100644 index 0000000..8de3c48 --- /dev/null +++ b/Iyzipay/Model/UcsInit.cs @@ -0,0 +1,25 @@ +using Iyzipay.Request; +using System; +using Newtonsoft.Json; + +namespace Iyzipay.Model +{ + public class UcsInit : IyzipayResourceV2 + { + public string UcsToken { get; set; } + public string BuyerProtectedConsumer { get; set; } + public string BuyerProtectedMerchant { get; set; } + public string GsmNumber { get; set; } + public string MaskedGsmNumber { get; set; } + public string MerchantName { get; set; } + public string Script { get; set; } + public string ScriptType { get; set; } + + public static UcsInit Create(InitUcsRequest request, Options options) + { + string uri = options.BaseUrl + "/v2/ucs/init"; + UcsInit response = RestHttpClientV2.Create().Post(uri, GetHttpHeadersWithRequestBody(request, uri, options), request); + return response; + } + } +} diff --git a/Iyzipay/Request/CreatePaymentRequest.cs b/Iyzipay/Request/CreatePaymentRequest.cs index 72f2c61..21ec034 100644 --- a/Iyzipay/Request/CreatePaymentRequest.cs +++ b/Iyzipay/Request/CreatePaymentRequest.cs @@ -23,6 +23,7 @@ public class CreatePaymentRequest : BaseRequest public String ConnectorName { get; set; } public String Currency { get; set; } public LoyaltyReward Reward { get; set; } + public String GsmNumber { get; set; } public override String ToPKIRequestString() { @@ -44,6 +45,7 @@ public override String ToPKIRequestString() .Append("posOrderId", PosOrderId) .Append("connectorName", ConnectorName) .Append("callbackUrl", CallbackUrl) + .Append("gsmNumber", GsmNumber) .GetRequestString(); } } diff --git a/Iyzipay/Request/InitUcsRequest.cs b/Iyzipay/Request/InitUcsRequest.cs new file mode 100644 index 0000000..72881e6 --- /dev/null +++ b/Iyzipay/Request/InitUcsRequest.cs @@ -0,0 +1,12 @@ +using System; +using Newtonsoft.Json; + + +namespace Iyzipay.Request +{ + public class InitUcsRequest : BaseRequestV2 + { + public string Email { get; set; } + public string GsmNumber { get; set; } + } +} \ No newline at end of file