PHPackages                             furkanmeclis/paytr-link - 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. furkanmeclis/paytr-link

ActiveLibrary[Payment Processing](/categories/payments)

furkanmeclis/paytr-link
=======================

PayTR Link API integration for Laravel

v1.0(6mo ago)012[2 PRs](https://github.com/furkanmeclis/paytr-link/pulls)MITPHPPHP ^8.1CI passing

Since Dec 27Pushed 2mo agoCompare

[ Source](https://github.com/furkanmeclis/paytr-link)[ Packagist](https://packagist.org/packages/furkanmeclis/paytr-link)[ Docs](https://github.com/furkanmeclis/paytr-link)[ GitHub Sponsors](https://github.com/furkanmeclis)[ RSS](/packages/furkanmeclis-paytr-link/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (17)Versions (5)Used By (0)

PayTR Link API Laravel Package
==============================

[](#paytr-link-api-laravel-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2f0013e2520159b538e3c977ebf86d02da07c053b7ebb7e9935ec9f38da20663/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6675726b616e6d65636c69732f70617974722d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/furkanmeclis/paytr-link)[![GitHub Tests Action Status](https://camo.githubusercontent.com/1df83e4a8096e544fabde804828b22e82028f806a4d19192759fd2862f040cb3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6675726b616e6d65636c69732f70617974722d6c696e6b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/furkanmeclis/paytr-link/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b849f3c751c28522429287d7ac2e07456ce2130dcdfd5ed79807858d9fc30a35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6675726b616e6d65636c69732f70617974722d6c696e6b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/furkanmeclis/paytr-link)

Laravel package for PayTR Link API integration. This package allows you to easily integrate with PayTR Link API.

Features
--------

[](#features)

- ✅ All PayTR Link API endpoints
- ✅ Type-safe Data Transfer Objects (Spatie Laravel Data)
- ✅ Settings management (Spatie Laravel Settings)
- ✅ Event system (Link creation, deletion, SMS/Email sending, Callback)
- ✅ Facade support for easy usage
- ✅ Comprehensive test coverage
- ✅ PHP 8.1+ support

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require furkanmeclis/paytr-link
```

Run the install command to publish config and optionally set up settings:

```
php artisan paytr-link:install
```

Or with settings support:

```
php artisan paytr-link:install --settings
php artisan migrate
php artisan paytr-link:setup-settings --init
```

Configuration
-------------

[](#configuration)

Add your PayTR credentials to your `.env` file:

```
PAYTR_MERCHANT_ID=your_merchant_id
PAYTR_MERCHANT_KEY=your_merchant_key
PAYTR_MERCHANT_SALT=your_merchant_salt
PAYTR_DEBUG_ON=1
```

You can also configure via the config file (`config/paytr-link.php`).

Usage
-----

[](#usage)

### Creating a Link

[](#creating-a-link)

```
use FurkanMeclis\PayTRLink\Facades\PayTRLink;
use FurkanMeclis\PayTRLink\Data\CreateLinkData;
use FurkanMeclis\PayTRLink\Enums\CurrencyEnum;
use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum;

$data = CreateLinkData::from([
    'name' => 'Web Design Service',
    'price' => 1500.00, // in TL
    'currency' => CurrencyEnum::TL,
    'link_type' => LinkTypeEnum::Product,
    'max_installment' => 12,
    'lang' => 'tr',
    'expiry_date' => '2025-12-31 23:59:59',
]);

$response = PayTRLink::create($data);

if ($response->isSuccess()) {
    $link = $response->link;
    $linkId = $response->id;
}
```

### Creating a Collection Link

[](#creating-a-collection-link)

```
$data = CreateLinkData::from([
    'name' => 'Bulk Payment',
    'price' => 5000.00,
    'currency' => CurrencyEnum::TL,
    'link_type' => LinkTypeEnum::Collection,
    'email' => 'customer@example.com', // Required for Collection
    'max_installment' => 12,
]);

$response = PayTRLink::create($data);
```

### Deleting a Link

[](#deleting-a-link)

```
use FurkanMeclis\PayTRLink\Data\DeleteLinkData;

$response = PayTRLink::delete(DeleteLinkData::from([
    'link_id' => 'link_id_here',
]));

// Or directly with a string
$response = PayTRLink::delete('link_id_here');
```

### Sending SMS

[](#sending-sms)

```
use FurkanMeclis\PayTRLink\Data\SendSmsData;

$response = PayTRLink::sendSms(SendSmsData::from([
    'link_id' => 'link_id_here',
    'phone' => '5551234567',
]));
```

### Sending Email

[](#sending-email)

```
use FurkanMeclis\PayTRLink\Data\SendEmailData;

$response = PayTRLink::sendEmail(SendEmailData::from([
    'link_id' => 'link_id_here',
    'email' => 'customer@example.com',
]));
```

### Callback Validation

[](#callback-validation)

```
use Illuminate\Http\Request;

public function handleCallback(Request $request)
{
    if (PayTRLink::validateCallback($request->all())) {
        // Transaction successful
        $callbackData = \FurkanMeclis\PayTRLink\Data\CallbackData::from($request->all());

        if ($callbackData->status === 'success') {
            // Payment successful, update the transaction
            echo "OK";
        } else {
            // Payment failed
            echo "OK";
        }
    } else {
        return response('Invalid hash', 400);
    }
}
```

### Service Injection

[](#service-injection)

You can also use dependency injection instead of Facade:

```
use FurkanMeclis\PayTRLink\PayTRLinkService;

class PaymentController
{
    public function __construct(
        protected PayTRLinkService $paytrLink
    ) {}

    public function createLink(CreateLinkData $data)
    {
        $response = $this->paytrLink->create($data);

        return response()->json($response);
    }
}
```

Spatie Laravel Settings Integration
-----------------------------------

[](#spatie-laravel-settings-integration)

The package works integrated with Spatie Laravel Settings. You can store settings in the database using Settings:

### Setting Up Settings

[](#setting-up-settings)

The package automatically registers PayTRSettings with Spatie Laravel Settings. To use settings:

1. **Publish and run migrations** (if you haven't already):

```
php artisan vendor:publish --provider="Spatie\LaravelSettings\LaravelSettingsServiceProvider" --tag="migrations"
php artisan paytr-link:install --settings
php artisan migrate
```

2. **Or use the setup command** (automatically creates settings entries):

```
php artisan paytr-link:setup-settings
```

To also initialize settings with values from your config file, use the `--init` flag:

```
php artisan paytr-link:setup-settings --init
```

### Using Settings

[](#using-settings)

```
use FurkanMeclis\PayTRLink\Settings\PayTRSettings;

// Assign values to Settings
$settings = app(PayTRSettings::class);
$settings->merchant_id = 'your_merchant_id';
$settings->merchant_key = 'your_merchant_key';
$settings->merchant_salt = 'your_merchant_salt';
$settings->debug_on = true; // or false
$settings->save();

// Reading values from Settings (also reads from config with fallback)
$settings = app(PayTRSettings::class);
$merchantId = $settings->getMerchantId();
$merchantKey = $settings->getMerchantKey();
$merchantSalt = $settings->getMerchantSalt();
$debugMode = $settings->getDebugOn();
```

When Settings is used, settings values are used instead of config values. The `getMerchantId()`, `getMerchantKey()`, `getMerchantSalt()`, and `getDebugOn()` methods automatically read from config if no value exists in settings.

Price Conversion
----------------

[](#price-conversion)

PayTR API expects prices in kuruş (cents). The package automatically converts TL prices to kuruş:

```
// 1500.00 TL is automatically converted to 150000 kuruş
$data = CreateLinkData::from([
    'name' => 'Product',
    'price' => 1500.00, // TL
    // ...
]);
```

Events
------

[](#events)

The package dispatches events for various operations. You can track operations and perform actions when needed by listening to these events:

### Event List

[](#event-list)

- `FurkanMeclis\PayTRLink\Events\LinkCreated` - When a link is created
- `FurkanMeclis\PayTRLink\Events\LinkDeleted` - When a link is deleted
- `FurkanMeclis\PayTRLink\Events\SmsSent` - When SMS is sent
- `FurkanMeclis\PayTRLink\Events\EmailSent` - When email is sent
- `FurkanMeclis\PayTRLink\Events\CallbackReceived` - When callback is received

### Event Usage

[](#event-usage)

#### Creating an Event Listener

[](#creating-an-event-listener)

Create a listener in the `app/Listeners` folder:

```
// app/Listeners/HandleLinkCreated.php
namespace App\Listeners;

use FurkanMeclis\PayTRLink\Events\LinkCreated;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class HandleLinkCreated implements ShouldQueue
{
    use InteractsWithQueue;

    public function handle(LinkCreated $event): void
    {
        $linkData = $event->createLinkData;
        $response = $event->response;

        // Actions to perform when link is created
        if ($response->isSuccess()) {
            logger()->info('Link created successfully', [
                'link_id' => $response->id,
                'link' => $response->link,
                'name' => $linkData->name,
                'price' => $linkData->price,
            ]);

            // Example: Save to database
            // Link::create([
            //     'paytr_link_id' => $response->id,
            //     'link' => $response->link,
            //     ...
            // ]);
        }
    }
}
```

#### Registering in Event Service Provider

[](#registering-in-event-service-provider)

In the `app/Providers/EventServiceProvider.php` file:

```
use App\Listeners\HandleLinkCreated;
use FurkanMeclis\PayTRLink\Events\LinkCreated;
use FurkanMeclis\PayTRLink\Events\LinkDeleted;
use FurkanMeclis\PayTRLink\Events\SmsSent;
use FurkanMeclis\PayTRLink\Events\EmailSent;
use FurkanMeclis\PayTRLink\Events\CallbackReceived;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        LinkCreated::class => [
            HandleLinkCreated::class,
        ],
        LinkDeleted::class => [
            // Your listeners
        ],
        SmsSent::class => [
            // Your listeners
        ],
        EmailSent::class => [
            // Your listeners
        ],
        CallbackReceived::class => [
            // Your listeners
        ],
    ];
}
```

#### Callback Event Usage

[](#callback-event-usage)

```
// app/Listeners/HandleCallbackReceived.php
namespace App\Listeners;

use FurkanMeclis\PayTRLink\Events\CallbackReceived;

class HandleCallbackReceived
{
    public function handle(CallbackReceived $event): void
    {
        $callbackData = $event->callbackData;
        $isValid = $event->isValid;

        if ($isValid && $callbackData->status === 'success') {
            // Payment successful - update order
            logger()->info('Payment successful', [
                'merchant_oid' => $callbackData->merchant_oid,
                'total_amount' => $callbackData->total_amount,
            ]);
        } else {
            // Payment failed
            logger()->warning('Payment failed', [
                'merchant_oid' => $callbackData->merchant_oid,
                'status' => $callbackData->status,
            ]);
        }
    }
}
```

#### Listening to Events with Closures

[](#listening-to-events-with-closures)

You can use closures instead of creating event listeners:

```
use FurkanMeclis\PayTRLink\Events\LinkCreated;
use Illuminate\Support\Facades\Event;

Event::listen(LinkCreated::class, function (LinkCreated $event) {
    if ($event->response->isSuccess()) {
        // Actions to perform when link is created
        logger()->info('Link created: ' . $event->response->link);
    }
});
```

Exception Handling
------------------

[](#exception-handling)

```
use FurkanMeclis\PayTRLink\Exceptions\PayTRRequestException;
use FurkanMeclis\PayTRLink\Exceptions\PayTRValidationException;

try {
    $response = PayTRLink::create($data);
} catch (PayTRRequestException $e) {
    // API request failed
    logger()->error('PayTR API Error', [
        'message' => $e->getMessage(),
        'response' => $e->response,
    ]);
} catch (PayTRValidationException $e) {
    // Validation error
    logger()->error('PayTR Validation Error', [
        'errors' => $e->errors,
    ]);
}
```

Testing
-------

[](#testing)

```
composer test
```

Test with coverage:

```
composer test-coverage
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability, please send an e-mail to . All security vulnerabilities will be promptly addressed.

Credits
-------

[](#credits)

- [Furkan Meclis](https://github.com/furkanmeclis)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance78

Regular maintenance activity

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96% 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

189d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/286faff943fc3453f69a6702fd3e6d794d430cb45404e2909142ad56b5a6dc9a?d=identicon)[furkanmeclis](/maintainers/furkanmeclis)

---

Top Contributors

[![furkanmeclis](https://avatars.githubusercontent.com/u/71632315?v=4)](https://github.com/furkanmeclis "furkanmeclis (48 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellinkpaymentpaytrfurkanmeclispaytr-link

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/furkanmeclis-paytr-link/health.svg)

```
[![Health](https://phpackages.com/badges/furkanmeclis-paytr-link/health.svg)](https://phpackages.com/packages/furkanmeclis-paytr-link)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.9k3](/packages/defstudio-telegraph)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.0k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[stephenjude/laravel-payment-gateways

A simple Laravel API implementation for all payment providers like Paystack, Flutterwave, &amp; Paypal etc.

1105.2k](/packages/stephenjude-laravel-payment-gateways)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

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