1. Go to this page and download the library: Download alma/alma-php-client 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/ */
alma / alma-php-client example snippets
$alma = new Alma\API\Client($apiKey, ['mode' => Alma\API\Client::TEST_MODE]);
// ...
$amountInCents = 150000; // 1500 euros
$customerBillingCountry = ""; // can be an empty string but NOT null
$customerShippingCountry = "FR"; // billing_address has priority over shipping_address (if not empty)
try {
$eligibilities = $alma->payments->eligibility(
[
'purchase_amount' => $amountInCents,
'billing_address' => [ // (optional) useful to check eligibility for a specific billing country
'country' => $customerBillingCountry // can be an empty string but not null
],
'shipping_address' => [ // (optional) useful to check eligibility for a specific shipping country
'country' => $customerShippingCountry
],
'queries' =>
[
[
'installments_count' => 1,
'deferred_days' => 30,
],
[
'installments_count' => 2,
],
[
'installments_count' => 3,
],
[
'installments_count' => 4,
],
[
'installments_count' => 10,
],
],
],
$raiseOnError = true // throws an exception on 4xx or 5xx http return code
// instead of just returning an Eligibility Object with isEligible() === false
);
} catch (Alma\API\RequestError $error) {
header("HTTP/1.1 500 Internal Server Error");
die($error->getMessage());
}
foreach($eligibilities as $eligibility) {
if (!$eligibility->isEligible()) {
die('cart is not eligible');
}
}
// ...
// ...
if (!isset($_GET['pid']) || empty($_GET['pid'])) {
header("HTTP/1.1 400 Bad Request");
die();
}
// retrieve your local order by payment id
$order = getOrderByPaymentId($_GET['pid'])
if (!$order) {
header("HTTP/1.1 404 Not Found");
die();
}
// check $payment->state & do the order / customer stuff you want here :D
header("HTTP/1.1 200");
exit();
// ...
// ...
$payment = $alma->payments->fetch($paymentId);
switch($payment->state) {
case Alma\API\Entities\Payment::STATE_IN_PROGRESS: break;
case Alma\API\Entities\Payment::STATE_PAID: break;
}
// ...
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.