SubmitPaymentRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 7 2
A setPaymentData() 0 23 5
1
<?php
2
3
/**
4
 * PHP version 5.4 and 8
5
 *
6
 * @category  RequestEntity
7
 * @package   Payever\Payments
8
 * @author    payever GmbH <[email protected]>
9
 * @copyright 2017-2021 payever GmbH
10
 * @license   MIT <https://opensource.org/licenses/MIT>
11
 * @link      https://docs.payever.org/shopsystems/api/getting-started
12
 */
13
14
namespace Payever\ExternalIntegration\Payments\Http\RequestEntity;
15
16
use Payever\ExternalIntegration\Payments\Http\MessageEntity\CartItemEntity;
17
use Payever\ExternalIntegration\Payments\Http\MessageEntity\PaymentDataEntity;
18
19
/**
20
 * This class represents Create Payment RequestInterface Entity
21
 *
22
 * @method string                 getChannel()
23
 * @method integer                getChannelSetId()
24
 * @method float                  getAmount()
25
 * @method float                  getFee()
26
 * @method string                 getOrderId()
27
 * @method string                 getCurrency()
28
 * @method CartItemEntity[]       getCart()
29
 * @method PaymentDataEntity|null getPaymentData()
30
 * @method string                 getSalutation()
31
 * @method string                 getPaymentMethod()
32
 * @method string|null            getVariantId()
33
 * @method string                 getFirstName()
34
 * @method string                 getLastName()
35
 * @method string                 getStreet()
36
 * @method string                 getStreetNumber()
37
 * @method string                 getZip()
38
 * @method string                 getCity()
39
 * @method string                 getRegion()
40
 * @method string                 getCountry()
41
 * @method string                 getSocialSecurityNumber()
42
 * @method \DateTime|false        getBirthdate()
43
 * @method string                 getPhone()
44
 * @method string                 getEmail()
45
 * @method string                 getSuccessUrl()
46
 * @method string                 getFailureUrl()
47
 * @method string                 getCancelUrl()
48
 * @method string                 getNoticeUrl()
49
 * @method string                 getPendingUrl()
50
 * @method string                 getCustomerRedirectUrl()
51
 * @method string                 getXFrameHost()
52
 * @method string                 getPluginVersion()
53
 * @method self                   setChannel(string $channel)
54
 * @method self                   setChannelSetId(int $id)
55
 * @method self                   setAmount(float $amount)
56
 * @method self                   setFee(float $fee)
57
 * @method self                   setOrderId(string $id)
58
 * @method self                   setPaymentMethod(string $method)
59
 * @method self                   setVariantId(string|null $variantId)
60
 * @method self                   setCurrency(string $currency)
61
 * @method self                   setSalutation(string $salutation)
62
 * @method self                   setFirstName(string $name)
63
 * @method self                   setLastName(string $name)
64
 * @method self                   setStreet(string $street)
65
 * @method self                   setStreetNumber(string $streetNumber)
66
 * @method self                   setZip(string $zip)
67
 * @method self                   setCity(string $city)
68
 * @method self                   setRegion(string $region)
69
 * @method self                   setCountry(string $country)
70
 * @method self                   setSocialSecurityNumber(string $ssn)
71
 * @method self                   setPhone(string $phone)
72
 * @method self                   setEmail(string $email)
73
 * @method self                   setSuccessUrl(string $url)
74
 * @method self                   setFailureUrl(string $url)
75
 * @method self                   setCancelUrl(string $url)
76
 * @method self                   setNoticeUrl(string $url)
77
 * @method self                   setPendingUrl(string $url)
78
 * @method self                   setCustomerRedirectUrl(string $url)
79
 * @method self                   setXFrameHost(string $host)
80
 * @method self                   setPluginVersion(string $version)
81
 */
82
class SubmitPaymentRequest extends CreatePaymentRequest
83
{
84
    /** @var PaymentDataEntity $paymentData */
85
    protected $paymentData;
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function isValid()
91
    {
92
        if (!$this->paymentData instanceof PaymentDataEntity) {
0 ignored issues
show
introduced by
$this->paymentData is always a sub-type of Payever\ExternalIntegrat...ntity\PaymentDataEntity.
Loading history...
93
            return false;
94
        }
95
96
        return parent::isValid();
97
    }
98
99
    /**
100
     * Sets payment data
101
     *
102
     * @param PaymentDataEntity|array|string $paymentData
103
     *
104
     * @return $this
105
     */
106
    public function setPaymentData($paymentData)
107
    {
108
        if (!$paymentData) {
109
            return $this;
110
        }
111
112
        if ($paymentData instanceof PaymentDataEntity) {
113
            $this->paymentData = $paymentData;
114
115
            return $this;
116
        }
117
118
        if (is_string($paymentData)) {
119
            $paymentData = json_decode($paymentData, true);
120
        }
121
122
        if (!is_array($paymentData)) {
123
            return $this;
124
        }
125
126
        $this->paymentData = new PaymentDataEntity($paymentData);
127
128
        return $this;
129
    }
130
}
131