bank [id] => 103953585 [amount] => stdClass Object ( [amount] => 480.66 [currency] => USD ) [categoryType] => UNCATEGORIZE [categoryId] => 1 [category] => Uncategorized [categorySource] => SYSTEM [highLevelCategoryId] => 10000017 [createdDate] => 2022-08-04T21:50:17Z [lastUpdated] => 2022-08-04T21:50:17Z [description] => stdClass Object ( [original] => CHEROKEE NATION TAX TA TAHLEQUAH OK ) [isManual] => [sourceType] => AGGREGATED [date] => 2022-08-03 [transactionDate] => 2022-08-03 [postDate] => 2022-08-03 [status] => POSTED [accountId] => 12331794 [runningBalance] => stdClass Object ( [amount] => 480.66 [currency] => USD ) [checkNumber] => 998 ) */ class IncomeTransformer implements BankRevenueInterface { use AppSetup; public function transform($transaction) { $data = []; if(!property_exists($transaction, 'transaction')) return $data; foreach($transaction->transaction as $transaction) { $data[] = $this->transformTransaction($transaction); } return $data; } public function transformTransaction($transaction) { return [ 'transaction_id' => $transaction->id, 'amount' => $transaction->amount->amount, 'currency_id' => $this->convertCurrency($transaction->amount->currency), 'account_type' => $transaction->CONTAINER, 'category_id' => $transaction->highLevelCategoryId, 'category_type' => $transaction->categoryType, 'date' => $transaction->date, 'bank_account_id' => $transaction->accountId, 'description' => $transaction->description->original, 'base_type' => property_exists($transaction, 'baseType') ? $transaction->baseType : $this->calculateBaseType($transaction), ]; } private function calculateBaseType($transaction) { //CREDIT / DEBIT if(property_exists($transaction, 'highLevelCategoryId') && $transaction->highLevelCategoryId == 10000012) return 'CREDIT'; return 'DEBIT'; } private function convertCurrency(string $code) { $currencies = Cache::get('currencies'); if (! $currencies) { $this->buildCache(true); } $currency = $currencies->filter(function ($item) use($code){ return $item->code == $code; })->first(); if($currency) return $currency->id; return 1; } }