Class Initialization

PhonePe PG PHP SDK

Class Initialisation for StandardCheckoutClient

StandardCheckoutClient class will be used to communicate with the PhonePe APIs. Merchant can create the instance only once per runtime; hence use the correct credentials while initializing the object.

Parameters :

Parameter NameData TypeMandatoryDescription
clientIdStringYesClient ID for secure communication with PhonePe.
clientVersionIntegerYesClient version for secure communication with PhonePe.
clientSecretStringYesSecret provided by PhonePe. To be kept secure on the merchant side.
envStringYesEnvironment for the StandardCheckoutClient:

Env::PRODUCTION (Production)

Note:

  • PHP Backend SDK is supported and can be tested in Production only

Throws PhonePeException:

If another StandardCheckoutClient object is initialized, PhonePeException is thrown.

Example usage:

<?php

require_once 'vendor/autoload.php'; // Include Composer autoloader

use PhonePe\payments\v2\standardCheckout\StandardCheckoutClient;
use PhonePe\Env;

$clientId = "YOUR_CLIENT_ID"; // Replace with your Client ID
$clientVersion = 1;           // Replace with your Client Version
$clientSecret = "YOUR_CLIENT_SECRET"; // Replace with your Client Secret
$env = Env::PRODUCTION;  // Use Env::PRODUCTION for live environment

$client = StandardCheckoutClient::getInstance(
    $clientId,
    $clientVersion,
    $clientSecret,
    $env
);

// Now you can use $client to interact with the PhonePe API.

?>

Key Notes

  • Replace “YOUR_CLIENT_ID”, 1, and “YOUR_CLIENT_SECRET” with your actual PhonePe Merchant credentials.
  • Choose the environment: Env::PRODUCTION for the Production
    Note: Currently the PHP SDK has support only for Production.
  • The fifth parameter ($shouldPublishEvents) is optional.  Set it to true to enable event publishing. Event Publishing enables sending events to PhonePe for analytics and monitoring. Defaults to false.

Important Considerations

  • Security:  Protect your Client Secret like a password. Do not expose it in client-side code or commit it to version control systems. Store it securely using environment variables or a secure configuration management system.

Singleton Pattern: The StandardCheckoutClient uses the singleton pattern. This means that getInstance() will always return the same instance of the client for a given set of credentials.