PHP code example of masoodrehman / php-payment-gateway-hbl

1. Go to this page and download the library: Download masoodrehman/php-payment-gateway-hbl 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/ */

    

masoodrehman / php-payment-gateway-hbl example snippets


$hblPay = new Client([
    "env" => Constant::ENV_SANDBOX,
    "authentication" => new AuthenticationFields([
        "USER_ID" => "user-id",
        "PASSWORD" => "password",
        "CHANNEL" => "channel-name",
        "RETURN_URL" => "http://localhost:8001/example/success.php", // replace with your own
        "CANCEL_URL" => "http://localhost:8001/example/fail.php" // replace with your own
    ]),
    "rsa" => [
        "publicKeyPath" => "<hbl-public-key-file-path>",
        "privateKeyPath" => "<your-private-key-file-path>",
    ]
]);

    use HBLPay\Client;
    use HBLPay\Common\Constant;
    use HBLPay\Model\AdditionalData;
    use HBLPay\Model\AuthenticationFields;
    use HBLPay\Model\CheckoutReq;
    use HBLPay\Model\Item;
    use HBLPay\Model\Order;
    use HBLPay\Model\ShippingDetail;
    
    try
    {
        // Request construction. Given the minimum name",
                        "CATEGORY" => "category name",
                        "SUB_CATEGORY" => "item sub category name",
                        "UNIT_PRICE" => 100,
                        "QUANTITY" => 1
                    ])
                ] // Required
            ]),
            "SHIPPING_DETAIL" => new ShippingDetail([
                "NAME" => "NULL", // Required
            ]),
            "ADDITIONAL_DATA" => new AdditionalData([
                "REFERENCE_NUMBER" => sprintf("INVOICE%s", time()), // Required
                "CUSTOMER_ID" => "1", // Required - (Did not mention in document)
                "CURRENCY" => "PKR", // Required
                "BILL_TO_FORENAME" => "First name", // Required
                "BILL_TO_SURNAME" => "Last name", // Required
                "BILL_TO_EMAIL" => "[email protected]", // Required
                "BILL_TO_PHONE" => "+921112222222", // Required
                "BILL_TO_ADDRESS_LINE" => "Street address", // Required
                "BILL_TO_ADDRESS_CITY" => "City", // Required
                "BILL_TO_ADDRESS_STATE" => "State", // Required
                "BILL_TO_ADDRESS_COUNTRY" => "PK", // Required
                "BILL_TO_ADDRESS_POSTAL_CODE" => "00000", // Required
            ])
        ]);
    
        // Call service
        $hblPay->getSessionAndRedirectToPortal($checkoutReq);
    }
    catch (Exception $e)
    {
        echo $e->getMessage();
    }

composer