Ana içeriğe geç
Bu sayfa henüz Türkçeye çevrilmedi; İngilizce sürümü gösteriliyor.
Versiyon: 8.0

Usage

There are two ways to use the library: through dependency injection, or the same way as the official iyzipay library.

With dependency injection​

After registering the integration, inject IRestHttpClient and pass it to the resource you need. This example cancels a payment:

using Milvasoft.Iyzipay.Model;
using Milvasoft.Iyzipay.Request;
using Milvasoft.Iyzipay.Utils.Abstract;

private readonly IRestHttpClient _restHttpClient;

public PaymentController(IRestHttpClient restHttpClient)
{
_restHttpClient = restHttpClient;
}

public async Task<IActionResult> CancelPaymentAsync()
{
CreateCancelRequest request = new()
{
ConversationId = "123456789",
Locale = Locale.TR.ToString(),
PaymentId = "1",
Ip = "85.34.78.112"
};

var cancel = new Cancel(_restHttpClient);

cancel = await cancel.CreateAsync(request).ConfigureAwait(false);

_restHttpClient.Dispose();

if (cancel.Status == Status.SUCCESS.ToString())
return Ok();
else
return BadRequest();
}

Like the official library​

You can also create the options and the client yourself. This example creates a payment (shortened; the full request in the repository also sets the buyer, the shipping and billing addresses and several basket items):

IOptions options = new Options
{
ApiKey = "your api key",
SecretKey = "your secret key",
BaseUrl = "https://sandbox-api.iyzipay.com"
};

CreatePaymentRequest request = new();
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.CardHolderName = "John Doe";
paymentCard.CardNumber = "5528790000000008";
paymentCard.ExpireMonth = "12";
paymentCard.ExpireYear = "2030";
paymentCard.Cvc = "123";
paymentCard.RegisterCard = 0;
request.PaymentCard = paymentCard;

Buyer buyer = new();
// ... buyer details
request.Buyer = buyer;

Address shippingAddress = new();
// ... shipping address
request.ShippingAddress = shippingAddress;

Address billingAddress = new();
// ... billing address
request.BillingAddress = billingAddress;

List<BasketItem> basketItems = new();
BasketItem firstBasketItem = new();
firstBasketItem.Id = "BI101";
firstBasketItem.Name = "Binocular";
firstBasketItem.Category1 = "Collectibles";
firstBasketItem.Category2 = "Accessories";
firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString();
firstBasketItem.Price = "0.3";
basketItems.Add(firstBasketItem);
// ... more basket items
request.BasketItems = basketItems;

var client = new RequestHttpClient(new HttpClient(), options);

var payment = new Payment(client);

payment = await payment.CreateAsync(request).ConfigureAwait(false);

client.Dispose();

More samples​

The Milvasoft.Iyzipay.Samples project in the repository has a sample for each area of the API, including payments, 3D Secure, cancel and refund, approve and disapprove, installments, BIN number lookup, card storage, checkout form, Pay with iyzico, BKM, APM, sub-merchants, iyzilink, subscriptions (products, plans, customers) and transaction reports. See Milvasoft.Iyzipay.Samples on GitHub.