Created
February 8, 2019 16:29
-
-
Save RiRe/7af0456c7e3ec04bf31a9d60fe1bd558 to your computer and use it in GitHub Desktop.
Penta: Get account statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]¤cy=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