Passed
Push — main ( cade56...9c07c4 )
by Michael
05:36 queued 02:40
created

ManagesPaymentIntents::retrievePaymentIntent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\StripeIntegration\Behaviors;
6
7
use Illuminate\Database\Eloquent\Model;
8
use MichaelRubel\StripeIntegration\DataTransferObjects\PaymentIntentData;
9
use Stripe\PaymentIntent;
10
use Stripe\SetupIntent;
11
12
trait ManagesPaymentIntents
13
{
14
    /**
15
     * Create the Stripe Setup Intent.
16
     *
17
     * @param  Model  $model
18
     * @param  array  $options
19
     *
20
     * @return SetupIntent
21
     */
22 1
    public function setupIntentUsing(Model $model, array $options = []): SetupIntent
23
    {
24 1
        $options = collect(['usage' => 'off_session'])
0 ignored issues
show
Bug introduced by
array('usage' => 'off_session') of type array<string,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 ignore-type  annotation

24
        $options = collect(/** @scrutinizer ignore-type */ ['usage' => 'off_session'])
Loading history...
25 1
            ->merge($options)
0 ignored issues
show
Bug introduced by
$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 ignore-type  annotation

25
            ->merge(/** @scrutinizer ignore-type */ $options)
Loading history...
26 1
            ->toArray();
27
28 1
        return call($model)->createSetupIntent($options);
29
    }
30
31
    /**
32
     * Create a payment intent.
33
     *
34
     * @param  PaymentIntentData  $data
35
     *
36
     * @return PaymentIntent
37
     */
38 2
    public function createPaymentIntent(PaymentIntentData $data): PaymentIntent
39
    {
40 2
        $makeIntentParams = collect([
0 ignored issues
show
Bug introduced by
array('amount' => $data-...ypes' => array('card')) 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 ignore-type  annotation

40
        $makeIntentParams = collect(/** @scrutinizer ignore-type */ [
Loading history...
41 2
            'amount'               => $data->paymentAmount?->getAmount(),
42 2
            'currency'             => $data->paymentAmount?->getCurrency()->getCode(),
43
            'payment_method_types' => ['card'],
44
        ])
45 2
        ->when($data->model?->stripeId(), fn ($params) => $params->merge([
46 1
            'customer' => $data->model?->stripeId(),
47
        ]))
48 2
        ->merge($data->params)
0 ignored issues
show
Bug introduced by
$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 ignore-type  annotation

48
        ->merge(/** @scrutinizer ignore-type */ $data->params)
Loading history...
49 2
        ->toArray();
50
51 2
        return call($this->stripeClient->paymentIntents)->create($makeIntentParams, $data->options);
52
    }
53
54
    /**
55
     * Update the payment intent.
56
     *
57
     * @param  PaymentIntentData  $data
58
     *
59
     * @return PaymentIntent
60
     */
61 1
    public function updatePaymentIntent(PaymentIntentData $data): PaymentIntent
62
    {
63 1
        $updateIntentParams = collect($data->params)
0 ignored issues
show
Bug introduced by
$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 ignore-type  annotation

63
        $updateIntentParams = collect(/** @scrutinizer ignore-type */ $data->params)
Loading history...
64 1
            ->when($data->model?->stripeId(), fn ($params) => $params->merge([
65 1
                'customer' => $data->model?->stripeId(),
66
            ]))
67 1
            ->toArray();
68
69 1
        return call($this->stripeClient->paymentIntents)->update(
70 1
            $data->intentId, $updateIntentParams, $data->options,
71
        );
72
    }
73
74
    /**
75
     * Retrieve the payment intent.
76
     *
77
     * @param  PaymentIntentData  $data
78
     *
79
     * @return PaymentIntent
80
     */
81 1
    public function retrievePaymentIntent(PaymentIntentData $data): PaymentIntent
82
    {
83 1
        return call($this->stripeClient->paymentIntents)->retrieve(
84 1
            $data->intentId, $data->params, $data->options,
85
        );
86
    }
87
88
    /**
89
     * Confirm the payment intent.
90
     *
91
     * @param  PaymentIntentData  $data
92
     *
93
     * @return PaymentIntent
94
     */
95 2
    public function confirmPaymentIntent(PaymentIntentData $data): PaymentIntent
96
    {
97 2
        return call($this->stripeClient->paymentIntents)->confirm(
98 2
            $data->paymentIntent?->id, $data->params, $data->options,
99
        );
100
    }
101
}
102