• Getting Started
    • Mobile Integration (Android/IOS)
      Enterprise Solutions
      Retail Solutions
      Accept Payments
      Process Payments
      API References
      Other Processes
      Mini Program Platform

      PHP SDK Integration

      Installation Guide


      PHP 5.6.0 or later

      Installing Paytm's payment gateway SDK with composer

      1. To install PHP SDK available on packagist.org, run below command

        composer require paytm/paytm-pg

        OR Add below lines to composer.json of your project

        "require": {
                "paytm/paytm-pg": "*"
      2. To enable autoloading, add below lines to composer.json of your project

        "autoload": {
            "psr-4": {
            "paytmpg\\": "vendor/paytm/paytm-pg"

        Note:You might have to change the path of paytm-pg depending on your project's folder structure.

      3. Run below command on command line to install dependencies to your project.

        composer install
      4. Run below command on command line to autoload files in your project

        composer dumpautoload -o
      5. To start using SDK functions, add the following lines in your project


        Note:You might have to change the path of autoload.php depending on your project's folder structure.

      Generate API Keys

      MIDA unique merchant identifier issued by Paytm for your account.
      Merchant KeyA 16-digit unique merchant identifier issued by Paytm for your account.

      Note: Merchant Key is a secret key used for encryption so never share this with anyone. And, You have to generate separate API Keys for test and production environment.

      Steps to generate API keys

      1. Log into your Dashboard.
      2. Select the environment (Test/Production) for which you want to generate the API key.
      3. For Test mode, click Generate Key to generate key under Test API details tab.
      4. For Production mode, activate your account here to generate Production API details.

      SDK code


      Merchant will initialize the following mandatory parameters: environment, mid, key and website, after which merchant can directly call SDK methods to call APIs of payment gateway.

      // For Staging 
      $environment = LibraryConstants::STAGING_ENVIRONMENT;
      // For Production 
      // $environment = LibraryConstants::PRODUCTION_ENVIRONMENT;
      // Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys 
      $mid = "YOUR_MID_HERE";
      $key = "YOUR_KEY_HERE";
      $website = "YOUR_WEBSITE_NAME";
      $client_id = "YOUR_CLIENT_ID_HERE";
      $callbackUrl = "MERCHANT_CALLBACK_URL";
      MerchantProperties::initialize($environment, $mid, $key, $client_id, $website);
      // If you want to add log file to your project, use below code
      Config::$monologName = '[PAYTM]';
      Config::$monologLevel = MonologLogger::INFO;
      Config::$monologLogfile = '/path/log/file.log';

      Note: Make sure log file (/path/log/file.log) has write permission.


      Create Transaction Token

      $channelId = EChannelId::WEB;
      $orderId = "UNIQUE_ORDER_ID";
      $txnAmount = Money::constructWithCurrencyAndValue(EnumCurrency::INR, "1.00");
      $userInfo = new UserInfo("CUSTOMER_ID"); 
      $paymentDetailBuilder = new PaymentDetailBuilder($channelId, $orderId, $txnAmount, $userInfo);
      $paymentDetail = $paymentDetailBuilder->build();
      $response = Payment::createTxnToken($paymentDetail);


      $orderId = "YOUR_ORDER_ID";
      $readTimeout = 80000;
      $paymentStatusDetailBuilder = new PaymentStatusDetailBuilder($orderId);
      $paymentStatusDetail = $paymentStatusDetailBuilder->setReadTimeout($readTimeout)->build();
      $response = Payment::getPaymentStatus($paymentStatusDetail);



      $orderId = "YOUR_ORDER_ID";
      $refId = "REFERENCE_ID";
      $txnId = "TRANSACTION_ID";
      $txnType = "REFUND";
      $refundAmount = "1";
      $readTimeout = 80000;
      $subWalletAmount = array();
      $subWalletAmount[UserSubWalletType::FOOD] = 1.00;
      $subWalletAmount[UserSubWalletType::GIFT] = 1.00;
      $refund = new RefundDetailBuilder($orderId, 
              $refId, $txnId, $txnType, $refundAmount);
      $refundDetail = $refund->setReadTimeout($readTimeout)
      $response = Refund::initiateRefund($refundDetail);


      $orderId = "YOUR_ORDER_ID";
      $refId = "REFERENCE_ID";
      $readTimeout = 8000;
      $refundStatusDetailBuilder = new RefundStatusDetailBuilder($orderId, $refId);
      $refundStatusDetail = $refundStatusDetailBuilder->setReadTimeout($readTimeout)->build();
      $response = Refund::getRefundStatus($refundStatusDetail);

      SDK Method References

      ClassMethodsHTTP requestDescription


      createTxnToken POST /theia/api/v1/initiateTransaction Returns a token which will be used in further frontend Payment calls
      getPaymentStatusPOST /merchant-status/api/v1/getPaymentStatus Returns the Payment status


      initiateRefundPOST /refund/api/v1/async/refundInitiates the Refund
      getRefundStatusPOST /refund/api/v1/refundStatusReturns the Refund status


      Download the sample application

      Download the SDK