Created
September 5, 2023 10:04
-
-
Save basst85/eaed1e8b23fd718efaa22a118aea56cb to your computer and use it in GitHub Desktop.
bunq_MastercardAction_notes.php
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 | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use bunq\Context\ApiContext; | |
use bunq\Http\ApiClient; | |
use bunq\Model\Generated\Endpoint\MasterCardAction; | |
use bunq\Model\Generated\Endpoint\NoteAttachmentMasterCardAction; | |
use bunq\Util\BunqEnumApiEnvironmentType; | |
use bunq\Context\BunqContext; | |
use bunq\Model\Generated\Endpoint\MonetaryAccountBank; | |
use bunq\Util\ModelUtil; | |
$environmentType = BunqEnumApiEnvironmentType::PRODUCTION(); | |
$fileName = 'bunq.json'; // Replace with your own secure location to load the stored API context from | |
$apiContext = ApiContext::restore($fileName); | |
BunqContext::loadApiContext($apiContext); | |
$user = BunqContext::getUserContext()->getUserPerson(); | |
$userId = BunqContext::getUserContext()->getUserPerson()->getId(); | |
$allMonetaryAccount = MonetaryAccountBank::listing()->getValue(); | |
$allActiveMonetaryAccount = []; | |
foreach ($allMonetaryAccount as $monetaryAccount) { | |
if ($monetaryAccount->getStatus() === 'ACTIVE') { | |
$allActiveMonetaryAccount[] = $monetaryAccount; | |
} | |
} | |
$monetaryAccount = $allActiveMonetaryAccount[2]; //Replace index to use the correct monetary account | |
$mastercardActions = MasterCardAction::listing( | |
$monetaryAccount->getId(), | |
['count' => 200] | |
)->getValue(); | |
$lastMastercardAction = $mastercardActions[0]; //Get last card payment | |
//Does not work, because of a bug in NoteAttachmentMasterCardAction::listing: | |
// | |
// $mastercardActionNoteAttachment = NoteAttachmentMasterCardAction::listing( | |
// $lastMastercardAction->getId(), | |
// $monetaryAccount->getId(), | |
// )->getValue(); | |
//Workaround: | |
$apiClient = new ApiClient($apiContext); | |
$responseRaw = $apiClient->get( | |
vsprintf( | |
'user/%s/monetary-account/%s/mastercard-action/%s/note-attachment', | |
[ | |
BunqContext::getUserContext()->getUserPerson()->getId(), | |
$monetaryAccount->getId(), | |
$lastMastercardAction->getId() | |
] | |
), | |
[], | |
[] | |
); | |
$json = $responseRaw->getBodyString(); | |
$responseArray = ModelUtil::deserializeResponseArray($json); | |
//Dump all mastercard payment note attachments | |
foreach ($responseArray['Response'] as $noteAttachment) { | |
var_dump($noteAttachment[array_key_first($noteAttachment)]['attachment']['urls'][0]['url']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment