This PHP library will allow make payments using "BAC Credomatic"'s credit card service via Cardinal.
- PHP >= 5.6
- BAC access
Before implementing cardinal, you will need the public and private keys that are provided by Bac (read their documentation).
Init your API access using the Api class like this:
use Bac\Cardinal\Api;
/**
* @param mixed $keyId Public key.
* @param string $key Private key.
* @param string $redirect Redirect servlet URL, who will process reponses from the server.
*/
$api = new Api($keyId, $key, $redirect);Instantiate the payment service like this:
use Bac\Cardinal\BacPayment;
/**
* @param Bac\Cardinal\Api $api Api instance.
*/
$service = new BacPayment($api);You will need to generate and fill a payment object if you want to make any request to the service.
Create payment object like this:
use Bac\Cardinal\Data\Payment;
$payment = new Payment;
// --- Fill minimum data
$payment->orderId = 304;
$payment->amount = 19.00;
// --- Fill credit card data
$payment->ccNumber = 410000000000000;
$payment->ccExpiration = '0120';
$payment->cvv = 123;
$payment->address = 'Billing address in one line';
// --- Fill transaction (for certain requests)
$payment->transactionId = 457464;
// --- Fill processor_id (optional)
$payment->processor_id = 1;This package supports authorize, capture, sale and cancel. These methods may throw exceptions before they attempt a request if some validations are not met, use try/catch to handle them.
use Bac\Cardinal\Exceptions\ApiException;
use Bac\Cardinal\Exceptions\PaymentException;
try {
$service->authorize($payment);
$service->capture($payment);
$service->sale($payment);
$service->cancel($payment);
} catch (ApiException $e) {
// API exceptions
} catch (PaymentException $e) {
// Payment exceptions
} catch (Exception $e) {
// Unknown exceptions
}This package provides all the functionality needed to read the upcoming response and prepare your servlet. Use getResponse() method in service to obtain the response, then do your code based on the results. Same as the example above, use try/catch to handle exceptions
This is a servlet example:
use Bac\Cardinal\Api;
use Bac\Cardinal\BacPayment;
use Bac\Cardinal\Exceptions\ApiException;
use Bac\Cardinal\Exceptions\PaymentException;
use Bac\Cardinal\Exceptions\ResponseException;
try {
// Prepare service
$service = new BacPayment(new Api('key', 'key'));
// Get response
$response = $service->getResponse();
// ------------- your code -----------
// GET PAYMENT info
// -----------------------------------
$payment = custom_get_payment_function($response->orderId);
// Update the `time` property if you want to compare and validate hashes
$response->time = $payment->time;
// Validate and check if approved
if ($service->isValid($response) && $service->isApproved($response)) {
// TODO
// Your code if valid and approved
// ------------- your code -----------
// EXAMPLE IF WE WANT TO CAPTURE AN AUTHORIZED REQUEST
// -----------------------------------
$payment->transactionId = $response->transactionId;
$service->capture($payment);
} else {
// TODO
// Your code if denied or with data error
// NOTE: Unmatching hashes will throw ResponseException
}
} catch (ApiException $e) {
// API exceptions
} catch (ResponseException $e) {
// Response exceptions
} catch (PaymentException $e) {
// Payment exceptions
} catch (Exception $e) {
// Unknown exceptions
}Response object may containt:
// --- Response data (base response from service)
$response->response; // 1,2,3
$response->responseText;
$response->responseCode;
$response->avsResponse;
$response->cvvResponse;
$response->rawHash;
// --- Auth data
$response->authCode;
// --- Transaction data
$response->transactionId;
$response->orderId;
$response->amount;
// --- Payment data
$response->time;
// --- Generated data
$response->hash;
$response->isValidHash;
// --- Other BAC data
$response->points;(c) 2018 - 10 Quality.