protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     if (!($primaryCreditor = $this->showPrimaryCreditor())) {
         $output->writeln("");
         $output->writeln("Please ensure the primary creditor is setup correctly before running this");
         return;
     }
     if (isset($primaryCreditor->toArray()['links']['default_gbp_payout_account'])) {
         $defaultGdpAccount = $primaryCreditor->toArray()['links']['default_gbp_payout_account'];
     } else {
         $defaultGdpAccount = false;
     }
     if ($defaultGdpAccount) {
         $output->writeln("");
         $output->writeln("This creditor has a default Gdp account set with Id '" . $defaultGdpAccount . "'");
         $output->writeln("");
         $output->writeln("Current account details");
         $account = $this->getGocardlessClient()->getCreditorBankAccount($defaultGdpAccount);
         $this->showCreditorBankAccount($account);
     } else {
         $output->writeln("");
         $output->writeln("This creditor does not have a default Gdp account set");
     }
     $output->writeln("");
     $continue = $this->ask(new ConfirmationQuestion('Would you like to create a new default account?'));
     if (!$continue) {
         return;
     }
     $accountNumber = $this->ask(new Question('Bank account number:'));
     $sortCode = $this->ask(new Question('Sort Code:'));
     $accountHolderName = $this->ask(new Question('Account holder name:'));
     $creditorBankAccount = new CreditorBankAccount();
     $creditorBankAccount->setAccountNumber($accountNumber);
     //55779922
     $creditorBankAccount->setSortCode($sortCode);
     //200000
     $creditorBankAccount->setAccountHolderName($accountHolderName);
     $creditorBankAccount->setCountryCode('GB');
     $creditorBankAccount->setCreditor($primaryCreditor);
     $newAccount = $this->getGocardlessClient()->createCreditorBankAccount($creditorBankAccount, true);
     $output->writeln("");
     $output->writeln("Details of the new account just created");
     $output->writeln("");
     $this->showCreditorBankAccount($newAccount);
     return;
 }
 /**
  * @param CreditorBankAccount $account
  * @param bool $setAsDefault
  * @return CreditorBankAccount
  */
 public function createCreditorBankAccount(CreditorBankAccount $account, $setAsDefault = false)
 {
     $response = $this->post(self::ENDPOINT_CREDITOR_BANK, ["set_as_default_payout_account" => $setAsDefault] + $account->toArray());
     $account->fromArray($response);
     return $account;
 }
 public function disableCreditorBankAccount($id)
 {
     $response = $this->post(self::ENDPOINT_CREDITOR_BANK, '', $id . '/actions/disable');
     $account = new CreditorBankAccount();
     $account->fromArray($response);
     return $account;
 }
 public function fromArray($data)
 {
     parent::fromArray($data);
     $this->setCreatedAt(new \DateTime($this->getCreatedAt()));
 }
 protected function showCreditorBankAccount(CreditorBankAccount $account)
 {
     $output = $this->output;
     $output->writeln("Creditor Bank Account Id: " . $account->getId());
     $output->writeln("Account holder name: " . $account->getAccountHolderName());
     $output->writeln("Account number ending: " . $account->getAccountNumberEnding());
     $output->writeln("Country code: " . $account->getCountryCode());
     $output->writeln("Currency: " . $account->getCurrency());
     $output->writeln("Bank Name: " . $account->getBankName());
     $output->writeln("------------");
 }