PHP code example of juspay / expresscheckout-php-sdk
1. Go to this page and download the library: Download juspay/expresscheckout-php-sdk library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
juspay / expresscheckout-php-sdk example snippets
JuspayEnvironment::init()
->withApiKey("your_api_key")
JuspayEnvironment::init()
->withApiKey("yourApiKey")
->withBaseUrl(JuspayEnvironment::SANDBOX_BASE_URL)
JuspayEnvironment::init()
->withApiKey("yourApiKey")
->withConnectTimeout(connectTimeout)
->withReadTimeout(readTimeout);
JuspayEnvironment::init()
->withApiKey("yourApiKey")
->withBaseUrl(JuspayEnvironment::SANDBOX_BASE_URL)
->withConnectTimeout(connectTimeout)
->withReadTimeout(readTimeout);
JuspayEnvironment::init()
->withApiKey("yourApiKey")
->withBaseUrl(JuspayEnvironment::SANDBOX_BASE_URL)
->withCACertificatePath("file path to ca certificate");
$params = array ();
$params ['merchant_id'] = "merchantId";
$params ['customer_id'] = "customerId";
$params ['customer_email'] = "[email protected] ";
$params ['card_number'] = "4111111111111111";
$params ['card_exp_year'] = "2018";
$params ['card_exp_month'] = "07";
$params ['name_on_card'] = "Juspay Technologies";
$params ['nickname'] = "ICICI VISA";
$card = Card::create ( $params );
$params = array ();
$params ['order_id'] = $this->order->orderId;
$keys = [];
$privateKey = file_get_contents("./tests/privateKey.pem");
$publicKey = file_get_contents("./tests/publicKey.pem");
$order = Order::encryptedOrderStatus($params, new RequestOptions(new JuspayJWT("testJwe", $publicKey, $privateKey)));
$params = array ();
$params ['order_id'] = $this->order->orderId;
$keys = [];
$privateKey = file_get_contents("./tests/privateKey.pem");
$publicKey = file_get_contents("./tests/publicKey.pem");
JuspayEnvironment::init()->withJuspayJWT(new JuspayJWT("testJwe", $publicKey, $privateKey));
$order = Order::status($params, null);
use Juspay\Exception\AuthenticationException;
use Juspay\Exception\APIConnectionException;
use Juspay\Exception\APIException;
use Juspay\Exception\InvalidRequestException;
use Juspay\Exception\JuspayException;
use Juspay\Model\Order;
try {
$params = array ();
$params ['order_id'] = "order id";
$order = Order::status ( $params );
}
catch (APIConnectionException ex)
{
// Handle API connection exception
}
catch (APIException ex)
{
// Handle API exception
}
catch (AuthenticationException ex)
{
// Handle Authentication exception
}
catch (InvalidRequestException ex)
{
// Handle invalid request exception
}
catch (JuspayException ex)
{
// All above exception extends juspay exception
// Default exception handler
}
use Juspay\JuspayEnvironment;
use Juspay\Model\Order;
use Juspay\Exception\JuspayException;
JuspayEnvironment::init ()
->withApiKey ("api key")
->withBaseUrl ("base url")
->withJuspay(new JuspayJWT($keys, "public key id");
try {
// create order
$orderId = uniqid ();
$params = array ();
$params ['order_id'] = $orderId;
$params ['amount'] = 10000.0;
$order = Order::create ( $params );
$orderId = $order->orderId;
// Get order
$params = array ();
$params ['order_id'] = $orderId;
$order = Order::status ( $params );
$status = $order->status; // verify status of the order ("NEW", "CHARGED"..)
// update order
$params = array ();
$params ['amount'] = $order->amount + 100;
$order = Order::update ( $params, $orderId );
//Refund order
$params = array ();
$params ['order_id'] = $orderId;
$params ['amount'] = 10;
$params['unique_request_id'] = uniqid('php_sdk_test_');
$order = Order::refund ( $params );
$amountRefunded = $order->amountRefunded
}
catch (JuspayException $ex) {
// Handle exception
}
## To Run Test
### PHP Version >=7.1 and <= 7.2
### PHP Version > 7.2
### PHP Version 5