ChargeSubscription::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 8
rs 10
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
}
35