-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManagesCustomer.php
81 lines (67 loc) · 1.89 KB
/
ManagesCustomer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Mosaiqo\LaravelPayments\Concerns;
use Mosaiqo\LaravelPayments\ApiClients\LemonSqueezyApiClient;
use Mosaiqo\LaravelPayments\LaravelPayments;
use Mosaiqo\LaravelPayments\Models\Customer;
trait ManagesCustomer
{
/**
* Get the customer related to the billable model.
*/
public function customer(): \Illuminate\Database\Eloquent\Relations\MorphOne
{
$model = LaravelPayments::resolveCustomerModel();
return $this->morphOne($model, 'billable');
}
/**
* Create a customer record for the billable model.
*/
public function createAsCustomer(array $attributes = []): Customer
{
LaravelPayments::checkProviderIsConfigured();
return $this->customer()->create($attributes);
}
public function customerPortalUrl(): ?string
{
if ($this->customer) {
$response = LaravelPayments::api()->getCustomer($this->customer->provider_id);
return $response['data']['attributes']['urls']['customer_portal'];
}
return null;
}
/**
* Get the billable's name to associate with Provider.
*/
public function customerName(): ?string
{
return $this->name ?? null;
}
/**
* Get the billable's email to associate with Provider.
*/
public function customerEmail(): ?string
{
return $this->email ?? null;
}
/**
* Get the billable's country to associate with Provider.
*/
public function customerCountry(): ?string
{
return $this->country ?? null;
}
/**
* Get the billable's zip to associate with Provider.
*/
public function customerZip(): ?string
{
return $this->zip ?? null;
}
/**
* Get the billable's tax_number to associate with Provider.
*/
public function customerTaxNumber(): ?string
{
return $this->tax_number ?? null;
}
}