Install iyzipay-php via Composer
masterThe recommended way to install the iyzico PHP bindings is using Composer. This will handle dependencies and autoloading for you.
composer require iyzico/iyzipay-phprequire_once('vendor/autoload.php');repository·master·Indexed 43 days ago
https://github.com/iyzico/iyzipay-phpOfficial PHP SDK for integrating iyzico payment services. Provides object-oriented wrappers for iyzico APIs to handle payments, basket items, and customer information. Includes support for CreatePaymentRequest, installment details via InstallmentInfo and InstallmentHtml, and PlusInstallmentPayment.
The recommended way to install the iyzico PHP bindings is using Composer. This will handle dependencies and autoloading for you.
composer require iyzico/iyzipay-phprequire_once('vendor/autoload.php');Ensure you have installed dependencies via Composer. You can run the full PHPUnit test suite or a specific test file.
# Run all tests
./vendor/bin/phpunit
# Run a specific test file
./vendor/bin/phpunit tests/Iyzipay/Tests/Model/PaymentTest.phpIf you prefer not to use Composer, you can download the latest release from GitHub and include the IyzipayBootstrap.php file in your project to initialize the bindings.
require_once('/path/to/iyzipay-php/IyzipayBootstrap.php');To process a payment, you need to configure Iyzipay\Options with your API credentials and base URL, then build a CreatePaymentRequest object containing the transaction details, card information, buyer information, addresses, and basket items. Finally, call \Iyzipay\Model\Payment::create($request, $options) to execute the payment.
$options = new \Iyzipay\Options();
$options->setApiKey("your api key");
$options->setSecretKey("your secret key");
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
$request = new \Iyzipay\Request\CreatePaymentRequest();
$request->setLocale(\Iyzipay\Model\Locale::TR);
$request->setConversationId("123456789");
$request->setPrice("1");
$request->setPaidPrice("1.2");
$request->setCurrency(\Iyzipay\Model\Currency::TL);
$request->setInstallment(1);
$request->setBasketId("B67832");
$request->setPaymentChannel(\Iyzipay\Model\PaymentChannel::WEB);
$request->setPaymentGroup(\Iyzipay\Model\PaymentGroup::PRODUCT);
$paymentCard = new \Iyzipay\Model\PaymentCard();
$paymentCard->setCardHolderName("John Doe");
$paymentCard->setCardNumber("5528790000000008");
$paymentCard->setExpireMonth("12");
$paymentCard->setExpireYear("2030");
$paymentCard->setCvc("123");
$paymentCard->setRegisterCard(0);
$request->setPaymentCard($paymentCard);
$buyer = new \Iyzipay\Model\Buyer();
$buyer->setId("BY789");
$buyer->setName("John");
$buyer->setSurname("Doe");
$buyer->setGsmNumber("+905350000000");
$buyer->setEmail("email@email.com");
$buyer->setIdentityNumber("74300864791");
$buyer->setLastLoginDate("2015-10-05 12:43:35");
$buyer->setRegistrationDate("2013-04-21 15:12:09");
$buyer->setRegistrationAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$buyer->setIp("85.34.78.112");
$buyer->setCity("Istanbul");
$buyer->setCountry("Turkey");
$buyer->setZipCode("34732");
$request->setBuyer($buyer);
$shippingAddress = new \Iyzipay\Model\Address();
$shippingAddress->setContactName("Jane Doe");
$shippingAddress->setCity("Istanbul");
$shippingAddress->setCountry("Turkey");
$shippingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$shippingAddress->setZipCode("34742");
$request->setShippingAddress($shippingAddress);
$billingAddress = new \Iyzipay\Model\Address();
$billingAddress->setContactName("Jane Doe");
$billingAddress->setCity("Istanbul");
$billingAddress->setCountry("Turkey");
$billingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$billingAddress->setZipCode("34742");
$request->setBillingAddress($billingAddress);
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId("BI101");
$firstBasketItem->setName("Binocular");
$firstBasketItem->setCategory1("Collectibles");
$firstBasketItem->setCategory2("Accessories");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::PHYSICAL);
$firstBasketItem->setPrice("0.3");
$basketItems[0] = $firstBasketItem;
$secondBasketItem = new \Iyzipay\Model\BasketItem();
$secondBasketItem->setId("BI102");
$secondBasketItem->setName("Game code");
$secondBasketItem->setCategory1("Game");
$secondBasketItem->setCategory2("Online Game Items");
$secondBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$secondBasketItem->setPrice("0.5");
$basketItems[1] = $secondBasketItem;
$thirdBasketItem = new \Iyzipay\Model\BasketItem();
$thirdBasketItem->setId("BI103");
$thirdBasketItem->setName("Usb");
$thirdBasketItem->setCategory1("Electronics");
$thirdBasketItem->setCategory2("Usb / Cable");
$thirdBasketItem->setItemType(\Iyzipay\Model\BasketItemType::PHYSICAL);
$thirdBasketItem->setPrice("0.2");
$basketItems[2] = $thirdBasketItem;
$request->setBasketItems($basketItems);
$payment = \Iyzipay\Model\Payment::create($request, $options);To simulate Alternative Payment Methods (APM), use these mock account holder names:
| Account Holder Name | Description |
|------------------------|----------------------------------------------------|
| success | Succeeded payment after succeeded initialize |
| fail-after-init | Failed payment after succeeded initialize |
| error | Failed initialize |To simulate non-Turkish card transactions, use these card numbers:
| Card Number | Country |
|-----------------|-------------------|
| 4054180000000007 | Non-Turkish (Debit) |
| 5400010000000004 | Non-Turkish (Credit) |Use these card numbers to test how your application handles specific error scenarios:
| Card Number | Description |
|-----------------|------------------------------------------------------------|
| 5406670000000009 | Success but cannot be cancelled, refund or post auth |
| 4111111111111129 | Not sufficient funds |
| 4129111111111111 | Do not honour |
| 4128111111111112 | Invalid transaction |
| 4127111111111113 | Lost card |
| 4126111111111114 | Stolen card |
| 4125111111111115 | Expired card |
| 4124111111111116 | Invalid cvc2 |
| 4123111111111117 | Not permitted to card holder |
| 4122111111111118 | Not permitted to terminal |
| 4121111111111119 | Fraud suspect |
| 4120111111111110 | Pickup card |
| 4130111111111118 | General error |
| 4131111111111117 | Success but mdStatus is 0 |
| 4141111111111115 | Success but mdStatus is 4 |
| 4151111111111112 | 3dsecure initialize failed |Use the following card numbers to simulate successful transactions in the sandbox environment. They are categorized by bank and card type (e.g., Visa, Mastercard, Troy).
| Card Number | Bank | Card Type |
|-----------------|---------------------------|--------------------------|
| 5890040000000016 | Akbank | Master Card (Debit) |
| 5526080000000006 | Akbank | Master Card (Credit) |
| 4766620000000001 | Denizbank | Visa (Debit) |
| 4603450000000000 | Denizbank | Visa (Credit) |
| 4729150000000005 | Denizbank Bonus | Visa (Credit) |
| 4987490000000002 | Finansbank | Visa (Debit) |
| 5311570000000005 | Finansbank | Master Card (Credit) |
| 9792020000000001 | Finansbank | Troy (Debit) |
| 9792030000000000 | Finansbank | Troy (Credit) |
| 5170410000000004 | Garanti Bankası | Master Card (Debit) |
| 5400360000000003 | Garanti Bankası | Master Card (Credit) |
| 374427000000003 | Garanti Bankası | American Express |
| 4475050000000003 | Halkbank | Visa (Debit) |
| 5528790000000008 | Halkbank | Master Card (Credit) |
| 4059030000000009 | HSBC Bank | Visa (Debit) |
| 5504720000000003 | HSBC Bank | Master Card (Credit) |
| 5892830000000000 | Türkiye İş Bankası | Master Card (Debit) |
| 4543590000000006 | Türkiye İş Bankası | Visa (Credit) |
| 4910050000000006 | Vakıfbank | Visa (Debit) |
| 4157920000000002 | Vakıfbank | Visa (Credit) |
| 5168880000000002 | Yapı ve Kredi Bankası | Master Card (Debit) |
| 5451030000000000 | Yapı ve Kredi Bankası | Master Card (Credit) |Use the InstallmentHtml::retrieve() method to fetch the HTML content required for displaying installment options (e.g., for horizontal layouts) in your payment interface. This method requires a RetrieveInstallmentInfoRequest object containing the necessary payment details and an Options object for API configuration. It returns an instance of InstallmentHtml containing the HTML string.
use Iyzipay\
Model\\InstallmentHtml;
use Iyzipay\\Request\\RetrieveInstallmentInfoRequest;
use Iyzipay\\Options;
// Assuming $request and $options are already configured
$installmentHtml = InstallmentHtml::retrieve($request, $options);
$html = $installmentHtml->getHtmlContent();Use the InstallmentInfo::retrieve() method to fetch available installment information for a payment via iyzicoPOS. This method requires a RetrieveInstallmentInfoRequest object containing the necessary payment details and an Options object for API configuration. It returns an instance of InstallmentInfo populated with the response data.
use Iyzipay\Model\InstallmentInfo;
use Iyzipay\Request\RetrieveInstallmentInfoRequest;
use Iyzipay\Options;
$request = new RetrieveInstallmentInfoRequest();
// ... configure $request with required payment details ...
$options = new Options();
// ... configure $options with API keys and base URL ...
$installmentInfo = InstallmentInfo::retrieve($request, $options);Use the PlusInstallmentPayment::create() method to initiate a plus installment payment. This method requires a CreatePlusInstallmentPaymentRequest object containing the payment details and an Options object for configuration (such as the base URL and API credentials). The method returns a PlusInstallmentPayment object representing the result of the operation.
use Iyzipay\'Model\'\PlusInstallmentPayment;
use Iyzipay\\'Request\'\CreatePlusInstallmentPaymentRequest;
use Iyzipay\\'Options\'\Options;
// Assuming $request and $options are already instantiated
$payment = PlusInstallmentPayment::create($request, $options);The BasicPaymentResource class contains the following properties and corresponding getter/setter methods:
price: The original price.paidPrice: The actual amount paid.currency: The currency of the transaction.installment: The number of installments.paymentId: The unique identifier for the payment.paymentTransactionId: The transaction ID associated with the payment.authCode: The authorization code.merchantCommissionRate: The commission rate for the merchant.merchantCommissionRateAmount: The commission amount for the merchant.iyziCommissionFee: The commission fee charged by iyzico.cardType: The type of card used.cardAssociation: The card association (e.g., Visa, Mastercard).cardFamily: The card family.cardToken: The token associated with the card.cardUserKey: The user key for the card.binNumber: The Bank Identification Number (BIN).connectorName: The name of the connector used.phase: The current phase of the payment process.