PHP code example of apcopay / apcopay_php
1. Go to this page and download the library: Download apcopay/apcopay_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/ */
apcopay / apcopay_php example snippets
$gateway = new ApcoPay\ApcoPayGateway(
new ApcoPay\Configuration(
"1234",
"dfnu2345b2354vbu",
"3ui423ui4",
"https://merchanturl.com/apcopay/notification",
"https://merchanturl.com/apcopay/redirect"
)
);
$transactionRequest = new ApcoPay\TransactionRequest();
$transactionRequest->amount = "2.40";
$transactionRequest->currency_code = "978";
$transactionRequest->order_reference = "1234";
$transactionRequest->transaction_type = ApcoPay\TransactionType::Purchase;
$transactionRequest->card_number = "4444444444444444";
$transactionRequest->card_cvv = "123";
$transactionRequest->card_holder = "John Doe";
$transactionRequest->card_expiry_month = "12";
$transactionRequest->card_expiry_year = "2023";
$transactionResponse = $gateway->processTransaction($transactionRequest);
if ($transactionResponse->result === "CAPTURED" || $transactionResponse->result === "APPROVED" || $transactionResponse->result === "VOIDED") {
// Transaction successful
} else if ($transactionResponse->result == 'ENROLLED') {
$redirectUrl = "https://www.apsp.biz/pay/3DSFP2/verify.aspx?id=" . $transactionResponse->psp_id;
// Redirect to $redirectUrl
} else {
// Transaction failed
}
$request = $_POST["params"];
$request = urldecode($request);
if (!$gateway->verify($request)) {
die("Hash mismatch");
return;
}
$notificationRequest = $gateway->parseNotification($request);
if ($notificationRequest->result === "OK") {
// TODO: update order to successful
} else {
// TODO: update order to declined
}
echo 'OK';
header("HTTP/1.1 200 OK");
$request = $_GET["params"];
$request = str_replace("\\\"", "\"", $request);
if (!$gateway->verify($request)) {
die("Hash mismatch");
return;
}
$redirectRequest = $gateway->parseRedirect($request);
if ($redirectRequest->result === "OK") {
echo '<div>Transaction successful</div>';
echo '<div>Order reference: ' . $redirectRequest->order_reference . '</div>';
} else {
echo '<div>Transaction failed</div>';
echo '<div>Order reference: ' . $redirectRequest->order_reference . '</div>';
echo '<div>Result: ' . $redirectRequest->result . '</div>';
}
bash
composer