PHP 7 Script to Integrate Paykun Payment Gateway in Website Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments


Welcome folks today in this blog post we will be integrating paykun payment gateway in website using php 7. All the full source code of the application is shown below.




Get Started




In order to get started you need to install the paykun payment gateway php library from the below link



direct download






Install using composer



  • If your project uses composer, run the below command


composer require paykun/checkout



First of all, create index.php and write our HTML code for the HTML payment form







<form method="POST" action="request.php">
    <input type="hidden" name="response_url" value="response.php">

        <input type="text" name="amount" value="25.00" readonly="readonly"/> 
        Product Name<br>
        <input type="text" name="product_name" value="PRODUCT 123" readonly="readonly" />  
        Full Name<br>
        <input type="text" name="full_name" placeholder="Full Name" />
        <input type="text" name="email" placeholder="Email" /> 
        Contact No<br>
        <input type="text" name="customer_phone" maxlength="10" placeholder="Contact No" /> 
        <input type="text" name="address" placeholder="Address" />  
        <input type="text" name="country" placeholder="country" value="India" />  
        <input type="text" name="state" id="state" placeholder="State" />  
        <input type="text" name="city" maxlength="10"  id="city" placeholder="City" />  
        Postal Code<br>
        <input type="text" name="postalcode" id="postalcode" placeholder="Postal Code" /> 
        <button type="submit" class="btn btn-primary mt-4 float-right">Pay Now</button>

// Merchant ID, Access token and encryption key from PayKun
$merchant_id = "XXXXXXXXXX";


require 'src/Payment.php';
require 'src/Validator.php';
require 'src/Crypto.php';
//For composer
//use Paykun\Checkout\Payment;

// Change the false value into true for production mode. Currently it is in test or sandbox mode
$obj = new Payment($merchant_id, $access_token, $enc_key, false, true);
$response = $obj->getTransactionInfo($_REQUEST['payment-id']);
$message = '';
if(is_array($response) && !empty($response)) {

    if($response['status'] && $response['data']['transaction']['status'] == "Success") {
        $message = 'Payment was made successfully';
    else {
        //tampered or failed
        $message = 'Transaction failed';

      <h2>PayKun Payment Gateway Integration using PHP</h2>
  <div style="text-align: center;">
    <h3><?php print $message;?></h3>
      <p class="lead">Please check out your email for further instructions.</p>
      <p class="lead">
      <a class="btn btn-primary btn-sm" href="#" role="button">Continue to home</a>

Leave a Reply