PHP code example of shift4 / shift4-php
1. Go to this page and download the library: Download shift4/shift4-php 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/ */
shift4 / shift4-php example snippets
\Shift4\Util\Shift4Autoloader::register();
use Shift4\Shift4Gateway;
use Shift4\Exception\Shift4Exception;
$gateway = new Shift4Gateway('sk_test_[YOUR_SECRET_KEY]');
$request = [
'amount' => 499,
'currency' => 'EUR',
'card' => [
'number' => '4242424242424242',
'expMonth' => 11,
'expYear' => 2022
]
];
try {
$charge = $gateway->createCharge($request);
// do something with charge object - see https://dev.shift4.com/docs/api#charge-object
$chargeId = $charge->getId();
} catch (Shift4Exception $e) {
// handle error response - see https://dev.shift4.com/docs/api#error-object
$errorType = $e->getType();
$errorCode = $e->getCode();
$errorMessage = $e->getMessage();
}
composer