Passed
Push — master ( 19a915...d9efc8 )
by Gabriel
14:56
created

ChargeSubscription   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 13
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 2
1
<?php
2
3
namespace ByTIC\Payments\Actions\Subscriptions;
4
5
use ByTIC\Payments\Actions\Purchases\DuplicatePurchase;
6
use ByTIC\Payments\Actions\Subscriptions\Charges\CalculateNextCharge;
7
use ByTIC\Payments\Actions\Subscriptions\Charges\ChargedFailed;
8
use ByTIC\Payments\Actions\Transactions\ChargeWithToken;
9
use ByTIC\Payments\Actions\Transactions\CreateNewForSubscription;
10
use ByTIC\Payments\Models\Subscriptions\Subscription;
11
use ByTIC\Payments\Models\Tokens\Token;
12
use ByTIC\Payments\Subscriptions\Statuses\Active;
13
use ByTIC\Payments\Utility\PaymentsModels;
14
15
/**
16
 * Class ChargeSubscription
17
 * @package ByTIC\Payments\Actions\Subscriptions
18
 */
19
class ChargeSubscription
20
{
21
    /**
22
     * @param Subscription $subscription
23
     */
24
    public static function handle($subscription)
25
    {
26
        $transaction = CreateNewForSubscription::handle($subscription);
27
28
        try {
29
            ChargeWithToken::process($transaction);
30
        } catch (\Exception $exception) {
31
            ChargedFailed::handle($subscription);
32
        }
33
    }
34
}