### Example Installment Calculation Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md An example demonstrating the calculation of installment details for a given price and term. ```plaintext Original Price: 100.00 TL 6-Month Total: 106.00 TL Per-Installment: 106.00 / 6 = 17.67 TL Interest: 6.00 TL Interest %: 6% ``` -------------------------------- ### Install iyzipay-php via Composer Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md Use Composer to install the iyzipay-php SDK. This is the recommended method for managing dependencies. ```bash composer require iyzico/iyzipay-php ``` -------------------------------- ### Install Dependencies for Development Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md Install project dependencies using Composer for development purposes. ```bash composer install ``` -------------------------------- ### Create Payment with Multiple Installments (With Interest) Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Example of how to create a payment with multiple installments, including interest calculation. ```APIDOC ## Create Payment with Multiple Installments (With Interest) ### Description Creates a payment with multiple installments, calculating the total price including interest based on the selected installment plan. ### Method ```php // Retrieve installment information $installmentInfo = InstallmentInfo::retrieve($request, $options); // User selects installment plan (e.g., 6-month plan) $selectedPlan = $installmentInfo->getInstallmentDetails()[0]->getInstallmentPrices()[3]; // Create payment with selected installment $paymentRequest = new CreatePaymentRequest(); $paymentRequest->setPrice("100.00"); $paymentRequest->setPaidPrice($selectedPlan->getTotalPrice()); // Price with interest $paymentRequest->setInstallment($selectedPlan->getInstallmentNumber()); // 6 ``` ``` -------------------------------- ### Initialize Iyzipay Options Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/configuration.md Example of initializing the Options class and setting authentication credentials and the base URL for the Iyzipay API client. ```php use Iyzipay\Options; $options = new Options(); $options->setApiKey("your_api_key"); $options->setSecretKey("your_secret_key"); $options->setBaseUrl("https://sandbox-api.iyzipay.com"); ``` -------------------------------- ### Install iyzico PHP SDK via Composer Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md Use Composer to install the iyzico PHP SDK. This is the recommended method for managing dependencies. ```bash composer require iyzico/iyzipay-php ``` -------------------------------- ### Create Subscription Example Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/subscription.md Demonstrates how to create a new subscription for a customer. Ensure you have set up the SubscriptionCreateRequest with necessary details and provided valid Options. ```php use Iyzipay\Model\Subscription\SubscriptionCreate; use Iyzipay\Request\Subscription\SubscriptionCreateRequest; $request = new SubscriptionCreateRequest(); $request->setCustomerEmail("customer@example.com"); $request->setProductReferenceCode("product_123"); $request->setPlanCode("plan_monthly"); $request->setCardUserKey("stored_card_key"); $request->setStartDate("2024-06-01"); $subscription = SubscriptionCreate::create($request, $options); if ($subscription->getStatus() == "success") { echo "Subscription created: " . $subscription->getSubscriptionReferenceCode(); } else { echo "Error: " . $subscription->getErrorMessage(); } ``` -------------------------------- ### Manual Installation of iyzipay-php Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md Alternatively, you can manually include the SDK by requiring the bootstrap file. Ensure the path is correct. ```php require_once('/path/to/iyzipay-php/IyzipayBootstrap.php'); ``` -------------------------------- ### Manual Installation of iyzico PHP SDK Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md If not using Composer, download the latest release and include the IyzipayBootstrap.php file to use the bindings. ```php require_once('/path/to/iyzipay-php/IyzipayBootstrap.php'); ``` -------------------------------- ### Instantiate and Populate Buyer Object Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/data-models.md This example shows how to create a new Buyer object and set its various properties using the provided setter methods. This is useful for preparing buyer data before a transaction. ```php $buyer = new Buyer(); $buyer->setId("buyer_123"); $buyer->setName("John"); $buyer->setSurname("Doe"); $buyer->setEmail("john@example.com"); $buyer->setGsmNumber("+905350000000"); $buyer->setIdentityNumber("12345678901"); $buyer->setCity("Istanbul"); $buyer->setCountry("Turkey"); $buyer->setZipCode("34000"); $buyer->setIp("192.168.1.1"); $buyer->setRegistrationDate("2023-01-15 10:30:00"); $buyer->setLastLoginDate("2024-01-15 14:20:00"); ``` -------------------------------- ### Create Payment with Single Installment (No Interest) Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Example of how to create a payment for a single installment (no interest). ```APIDOC ## Create Payment with Single Installment (No Interest) ### Description Creates a payment for a single installment without any additional interest. ### Method ```php $request = new CreatePaymentRequest(); $request->setInstallment(1); $request->setPrice("100.00"); $request->setPaidPrice("100.00"); // No interest added ``` ``` -------------------------------- ### Create a Basic Payment Transaction Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md This example demonstrates how to create a payment request with all necessary details, including card, buyer, address, and basket items, and then process the payment. ```php use Iyzipay\Request\CreatePaymentRequest; use Iyzipay\Model\Payment; use Iyzipay\Model\PaymentCard; use Iyzipay\Model\Buyer; use Iyzipay\Model\Address; use Iyzipay\Model\BasketItem; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; use Iyzipay\Model\PaymentChannel; use Iyzipay\Model\PaymentGroup; use Iyzipay\Model\BasketItemType; // Create payment request $request = new CreatePaymentRequest(); $request->setLocale(Locale::EN); $request->setConversationId("unique_conversation_id"); $request->setPrice("100.00"); $request->setPaidPrice("100.00"); $request->setCurrency(Currency::TL); $request->setInstallment(1); $request->setBasketId("basket_123"); $request->setPaymentChannel(PaymentChannel::WEB); $request->setPaymentGroup(PaymentGroup::PRODUCT); // Add payment card $card = new PaymentCard(); $card->setCardHolderName("John Doe"); $card->setCardNumber("5528790000000008"); $card->setExpireMonth("12"); $card->setExpireYear("2030"); $card->setCvc("123"); $card->setRegisterCard(0); $request->setPaymentCard($card); // Add buyer information $buyer = new Buyer(); $buyer->setId("buyer_123"); $buyer->setName("John"); $buyer->setSurname("Doe"); $buyer->setEmail("john@example.com"); $buyer->setGsmNumber("+905350000000"); $buyer->setIdentityNumber("12345678901"); $buyer->setIp("192.168.1.1"); $buyer->setCity("Istanbul"); $buyer->setCountry("Turkey"); $buyer->setZipCode("34000"); $request->setBuyer($buyer); // Add address $address = new Address(); $address->setContactName("Jane Doe"); $address->setCity("Istanbul"); $address->setCountry("Turkey"); $address->setAddress("Street Address 1"); $address->setZipCode("34000"); $request->setShippingAddress($address); $request->setBillingAddress($address); // Add basket items $basketItems = array(); $item = new BasketItem(); $item->setId("item_1"); $item->setName("Product"); $item->setPrice("100.00"); $item->setCategory1("Electronics"); $item->setItemType(BasketItemType::PHYSICAL); $basketItems[] = $item; $request->setBasketItems($basketItems); // Process payment $payment = Payment::create($request, $options); // Handle response if ($payment->getStatus() == "success") { echo "Payment successful! Payment ID: " . $payment->getPaymentId(); } else { echo "Payment failed. Error: " . $payment->getErrorMessage(); } ``` -------------------------------- ### Include Autoloader after Composer Installation Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md After installing the SDK with Composer, include the autoloader to use the bindings. ```php require_once('vendor/autoload.php'); ``` -------------------------------- ### Set Currency to TRY Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Set the currency for installment calculations to Turkish Lira (TRY). ```php $request->setCurrency(Currency::TL); ``` -------------------------------- ### Create Payment Request with iyzico PHP SDK Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md This example demonstrates how to create a payment request using the iyzico PHP SDK. It includes setting up options, defining the payment request details, and adding buyer, shipping, billing, and basket item information. ```php $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); ``` -------------------------------- ### Retrieve Installment Info Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Retrieve available installment plans and pricing for a given amount. This method requires a RetrieveInstallmentInfoRequest object containing details like price, BIN number, currency, and locale, along with an Options object for configuration. ```APIDOC ## Retrieve Installment Info ### Description Retrieve available installment plans and pricing for a given amount. ### Method POST ### Endpoint /v1/installment/plans ### Parameters #### Request Body - **binNumber** (string) - Required - The first 6 digits of the card number. - **price** (string) - Required - The price for which to retrieve installment plans. - **currency** (enum) - Required - The currency of the price (e.g., TL, EUR, USD). - **locale** (enum) - Optional - The locale for the response (e.g., EN, TR). - **conversationId** (string) - Optional - A unique identifier for the conversation. ### Request Example ```json { "binNumber": "552879", "price": "1000.00", "currency": "TL", "locale": "EN", "conversationId": "installment_123" } ``` ### Response #### Success Response (200) - **status** (string) - The status of the operation ('success' or 'failure'). - **installmentDetails** (array) - An array of bank-specific installment details. - **bankName** (string) - The name of the bank. - **cardFamily** (string) - The card family (e.g., Visa, Mastercard). - **installmentPrices** (array) - An array of available installment plans. - **installments** (integer) - The number of installments. - **totalPrice** (string) - The total price for the installment plan. - **price** (string) - The price per installment. - **errorMessage** (string) - If the status is 'failure', this field contains the error message. #### Response Example ```json { "status": "success", "installmentDetails": [ { "bankName": "Example Bank", "cardFamily": "Visa", "installmentPrices": [ { "installments": 2, "totalPrice": "1020.00", "price": "510.00" }, { "installments": 3, "totalPrice": "1050.00", "price": "350.00" } ] } ] } ``` ``` -------------------------------- ### Run All PHPUnit Tests Source: https://github.com/iyzico/iyzipay-php/blob/master/README.md Execute the entire test suite for the Iyzipay PHP library using the PHPUnit command-line tool. Ensure all dependencies are installed before running. ```bash ./vendor/bin/phpunit ``` -------------------------------- ### Initialize 3D Secure Flow Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/three-ds-payment.md Use this method to start the 3D Secure payment process. It requires a `CreateThreedsInitializeRequest` object and `Options` to return the necessary data for customer verification. ```php public static function create(CreateThreedsInitializeRequest $request, Options $options): ThreedsInitialize ``` -------------------------------- ### Retrieve Installment Info Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Use this method to fetch available installment plans and pricing for a specific amount. Ensure you have the necessary request object with details like price, BIN number, locale, and currency, along with valid options. ```php use Iyzipay\Model\InstallmentInfo; use Iyzipay\Request\RetrieveInstallmentInfoRequest; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; $request = new RetrieveInstallmentInfoRequest(); $request->setLocale(Locale::EN); $request->setConversationId("installment_123"); $request->setPrice("1000.00"); $request->setBinNumber("552879"); // First 6 digits of card $request->setCurrency(Currency::TL); $installmentInfo = InstallmentInfo::retrieve($request, $options); if ($installmentInfo->getStatus() == "success") { $installmentDetails = $installmentInfo->getInstallmentDetails(); foreach ($installmentDetails as $bank) { echo "Bank: " . $bank->getBankName(); echo "Card Family: " . $bank->getCardFamily(); foreach ($bank->getInstallmentPrices() as $plan) { echo " " . $plan->getInstallmentNumber() . " months: " . $plan->getTotalPrice() . " TL (" . $plan->getPrice() . " each)"; } } } else { echo "Error: " . $installmentInfo->getErrorMessage(); } ``` -------------------------------- ### BKM Initialize create() Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/bkm.md Initializes a BKM Express payment flow by creating a payment form and token. This method is used to start the BKM payment process. ```APIDOC ## BKM Initialize create() ### Description Initializes a BKM Express payment flow. This method generates the necessary form and token for customers to complete their payment via BKM. ### Method `static create(CreateBkmInitializeRequest $request, Options $options): BkmInitialize` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **request** (CreateBkmInitializeRequest) - Required - BKM initialization request object containing payment details. * **options** (Options) - Required - Configuration options for the API call. ### Request Example ```php use Iyzipay\Model\BkmInitialize; use Iyzipay\Request\CreateBkmInitializeRequest; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; use Iyzipay\Model\PaymentGroup; use Iyzipay\Model\Buyer; use Iyzipay\Model\Address; use Iyzipay\Model\BasketItem; use Iyzipay\Model\BasketItemType; $request = new CreateBkmInitializeRequest(); $request->setLocale(Locale::TR); $request->setConversationId("bkm_123"); $request->setPrice("100.00"); $request->setPaidPrice("100.00"); $request->setCurrency(Currency::TL); $request->setBasketId("basket_123"); $request->setPaymentGroup(PaymentGroup::PRODUCT); $request->setCallbackUrl("https://your-merchant.com/bkm/callback"); $buyer = new Buyer(); $buyer->setId("buyer_123"); $buyer->setName("John"); $buyer->setSurname("Doe"); $buyer->setEmail("john@example.com"); $buyer->setIp("192.168.1.1"); $request->setBuyer($buyer); $address = new Address(); $address->setContactName("Jane Doe"); $address->setCity("Istanbul"); $address->setCountry("Turkey"); $address->setAddress("Street Address"); $address->setZipCode("34000"); $request->setShippingAddress($address); $request->setBillingAddress($address); $basketItems = array(); $item = new BasketItem(); $item->setId("item_1"); $item->setName("Product"); $item->setPrice("100.00"); $item->setCategory1("Electronics"); $item->setItemType(BasketItemType::PHYSICAL); $basketItems[] = $item; $request->setBasketItems($basketItems); $init = BkmInitialize::create($request, $options); if ($init->getStatus() == "success") { // Display form to customer echo $init->getHtmlContent(); } else { echo "Error: " . $init->getErrorMessage(); } ``` ### Response #### Success Response (200) * **htmlContent** (string) - The HTML content of the BKM payment form to be displayed to the customer. * **status** (string) - Indicates the status of the operation, e.g., "success". #### Response Example ```json { "status": "success", "htmlContent": "
...
" } ``` #### Error Response * **status** (string) - Indicates the status of the operation, e.g., "failure". * **errorMessage** (string) - A message describing the error that occurred. #### Error Response Example ```json { "status": "failure", "errorMessage": "Invalid payment details" } ``` ``` -------------------------------- ### Initialize APM Payment Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/apm.md Use this method to start an alternative payment flow. It requires a CreateApmInitializeRequest object containing payment details and configuration options. The response includes a redirect URL for payment completion. ```php use Iyzipay\Model\Apm; use Iyzipay\Request\CreateApmInitializeRequest; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; use Iyzipay\Model\PaymentGroup; use Iyzipay\Model\Buyer; use Iyzipay\Model\Address; use Iyzipay\Model\BasketItem; use Iyzipay\Model\BasketItemType; $request = new CreateApmInitializeRequest(); $request->setLocale(Locale::EN); $request->setConversationId("apm_123"); $request->setPrice("100.00"); $request->setPaidPrice("100.00"); $request->setCurrency(Currency::TL); $request->setBasketId("basket_123"); $request->setPaymentGroup(PaymentGroup::PRODUCT); $request->setApmType("PAYPAL"); // Alternative payment method type $request->setCallbackUrl("https://your-merchant.com/apm/callback"); $buyer = new Buyer(); $buyer->setId("buyer_123"); $buyer->setName("John"); $buyer->setSurname("Doe"); $buyer->setEmail("john@example.com"); $buyer->setIp("192.168.1.1"); $request->setBuyer($buyer); $address = new Address(); $address->setContactName("Jane Doe"); $address->setCity("Istanbul"); $address->setCountry("Turkey"); $address->setAddress("Street Address"); $address->setZipCode("34000"); $request->setShippingAddress($address); $request->setBillingAddress($address); $basketItems = array(); $item = new BasketItem(); $item->setId("item_1"); $item->setName("Product"); $item->setPrice("100.00"); $item->setCategory1("Electronics"); $item->setItemType(BasketItemType::PHYSICAL); $basketItems[] = $item; $request->setBasketItems($basketItems); $apm = Apm::initialize($request, $options); if ($apm->getStatus() == "success") { $redirectUrl = $apm->getRedirectUrl(); header("Location: " . $redirectUrl); } else { echo "Error: " . $apm->getErrorMessage(); } ``` -------------------------------- ### Basic BKM Initialization Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/bkm.md Initializes a basic BKM payment. This method is used to start the BKM payment process with the provided request details and configuration options. ```APIDOC ## Basic BKM Initialization ### Description Initializes a basic BKM payment. This method is used to start the BKM payment process with the provided request details and configuration options. ### Method `static create(CreateBasicBkmInitializeRequest $request, Options $options): BasicBkm` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (parameters are passed directly to the method) ### Request Example ```php // Assuming $request and $options are already defined $basicBkm = Iyzipay\Model\BasicBkm::create($request, $options); ``` ### Response #### Success Response `BasicBkm` object containing form HTML and token. #### Response Example ```json { "formHtml": "
...
", "token": "payment_token" } ``` ``` -------------------------------- ### Create 3D Secure Payment - PHP Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/three-ds-payment.md This snippet demonstrates the complete process of a 3D Secure payment. It includes initializing the payment to get the 3DS form, displaying it to the customer, and then completing the payment after successful verification. Ensure all necessary request objects and options are correctly configured. ```php use Iyzipay\Options; use Iyzipay\Request\CreateThreedsInitializeRequest; use Iyzipay\Request\CreateThreedsPaymentRequest; use Iyzipay\Model\ThreedsInitialize; use Iyzipay\Model\ThreedsPayment; use Iyzipay\Model\PaymentCard; use Iyzipay\Model\Buyer; use Iyzipay\Model\Address; use Iyzipay\Model\BasketItem; use Iyzipay\Model\BasketItemType; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; use Iyzipay\Model\PaymentChannel; use Iyzipay\Model\PaymentGroup; $options = new Options(); $options->setApiKey("api_key"); $options->setSecretKey("secret_key"); $options->setBaseUrl("https://sandbox-api.iyzipay.com"); // Step 1: Initialize 3DS payment to get form HTML $initRequest = new CreateThreedsInitializeRequest(); $initRequest->setLocale(Locale::EN); $initRequest->setConversationId("3ds_init_123"); $initRequest->setPrice("100.00"); $initRequest->setPaidPrice("100.00"); $initRequest->setCurrency(Currency::TL); $initRequest->setInstallment(1); $initRequest->setBasketId("basket_123"); $initRequest->setPaymentChannel(PaymentChannel::WEB); $initRequest->setPaymentGroup(PaymentGroup::PRODUCT); $initRequest->setCallbackUrl("https://your-merchant.com/threeds/callback"); $card = new PaymentCard(); $card->setCardHolderName("John Doe"); $card->setCardNumber("5528790000000008"); $card->setExpireMonth("12"); $card->setExpireYear("2030"); $card->setCvc("123"); $initRequest->setPaymentCard($card); $buyer = new Buyer(); $buyer->setId("buyer_123"); $buyer->setName("John"); $buyer->setSurname("Doe"); $buyer->setEmail("john@example.com"); $buyer->setGsmNumber("+905350000000"); $buyer->setIp("192.168.1.1"); $buyer->setCity("Istanbul"); $buyer->setCountry("Turkey"); $initRequest->setBuyer($buyer); $address = new Address(); $address->setContactName("Jane Doe"); $address->setCity("Istanbul"); $address->setCountry("Turkey"); $address->setAddress("Street Address"); $address->setZipCode("34000"); $initRequest->setShippingAddress($address); $initRequest->setBillingAddress($address); $basketItems = array(); $item = new BasketItem(); $item->setId("item_1"); $item->setName("Product"); $item->setPrice("100.00"); $item->setCategory1("Electronics"); $item->setItemType(BasketItemType::PHYSICAL); $basketItems[] = $item; $initRequest->setBasketItems($basketItems); $init = ThreedsInitialize::create($initRequest, $options); // Step 2: Display 3DS form to customer echo $init->getHtmlContent(); // Customer completes 3DS verification here // Step 3: Complete payment after 3DS verification $paymentRequest = new CreateThreedsPaymentRequest(); $paymentRequest->setLocale(Locale::EN); $paymentRequest->setConversationId("3ds_payment_123"); $paymentRequest->setPaymentId($init->getPaymentId()); $paymentRequest->setToken($init->getToken()); $payment = ThreedsPayment::create($paymentRequest, $options); if ($payment->getStatus() == "success") { echo "3D Secure payment successful"; echo "Payment ID: " . $payment->getPaymentId(); } else { echo "Payment failed: " . $payment->getErrorMessage(); } ``` -------------------------------- ### Get BKM Installments Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/bkm.md Retrieves available installment information for BKM payments. This helps in offering installment options to customers. ```APIDOC ## POST /installment/bkm ### Description Retrieves available installment information for BKM payments. This helps in offering installment options to customers. ### Method POST ### Endpoint /installment/bkm ### Parameters #### Request Body - **conversationId** (string) - Required - Unique identifier for the conversation. - **binNumber** (string) - Required - The BIN number of the card. - **price** (string) - Required - The payment amount. - **locale** (string) - Required - Language of the response. ### Request Example { "conversationId": "12345", "binNumber": "454185", "price": "100.00", "locale": "en" } ### Response #### Success Response (200) - **status** (string) - Payment status. - **locale** (string) - Language of the response. - **systemTime** (number) - System time. - **conversationId** (string) - Unique identifier for the conversation. - **installmentDetails** (array) - List of installment options. - **installmentNumber** (integer) - The number of installments. - **totalPrice** (string) - The total price for the installment plan. - **marketingTitle** (string) - The marketing title for the installment plan. - **rizione** (string) - Description of the installment plan. #### Response Example { "status": "success", "locale": "en", "systemTime": 1678886400000, "conversationId": "12345", "installmentDetails": [ { "installmentNumber": 2, "totalPrice": "102.00", "marketingTitle": "2x 51.00 TL", "rizione": "2 installments" }, { "installmentNumber": 3, "totalPrice": "103.00", "marketingTitle": "3x 34.33 TL", "rizione": "3 installments" } ] } ``` -------------------------------- ### Get Installment Plans Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/endpoints.md Retrieves available installment options for a given card and price. This endpoint helps in displaying various installment plans offered by different banks. ```APIDOC ## POST /installment/installmentinfo ### Description Retrieves available installment options for a card. ### Method POST ### Endpoint /installment/installmentinfo ### Parameters #### Request Body - **price** (string) - Required - Transaction amount - **binNumber** (string) - Required - First 6 digits of card - **currency** (string) - Required - Transaction currency ### Response #### Success Response (200) - **status** (string) - Status of the request. - **installmentDetails** (array) - Per-bank options. - **bankName** (string) - Name of the bank. - **cardFamily** (string) - Card family. - **installmentPrices** (array) - **installmentNumber** (int) - Number of installments. - **totalPrice** (string) - Total price for the installment. - **price** (string) - Price per installment. ``` -------------------------------- ### Initialize iyzipay SDK Configuration Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md Configure the SDK with your API credentials and base URL. Use the sandbox URL for testing and the production URL for live transactions. ```php use Iyzipay\Options; $options = new Options(); $options->setApiKey("your_api_key"); $options->setSecretKey("your_secret_key"); $options->setBaseUrl("https://sandbox-api.iyzipay.com"); // Use production URL for live ``` -------------------------------- ### Retrieve Installment Information Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Call this method to fetch available installment plans for a given request. This is a prerequisite for offering installment options to users. ```php $installmentInfo = InstallmentInfo::retrieve($request, $options); ``` -------------------------------- ### Installment API Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/MANIFEST.md Methods for retrieving installment information. ```APIDOC ## InstallmentInfo::retrieve() ### Description Retrieves available installment information for a given price and card BIN. ### Method POST ### Endpoint /installment/info ### Parameters #### Request Body - **request** (InstallmentInfoRequest) - Required - The request object containing the price, currency, and card BIN. ### Response #### Success Response (200) - **status** (string) - The status of the retrieval. - **installmentPrices** (array) - An array of available installment options. ### Request Example ```json { "request": { "price": "100.00", "currency": "TRY", "binNumber": "554960" } } ``` ### Response Example ```json { "status": "success", "installmentPrices": [ { "installmentNumber": 2, "price": "50.00", "paidPrice": "100.00", "regularPrice": "50.00" }, { "installmentNumber": 3, "price": "33.33", "paidPrice": "99.99", "regularPrice": "33.33" } ] } ``` ``` -------------------------------- ### Installment Plans Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/INDEX.txt Reference for retrieving installment plan information. ```APIDOC ## Installment Plans ### Description This section details the API endpoints for retrieving installment plan information. ### Endpoints - `GET /installment/plans` - Retrieve available installment plans. ``` -------------------------------- ### BKM Installment Properties Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/bkm.md These methods are used to access and set the bank name and installment prices for BKM payments. Retrieve available installment options for BKM transactions. ```php public function getBankName(): string public function setBankName(string $bankName): void public function getInstallmentPrices(): array public function setInstallmentPrices(array $prices): void ``` -------------------------------- ### Check Installment Eligibility Based on Card Family Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/bin-lookup.md Determine if a card supports installments by checking its family type. This is important as prepaid cards often do not support installments. ```php getCardFamily() == "PREPAID") { // Prepaid cards often don't support installments disableInstallmentOption(); } ?> ``` -------------------------------- ### Implement Payment Creation with Error Handling Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md This snippet demonstrates how to create a payment using the SDK and includes comprehensive error handling for both successful and failed payment scenarios, as well as network exceptions. Always wrap payment creation calls in a try-catch block. ```php try { $payment = Payment::create($request, $options); if ($payment->getStatus() == "success") { // Process successful payment } elseif ($payment->getErrorCode() == 1) { // Handle specific error } else { // Handle generic error error_log("Payment error: " . $payment->getErrorMessage()); } } catch (Exception $e) { // Handle connection/network errors error_log("Exception: " . $e->getMessage()); } ``` -------------------------------- ### Calculate Per-Installment Amount Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Determine the amount to be paid per installment by dividing the total price by the number of installments. ```plaintext Per-Installment = Total Price / Installment Number ``` -------------------------------- ### SubscriptionProduct::create() Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/subscription.md Creates a new subscription product with specified details and pricing plans. ```APIDOC ## SubscriptionProduct::create() ### Description Create a new subscription product. ### Method `static` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **request** (SubscriptionCreateProductRequest) - Required - Product creation request - **options** (Options) - Required - Configuration options ### Request Example ```php use Iyzipay\Model\Subscription\SubscriptionProduct; use Iyzipay\Request\Subscription\SubscriptionCreateProductRequest; $request = new SubscriptionCreateProductRequest(); $request->setReferenceCode("product_123"); $request->setName("Monthly Subscription"); $request->setDescription("Premium access subscription"); $product = SubscriptionProduct::create($request, $options); if ($product->getStatus() == "success") { echo "Product created: " . $product->getReferenceCode(); } else { echo "Error: " . $product->getErrorMessage(); } ``` ### Response #### Success Response (200) - **SubscriptionProduct** - SubscriptionProduct with product details and pricing plans. #### Response Example (Response structure depends on the SubscriptionProduct model) ``` -------------------------------- ### Create Payment Request for Multiple Installments (With Interest) Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md This snippet demonstrates how to create a payment request for a multi-month installment plan, including the calculated interest. Ensure 'paidPrice' reflects the total cost with interest and 'installment' matches the selected plan's number. ```php $request = new CreatePaymentRequest(); $installmentInfo = InstallmentInfo::retrieve($request, $options); // User selects installment plan $selectedPlan = $installmentInfo->getInstallmentDetails()[0] ->getInstallmentPrices()[3]; // 6-month plan // Create payment with selected installment $paymentRequest = new CreatePaymentRequest(); $paymentRequest->setPrice("100.00"); $paymentRequest->setPaidPrice($selectedPlan->getTotalPrice()); // Price with interest $paymentRequest->setInstallment($selectedPlan->getInstallmentNumber()); // 6 ``` -------------------------------- ### Initialize Pay with iyzico Form Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/apm.md Use this method to initialize the 'Pay with iyzico' payment form. It requires a `CreatePayWithIyzicoInitializeRequest` object and `Options` for configuration. The response contains checkout form content upon successful initialization. ```php use Iyzipay\Model\PayWithIyzico; use Iyzipay\Request\CreatePayWithIyzicoInitializeRequest; $request = new CreatePayWithIyzicoInitializeRequest(); // Configure payment request // ... $payWithIyzico = PayWithIyzico::initialize($request, $options); if ($payWithIyzico->getStatus() == "success") { echo $payWithIyzico->getCheckoutFormContent(); } ``` -------------------------------- ### Retrieve Installment Info Request Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md This section describes the properties required to retrieve installment information. The `currency`, `locale`, and `conversationId` are optional. ```APIDOC ## Retrieve Installment Info Request ### Description Retrieves available installment information based on the provided transaction details. ### Namespace `Iyzipay\Request\RetrieveInstallmentInfoRequest` ### Request Properties #### Parameters - **price** (string) - Required - Transaction amount in string format - **binNumber** (string) - Required - First 6 digits of card number (BIN) - **currency** (string) - Optional - Currency code (defaults to TRY) - **locale** (string) - Optional - Response locale (tr or en) - **conversationId** (string) - Optional - Unique conversation identifier ``` -------------------------------- ### Initialize Options Object Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/README.md Every API call requires an Options object with credentials. Set your API key, secret key, and base URL. ```php $options = new Iyzipay\Options(); $options->setApiKey("api_key"); $options->setSecretKey("secret_key"); $options->setBaseUrl("https://sandbox-api.iyzipay.com"); ``` -------------------------------- ### Retrieve Installment Info Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Retrieves all available installment plans for a given card. This endpoint is crucial for offering flexible payment options to customers. ```APIDOC ## POST /installment/installmentinfo ### Description Retrieves all available installment plans for the card. This endpoint is essential for providing customers with flexible payment options. ### Method POST ### Endpoint /installment/installmentinfo ### Authentication Uses IyziAuthV2 authentication. ### Response #### Success Response - The response includes all available installment plans for the card. ``` -------------------------------- ### Instantiate and Set PaymentCard Details Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/data-models.md Demonstrates how to create a new PaymentCard object and populate its properties using setter methods. This is useful for preparing card data for payment requests. ```php $card = new PaymentCard(); $card->setCardHolderName("John Doe"); $card->setCardNumber("5528790000000008"); $card->setExpireYear("2030"); $card->setExpireMonth("12"); $card->setCvc("123"); $card->setRegisterCard(1); $card->setCardAlias("Primary Card"); ``` -------------------------------- ### Enable Plus Installment Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Set this flag to true to enable additional installment plans from cooperating banks. This enhances the available payment options for customers. ```php $request->setPlusInstallmentUsage(true); ``` -------------------------------- ### Configure Production Environment Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/quick-start.md Set the base URL for the iyzipay API to the production environment. This should be used for live transactions after thorough testing in the sandbox. ```php $options->setBaseUrl("https://api.iyzipay.com"); ``` -------------------------------- ### Create Payment Request for Single Installment (No Interest) Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/installment.md Use this snippet to set up a payment request for a single, interest-free transaction. Ensure the 'installment' property is set to 1. ```php $request = new CreatePaymentRequest(); $request->setInstallment(1); $request->setPrice("100.00"); $request->setPaidPrice("100.00"); ``` -------------------------------- ### Configure Iyzipay Options Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/README.md Set up your API key, secret key, and base URL for Iyzipay operations. Ensure you use the correct sandbox or production URL. ```php $options = new Iyzipay\Options(); $options->setApiKey("your_api_key"); $options->setSecretKey("your_secret_key"); $options->setBaseUrl("https://sandbox-api.iyzipay.com"); ``` -------------------------------- ### Create Iyzilink Product Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/iyzilink.md Allows creation of a new product within the Iyzilink system. Requires product name, price, and currency. ```APIDOC ## Create Iyzilink Product ### Description Creates a new product with specified details. ### Parameters #### Request Body - **name** (string) - Required - Product name - **description** (string) - Optional - Product description - **price** (string) - Required - Product price - **currency** (string) - Required - Currency code (TRY, USD, EUR) - **imageUrl** (string) - Optional - Product image URL - **linkDescription** (string) - Optional - Payment link description - **locale** (string) - Optional - Response locale (tr/en) - **conversationId** (string) - Optional - Conversation identifier ``` -------------------------------- ### Retrieve Sub-Merchant Example Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/sub-merchant.md Example of how to retrieve a sub-merchant's details using the retrieve() method. This snippet demonstrates setting request parameters like locale, conversation ID, and sub-merchant key, then accessing the status and name from the response. ```php use Iyzipay\Request\RetrieveSubMerchantRequest; $request = new RetrieveSubMerchantRequest(); $request->setLocale(Locale::EN); $request->setConversationId("retrieve_123"); $request->setSubMerchantKey("submerchant_key"); $subMerchant = SubMerchant::retrieve($request, $options); echo "Sub-merchant status: " . $subMerchant->getStatus(); echo "Name: " . $subMerchant->getName(); ``` -------------------------------- ### Get Secret Key Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/configuration.md Retrieve the configured secret key from the Iyzipay Options. ```php public function getSecretKey(): string ``` -------------------------------- ### Create Iyzilink Fast Link Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/api-reference/iyzilink.md Use this snippet to create a one-time payment link without pre-saving product information. The `create` method requires an array of product details and your API options. The returned object contains the shareable payment link. ```php use Iyzipay\Model\Iyzilink\IyziLinkFastLink; $fastLink = IyziLinkFastLink::create(array( 'name' => 'One-time Product', 'price' => '99.99', 'currency' => 'TRY' ), $options); echo $fastLink->getUrl(); // Shareable payment link ``` -------------------------------- ### Get API Key Source: https://github.com/iyzico/iyzipay-php/blob/master/_autodocs/configuration.md Retrieve the configured API key from the Iyzipay Options. ```php public function getApiKey(): string ```