PHPackages                             izal/knet-payment-php - 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. izal/knet-payment-php

ActiveLibrary[Payment Processing](/categories/payments)

izal/knet-payment-php
=====================

Php SDK for Knet Payment Gateway

3.1(5y ago)202.3k5[5 issues](https://github.com/iZaL/knet-payment-php/issues)MITPHPPHP &gt;=5.5.9CI failing

Since Sep 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/iZaL/knet-payment-php)[ Packagist](https://packagist.org/packages/izal/knet-payment-php)[ RSS](/packages/izal-knet-payment-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Knet Payment Php SDK
--------------------

[](#knet-payment-php-sdk)

[![Packagist License](https://camo.githubusercontent.com/b5924d4b515082b8e54cd79c8ac6f34a2cd87907b0c3e593dd80839d7cb39380/68747470733a2f2f706f7365722e707567782e6f72672f62617272797664682f6c61726176656c2d64656275676261722f6c6963656e73652e706e67)](http://choosealicense.com/licenses/mit/)[![Build Status](https://camo.githubusercontent.com/68c28f043a86702ae9bcac5283c9ce5d2aa17f6aa6fc2daf8943244128602433/68747470733a2f2f7472617669732d63692e6f72672f695a614c2f6b6e65742d7061796d656e742d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/iZaL/knet-payment-php)

This is a package to integrate KNET Payment Gateway in Php.

Documentation
-------------

[](#documentation)

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

[](#installation)

Require this package with composer:

```
composer require izal/knet-payment-php
```

### Usage:

[](#usage)

Initialise the Payment Process
==============================

[](#initialise-the-payment-process)

```
$knetGateway = new KnetBilling([
                'alias'        => 'YOUR_KNET_ALIAS',
                'resourcePath' => '/home/my_web_app_folder/' //Absolute Path to where the resource.cgn file is located
            ]);
```

configure the URL
=================

[](#configure-the-url)

```
$knetGateway->setResponseURL('http://mywebapp.com/payment/response.php');
$knetGateway->setErrorURL('http://mywebapp.com/payment/error.php);
$knetGateway->setAmt(100);
$knetGateway->setTrackId('123456'); // unique string

// Refer the KnetBilling class for other configurations that can be set like currency, language etc
```

Now to accept payments from the customer, first step is to Request the KNET gateway for the payment URL, by calling requestPayment method on the KnetBilling Class, we have completed our initial step to collect the payment.

```
$knetGateway->requestPayment();
```

Second step is to get the payment URL. and to get the payment url just call the method getPaymentURl

```
/**
* Get the URL for the Payment and assign it to a variable. this is the URL we will use to redirect the
* customer to payment gateway
*/

$paymentURL = $knetGateway->getPaymentURL();
```

```
Note: If the Payment URL returns null, most probably you messed up with configuration, or resource path. Check the example in the below section how to ideally request for the payment, which helps to debug for the errors
```

Third step is to Redirect the user to the Payment URL

```
// Redirect the USER to the Payment URL
header('Location: '.$paymentURL);
```

```
NOTE: Behind the scenes, Customer will be forwarded to the Knet Payment Page, If the payment process was success, Then he will be redirected to the Response URL we set in setResponseURL method. i.e http://mywebapp.com/payment/response.php
```

Fourth step is to get the response returned from the Knet Gateway and redirect the user to success or error page in your application.

```
// handle gateway response in http://mywebapp.com/payment/response.php

$paymentID = $_POST['paymentid'];
$result = $_POST['result']; // if the transaction is success, string "CAPTURED" will be return
$tranid = $_POST['tranid']; // transaction id
$trackid = $_POST['trackid'];

// build URL
$urlParams = "/?paymentID=" . $paymentID . "&transactionID=" . $transactionID . "&trackID=" . $trackID;

if ($result === "CAPTURED") {
    $redirectURL = 'http://mywebapp.com/payment/success.php';
} else {
    $redirectURL = 'http://mywebapp.com/payment/error.php';
}

return "REDIRECT=" . $redirectURL . $urlParams;

/** Above line is very important
 * KNET expects the return value from the page or method to be starting with
 * REDIRECT=http://mywebapp.com/payment/success/?paymentID.. etc.
 */
```

This is it. KNET will redirect the USER to the success page in a GET request. i.e to

```
http://mywebapp.com/payment/success.php
```

Example
-------

[](#example)

```
    $responseURL = 'http://mywebapp.com/payment/response.php';
    $successURL = 'http://mywebapp.com/payment/success.php';
    $errorURL = 'http://mywebapp.com/payment/error.php';
    $knetAlias = 'TEST_ALIAS';
    $resourcePath = '/home/mywebapp/';
    $amount = 150;
    $trackID = 'UNIQUETRACKID';

    try {

        $knetGateway = new KnetBilling([
            'alias'        => $knetAlias,
            'resourcePath' => $resourcePath
        ]);

        $knetGateway->setResponseURL($successURL);
        $knetGateway->setErrorURL($errorURL);
        $knetGateway->setAmt($amount);
        $knetGateway->setTrackId($trackID);

        $knetGateway->requestPayment();
        $paymentURL = $knetGateway->getPaymentURL();

        // helper function to redirect
        return header('Location: '.$paymentURL);

    } catch (\Exception $e) {

        // to debug error message
        // die(var_dump($e->getMessage()));

        return header('Location: '.$errorUrl);
    }

```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Every ~275 days

Total

5

Last Release

2064d ago

Major Versions

1.0.0 → 2.0.02017-09-12

2.0.1 → 3.02020-09-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ccffc4b33b9570ecc45e465f0ab888c78e87f900febcf3410b66a20cd2b2cde?d=identicon)[afzal](/maintainers/afzal)

---

Top Contributors

[![iZaL](https://avatars.githubusercontent.com/u/6410176?v=4)](https://github.com/iZaL "iZaL (15 commits)")

---

Tags

knetknet-phpknet-php-sdkknet-sdkpayment-gatewayknetknet paymentknet clientknet sdkknet php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/izal-knet-payment-php/health.svg)

```
[![Health](https://phpackages.com/badges/izal-knet-payment-php/health.svg)](https://phpackages.com/packages/izal-knet-payment-php)
```

###  Alternatives

[imdhemy/google-play-billing

Google Play Billing

491.3M5](/packages/imdhemy-google-play-billing)[bitpay/sdk

Complete version of the PHP library for the new cryptographically secure BitPay API

42337.5k4](/packages/bitpay-sdk)[buckaroo/sdk

Buckaroo payment SDK

12189.1k9](/packages/buckaroo-sdk)[contica/facturador-electronico-cr

Un facturador de código libre para integrar facturación electrónica en Costa Rica a un proyecto PHP

2128.8k](/packages/contica-facturador-electronico-cr)[asciisd/knet

Knet package is provides an expressive, fluent interface to KNet's payment services.

141.1k](/packages/asciisd-knet)

PHPackages © 2026

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