PHPackages                             tarfin-labs/moka - 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. tarfin-labs/moka

ActiveLibrary[Payment Processing](/categories/payments)

tarfin-labs/moka
================

Laravel package for Moka Payment integration with 3D Secure support

1.2.0(2mo ago)83.4k↓35.8%1MITPHPPHP ^8.2|^8.3|^8.4|^8.5CI passing

Since Mar 10Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/tarfin-labs/moka)[ Packagist](https://packagist.org/packages/tarfin-labs/moka)[ RSS](/packages/tarfin-labs-moka/feed)WikiDiscussions main Synced yesterday

READMEChangelog (6)Dependencies (18)Versions (18)Used By (0)

Moka Payment Integration for Laravel
====================================

[](#moka-payment-integration-for-laravel)

This package provides an easy way to integrate Moka Payment system into your Laravel application.

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

[](#installation)

You can install the package via composer:

```
composer require tarfin/moka
```

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

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag="moka-config"
```

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

```
MOKA_DEALER_CODE=your-dealer-code
MOKA_USERNAME=your-username
MOKA_PASSWORD=your-password
MOKA_SANDBOX_MODE=true

# Optional: Configure redirect URLs
MOKA_PAYMENT_SUCCESS_URL=/moka-payment/success
MOKA_PAYMENT_FAILURE_URL=/moka-payment/failed
```

Usage
-----

[](#usage)

### Creating a 3D Payment

[](#creating-a-3d-payment)

```
use Tarfin\Moka\Facades\Moka;

// With minimal parameters
public function checkoutMinimal()
{
    $result = Moka::threeDPayment()->create(
        amount: 100.00,
        cardHolderName: 'John Doe',
        cardNumber: '5555555555555555',
        expMonth: '12',
        expYear: '2025',
        cvc: '123'
    );

    return $result; // Returns RedirectResponse
}

// With all parameters
public function checkout()
{
    $result = Moka::threeDPayment()->create(
        amount: 100.00,
        cardHolderName: 'John Doe',
        cardNumber: '5555555555555555',
        expMonth: '12',
        expYear: '2025',
        cvc: '123',
        software: 'Tarfin',
        // Optional parameters
        returnUrl: 'https://your-site.com/moka-callback', // Defaults to route('callback.handle3D')
        installment: 1,
        otherTrxCode: 'your-unique-id', // If not provided, a UUID will be generated
        isPoolPayment: 0,
        isTokenized: 0,
        currency: 'TL',
        redirectType: 1,
        language: 'TR',
        description: 'Payment description'
    );

    // The user will be redirected to Moka's 3D secure page
    return $result; // Returns RedirectResponse
}

// With buyer information using method chaining
public function checkoutWithBuyerInfo()
{
    $result = Moka::threeDPayment()
        ->buyerInformation(
            fullName: 'John Doe',
            gsmNumber: '5551234567',
            email: 'john@example.com',
            address: '123 Main St, City'
        )
        ->create(
            amount: 100.00,
            cardHolderName: 'John Doe',
            cardNumber: '5555555555555555',
            expMonth: '12',
            expYear: '2025',
            cvc: '123'
        );

    return $result; // Returns RedirectResponse
}

// Without redirect away if you want to handle the payment in your own view
public function checkoutMinimal()
{
    $result = Moka::threeDPayment()->create(
        amount: 100.00,
        cardHolderName: 'John Doe',
        cardNumber: '5555555555555555',
        expMonth: '12',
        expYear: '2025',
        cvc: '123',
        redirectAway: false // Set false to not redirect away
    );

    return $result; // Returns Array with parameters Url and CodeForHash
}
```

### Handling the 3D Callback

[](#handling-the-3d-callback)

The package automatically sets up a callback route at `POST /moka-callback` (named `moka-callback.handle3D`) to handle the 3D payment result. The callback will:

1. Validate the payment
2. Update the payment status
3. Redirect to your success/failure URL with the payment result

You can configure the success and failure URLs in your `.env` file:

```
MOKA_PAYMENT_SUCCESS_URL=/moka-payment/success
MOKA_PAYMENT_FAILURE_URL=/moka-payment/failure
```

The callback will redirect to these URLs with the following session data:

```
[
    'other_trx_code' => 'other_transaction_id',
    'status' => 'success|failed',
    'message' => 'Payment result message'
]
```

### Events Fired After Payment

[](#events-fired-after-payment)

The package includes an event system to help you manage payment outcomes. When a 3D Secure payment is processed, one of the following events will be dispatched:

```
// For successful payments
Tarfin\Moka\Events\MokaPaymentSucceededEvent::dispatch($payment);

// For failed payments
Tarfin\Moka\Events\MokaPaymentFailedEvent::dispatch($payment);
```

#### Listening for Payment Events

[](#listening-for-payment-events)

To react to these events, you can create listeners in your application. There are multiple ways to register event listeners in Laravel.

Then create your listener classes:

```
// app/Listeners/HandleSuccessfulMokaPayment.php

namespace App\Listeners;

use Tarfin\Moka\Events\MokaPaymentSucceededEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class HandleSuccessfulMokaPayment implements ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Handle the event.
     */
    public function handle(MokaPaymentSucceededEvent $event): void
    {
        $payment = $event->mokaPayment;

        // Access payment details
        $transactionId = $payment->other_trx_code;
        $amount = $payment->amount;

        // Implement your business logic
        // - Complete the order
        // - Generate invoice
        // - Send confirmation email
        // - Update inventory
    }
}
```

```
// app/Listeners/HandleFailedMokaPayment.php

namespace App\Listeners;

use Tarfin\Moka\Events\MokaPaymentFailedEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class HandleFailedMokaPayment implements ShouldQueue
{
    use InteractsWithQueue;

    /**
     * Handle the event.
     */
    public function handle(MokaPaymentFailedEvent $event): void
    {
        $payment = $event->mokaPayment;

        // Access payment details
        $transactionId = $payment->other_trx_code;
        $failureCode = $payment->result_code;
        $failureMessage = $payment->result_message;

        // Implement your business logic
        // - Update order status
        // - Notify customer
        // - Log payment failure
    }
}
```

### Dynamic Redirect URLs

[](#dynamic-redirect-urls)

You can specify custom success and failure URLs for each payment by adding them as query parameters to the return URL:

```
$result = Moka::threeDPayment()->create(
    amount: 100.00,
    cardHolderName: 'John Doe',
    cardNumber: '5555555555555555',
    expMonth: '12',
    expYear: '2025',
    cvc: '123',
    returnUrl: route('moka-callback.handle3D', [
        'success_url' => 'https://your-site.com/orders/123/payment-success',
        'failure_url' => 'https://your-site.com/orders/123/payment-failed',
    ]),
    installment: 1,
);
```

With this approach, you can dynamically specify different URLs for each payment transaction. The callback handler will:

1. Check for `success_url` or `failure_url` parameters in the request
2. Redirect to these URLs if present
3. Fall back to the configured `MOKA_PAYMENT_SUCCESS_URL` or `MOKA_PAYMENT_FAILURE_URL` if not specified

This is useful for applications that require different redirect destinations based on the payment context, such as returning users to specific order pages or application sections.

### Calculating Payment Amount

[](#calculating-payment-amount)

You can calculate the payment amount including commission rates and bank card details using the `MokaPaymentAmount` service:

```
use TarfinMokaServicesInformationMokaPaymentAmount;

// With minimal parameters
$paymentAmount = app(MokaPaymentAmount::class);
$result = $paymentAmount->calculate(
    binNumber: '526911',
    amount: 100.00
);

// With all parameters
$result = $paymentAmount->calculate(
    binNumber: '526911',
    amount: 100.00,
    installment: 3,
    isThreeD: 0,
    currency: 'USD'
);
```

The service will return an array containing detailed payment information:

```
[
    'PaymentAmount' => 101.56,
    'DealerDepositAmount' => 95.0,
    'DealerCommissionRate' => 6.46,
    'DealerCommissionAmount' => 6.56,
    'DealerCommissionFixedAmount' => 0.0,
    'DealerGroupCommissionRate' => 1.54,
    'DealerGroupCommissionAmount' => 1.56,
    'DealerGroupCommissionFixedAmount' => 0.0,
    'GroupRevenueRate' => 5.0,
    'GroupRevenueAmount' => 5.0,
    'BankCard' => [
        'BankName' => 'FINANSBANK',
        'BankCode' => '111',
        'BinNumber' => '526911',
        'CardType' => 'MASTER',
        'CreditType' => 'CreditCard',
        'ProductCategory' => 'Bireysel'
    ]
]
```

If there's an error with the calculation, the service will throw a `MokaException` with the error code and message.

### Storing Failed Payments

[](#storing-failed-payments)

By default, failed payments are not stored in the database. If you want to store them, set this in your `.env`:

```
MOKA_STORE_FAILED_PAYMENTS=true
```

### BIN Inquiry

[](#bin-inquiry)

You can use the BIN inquiry service to get information about a credit card based on its BIN number (first 6 digits):

```
use Tarfin\Moka\Facades\Moka;

$binInfo = Moka::binInquiry()->get('526911');

// Response structure
[
    'BankName' => 'FİNANSBANK',
    'BankCode' => '111',
    'BinNumber' => '526911',
    'CardName' => '',
    'CardType' => 'MASTER',
    'CreditType' => 'CreditCard',
    'CardLogo' => 'https://cdn.moka.com/Content/BankLogo/CARDFINANS.png',
    'CardTemplate' => 'https://cdn.moka.com/Content/BankCardTemplate/FINANS-MASTER-CREDIT.png',
    'ProductCategory' => 'Bireysel',
    'GroupName' => 'CARDFINANS'
]
```

The BIN inquiry service provides information about:

- Bank details (name and code)
- Card type (MASTER/VISA)
- Credit type (CreditCard/DebitCard)
- Card logos and templates
- Product category and group name

If the BIN inquiry fails, a `MokaException` will be thrown with the error message and code from Moka.

### Payment Table

[](#payment-table)

You can get payment table information including installment options and commission rates using the `MokaPaymentTable` service:

```
use Tarfin\Moka\Facades\Moka;

// With minimal parameters
$result = Moka::paymentTable()->calculate(
    amount: 100.00
);

// With BIN number
$result = Moka::paymentTable()->calculate(
    amount: 100.00,
    binNumber: '526911'
);

// With all parameters
$result = Moka::paymentTable()->calculate(
    amount: 100.00,
    binNumber: '526911',
    isThreeD: 0,
    isIncludedCommissionAmount: 0,
    currency: 'TL',
);
```

The service will return an array containing available installment options and commission rates:

```
'BankPaymentInstallmentInfoList' => [
    [
        'BankInfoName' => 'GENEL',
        'PaymentInstallmentInfoList' => [
            [
                'CommissionType' => 'CreditCard',
                'InstallmentNumber' => 1,
                'DealerCommissionRate' => 2.2,
                'DealerCommissionFixedAmount' => 0,
                'DealerCommissionAmount' => 2.2,
                'PerInstallmentAmount' => 100,
                'Amount' => 100,
            ],
            // ... more installment options
        ],
    ],
    [
        'BankInfoName' => 'AXESS',
        'PaymentInstallmentInfoList' => [
            [
                'CommissionType' => 'CreditCard',
                'InstallmentNumber' => 1,
                'DealerCommissionRate' => 3,
                'DealerCommissionFixedAmount' => 0,
                'DealerCommissionAmount' => 3,
                'PerInstallmentAmount' => 100,
                'Amount' => 100,
            ],
            // ... more installment options
        ],
    ],
],
```

### Payment Detail List

[](#payment-detail-list)

You can retrieve detailed information about a payment and its transactions using the `PaymentDetailList` service:

```
use Tarfin\Moka\Facades\Moka;

// Get payment details using paymentId
$paymentDetails = Moka::paymentDetailList()->get('1170');

// Or get payment details using your transaction code
$paymentDetails = Moka::paymentDetailList()->get(null, 'YOUR_ORDER_CODE_123');
```

The service will return an array containing both the main payment record and transaction details:

```
[
    'IsSuccessful' => true,
    'ResultCode' => '00',
    'ResultMessage' => '',
    'PaymentDetail' => [
        'DealerPaymentId' => 27405,
        'OtherTrxCode' => 'YOUR_ORDER_CODE_123',
        'CardHolderFullName' => 'John Doe',
        'CardNumberFirstSix' => '554960',
        'CardNumberLastFour' => '5523',
        'PaymentDate' => '2023-06-15T14:42:17.26',
        'Amount' => 100.00,
        'RefAmount' => 0.00,
        'CurrencyCode' => 'TL',
        'InstallmentNumber' => 0,
        'DealerCommissionAmount' => 2.50,
        'IsThreeD' => true,
        'Description' => 'Payment description',
        'PaymentStatus' => 2,
        'TrxStatus' => 1
    ],
    'ListItemCount' => 1,
    'PaymentTrxDetailList' => [
        [
            'DealerPaymentTrxId' => 2971,
            'DealerPaymentId' => 27405,
            'TrxCode' => '26ba712e-6381-4291-8c59-702c13b30d4d',
            'TrxDate' => '2023-06-15T14:42:17.837',
            'Amount' => 100.00,
            'TrxType' => 2,
            'TrxStatus' => 1,
            'PaymentReason' => 1,
            'VoidRefundReason' => 0,
            'VirtualPosOrderId' => 'ORDER-23060RYOG07011948',
            'ResultMessage' => ''
        ]
    ]
]
```

You must provide either the `paymentId` (Moka's internal payment ID) or `otherTrxCode` (your order/transaction code). If both are null, an exception will be thrown.

If the request fails, a `MokaPaymentDetailListException` will be thrown with the error message and code from Moka.

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance83

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

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

Every ~66 days

Recently: every ~73 days

Total

6

Last Release

86d ago

PHP version history (2 changes)1.0.0PHP ^8.2|^8.3|^8.4

1.2.0PHP ^8.2|^8.3|^8.4|^8.5

### Community

Maintainers

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

![](https://www.gravatar.com/avatar/e252316490c5fc7bae7eb25b6c0cb301b49fbc706c32896fea9467b64cf3653b?d=identicon)[Tarfin Labs](/maintainers/Tarfin%20Labs)

---

Top Contributors

[![deligoez](https://avatars.githubusercontent.com/u/3030815?v=4)](https://github.com/deligoez "deligoez (71 commits)")[![frkcn](https://avatars.githubusercontent.com/u/374634?v=4)](https://github.com/frkcn "frkcn (19 commits)")[![tkaratug](https://avatars.githubusercontent.com/u/4394344?v=4)](https://github.com/tkaratug "tkaratug (11 commits)")[![MrKacmaz](https://avatars.githubusercontent.com/u/57367737?v=4)](https://github.com/MrKacmaz "MrKacmaz (6 commits)")[![aydinfatih](https://avatars.githubusercontent.com/u/14280894?v=4)](https://github.com/aydinfatih "aydinfatih (5 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/tarfin-labs-moka/health.svg)

```
[![Health](https://phpackages.com/badges/tarfin-labs-moka/health.svg)](https://phpackages.com/packages/tarfin-labs-moka)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)[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.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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