PHPackages                             abheranj/iyzipay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. abheranj/iyzipay

ActiveLibrary[Payment Processing](/categories/payments)

abheranj/iyzipay
================

Iyzipay (by AbheRanj) integration for your Laravel projects.

1.0.0(3y ago)1201MITPHP

Since Aug 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/abheranj/iyzipay-laravel)[ Packagist](https://packagist.org/packages/abheranj/iyzipay)[ RSS](/packages/abheranj-iyzipay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Iyzipay laravel Package
=======================

[](#iyzipay-laravel-package)

[![Issues](https://camo.githubusercontent.com/78d800db90bbe4e49fd38bbd9b51eef4359d138cfeb3557116b3b7c32c838f88/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6162686572616e6a2f69797a697061792d6c61726176656c3f7374796c653d666c61742d737175617265)](https://github.com/abheranj/iyzipay-laravel/issues)[![Stars](https://camo.githubusercontent.com/828757682e762fe54f0708e1737fb6798461a24a530d2ad4cc615efc9e096e7b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6162686572616e6a2f69797a697061792d6c61726176656c3f7374796c653d666c61742d737175617265)](https://github.com/abheranj/iyzipay-laravel/stargazers)

Iyzipay (by AbheRanj) integration for your Laravel projects.

You can sign up for an iyzipay sandbox account at

Install
-------

[](#install)

```
composer require abheranj/iyzipay
```

Service provider

> config/app.php

```
'providers' => [
    ...
    Abheranj\Iyzipay\IyzipayServiceProvider::class,
];
```

Facades

> config/app.php

```
'aliases' => [
    ...
    'Iyzipay' => Abheranj\Iyzipay\Facades\IyzipayService::class,
];
```

.env

> .env

```
# IYZIPAY_PAYMENT_MODE for sanbox will be "test" and for live will be "live"
IYZIPAY_PAYMENT_MODE="test"
SANDBOX_IYZIPAY_BASE_URL="https://sandbox-api.iyzipay.com"
SANDBOX_IYZIPAY_API_KEY="Sanbox Api Key"
SANDBOX_IYZIPAY_SECRET_KEY="Sanbox Secret Key"

LIVE_IYZIPAY_BASE_URL="Live url"
LIVE_IYZIPAY_API_KEY="Live Api Key"
LIVE_IYZIPAY_SECRET_KEY="Live Secret Key"
```

Features
--------

[](#features)

- Iyzipay::addCreditCard($email, $iyzipay\_key, array $attributes)
- Iyzipay::removeCreditCard($iyzipay\_key, $token)
- Iyzipay::singlePayment($creditCard, $buyer\_arr, $billaddress, $shipaddress, $products, $currency, $installment, $subscription = false)
- Iyzipay::cancelPayment($iyzipay\_key)
- Iyzipay::refundPayment($iyzipay\_key, $price, $currency)
- Iyzipay::ThreedsInitializePayment($CardArr, $BuyerArr, $AddressArr, $AddressArr, $ProductArr, $Currency, $Installment, $CallBackUrl);
- Iyzipay::PayThreedsPayment($requestArr)

Usage
-----

[](#usage)

### Add Credit Card

[](#add-credit-card)

```

    // Add Credit Card

    $card_details = [];
    $card_details['alias']  = 'Card'.Auth::user()->id;
    $card_details['holder'] = $request->card_name;
    $card_details['number'] = $request->card_number;
    $card_details['month']  = $request->exp_month;
    $card_details['year']   = $request->exp_year;
    $iyzipay_key = '';

    $CardRes = Iyzipay::addCreditCard(Auth::user()->email, $iyzipay_key, $card_details);

    if($CardRes->getStatus() != 'success'){
        Session::flash('message', $CardRes->getErrorMessage());
        Session::flash('icon', 'warning');
        return redirect()->back()->withInput($request->input());
    }

    // Store in MySQL Database

    $Card = $this->CardsRep->AddEditCards(
        $request->card_name,
        $CardRes->getCardAlias(),
        $request->card_number,
        $CardRes->getCardToken(),
        $CardRes->getCardUserKey(),  //iyzipay_key
        $CardRes->getCardBankName()
    );
```

### Remove Credit Card

[](#remove-credit-card)

```
    // Remove credit card

    $CardData       = $this->CardsRep->GetCardById($id); // From MySQL Database
    $IyzipayCard    = Iyzipay::removeCreditCard($CardData->iyzipay_key, $CardData->token);

    if ($IyzipayCard->getStatus() != 'success') {
        Session::flash('message', $IyzipayCard->getErrorMessage());
        Session::flash('icon', 'warning');
        return redirect()->back();
    }

    $CardData->delete(); // Delete From MySQL Database
```

### Single Payment

[](#single-payment)

```
    use Iyzipay\Model\BasketItemType;
    use Iyzipay\Model\Currency;
    use Illuminate\Support\Facades\DB;

    DB::beginTransaction();

        $ProductData = $this->ProductRep->GetProductById($request->pid); //From MySQL Database

        $CardArr = [];
        $CardArr['iyzipay_key'] = $Card->iyzipay_key; // From MySQL Database
        $CardArr['token']       = $Card->token;

        $BuyerArr = [];
        $BuyerArr['id']             = 'B'.Auth::user()->id;
        $BuyerArr['firstName']      = Auth::user()->name;
        $BuyerArr['lastName']       = Auth::user()->surname;
        $BuyerArr['email']          = Auth::user()->email;
        $BuyerArr['mobileNumber']   = Auth::user()->phone_no;
        $BuyerArr['identityNumber'] = Auth::user()->phone_no;
        $BuyerArr['city']           = $request->city;
        $BuyerArr['country']        = $request->country;
        $BuyerArr['address']        = $request->address;

        $AddressArr = [];
        $AddressArr['name']     = $request->name;
        $AddressArr['city']     = $request->city;
        $AddressArr['country']  = $request->country;
        $AddressArr['address']  = $request->address;
        $AddressArr['zipcode']  = $request->postcode;

        $ShipAddressArr = $AddressArr;

        $ProductArr = [];
        $ProductArr[0]['id']       = $ProductData['id'];
        $ProductArr[0]['name']     = $ProductData['name'];
        $ProductArr[0]['category'] = 'Cloth';
        $ProductArr[0]['type']     = BasketItemType::VIRTUAL;
        $ProductArr[0]['price']    = $ProductData['price'];

        $Currency       = Currency::TL;
        $Installment    = 1;

        $Transaction = Iyzipay::singlePayment($CardArr, $BuyerArr, $AddressArr, $ShipAddressArr, $ProductArr, $Currency, $Installment);

        if($Transaction->getStatus() == 'success'){

            $Products       = [];
            $PayoutMerchant = [];
            foreach ($Transaction->getPaymentItems() as $paymentItem) {
                $Products[] = [
                    'iyzipay_key'                   => $paymentItem->getPaymentTransactionId(),
                    'paidPrice'                     => $paymentItem->getPaidPrice(),
                    'product'                       => [$ProductData]
                ];
                $PayoutMerchant[] = [
                    'merchantCommissionRate'        => $paymentItem->getMerchantCommissionRate(),
                    'merchantCommissionRateAmount'  => $paymentItem->getMerchantCommissionRateAmount(),
                    'merchantCommissionRateAmount'  => $paymentItem->getMerchantCommissionRateAmount(),
                    'iyziCommissionRateAmount'      => $paymentItem->getIyziCommissionRateAmount(),
                    'iyziCommissionFee'             => $paymentItem->getIyziCommissionFee(),
                    'merchantPayoutAmount'          => $paymentItem->getMerchantPayoutAmount()
                ];
            }
            // $Transaction->getPaymentId() // iyzipay_key

            $Payment = $this->TransactionsRep->AddTransaction($Transaction->getPaidPrice(), $Transaction->getPaymentId(), $Transaction->getCurrency(), $Card->id, $Products, $PayoutMerchant, $AddressArr); // Store in MySQL Database

            DB::commit();

            Session::flash('message', 'Order placed successfully.');
            Session::flash('icon', 'success');
            return redirect()->back();

        } else {
            DB::rollback();
            Session::flash('message', $Transaction->getErrorMessage());
            Session::flash('icon', 'warning');
            return redirect()->back()->withInput($request->input());
        }
```

### Cancel Payment

[](#cancel-payment)

```
        $transactionObj =  $this->TransactionsRep->GetTransactionById($id); // Get From MySQL Database
        $IyzipayCancel  = Iyzipay::cancelPayment($transactionObj->iyzipay_key);

        if ($IyzipayCancel->getStatus() != 'success') {
            Session::flash('message', $IyzipayCancel->getErrorMessage());
            Session::flash('icon', 'warning');
            return redirect()->back();
        }

        $Cancel[] = [
            'type'        => 'cancel',
            'amount'      => $IyzipayCancel->getPrice(),
            'iyzipay_key' => $IyzipayCancel->getPaymentId()
        ];

        $this->TransactionsRep->refundTransaction($transactionObj, $Cancel); // Update record in MySQL Database
```

### Refund Payment

[](#refund-payment)

```
        $transactionObj =  $this->TransactionsRep->GetTransactionById($id); // Get From MySQL Database
        $Currency       = Currency::TL;
        $Products       = json_decode($transactionObj->products);
        $Refunds        = [];

        foreach ($Products as $Product) {
            $IyzipayRefund  = Iyzipay::refundPayment($Product->iyzipay_key, $Product->paidPrice, $Currency);
            if ($IyzipayRefund->getStatus() != 'success') {
                Session::flash('message', $IyzipayRefund->getErrorMessage());
                Session::flash('icon', 'warning');
                return redirect()->back();
            }
            $Refunds[] = [
                'type'                      => 'refund',
                'amount'                    => $IyzipayRefund->getPrice(),
                'iyzipay_payment_key'       => $IyzipayRefund->getPaymentId(),
                'iyzipay_transaction_key'   => $IyzipayRefund->getPaymentTransactionId(),
                'currency'                  => $IyzipayRefund->getCurrency()
            ];
        }

        $this->TransactionsRep->refundTransaction($transactionObj, $Refunds); // Update record in MySQL Database
        $Amount = $transactionObj->currency.' '.$IyzipayRefund->getPrice();

        Session::flash('message', $Amount.' Amount Refunded successfully.');
        Session::flash('icon', 'success');
        return redirect()->back();
```

3D Auth (3D Secure)
-------------------

[](#3d-auth-3d-secure)

### Initialize 3D Auth payment

[](#initialize-3d-auth-payment)

```
    try{
        DB::beginTransaction();
        $SubscriptionData = $this->SubscriptionsRep->GetSubscriptionById($request->pid);

        $card_details = [];
        $card_details['alias']  = 'Card'.Auth::user()->id;
        $card_details['holder'] = $request->card_name;
        $card_details['number'] = $request->card_number;
        $card_details['month']  = $request->exp_month;
        $card_details['year']   = $request->exp_year;

        $CardRes = Iyzipay::addCreditCard(Auth::user()->email, '', $card_details);
        if($CardRes->getStatus() != 'success'){
            Session::flash('message', $CardRes->getErrorMessage());
            Session::flash('icon', 'warning');
            Session::flash('heading', __('messages.common.warning'));
            return redirect()->back()->withInput($request->input());
        }

        $Card = $this->CardsRep->AddEditCards(
            $request->card_name,
            $CardRes->getCardAlias(),
            $request->card_number,
            $CardRes->getCardToken(),
            $CardRes->getCardUserKey(),
            $CardRes->getCardBankName()
        );

        $CardArr = [];
        $CardArr['iyzipay_key'] = $Card->iyzipay_key;
        $CardArr['token']       = $Card->token;

        $BuyerArr = [];
        $BuyerArr['id']             = 'B'.Auth::user()->id;
        $BuyerArr['firstName']      = Auth::user()->name;
        $BuyerArr['lastName']       = Auth::user()->surname;
        $BuyerArr['email']          = Auth::user()->email;
        $BuyerArr['mobileNumber']   = Auth::user()->phone_no;
        $BuyerArr['identityNumber'] = Auth::user()->phone_no;
        $BuyerArr['city']           = $request->city;
        $BuyerArr['country']        = $request->country;
        $BuyerArr['address']        = $request->address;

        $AddressArr = [];
        $AddressArr['name']     = $request->name;
        $AddressArr['city']     = $request->city;
        $AddressArr['country']  = $request->country;
        $AddressArr['address']  = $request->address;
        $AddressArr['zipcode']  = $request->postcode;

        $ProductArr = [];
        $ProductArr[0]['id']       = $SubscriptionData['id'];
        $ProductArr[0]['name']     = $SubscriptionData['name'];
        $ProductArr[0]['category'] = 'Subscription';
        $ProductArr[0]['type']     = BasketItemType::VIRTUAL;
        $ProductArr[0]['price']    = $SubscriptionData['price'];

        $Currency       = Currency::TL;
        $Installment    = 1;
        $CallBackUrl    = route('payment_confirm');

        $Card->billing_info = json_encode($AddressArr);
        $Card->save();

        $Transaction = Iyzipay::ThreedsInitializePayment($CardArr, $BuyerArr, $AddressArr, $AddressArr, $ProductArr, $Currency, $Installment, $CallBackUrl);
        if($Transaction->getStatus() == 'success'){
            DB::commit();
            return view('subscriptions.payment_response', ['htmlform' => base64_encode($Transaction->getHtmlContent()), 'page_name'=>'Payment response']);

        } else {
            Session::flash('message', $Transaction->getErrorMessage());
            Session::flash('icon', 'warning');
            Session::flash('heading', __('messages.common.warning'));
            return redirect()->back()->withInput($request->input());
        }
    } catch (Exception $e) {
        DB::rollback();
        return response()->view('error.500', ['message'=>$e->getMessage()], 500);
    }
```

### 3D Auth payment

[](#3d-auth-payment)

```
    try{
            if($request->mdStatus!="1"){
                Session::flash('message', __('messages.transactions.mdStatus'.$request->mdStatus));
                Session::flash('icon', 'warning');
                Session::flash('heading', __('messages.common.warning'));
                return redirect()->route('dissubscriptions', ['page_name'=>'Subscription Plans']);
            }

            if ($request->status != 'success') {
                Session::flash('message', __('messages.common.somthing_wrong'));
                Session::flash('icon', 'warning');
                Session::flash('heading', __('messages.common.warning'));
                return redirect()->route('dissubscriptions', ['page_name'=>'Subscription Plans']);
            }

            if(empty($request->paymentId)){
                Session::flash('message', __('messages.common.somthing_wrong'));
                Session::flash('icon', 'warning');
                Session::flash('heading', __('messages.common.warning'));
                return redirect()->route('dissubscriptions', ['page_name'=>'Subscription Plans']);
            }

            $requestArr = array('paymentId'=>$request->paymentId, 'conversationData'=>$request->conversationData, 'conversationId'=>$request->conversationId);
            $Transaction    = Iyzipay::PayThreedsPayment($requestArr);

            if($Transaction->getStatus() == 'success'){
                $Transactions       = $Transaction->getPaymentItems();
                $SubscriptionData   = $this->SubscriptionsRep->GetSubscriptionById($Transactions[0]->getItemId());
                $CardToken          = $Transaction->getCardToken();
                $Card               = $this->CardsRep->GetCardByToken($CardToken);

                if(empty($SubscriptionData)){
                    Session::flash('message', __('messages.subscriptions.not_found'));
                    Session::flash('icon', 'warning');
                    Session::flash('heading', __('messages.common.warning'));
                    return redirect()->route('dissubscriptions', ['page_name'=>'Subscription Plans']);
                }

                $Products       = [];
                $PayoutMerchant = [];
                foreach ($Transaction->getPaymentItems() as $paymentItem) {
                    $Products[] = [
                        'iyzipay_key'                   => $paymentItem->getPaymentTransactionId(),
                        'paidPrice'                     => $paymentItem->getPaidPrice(),
                        'product'                       => [$SubscriptionData]
                    ];
                    $PayoutMerchant[] = [
                        'merchantCommissionRate'        => $paymentItem->getMerchantCommissionRate(),
                        'merchantCommissionRateAmount'  => $paymentItem->getMerchantCommissionRateAmount(),
                        'iyziCommissionRateAmount'      => $paymentItem->getIyziCommissionRateAmount(),
                        'iyziCommissionFee'             => $paymentItem->getIyziCommissionFee(),
                        'merchantPayoutAmount'          => $paymentItem->getMerchantPayoutAmount()
                    ];
                }

                $Payment = $this->TransactionsRep->AddTransaction($Transaction->getPaidPrice(), $Transaction->getPaymentId(), $Transaction->getCurrency(), $Card->id, $Products, $PayoutMerchant, json_decode($Card->billing_info));
                DB::commit();

                Session::flash('message', __('messages.subscriptions.buy_success'));
                Session::flash('icon', 'success');
                Session::flash('heading', __('messages.common.success'));
                return redirect()->route('dissubscriptions', ['page_name'=>'Subscription Plans']);

            } else {
                DB::rollback();
                Session::flash('message', $Transaction->getErrorMessage());
                Session::flash('icon', 'warning');
                Session::flash('heading', __('messages.common.warning'));
                return redirect()->back()->withInput($request->input());
            }
        } catch (Exception $e) {
            DB::rollback();
            return response()->view('error.500', ['message'=>$e->getMessage()], 500);
        }
```

Test Cards
----------

[](#test-cards)

Test cards that can be used to simulate a *successful* payment:

Card NumberBankCard Type5890040000000016AkbankMaster Card (Debit)5526080000000006AkbankMaster Card (Credit)4766620000000001DenizbankVisa (Debit)4603450000000000DenizbankVisa (Credit)4729150000000005Denizbank BonusVisa (Credit)4987490000000002FinansbankVisa (Debit)5311570000000005FinansbankMaster Card (Credit)9792020000000001FinansbankTroy (Debit)9792030000000000FinansbankTroy (Credit)5170410000000004Garanti BankasıMaster Card (Debit)5400360000000003Garanti BankasıMaster Card (Credit)374427000000003Garanti BankasıAmerican Express4475050000000003HalkbankVisa (Debit)5528790000000008HalkbankMaster Card (Credit)4059030000000009HSBC BankVisa (Debit)5504720000000003HSBC BankMaster Card (Credit)5892830000000000Türkiye İş BankasıMaster Card (Debit)4543590000000006Türkiye İş BankasıVisa (Credit)4910050000000006VakıfbankVisa (Debit)4157920000000002VakıfbankVisa (Credit)5168880000000002Yapı ve Kredi BankasıMaster Card (Debit)5451030000000000Yapı ve Kredi BankasıMaster Card (Credit)*Cross border* test cards:

Card NumberCountry4054180000000007Non-Turkish (Debit)5400010000000004Non-Turkish (Credit)6221060000000004IranTest cards to get specific *error* codes:

Card NumberDescription5406670000000009Success but cannot be cancelled, refund or post auth4111111111111129Not sufficient funds4129111111111111Do not honour4128111111111112Invalid transaction4127111111111113Lost card4126111111111114Stolen card4125111111111115Expired card4124111111111116Invalid cvc24123111111111117Not permitted to card holder4122111111111118Not permitted to terminal4121111111111119Fraud suspect4120111111111110Pickup card4130111111111118General error4131111111111117Success but mdStatus is 04141111111111115Success but mdStatus is 441511111111111123dsecure initialize failed

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c86dd074d2a775ef6f14837c905b146610cd9919a22188801c590d74b29c9068?d=identicon)[abheranj](/maintainers/abheranj)

---

Top Contributors

[![abheranj](https://avatars.githubusercontent.com/u/110759817?v=4)](https://github.com/abheranj "abheranj (7 commits)")

---

Tags

iyzicoiyzipayiyzipay-laravelAbheRanj-iyzipay

### Embed Badge

![Health badge](/badges/abheranj-iyzipay/health.svg)

```
[![Health](https://phpackages.com/badges/abheranj-iyzipay/health.svg)](https://phpackages.com/packages/abheranj-iyzipay)
```

###  Alternatives

[iyzico/iyzipay-php

iyzipay api php client

3271.1M26](/packages/iyzico-iyzipay-php)[iyzico/iyzipay-laravel

Iyzipay (by Iyzico) integration for your Laravel projects.

8612.1k](/packages/iyzico-iyzipay-laravel)[yasinkuyu/omnipay-iyzico

Iyzico gateway for Omnipay payment processing library

137.0k](/packages/yasinkuyu-omnipay-iyzico)[codenteq/iyzico-payment-gateway

The Laravel eCommerce Iyzico Payment Gateway

111.0k](/packages/codenteq-iyzico-payment-gateway)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
