Completed
Push — master ( 27c102...e85ee7 )
by Haralan
03:23 queued 01:27
created

AbstractRequest::getServer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Omnipay\PaypalRest\Message;
4
5
/**
6
 * @author    Ivan Kerin <[email protected]>
7
 * @copyright 2014, Clippings Ltd.
8
 * @license   http://spdx.org/licenses/BSD-3-Clause
9
 */
10
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
11
{
12
    const LIVE = 'https://api.paypal.com/v1';
13
    const SANDBOX = 'https://api.sandbox.paypal.com/v1';
14
15
    /**
16
     * @return string
17
     */
18
    public function getServer()
19
    {
20
        return $this->getTestMode() ? self::SANDBOX : self::LIVE;
21
    }
22
23
    /**
24
     * Requires a valid "card" parameter
25
     *
26
     * @return array
27
     */
28
    public function getPaypalCard()
29
    {
30
        $this->validate('card');
31
32
        $card = $this->getCard();
33
        $card->validate();
34
35
        return array_filter(array(
36
            'number' => $card->getNumber(),
37
            'type' => $card->getBrand(),
38
            'expire_month' => $card->getExpiryMonth(),
39
            'expire_year' => $card->getExpiryYear(),
40
            'cvv2' => $card->getCvv(),
41
            'first_name' => $card->getFirstName(),
42
            'last_name' => $card->getLastName(),
43
            'billing_address' => array_filter(array(
44
                'line1' => $card->getAddress1(),
45
                'line2' => $card->getAddress2(),
46
                'city' => $card->getCity(),
47
                'state' => $card->getState(),
48
                'postal_code' => $card->getPostcode(),
49
                'country_code' => strtoupper($card->getCountry()),
50
            ))
51
        ));
52
    }
53
}
54