Skip to content

Instantly share code, notes, and snippets.

@RiRe
Created February 8, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RiRe/7af0456c7e3ec04bf31a9d60fe1bd558 to your computer and use it in GitHub Desktop.
Save RiRe/7af0456c7e3ec04bf31a9d60fe1bd558 to your computer and use it in GitHub Desktop.
Penta: Get account statement
<?php
$email = "";
$pwd = "";
$ch = curl_init("https://app.getpenta.com/api/users/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"content-type: application/json; charset=utf-8",
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"email" => $email,
"password" => $pwd,
]));
$res = json_decode(curl_exec($ch), true);
if (!$res || empty($res["token"]) || empty($res["id_user"])) {
return false;
}
$token = $res["token"];
$userid = $res["id_user"];
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"content-type: application/json; charset=utf-8",
"penta-token: $token",
]);
curl_setopt($ch, CURLOPT_URL, "https://app.getpenta.com/api/users/$userid/business?details=true");
$res = json_decode(curl_exec($ch), true);
if (!$res || empty($res['id'])) {
return false;
}
$companyid = $res["id"];
curl_setopt($ch, CURLOPT_URL, "https://app.getpenta.com/api/businesses/$companyid/accounts");
$res = json_decode(curl_exec($ch), true);
if (!$res || !count($res)) {
return false;
}
$accid = $res[0]["id"];
if ($balance) {
curl_setopt($ch, CURLOPT_URL, "https://app.getpenta.com/api/businesses/$companyid/accounts/$accid/balance");
$res = json_decode(curl_exec($ch), true);
if (!$res || !isset($res["value"])) {
return false;
}
return $res["value"] / 100;
}
curl_setopt($ch, CURLOPT_URL, "https://app.getpenta.com/api/businesses/$companyid/accounts/$accid/transactions?page[number]=1&page[size]=50&states=[%22booked%22,+%22accepted%22]&currency=EUR&unit=cents&inflows=true&outflows=true&mode=list");
$res = json_decode(curl_exec($ch), true);
if (!is_array($res)) {
return false;
}
return $res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment