Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#33 bunq response #34

Merged
merged 4 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/api_context_save_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* You can also run `vendor/bin/bunq-install` from your command line.
*/
const API_KEY = '### Your API key ###'; // Insert your API key here.
const API_KEY = '### YOUR_API_KEY ###'; // Insert your API key here.
const DEVICE_DESCRIPTION = 'Server 1';
const PERMITTED_IPS = [];

Expand Down
5 changes: 3 additions & 2 deletions example/attachment_public_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
];

// Create public attachment.
$attachmentPublicUuid = AttachmentPublic::create($apiContext, $attachmentPublicBytes, $attachmentPublicHeadersMap);
$attachmentPublicUuid = AttachmentPublic::create($apiContext, $attachmentPublicBytes, $attachmentPublicHeadersMap)
->getValue();

// Download the attachment again.
$attachmentFile = AttachmentPublicContent::listing($apiContext, $attachmentPublicUuid);
$attachmentFile = AttachmentPublicContent::listing($apiContext, $attachmentPublicUuid)->getValue();

file_put_contents(__DIR__ . FILENAME_RESULT_ATTACHMENT, $attachmentFile);
16 changes: 12 additions & 4 deletions example/card_encrypted_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@
// Restore the API context.
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();

$monetaryAccount = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank();
// Retrieve the active user.
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccount = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank();

$aliasList = $monetaryAccount->getAlias();
$monetaryAccountAlias = null;
Expand All @@ -55,10 +62,11 @@
];

// Create a new card for this user.
$cardId = CardDebit::create($apiContext, $cardDebitMap, $userId);
$cardId = CardDebit::create($apiContext, $cardDebitMap, $userId)->getValue();

// List all cards for this user.
$cards = Card::listing($apiContext, $userId);
/** @var Card[] $cards */
$cards = Card::listing($apiContext, $userId)->getValue();

// Print information for each card.
foreach ($cards as $card) {
Expand Down
11 changes: 8 additions & 3 deletions example/customer_statement_export_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
$apiContext = ApiContext::restore();

// Retrieve the active user.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
$monetaryAccountId = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank()->getId();
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccountId = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank()->getId();

$dateStart = date(FORMAT_DATE, time() - SECONDS_IN_WEEK);
$dateEnd = date(FORMAT_DATE);
Expand All @@ -48,7 +52,8 @@
];

// Create a new customer statement and retrieve it's id.
$customerStatementId = CustomerStatementExport::create($apiContext, $customerStatementMap, $userId, $monetaryAccountId);
$customerStatementId = CustomerStatementExport::create($apiContext, $customerStatementMap, $userId, $monetaryAccountId)
->getValue();

// Delete the customer statement.
CustomerStatementExport::delete($apiContext, $userId, $monetaryAccountId, $customerStatementId);
Expand Down
12 changes: 7 additions & 5 deletions example/monetary_account_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

// Retrieve the active user.
// You can store this id to quickly retrieve the user at any time.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve all monetary accounts of the active user.
$monetaryAccountList = MonetaryAccount::listing($apiContext, $userId);
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();

foreach ($monetaryAccountList as $monetaryAccount) {
printf($monetaryAccount->getMonetaryAccountBank()->getDescription() . PHP_EOL);
foreach ($monetaryAccounts as $monetaryAccount) {
echo $monetaryAccount->getMonetaryAccountBank()->getDescription() . PHP_EOL;
}
14 changes: 10 additions & 4 deletions example/payment_batch_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

// Retrieve the active user.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
$monetaryAccountId = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank()->getId();
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccountId = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank()->getId();

// Create a payments map.
$payments = [
Expand All @@ -48,10 +52,12 @@
];

// Create a new payment batch and retrieve it's id.
$paymentBatchId = PaymentBatch::create($apiContext, $payments, $userId, $monetaryAccountId);
$paymentBatchId = PaymentBatch::create($apiContext, $payments, $userId, $monetaryAccountId)->getValue();

// Retrieve all payments in the payment batch.
$payments = PaymentBatch::get($apiContext, $userId, $monetaryAccountId, $paymentBatchId)->getPayments();
/** @var PaymentBatch $paymentBatch */
$paymentBatch = PaymentBatch::get($apiContext, $userId, $monetaryAccountId, $paymentBatchId)->getValue();
$payments = $paymentBatch->getPayments();

// Print the recipient's name and the description of the payment.
vprintf(
Expand Down
13 changes: 9 additions & 4 deletions example/payment_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
$apiContext = ApiContext::restore(FILENAME_BUNQ_CONFIG);

// Retrieve the active user.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
$monetaryAccountId = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank()->getId();
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccountId = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank()->getId();

// Create a payment map.
$paymentMap = [
Expand All @@ -47,9 +51,10 @@
];

// Create a new payment and retrieve it's id.
$paymentId = Payment::create($apiContext, $paymentMap, $userId, $monetaryAccountId);
$paymentId = Payment::create($apiContext, $paymentMap, $userId, $monetaryAccountId)->getValue();

// Retrieve the payment.
$payment = Payment::get($apiContext, $userId, $monetaryAccountId, $paymentId);
/** @var Payment $payment */
$payment = Payment::get($apiContext, $userId, $monetaryAccountId, $paymentId)->getValue();

vprintf(MESSAGE_MONETARY_ACCOUNT_NAME, [$payment->getAlias()->getDisplayName()]);
26 changes: 18 additions & 8 deletions example/request_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,23 @@
const STATUS_REVOKED = 'REVOKED';
const MESSAGE_REQUEST_STATUS = 'Request status: "%s".' . PHP_EOL;

/**
* The first index in an array.
*/
const INDEX_FIRST = 0;

// Restore the API context.
$apiContext = ApiContext::restore(FILENAME_BUNQ_CONFIG);

// Retrieve the active user.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
$monetaryAccountId = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank()->getId();
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccountId = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank()->getId();

$requestMap = [
RequestInquiry::FIELD_AMOUNT_INQUIRED => new Amount(REQUEST_AMOUNT, CURRENCY_EUR),
Expand All @@ -42,24 +51,25 @@
RequestInquiry::FIELD_ALLOW_BUNQME => true,
];

$requestInquiryUpdated = RequestInquiry::create($apiContext, $requestMap, $userId, $monetaryAccountId);
$requestInquiryUpdatedId = RequestInquiry::create($apiContext, $requestMap, $userId, $monetaryAccountId)->getValue();

$request = RequestInquiry::get($apiContext, $userId, $monetaryAccountId, $requestInquiryUpdated);
/** @var RequestInquiry $request */
$request = RequestInquiry::get($apiContext, $userId, $monetaryAccountId, $requestInquiryUpdatedId)->getValue();

vprintf(MESSAGE_REQUEST_STATUS, [$request->getStatus()]);

$requestMapUpdate = [
RequestInquiry::FIELD_STATUS => STATUS_REVOKED,
];

$requestInquiryUpdated = RequestInquiry::update(
$requestInquiryUpdatedId = RequestInquiry::update(
$apiContext,
$requestMapUpdate,
$userId,
$monetaryAccountId,
$requestInquiryUpdated
);
$requestInquiryUpdatedId
)->getValue();

$request = RequestInquiry::get($apiContext, $userId, $monetaryAccountId, $requestInquiryUpdated->getId());
$request = RequestInquiry::get($apiContext, $userId, $monetaryAccountId, $requestInquiryUpdatedId->getId())->getValue();

vprintf(MESSAGE_REQUEST_STATUS, [$request->getStatus()]);
24 changes: 14 additions & 10 deletions example/tab_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

// Retrieve the active user.
// You can store this id to quickly retrieve the user at any time.
$userId = User::listing($apiContext)[INDEX_FIRST]->getUserCompany()->getId();
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$userId = $users[INDEX_FIRST]->getUserCompany()->getId();

// Retrieve the first monetary account of the active user.
$monetaryAccountId = MonetaryAccount::listing($apiContext, $userId)[INDEX_FIRST]->getMonetaryAccountBank()->getId();
/** @var MonetaryAccount[] $monetaryAccounts */
$monetaryAccounts = MonetaryAccount::listing($apiContext, $userId)->getValue();
$monetaryAccountId = $monetaryAccounts[INDEX_FIRST]->getMonetaryAccountBank()->getId();

$attachmentPublicBytes = file_get_contents(__DIR__ . ATTACHMENT_FILENAME);
$requestHeadersMap = [
Expand All @@ -86,14 +89,14 @@


// Create a new public attachment.
$attachmentPublicUuid = AttachmentPublic::create($apiContext, $attachmentPublicBytes, $requestHeadersMap);
$attachmentPublicUuid = AttachmentPublic::create($apiContext, $attachmentPublicBytes, $requestHeadersMap)->getValue();

$attachmentPublicUuidMap = [
Avatar::FIELD_ATTACHMENT_PUBLIC_UUID => $attachmentPublicUuid,
];

// Create a new avatar using the public attachment.
$avatarUuid = Avatar::create($apiContext, $attachmentPublicUuidMap);
$avatarUuid = Avatar::create($apiContext, $attachmentPublicUuidMap)->getValue();

$geoLocation = new Geolocation();
$geoLocation->setAltitude(GEOLOCATION_ALTITUDE);
Expand All @@ -108,7 +111,7 @@
CashRegister::FIELD_STATUS => CASH_REGISTER_STATUS_PENDING_APPROVAL,
];

$cashRegisterId = CashRegister::create($apiContext, $cashRegisterMap, $userId, $monetaryAccountId);
$cashRegisterId = CashRegister::create($apiContext, $cashRegisterMap, $userId, $monetaryAccountId)->getValue();

$attachmentTabBytes = file_get_contents(__DIR__ . ATTACHMENT_FILENAME);
$requestHeadersMap = [
Expand All @@ -122,7 +125,7 @@
$userId,
$monetaryAccountId,
$requestHeadersMap
);
)->getValue();

$tabUsageSingleMap = [
TabUsageSingle::FIELD_DESCRIPTION => TAB_USAGE_SINGLE_DESCRIPTION,
Expand All @@ -139,7 +142,7 @@
$userId,
$monetaryAccountId,
$cashRegisterId
);
)->getValue();

$tabItemMap = [
TabItemShop::FIELD_DESCRIPTION => TAB_ITEM_DESCRIPTION,
Expand All @@ -153,7 +156,7 @@
$monetaryAccountId,
$cashRegisterId,
$tabUsageSingleUuid
);
)->getValue();

$tabUsageSingleMap = [
TabUsageSingle::FIELD_STATUS => TAB_USAGE_SINGLE_STATUS_WAITING_FOR_PAYMENT,
Expand All @@ -169,7 +172,8 @@
$tabUsageSingleUuid
);

$tabUsageSingleArray = TabUsageSingle::listing($apiContext, $userId, $monetaryAccountId, $cashRegisterId);
/** @var TabUsageSingle[] $tabUsageSingleArray */
$tabUsageSingleArray = TabUsageSingle::listing($apiContext, $userId, $monetaryAccountId, $cashRegisterId)->getValue();

foreach ($tabUsageSingleArray as $tabUsageSingle) {
vprintf(
Expand Down
10 changes: 6 additions & 4 deletions example/user_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
// Restore tha API context
$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);

// Retrieve the user associated with this API key.
$user = User::listing($apiContext)[INDEX_FIRST]->getUserCompany();

// Retrieve the active user.
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$user = $users[INDEX_FIRST]->getUserCompany();
$userId = $user->getId();

// Update the publicly visible name of your company.
Expand All @@ -35,6 +36,7 @@
UserCompany::update($apiContext, $userCompanyMap, $userId);

// You can retrieve the UserCompany again with the id.
$userCompany = UserCompany::get($apiContext, $userId);
/** @var UserCompany $userCompany */
$userCompany = UserCompany::get($apiContext, $userId)->getValue();

vprintf(MESSAGE_USER_COMPANY_NICKNAME, [$userCompany->getPublicNickName()]);
3 changes: 2 additions & 1 deletion example/user_list_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
require_once __DIR__ . '/../vendor/autoload.php';

$apiContext = ApiContext::restore(ApiContext::FILENAME_CONFIG_DEFAULT);
$users = User::listing($apiContext);
/** @var User[] $users */
$users = User::listing($apiContext)->getValue();
$apiContext->save();

foreach ($users as $user) {
Expand Down
8 changes: 5 additions & 3 deletions src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ private function initializeInstallationContext()
{
$keyPairClient = KeyPair::generate();

/** @var Installation $installation */
$installation = Installation::create(
$this,
$keyPairClient->getPublicKey()->getKey()
);
)->getValue();

$this->installationContext = new InstallationContext(
$installation->getToken(),
Expand Down Expand Up @@ -145,8 +146,9 @@ private function registerDevice($description, array $permittedIps)
*/
private function initializeSessionContext()
{
$session = SessionServer::create($this);
$this->sessionContext = SessionContext::create($session);
/** @var SessionServer $sessionServer */
$sessionServer = SessionServer::create($this)->getValue();
$this->sessionContext = SessionContext::create($sessionServer);
}

/**
Expand Down
Loading