Skip to content
Open
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
33 changes: 33 additions & 0 deletions src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ public function charges(): Repositories\ChargeRepository
);
}

/**
* @return Repositories\CustomerRepository
*/
public function customers(): Repositories\CustomerRepository
{
return new Repositories\CustomerRepository(
app(Client::class),
$this->accountId()
);
}

/**
* @return Repositories\EventRepository
*/
Expand All @@ -99,6 +110,28 @@ public function events(): Repositories\EventRepository
);
}

/**
* @return Repositories\InvoiceRepository
*/
public function invoices(): Repositories\InvoiceRepository
{
return new Repositories\InvoiceRepository(
app(Client::class),
$this->accountId()
);
}

/**
* @return Repositories\InvoiceItemRepository
*/
public function invoiceItems(): Repositories\InvoiceItemRepository
{
return new Repositories\InvoiceItemRepository(
app(Client::class),
$this->accountId()
);
}

/**
* Create a payment intents client for the provided account.
*
Expand Down
57 changes: 57 additions & 0 deletions src/Repositories/CustomerRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright 2020 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\LaravelStripe\Repositories;

use CloudCreativity\LaravelStripe\Assert;
use Stripe\Customer;

class CustomerRepository extends AbstractRepository
{

use Concerns\All;
use Concerns\Retrieve;
use Concerns\Update;

/**
* Create a customer.
*
* @param iterable|array $params
* additional optional parameters.
* @return Customer
*/
public function create(iterable $params = []): Customer
{
$this->params($params);

return $this->send(
'create',
$this->params ?: null,
$this->options ?: null
);
}

/**
* @inheritDoc
*/
protected function fqn(): string
{
return Customer::class;
}
}
67 changes: 67 additions & 0 deletions src/Repositories/InvoiceItemRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright 2020 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\LaravelStripe\Repositories;

use CloudCreativity\LaravelStripe\Assert;
use Stripe\InvoiceItem;

class InvoiceItemRepository extends AbstractRepository
{

use Concerns\All;
use Concerns\Retrieve;
use Concerns\Update;

/**
* Create an invoice item.
*
* Only customer is a required parameter,
* currency and amount should be sent as parameter data.
*
* @param string $customer
* @param iterable|array $params
* additional optional parameters.
* @return InvoiceItem
*/
public function create(string $customer, iterable $params = []): InvoiceItem
{
if(isset($params['currency']) && isset($params['amount'])) {
Assert::chargeAmount($params['currency'], $params['amount']);
}

$this->params($params)->params(
compact('customer')
);

return $this->send(
'create',
$this->params ?: null,
$this->options ?: null
);
}

/**
* @inheritDoc
*/
protected function fqn(): string
{
return InvoiceItem::class;
}
}
80 changes: 80 additions & 0 deletions src/Repositories/InvoiceRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Copyright 2020 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\LaravelStripe\Repositories;

use CloudCreativity\LaravelStripe\Assert;
use Stripe\Invoice;

class InvoiceRepository extends AbstractRepository
{

use Concerns\All;
use Concerns\Retrieve;
use Concerns\Update;

/**
* Create an invoice.
*
* Only the customer is a required parameter.
*
* @param string $customer
* @param iterable|array $params
* additional optional parameters.
* @return Invoice
*/
public function create(string $customer, iterable $params = []): Invoice
{
$this->params($params)->params(
compact('customer')
);

return $this->send(
'create',
$this->params ?: null,
$this->options ?: null
);
}

/**
* Send an invoice to the customer.
*
* @param iterable|array $params
* additional optional parameters.
* @return Invoice
*/
public function sendInvoice(iterable $params = []): Invoice
{
$this->params($params);

return $this->send(
'sendInvoice',
$this->params ?: null,
$this->options ?: null
);
}

/**
* @inheritDoc
*/
protected function fqn(): string
{
return Invoice::class;
}
}