1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Ninja/Repositories/CustomerRepository.php

43 lines
1023 B
PHP
Raw Normal View History

<?php
namespace App\Ninja\Repositories;
use App\Models\PaymentMethod;
use App\Models\AccountGatewayToken;
use DB;
class CustomerRepository extends BaseRepository
{
public function getClassName()
{
return 'App\Models\AccountGatewayToken';
}
public function all()
{
return AccountGatewayToken::whereAccountId(auth()->user()->account_id)
->with(['contact'])
->get();
}
public function save($data)
{
$account = auth()->user()->account;
$customer = new AccountGatewayToken();
$customer->account_id = $account->id;
$customer->fill($data);
$customer->save();
$paymentMethod = PaymentMethod::createNew();
$paymentMethod->account_gateway_token_id = $customer->id;
$paymentMethod->fill($data['payment_method']);
$paymentMethod->save();
$customer->default_payment_method_id = $paymentMethod->id;
$customer->save();
return $customer;
}
}