1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace MichaelRubel\StripeIntegration\Behaviors; |
||||
6 | |||||
7 | use Illuminate\Database\Eloquent\Model; |
||||
8 | use Laravel\Cashier\PaymentMethod as CashierPaymentMethod; |
||||
9 | use MichaelRubel\StripeIntegration\DataTransferObjects\PaymentMethodAttachmentData; |
||||
10 | use Stripe\Customer; |
||||
11 | use Stripe\PaymentMethod; |
||||
12 | |||||
13 | trait PreparesPaymentMethods |
||||
14 | { |
||||
15 | /** |
||||
16 | * Prepare the customer. |
||||
17 | * |
||||
18 | * @param Model $model |
||||
19 | * |
||||
20 | * @return Customer |
||||
21 | */ |
||||
22 | 3 | public function makeCustomerUsing(Model $model): Customer |
|||
23 | { |
||||
24 | 3 | return call($model)->createOrGetStripeCustomer(); |
|||
25 | } |
||||
26 | |||||
27 | /** |
||||
28 | * Update a default payment method. |
||||
29 | * |
||||
30 | * @param Model $model |
||||
31 | * @param PaymentMethod|string $paymentMethod |
||||
32 | * |
||||
33 | * @return CashierPaymentMethod|null |
||||
34 | */ |
||||
35 | 5 | public function setPaymentMethodFor(Model $model, PaymentMethod|string $paymentMethod): ?CashierPaymentMethod |
|||
36 | { |
||||
37 | 5 | return call($model)->updateDefaultPaymentMethod($paymentMethod); |
|||
38 | } |
||||
39 | |||||
40 | /** |
||||
41 | * Attach the payment method to the customer. |
||||
42 | * |
||||
43 | * @param PaymentMethodAttachmentData $data |
||||
44 | * |
||||
45 | * @return PaymentMethod |
||||
46 | */ |
||||
47 | 3 | public function attachPaymentMethodToCustomer(PaymentMethodAttachmentData $data): PaymentMethod |
|||
48 | { |
||||
49 | 3 | $params = collect(['customer' => $data->customer->id]) |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
50 | 3 | ->merge($data->params) |
|||
0 ignored issues
–
show
$data->params of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $items of Illuminate\Support\Collection::merge() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
51 | 3 | ->toArray(); |
|||
52 | |||||
53 | 3 | return call($this->stripeClient->paymentMethods)->attach( |
|||
54 | 3 | $data->paymentMethod->id, $params, $data->options |
|||
55 | 3 | ); |
|||
56 | } |
||||
57 | } |
||||
58 |