|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Armut.Iyzipay.Model; |
| 4 | +using Armut.Iyzipay.Request; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace Armut.Iyzipay.Samples |
| 8 | +{ |
| 9 | + public class PayWithIyzicoSample : Sample |
| 10 | + { |
| 11 | + [Test] |
| 12 | + public async Task Should_Initialize_PayWithIyzico() |
| 13 | + { |
| 14 | + List<int> enabledInstallments = new List<int>(); |
| 15 | + enabledInstallments.Add(2); |
| 16 | + enabledInstallments.Add(3); |
| 17 | + enabledInstallments.Add(6); |
| 18 | + enabledInstallments.Add(9); |
| 19 | + |
| 20 | + Buyer buyer = new Buyer |
| 21 | + { |
| 22 | + Id = "BY789", |
| 23 | + Name = "John", |
| 24 | + Surname = "Doe", |
| 25 | + GsmNumber = "+905350000000", |
| 26 | + Email = "email@email.com", |
| 27 | + IdentityNumber = "74300864791", |
| 28 | + LastLoginDate = "2015-10-05 12:43:35", |
| 29 | + RegistrationDate = "2013-04-21 15:12:09", |
| 30 | + RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1", |
| 31 | + Ip = "85.34.78.112", |
| 32 | + City = "Istanbul", |
| 33 | + Country = "Turkey", |
| 34 | + ZipCode = "34732" |
| 35 | + }; |
| 36 | + |
| 37 | + Address shippingAddress = new Address |
| 38 | + { |
| 39 | + ContactName = "Jane Doe", |
| 40 | + City = "Istanbul", |
| 41 | + Country = "Turkey", |
| 42 | + Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1", |
| 43 | + ZipCode = "34742" |
| 44 | + }; |
| 45 | + |
| 46 | + Address billingAddress = new Address |
| 47 | + { |
| 48 | + ContactName = "Jane Doe", |
| 49 | + City = "Istanbul", |
| 50 | + Country = "Turkey", |
| 51 | + Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1", |
| 52 | + ZipCode = "34742" |
| 53 | + }; |
| 54 | + |
| 55 | + List<BasketItem> basketItems = new List<BasketItem> |
| 56 | + { |
| 57 | + new BasketItem |
| 58 | + { |
| 59 | + Id = "BI101", |
| 60 | + Name = "Binocular", |
| 61 | + Category1 = "Collectibles", |
| 62 | + Category2 = "Accessories", |
| 63 | + ItemType = BasketItemType.PHYSICAL.ToString(), |
| 64 | + Price = "0.3" |
| 65 | + }, |
| 66 | + new BasketItem |
| 67 | + { |
| 68 | + Id = "BI102", |
| 69 | + Name = "Game code", |
| 70 | + Category1 = "Game", |
| 71 | + Category2 = "Online Game Items", |
| 72 | + ItemType = BasketItemType.VIRTUAL.ToString(), |
| 73 | + Price = "0.5" |
| 74 | + }, |
| 75 | + new BasketItem |
| 76 | + { |
| 77 | + Id = "BI103", |
| 78 | + Name = "Usb", |
| 79 | + Category1 = "Electronics", |
| 80 | + Category2 = "Usb / Cable", |
| 81 | + ItemType = BasketItemType.PHYSICAL.ToString(), |
| 82 | + Price = "0.2" |
| 83 | + } |
| 84 | + }; |
| 85 | + |
| 86 | + CreatePayWithIyzicoInitializeRequest request = new CreatePayWithIyzicoInitializeRequest |
| 87 | + { |
| 88 | + Locale = Locale.TR.ToString(), |
| 89 | + ConversationId = "123456789", |
| 90 | + Price = "1", |
| 91 | + PaidPrice = "1.2", |
| 92 | + Currency = Currency.TRY.ToString(), |
| 93 | + BasketId = "B67832", |
| 94 | + PaymentGroup = PaymentGroup.PRODUCT.ToString(), |
| 95 | + CallbackUrl = "https://www.merchant.com/callback", |
| 96 | + EnabledInstallments = enabledInstallments, |
| 97 | + Buyer = buyer, |
| 98 | + ShippingAddress = shippingAddress, |
| 99 | + BillingAddress = billingAddress, |
| 100 | + BasketItems = basketItems |
| 101 | + }; |
| 102 | + |
| 103 | + PayWithIyzicoInitialize payWithIyzicoInitialize = await PayWithIyzicoInitialize.CreateAsync(request, Options); |
| 104 | + |
| 105 | + PrintResponse<PayWithIyzicoInitialize>(payWithIyzicoInitialize); |
| 106 | + |
| 107 | + Assert.AreEqual(Status.SUCCESS.ToString(), payWithIyzicoInitialize.Status); |
| 108 | + Assert.AreEqual(Locale.TR.ToString(), payWithIyzicoInitialize.Locale); |
| 109 | + Assert.AreEqual("123456789", payWithIyzicoInitialize.ConversationId); |
| 110 | + Assert.IsNotNull(payWithIyzicoInitialize.SystemTime); |
| 111 | + Assert.IsNull(payWithIyzicoInitialize.ErrorCode); |
| 112 | + Assert.IsNull(payWithIyzicoInitialize.ErrorMessage); |
| 113 | + Assert.IsNull(payWithIyzicoInitialize.ErrorGroup); |
| 114 | + Assert.IsNotNull(payWithIyzicoInitialize.CheckoutFormContent); |
| 115 | + Assert.IsNotNull(payWithIyzicoInitialize.PayWithIyzicoPageUrl); |
| 116 | + } |
| 117 | + |
| 118 | + [Test] |
| 119 | + public async Task Should_Retrieve_PayWithIyzico_Result() |
| 120 | + { |
| 121 | + RetrievePayWithIyzicoRequest request = new RetrievePayWithIyzicoRequest |
| 122 | + { |
| 123 | + ConversationId = "123456789", |
| 124 | + Token = "cb3f2681-e397-473a-931c-2567fd235627" |
| 125 | + }; |
| 126 | + |
| 127 | + PayWithIyzico payWithIyzicoResult = await PayWithIyzico.RetrieveAsync(request, Options); |
| 128 | + |
| 129 | + PrintResponse<PayWithIyzico>(payWithIyzicoResult); |
| 130 | + |
| 131 | + Assert.AreEqual(Status.SUCCESS.ToString(), payWithIyzicoResult.Status); |
| 132 | + Assert.AreEqual(Locale.TR.ToString(), payWithIyzicoResult.Locale); |
| 133 | + Assert.AreEqual("123456789", payWithIyzicoResult.ConversationId); |
| 134 | + Assert.IsNotNull(payWithIyzicoResult.SystemTime); |
| 135 | + Assert.IsNull(payWithIyzicoResult.ErrorCode); |
| 136 | + Assert.IsNull(payWithIyzicoResult.ErrorMessage); |
| 137 | + Assert.IsNull(payWithIyzicoResult.ErrorGroup); |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | + |
0 commit comments