Skip to content

Commit de0fb4e

Browse files
berkatilakselarzuman
authored andcommitted
* PayWithIyzico client added (#22)
* PayWithIyzico client added * version update
1 parent 1eb5942 commit de0fb4e

7 files changed

Lines changed: 272 additions & 1 deletion

src/Iyzipay/Armut.Iyzipay.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net45;netstandard2.0;netstandard1.3</TargetFrameworks>
55
<AssemblyName>Armut.Iyzipay</AssemblyName>
66
<RootNamespace>Armut.Iyzipay</RootNamespace>
7-
<Version>2.5.1</Version>
7+
<Version>2.6.0</Version>
88
<Title>Armut Iyzipay Client</Title>
99
<Authors>Armut Teknoloji A.Ş.</Authors>
1010
<Owners>Armut Teknoloji A.Ş.</Owners>

src/Iyzipay/Model/PayWithIyzico.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Threading.Tasks;
2+
using Armut.Iyzipay.Request;
3+
4+
namespace Armut.Iyzipay.Model
5+
{
6+
public class PayWithIyzico : PaymentResource
7+
{
8+
public string Token { get; set; }
9+
10+
public string CallbackUrl { get; set; }
11+
12+
public static PayWithIyzico Retrieve(RetrievePayWithIyzicoRequest request, Options options)
13+
{
14+
return RestHttpClient.Instance.Post<PayWithIyzico>(options.BaseUrl + "/payment/iyzipos/checkoutform/auth/ecom/detail", GetHttpHeaders(request, options), request);
15+
}
16+
17+
public static async Task<PayWithIyzico> RetrieveAsync(RetrievePayWithIyzicoRequest request, Options options)
18+
{
19+
return await RestHttpClient.Instance.PostAsync<PayWithIyzico>(options.BaseUrl + "/payment/iyzipos/checkoutform/auth/ecom/detail", GetHttpHeaders(request, options), request);
20+
}
21+
}
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Threading.Tasks;
2+
using Armut.Iyzipay.Request;
3+
4+
namespace Armut.Iyzipay.Model
5+
{
6+
public class PayWithIyzicoInitialize : PayWithIyzicoInitializeResource
7+
{
8+
public static PayWithIyzicoInitialize Create(CreatePayWithIyzicoInitializeRequest request, Options options)
9+
{
10+
return RestHttpClient.Instance.Post<PayWithIyzicoInitialize>(options.BaseUrl + "/payment/pay-with-iyzico/initialize", GetHttpHeaders(request, options), request);
11+
}
12+
13+
public static async Task<PayWithIyzicoInitialize> CreateAsync(CreatePayWithIyzicoInitializeRequest request, Options options)
14+
{
15+
return await RestHttpClient.Instance.PostAsync<PayWithIyzicoInitialize>(options.BaseUrl + "/payment/pay-with-iyzico/initialize", GetHttpHeaders(request, options), request);
16+
}
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Armut.Iyzipay.Model
2+
{
3+
public class PayWithIyzicoInitializeResource : IyzipayResource
4+
{
5+
public string Token { get; set; }
6+
7+
public string CheckoutFormContent { get; set; }
8+
9+
public long? TokenExpireTime { get; set; }
10+
11+
public string PayWithIyzicoPageUrl { get; set; }
12+
}
13+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Armut.Iyzipay.Model;
5+
6+
namespace Armut.Iyzipay.Request
7+
{
8+
public class CreatePayWithIyzicoInitializeRequest : BaseRequest
9+
{
10+
public string Price { get; set; }
11+
12+
public string PaidPrice { get; set; }
13+
14+
public string BasketId { get; set; }
15+
16+
public string PaymentGroup { get; set; }
17+
18+
public string PaymentSource { get; set; }
19+
20+
public string Currency { get; set; }
21+
22+
public Buyer Buyer { get; set; }
23+
24+
public Address ShippingAddress { get; set; }
25+
26+
public Address BillingAddress { get; set; }
27+
28+
public List<BasketItem> BasketItems { get; set; }
29+
30+
public string CallbackUrl { get; set; }
31+
32+
public int? ForceThreeDS { get; set; }
33+
34+
public string CardUserKey { get; set; }
35+
36+
public string PosOrderId { get; set; }
37+
38+
public List<int> EnabledInstallments { get; set; }
39+
40+
public override string ToPKIRequestString()
41+
{
42+
return ToStringRequestBuilder.NewInstance()
43+
.AppendSuper(base.ToPKIRequestString())
44+
.AppendPrice("price", Price)
45+
.Append("basketId", BasketId)
46+
.Append("paymentGroup", PaymentGroup)
47+
.Append("buyer", Buyer)
48+
.Append("shippingAddress", ShippingAddress)
49+
.Append("billingAddress", BillingAddress)
50+
.AppendList("basketItems", BasketItems)
51+
.Append("callbackUrl", CallbackUrl)
52+
.Append("paymentSource", PaymentSource)
53+
.Append("currency", Currency)
54+
.Append("posOrderId", PosOrderId)
55+
.AppendPrice("paidPrice", PaidPrice)
56+
.Append("forceThreeDS", ForceThreeDS)
57+
.Append("cardUserKey", CardUserKey)
58+
.AppendList("enabledInstallments", EnabledInstallments)
59+
.GetRequestString();
60+
}
61+
}
62+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Armut.Iyzipay.Request
2+
{
3+
public class RetrievePayWithIyzicoRequest : BaseRequest
4+
{
5+
public string Token { set; get; }
6+
7+
public override string ToPKIRequestString()
8+
{
9+
return ToStringRequestBuilder.NewInstance()
10+
.AppendSuper(base.ToPKIRequestString())
11+
.Append("token", Token)
12+
.GetRequestString();
13+
}
14+
}
15+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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

Comments
 (0)