Last active
June 6, 2018 11:35
-
-
Save basst85/6eedfde5b8f69584a5691b1d69fa8466 to your computer and use it in GitHub Desktop.
Add notification callback via bunq API
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 | |
// src/Controller/CallbackController.php | |
namespace App\Controller; | |
use Symfony\Component\HttpFoundation\Response; | |
use bunq\Context\ApiContext; | |
use bunq\Context\BunqContext; | |
use bunq\Model\Generated\Endpoint\User; | |
use bunq\Model\Generated\Endpoint\UserPerson; | |
use bunq\Util\BunqEnumApiEnvironmentType; | |
class CallbackController | |
{ | |
public function addCallback() | |
{ | |
$environmentType = BunqEnumApiEnvironmentType::SANDBOX(); // Can also be BunqEnumApiEnvironmentType::PRODUCTION(); | |
$apiKey = getenv('BUNQ_API_KEY'); | |
$deviceDescription = 'Replace this'; // Replace with your device description | |
$permittedIps = []; // List the real expected IPs of this device or leave empty to use the current IP | |
$psqlTable = $this->createTable(); | |
$apiContext = ApiContext::create( | |
$environmentType, | |
$apiKey, | |
$deviceDescription, | |
$permittedIps | |
); | |
BunqContext::loadApiContext($apiContext); | |
$bunqConfigFile = '/app/bunq.conf'; | |
$apiContext->save($bunqConfigFile); | |
$user = BunqContext::getUserContext()->getUserPerson(); | |
$userId = $user->getId(); | |
$monetaryAccounts = MonetaryAccountBank::listing([])->getValue(); | |
$notificationFilterMap[] = new NotificationFilter('URL', 'https://www.domain.com/webhook', 'BUNQME_TAB'); | |
$createNotificationFilter = MonetaryAccountBank::update($monetaryAccountId,null,null,null,null,null,null,null,$notificationFilterMap)->getValue(); | |
/** | |
* Return list of active monetary accounts with filters | |
*/ | |
$responseHtml = 'Active monetary accounts: <br/>'; | |
$index = 0; | |
foreach ($monetaryAccounts as $monetaryAccount) { | |
if ($monetaryAccount->getStatus() === 'ACTIVE') { | |
$filters = $monetaryAccount->getNotificationFilters(); | |
$responseHtml .= 'Index: ', $index,' Id: ', $monetaryAccount->getId(), ' Filters: ','<br/>'; | |
$responseHtml .= '<b>Created filter:</b>', '<br/>'; | |
$responseHtml .= 'Category: ', $filters[0]->getCategory(), '<br/>'; | |
$responseHtml .= 'URL: ', $filters[0]->getNotificationTarget(); | |
} | |
$index++; | |
} | |
return new Response($responseHtml); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment