Issues (15)

src/Providers/StripePaymentProvider.php (5 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\StripeIntegration\Providers;
6
7
use Illuminate\Support\Traits\Conditionable;
8
use Illuminate\Support\Traits\Macroable;
9
use Laravel\Cashier\Exceptions\IncompletePayment;
10
use Laravel\Cashier\Payment;
11
use MichaelRubel\StripeIntegration\Behaviors\ConfiguresCashier;
12
use MichaelRubel\StripeIntegration\Behaviors\ManagesPaymentIntents;
13
use MichaelRubel\StripeIntegration\Behaviors\PreparesPaymentMethods;
14
use MichaelRubel\StripeIntegration\DataTransferObjects\OffsessionChargeData;
15
use MichaelRubel\StripeIntegration\DataTransferObjects\PaymentIntentData;
16
use MichaelRubel\StripeIntegration\DataTransferObjects\StripeChargeData;
17
use Stripe\Exception\ApiErrorException;
18
use Stripe\PaymentIntent;
19
use Stripe\StripeClient;
20
21
class StripePaymentProvider
22
{
23
    /** @extendability */
24
    use Conditionable, Macroable;
0 ignored issues
show
The trait Illuminate\Support\Traits\Macroable requires the property $name which is not provided by MichaelRubel\StripeInteg...s\StripePaymentProvider.
Loading history...
25
26
    /** @behaviors */
27
    use ConfiguresCashier,
0 ignored issues
show
The trait MichaelRubel\StripeInteg...s\ManagesPaymentIntents requires some properties which are not provided by MichaelRubel\StripeInteg...s\StripePaymentProvider: $model, $paymentIntents, $params, $paymentAmount, $options, $id, $paymentIntent, $intentId
Loading history...
The trait MichaelRubel\StripeInteg...\PreparesPaymentMethods requires some properties which are not provided by MichaelRubel\StripeInteg...s\StripePaymentProvider: $paymentMethod, $params, $paymentMethods, $options, $id, $customer
Loading history...
28
        ManagesPaymentIntents,
29
        PreparesPaymentMethods;
30
31
    /**
32
     * @param  StripeClient  $stripeClient
33
     *
34
     * @return void
35
     */
36 17
    public function __construct(
37
        public StripeClient $stripeClient
38
    ) {
39 17
    }
40
41
    /**
42
     * Perform a simple charge.
43
     *
44
     * @param  StripeChargeData  $data
45
     *
46
     * @return Payment
47
     * @throws IncompletePayment
48
     */
49 3
    public function charge(StripeChargeData $data): Payment
50
    {
51 3
        return call($data->model)->charge(
52 3
            $data->paymentAmount->getAmount(),
53 3
            $data->paymentMethod->id,
54 3
            $data->options,
55 3
        );
56
    }
57
58
    /**
59
     * Perform an "off-session" charge.
60
     *
61
     * @param  OffsessionChargeData  $data
62
     *
63
     * @return PaymentIntent
64
     * @throws ApiErrorException
65
     */
66 2
    public function offsessionCharge(OffsessionChargeData $data): PaymentIntent
67
    {
68 2
        $paymentIntent = $this->createPaymentIntent(new PaymentIntentData(
69 2
            paymentAmount: $data->paymentAmount,
70 2
            model: $data->model,
71 2
            params: $data->intentParams,
72 2
            options: $data->intentOptions,
73 2
        ));
74
75 2
        $confirmationParams = collect(['payment_method' => call($data->model)->defaultPaymentMethod()?->id])
0 ignored issues
show
array('payment_method' =...ultPaymentMethod()->id) 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

75
        $confirmationParams = collect(/** @scrutinizer ignore-type */ ['payment_method' => call($data->model)->defaultPaymentMethod()?->id])
Loading history...
76 2
            ->merge($data->confirmationParams)
0 ignored issues
show
$data->confirmationParams 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

76
            ->merge(/** @scrutinizer ignore-type */ $data->confirmationParams)
Loading history...
77 2
            ->toArray();
78
79 2
        return $this->confirmPaymentIntent(new PaymentIntentData(
80 2
            paymentIntent: $paymentIntent,
81 2
            params: $confirmationParams,
82 2
            options: $data->confirmationOptions,
83 2
        ));
84
    }
85
}
86