Test Failed
Pull Request — master (#40)
by Бабичев
03:32
created

CanPay::paid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Bavix\Wallet\Traits;
4
5
use Bavix\Wallet\Exceptions\ProductEnded;
6
use Bavix\Wallet\Interfaces\Product;
7
use Bavix\Wallet\Models\Transfer;
8
use Bavix\Wallet\Objects\Cart;
9
use Illuminate\Database\Eloquent\Model;
10
use Illuminate\Database\Eloquent\ModelNotFoundException;
11
use Illuminate\Support\Facades\DB;
12
13
trait CanPay
14
{
15
16
    use HasWallet;
17
    use CartPay;
18
19
    /**
20
     * @param Product $product
21 2
     * @return Transfer
22
     */
23 2
    public function payFree(Product $product): Transfer
24 1
    {
25
        return \current($this->payFreeCart(Cart::make()->addItem($product)));
26
    }
27 2
28 2
    /**
29 2
     * @param Product $product
30 2
     * @param bool $force
31 2
     * @return Transfer|null
32
     */
33
    public function safePay(Product $product, bool $force = null): ?Transfer
34
    {
35
        try {
36
            return $this->pay($product, $force);
37
        } catch (\Throwable $throwable) {
38
            return null;
39
        }
40 1
    }
41
42
    /**
43 1
     * @param Product $product
44 1
     * @param bool $force
45 1
     * @return Transfer
46
     * @throws
47
     */
48
    public function pay(Product $product, bool $force = null): Transfer
49
    {
50
        return \current($this->payCart(Cart::make()->addItem($product), $force));
51
    }
52
53
    /**
54
     * @param Product $product
55 6
     * @return Transfer
56
     * @throws
57 6
     */
58 2
    public function forcePay(Product $product): Transfer
59
    {
60
        return \current($this->forcePayCart(Cart::make()->addItem($product)));
61 6
    }
62 1
63 1
    /**
64 1
     * @param Product $product
65 1
     * @param bool $force
66 1
     * @param bool $gifts
67
     * @return bool
68
     */
69
    public function safeRefund(Product $product, bool $force = null, bool $gifts = null): bool
70 5
    {
71 5
        return $this->safeRefundCart(Cart::make()->addItem($product), $force, $gifts);
72 5
    }
73 5
74 5
    /**
75
     * @param Product $product
76
     * @param bool $force
77
     * @param bool $gifts
78
     * @return bool
79
     * @throws
80
     */
81
    public function refund(Product $product, bool $force = null, bool $gifts = null): bool
82
    {
83 1
        return $this->refundCart(Cart::make()->addItem($product), $force, $gifts);
84
    }
85 1
86
    /**
87
     * @param Product $product
88
     * @param bool $gifts
89
     * @return bool
90
     * @throws
91
     */
92
    public function forceRefund(Product $product, bool $gifts = null): bool
93
    {
94 3
        return $this->forceRefundCart(Cart::make()->addItem($product), $gifts);
95
    }
96
97 3
    /**
98 3
     * @param Product $product
99 3
     * @param bool $force
100
     * @return bool
101
     */
102
    public function safeRefundGift(Product $product, bool $force = null): bool
103
    {
104
        return $this->safeRefundGiftCart(Cart::make()->addItem($product), $force);
105
    }
106
107
    /**
108
     * @param Product $product
109
     * @param bool $force
110 5
     * @return bool
111
     * @throws
112 5
     */
113
    public function refundGift(Product $product, bool $force = null): bool
114 5
    {
115 2
        return $this->refundGiftCart(Cart::make()->addItem($product), $force);
116 2
    }
117
118
    /**
119
     * @param Product $product
120 5
     * @return bool
121
     * @throws
122 5
     */
123 2
    public function forceRefundGift(Product $product): bool
124 2
    {
125 2
        return $this->forceRefundGiftCart(Cart::make()->addItem($product));
126 2
    }
127
128
}
129