Completed
Push — master ( 8e0025...04518a )
by
05:55
created

Charge   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreateData() 0 19 3
A getUpdateData() 0 7 1
A getRefunds() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhpMob\Omise\Domain;
13
14
use PhpMob\Omise\Country;
15
use PhpMob\Omise\Currency;
16
use PhpMob\Omise\Exception\InvalidRequestArgumentException;
17
use PhpMob\Omise\Model;
18
19
/**
20
 * @author Ishmael Doss <[email protected]>
21
 *
22
 *
23
 * @property string id
24
 * @property string object
25
 * @property boolean livemode
26
 * @property string location
27
 * @property string status
28
 * @property integer amount
29
 * @property string currency
30
 * @property string description
31
 * @property string metadata
32
 * @property boolean capture
33
 * @property boolean authorized
34
 * @property boolean reversed
35
 * @property boolean paid
36
 * @property string transaction
37
 * @property Card card
38
 * @property integer refunded
39
 * @property Pagination refunds
40
 * @property string failureCode
41
 * @property string failureMessage
42
 * @property Customer customer
43
 * @property string ip
44
 * @property Dispute dispute
45
 * @property string created
46
 * @property string returnUri
47
 * @property string authorizeUri
48
 *
49
 * @method static Pagination all(array $parameters = [])
50
 * @method static Charge find($id)
51
 * @method void refresh()
52
 * @method void update()
53
 * @method void capture()
54
 * @method void reverse()
55
 * @method void create()
56
 * @method void createUsingToken()
57
 * @method void createUsingCustomer()
58
 * @method void createUsingCustomerAndCard()
59
 */
60
class Charge extends Model
61
{
62
    /**
63
     * @var string
64
     */
65
    public $cardToken;
66
67
    /**
68
     * @param string $countryCode
69
     *
70
     * @return array
71
     */
72
    public function getCreateData($countryCode = Country::TH)
73
    {
74
        if (!in_array($this->currency, Currency::getSupporteds($countryCode))) {
75
            throw new InvalidRequestArgumentException(
76
                sprintf("The currency `%s` is not supported in your country `%s`.", $this->currency, $countryCode)
77
            );
78
        }
79
80
        return [
81
            'customer' => $this->customer ? $this->customer->id : null,
82
            'card' => $this->cardToken,
83
            'amount' => $this->amount,
84
            'currency' => $this->currency,
85
            'description' => $this->description,
86
            'metadata' => $this->metadata,
87
            'capture' => $this->capture,
88
            'return_uri' => $this->returnUri,
89
        ];
90
    }
91
92
    /**
93
     * @return array
94
     */
95
    public function getUpdateData()
96
    {
97
        return [
98
            'description' => $this->description,
99
            'metadata' => $this->metadata,
100
        ];
101
    }
102
103
    /**
104
     * @return array|Refund[]
105
     */
106
    public function getRefunds()
107
    {
108
        if (count($this->refunds)) {
109
            return $this->refunds->data;
110
        }
111
112
        return [];
113
    }
114
}
115