Sale   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 95
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 24 2
A getTotal() 0 3 1
A __construct() 0 9 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: WilliamWard
5
 * Date: 8/6/2018
6
 * Time: 8:40 AM
7
 */
8
9
namespace GivePay\Gateway\Transactions;
10
11
final class Sale
12
{
13
    /**
14
     * @var int The total amount of the transactions
15
     */
16
    private $total;
17
18
    /**
19
     * @var string The type of terminal
20
     */
21
    private $terminal_type = 'com.givepay.terminal-types.ecommerce';
22
23
    /**
24
     * @var Address The billing address
25
     */
26
    private $billing_address;
27
28
    /**
29
     * @var string Billing email address
30
     */
31
    private $email;
32
33
    /**
34
     * @var string Billing phone
35
     */
36
    private $phone;
37
38
    /**
39
     * @var Card The card to used for this transaction
40
     */
41
    private $card;
42
43
    /**
44
     * @var Order The optional order information for the transaction
45
     */
46
    private $order;
47
48
    /**
49
     * Sale constructor.
50
     * @param int $total
51
     * @param string $terminal_type
52
     * @param Address $billing_address
53
     * @param string $email
54
     * @param string $phone
55
     * @param Card $card
56
     * @param Order $order Optional order information
57
     */
58 2
    public function __construct($total, $terminal_type, $billing_address, $email, $phone, $card, $order = null)
59
    {
60 2
        $this->total = $total;
61 2
        $this->terminal_type = $terminal_type;
62 2
        $this->billing_address = $billing_address;
63 2
        $this->email = $email;
64 2
        $this->phone = $phone;
65 2
        $this->card = $card;
66 2
        $this->order = $order;
67 2
    }
68
69
    /**
70
     * @param string $merchant_id
71
     * @param string $terminal_id
72
     * @return array
73
     */
74 1
    public function serialize($merchant_id, $terminal_id)
75
    {
76
        $sale_request = array(
77 1
            'mid' => $merchant_id,
78
            'terminal' => array(
79 1
                'tid' => $terminal_id,
80 1
                'terminal_type' => $this->terminal_type
81
            ),
82
            'amount' => array(
83 1
                'base_amount' => $this->getTotal()
84
            ),
85
            'payer' => array(
86 1
                'billing_address' => $this->billing_address->serialize(),
87 1
                'email_address' => $this->email,
88 1
                'phone_number' => $this->phone
89
            ),
90 1
            'card' => $this->card->serialize()
91
        );
92
93 1
        if (NULL != $this->order) {
94 1
            $sale_request['order'] = $this->order->serialize();
95
        }
96
97 1
        return $sale_request;
98
    }
99
100
    /**
101
     * @return int The total amount for the sale in cents
102
     */
103 1
    public function getTotal()
104
    {
105 1
        return intval(round($this->total * 100));
106
    }
107
}