Improve bunq import for #1857

This commit is contained in:
James Cole
2018-11-23 08:31:58 +01:00
parent 886d05d436
commit 344742c493
2 changed files with 62 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ use bunq\Model\Generated\Endpoint\MonetaryAccount as BunqMonetaryAccount;
use bunq\Model\Generated\Endpoint\MonetaryAccountBank;
use bunq\Model\Generated\Endpoint\MonetaryAccountJoint;
use bunq\Model\Generated\Endpoint\MonetaryAccountLight;
use bunq\Model\Generated\Endpoint\MonetaryAccountSavings;
use bunq\Model\Generated\Object\CoOwner;
use bunq\Model\Generated\Object\Pointer;
use FireflyIII\Exceptions\FireflyException;
@@ -122,6 +123,11 @@ class StageNewHandler
/** @var MonetaryAccountLight $object */
$array = $this->processMal($object);
break;
case MonetaryAccountSavings::class;
/** @var MonetaryAccountSavings $object */
$array = $this->processMas($object);
break;
break;
default:
// @codeCoverageIgnoreStart
throw new FireflyException(sprintf('Bunq import routine cannot handle account of type "%s".', \get_class($object)));
@@ -279,6 +285,52 @@ class StageNewHandler
return $return;
}
/**
* @param MonetaryAccountSavings $object
*
* @return array
*/
private function processMas(MonetaryAccountSavings $object): array
{
$setting = $object->getSetting();
$return = [
'id' => $object->getId(),
'currency_code' => $object->getCurrency(),
'description' => $object->getDescription(),
'balance' => $object->getBalance(),
'status' => $object->getStatus(),
'type' => 'MonetaryAccountSavings',
'aliases' => [],
'savingsGoal' => [],
];
if (null !== $setting) {
$return['settings'] = [
'color' => $object->getSetting()->getColor(),
'default_avatar_status' => $object->getSetting()->getDefaultAvatarStatus(),
'restriction_chat' => $object->getSetting()->getRestrictionChat(),
];
}
if (null !== $object->getAlias()) {
/** @var Pointer $alias */
foreach ($object->getAlias() as $alias) {
$return['aliases'][] = [
'type' => $alias->getType(),
'name' => $alias->getName(),
'value' => $alias->getValue(),
];
}
}
$goal = $object->getSavingsGoal();
$return['savingsGoal'] = [
'currency' => $goal->getCurrency(),
'value' => $goal->getValue(),
'percentage' => $object->getSavingsGoalProgress(),
];
return $return;
}
/**
* Basic report method.
*