CreateStripeCustomerTask::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
c 0
b 0
f 0
rs 9.7666
cc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Containers\Stripe\Tasks;
4
5
use App\Containers\Stripe\Exceptions\StripeApiErrorException;
6
use App\Ship\Parents\Tasks\Task;
7
use Cartalyst\Stripe\Stripe;
8
use Exception;
9
use Illuminate\Support\Facades\Config;
10
11
/**
12
 * Class CreateStripeCustomerTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16 View Code Duplication
class CreateStripeCustomerTask extends Task
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
19
    private $stripe;
20
21
    /**
22
     * StripeApi constructor.
23
     *
24
     * @param \Cartalyst\Stripe\Stripe $stripe
25
     */
26
    public function __construct(Stripe $stripe)
27
    {
28
        $this->stripe = $stripe->make(Config::get('services.stripe.secret'), Config::get('services.stripe.version'));
29
    }
30
31
    /**
32
     * @param string $email
33
     * @param string $description
34
     *
35
     * @return array stripe customer object
36
     * @throws StripeApiErrorException
37
     */
38
    public function run($email, $description = '')
39
    {
40
        try {
41
42
            $response = $this->stripe->customers()->create([
43
                'email'       => $email,
44
                'description' => $description,
45
            ]);
46
47
        } catch (Exception $e) {
48
            throw (new StripeApiErrorException('Stripe API error (createCustomer)'))->debug($e->getMessage(), true);
49
        }
50
51
        return $response;
52
    }
53
54
}
55