michael-rubel /
laravel-stripe-integration
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace MichaelRubel\StripeIntegration\Behaviors; |
||||||
| 6 | |||||||
| 7 | use Illuminate\Database\Eloquent\Model; |
||||||
| 8 | use Illuminate\Support\Collection; |
||||||
| 9 | use MichaelRubel\StripeIntegration\DataTransferObjects\PaymentIntentData; |
||||||
| 10 | use Stripe\PaymentIntent; |
||||||
| 11 | use Stripe\SetupIntent; |
||||||
| 12 | |||||||
| 13 | trait ManagesPaymentIntents |
||||||
| 14 | { |
||||||
| 15 | /** |
||||||
| 16 | * Create the Stripe Setup Intent. |
||||||
| 17 | * |
||||||
| 18 | * @param Model $model |
||||||
| 19 | * @param array $options |
||||||
| 20 | * |
||||||
| 21 | * @return SetupIntent |
||||||
| 22 | */ |
||||||
| 23 | 1 | public function setupIntentUsing(Model $model, array $options = []): SetupIntent |
|||||
| 24 | { |
||||||
| 25 | 1 | $options = collect(['usage' => 'off_session']) |
|||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 26 | 1 | ->merge($options) |
|||||
|
0 ignored issues
–
show
$options 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
Loading history...
|
|||||||
| 27 | 1 | ->toArray(); |
|||||
| 28 | |||||||
| 29 | 1 | return call($model)->createSetupIntent($options); |
|||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | /** |
||||||
| 33 | * Create a payment intent. |
||||||
| 34 | * |
||||||
| 35 | * @param PaymentIntentData $data |
||||||
| 36 | * |
||||||
| 37 | * @return PaymentIntent |
||||||
| 38 | */ |
||||||
| 39 | 3 | public function createPaymentIntent(PaymentIntentData $data): PaymentIntent |
|||||
| 40 | { |
||||||
| 41 | 3 | $initialParams = [ |
|||||
| 42 | 3 | 'amount' => $data->paymentAmount?->getAmount(), |
|||||
| 43 | 3 | 'currency' => $data->paymentAmount?->getCurrency()->getCode(), |
|||||
| 44 | 3 | 'payment_method_types' => ['card'], |
|||||
| 45 | 3 | ]; |
|||||
| 46 | |||||||
| 47 | 3 | $intentParams = collect($initialParams) |
|||||
|
0 ignored issues
–
show
$initialParams of type array<string,array<integ...string>|integer|string> is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | 3 | ->when($data->model?->stripeId(), function (Collection $params) use ($data) { |
|||||
| 49 | 1 | return $params->merge(['customer' => $data->model->stripeId()]); |
|||||
|
0 ignored issues
–
show
The method
stripeId() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
array('customer' => $data->model->stripeId()) of type array<string,Illuminate\...oughRelationship|mixed> 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
Loading history...
|
|||||||
| 50 | 3 | }) |
|||||
| 51 | 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
Loading history...
|
|||||||
| 52 | 3 | ->toArray(); |
|||||
| 53 | |||||||
| 54 | 3 | return call($this->stripeClient->paymentIntents)->create($intentParams, $data->options); |
|||||
| 55 | } |
||||||
| 56 | |||||||
| 57 | /** |
||||||
| 58 | * Update the payment intent. |
||||||
| 59 | * |
||||||
| 60 | * @param PaymentIntentData $data |
||||||
| 61 | * |
||||||
| 62 | * @return PaymentIntent |
||||||
| 63 | */ |
||||||
| 64 | 1 | public function updatePaymentIntent(PaymentIntentData $data): PaymentIntent |
|||||
| 65 | { |
||||||
| 66 | 1 | $updateIntentParams = collect($data->params) |
|||||
|
0 ignored issues
–
show
$data->params of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 67 | 1 | ->when($data->model?->stripeId(), function (Collection $params) use ($data) { |
|||||
| 68 | 1 | return $params->merge(['customer' => $data->model->stripeId()]); |
|||||
|
0 ignored issues
–
show
array('customer' => $data->model->stripeId()) of type array<string,Illuminate\...oughRelationship|mixed> 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
Loading history...
|
|||||||
| 69 | 1 | }) |
|||||
| 70 | 1 | ->toArray(); |
|||||
| 71 | |||||||
| 72 | 1 | return call($this->stripeClient->paymentIntents)->update( |
|||||
| 73 | 1 | $data->intentId, $updateIntentParams, $data->options, |
|||||
| 74 | 1 | ); |
|||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | /** |
||||||
| 78 | * Retrieve the payment intent. |
||||||
| 79 | * |
||||||
| 80 | * @param PaymentIntentData $data |
||||||
| 81 | * |
||||||
| 82 | * @return PaymentIntent |
||||||
| 83 | */ |
||||||
| 84 | 1 | public function retrievePaymentIntent(PaymentIntentData $data): PaymentIntent |
|||||
| 85 | { |
||||||
| 86 | 1 | return call($this->stripeClient->paymentIntents)->retrieve( |
|||||
| 87 | 1 | $data->intentId, $data->params, $data->options, |
|||||
| 88 | 1 | ); |
|||||
| 89 | } |
||||||
| 90 | |||||||
| 91 | /** |
||||||
| 92 | * Confirm the payment intent. |
||||||
| 93 | * |
||||||
| 94 | * @param PaymentIntentData $data |
||||||
| 95 | * |
||||||
| 96 | * @return PaymentIntent |
||||||
| 97 | */ |
||||||
| 98 | 3 | public function confirmPaymentIntent(PaymentIntentData $data): PaymentIntent |
|||||
| 99 | { |
||||||
| 100 | 3 | return call($this->stripeClient->paymentIntents)->confirm( |
|||||
| 101 | 3 | $data->paymentIntent->id ?? $data->intentId, $data->params, $data->options, |
|||||
| 102 | 3 | ); |
|||||
| 103 | } |
||||||
| 104 | } |
||||||
| 105 |