Passed
Pull Request — master (#43)
by
unknown
01:45
created

GetHostedPaymentPageRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace CommerceGuys\AuthNet;
4
5
use CommerceGuys\AuthNet\DataTypes\HostedPaymentSettings;
6
use CommerceGuys\AuthNet\DataTypes\TransactionRequest;
7
use CommerceGuys\AuthNet\Request\RequestInterface;
8
use GuzzleHttp\Client;
9
10
/**
11
 * Retrieves a token to launch the Accept Hosted payment form.
12
 *
13
 * @link https://developer.authorize.net/api/reference/index.html#accept-suite-get-an-accept-payment-page
14
 */
15
class GetHostedPaymentPageRequest extends BaseApiRequest
16
{
17
    /**
18
     * @var \CommerceGuys\AuthNet\DataTypes\TransactionRequest|null
19
     */
20
    protected $transactionRequest;
21
22
    /**
23
     * @var \CommerceGuys\AuthNet\DataTypes\HostedPaymentSettings|null;
24
     */
25
    protected $hostedPaymentSettings;
26
27
    /**
28
     * Constructs a new GetHostedPaymentPageRequest object.
29
     *
30
     * @param Configuration $configuration
31
     *   The configuration object containing API credentials.
32
     * @param Client $client
33
     *   The HTTP client for making requests.
34
     * @param \CommerceGuys\AuthNet\DataTypes\TransactionRequest|null $transactionRequest
35
     *   The transaction request details.
36
     * @param \CommerceGuys\AuthNet\DataTypes\HostedPaymentSettings|null $hostedPaymentSettings
37
     *   The settings for the Accept Hosted payment form.
38
     */
39
    public function __construct(
40
        Configuration $configuration,
41
        Client $client,
42
        TransactionRequest $transactionRequest = null,
43
        HostedPaymentSettings $hostedPaymentSettings = null
44
    ) {
45
        parent::__construct($configuration, $client);
46
        $this->transactionRequest = $transactionRequest;
47
        $this->hostedPaymentSettings = $hostedPaymentSettings;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function attachData(RequestInterface $request)
54
    {
55
        // Attach transaction details.
56
        if ($this->transactionRequest) {
57
            $request->addDataType($this->transactionRequest);
58
        }
59
        // Add hosted payment settings.
60
        if ($this->hostedPaymentSettings) {
61
            $request->addDataType($this->hostedPaymentSettings);
62
        }
63
    }
64
65
    /**
66
     * Sets the transaction request.
67
     *
68
     * @param \CommerceGuys\AuthNet\DataTypes\TransactionRequest $transactionRequest
69
     *   The transaction details.
70
     *
71
     * @return $this
72
     */
73
    public function setTransactionRequest(TransactionRequest $transactionRequest)
74
    {
75
        $this->transactionRequest = $transactionRequest;
76
        return $this;
77
    }
78
79
    /**
80
     * Sets the hosted payment settings.
81
     *
82
     * @param \CommerceGuys\AuthNet\DataTypes\HostedPaymentSettings $hostedPaymentSettings
83
     *
84
     * @return $this
85
     */
86
    public function setHostedPaymentSettings(HostedPaymentSettings $hostedPaymentSettings)
87
    {
88
        $this->hostedPaymentSettings = $hostedPaymentSettings;
89
        return $this;
90
    }
91
}
92