CreateStripeCustomerTask   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 15 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
class CreateStripeCustomerTask extends Task
17
{
18
19
    public $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        $email
33
     * @param string $description
34
     *
35
     * @return  array stripe customer object
36
     */
37
    public function run($email, $description = '')
38
    {
39
        try {
40
41
            $response = $this->stripe->customers()->create([
42
                'email'       => $email,
43
                'description' => $description,
44
            ]);
45
46
        } catch (Exception $e) {
47
            throw (new StripeApiErrorException('Stripe API error (createCustomer)'))->debug($e->getMessage(), true);
48
        }
49
50
        return $response;
51
    }
52
53
}
54