SaleRequest::setStatusUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Skrill\Request;
6
7
use Money\Money;
8
use Skrill\ValueObject\Url;
9
use Skrill\ValueObject\Email;
10
use Skrill\ValueObject\Language;
11
use Skrill\ValueObject\Description;
12
use Skrill\ValueObject\TransactionID;
13
use Skrill\Request\Traits\GetPayloadTrait;
14
use Skrill\ValueObject\RecurringBillingNote;
15
use Skrill\Request\Traits\AmountFormatterTrait;
16
17
/**
18
 * Class SaleRequest.
19
 */
20
final class SaleRequest
21
{
22
    use GetPayloadTrait;
23
    use AmountFormatterTrait;
24
25
    /**
26
     * @param TransactionID $transactionId
27
     * @param Money         $amount
28
     */
29
    public function __construct(TransactionID $transactionId, Money $amount)
30
    {
31
        $this->payload = [
32
            'transaction_id' => strval($transactionId),
33
            'currency' => strval($amount->getCurrency()),
34
            'amount' => $this->formatToFloat($amount),
35
        ];
36
    }
37
38
    /**
39
     * @param Language $lang
40
     *
41
     * @return SaleRequest
42
     */
43
    public function setLang(Language $lang): self
44
    {
45
        $this->payload['language'] = strval($lang);
46
47
        return $this;
48
    }
49
50
    /**
51
     * @param Email $email
52
     *
53
     * @return SaleRequest
54
     */
55
    public function setPayFromEmail(Email $email): self
56
    {
57
        $this->payload['pay_from_email'] = strval($email);
58
59
        return $this;
60
    }
61
62
    /**
63
     * The detail1_description combined with the detail1_text is shown in the more information field of the merchant
64
     * account history CSV file.
65
     *
66
     * Example:
67
     * - detail1_description: "Product ID:"
68
     * - detail1_text: "4509334"
69
     *
70
     * Using the example values, this would be "Product ID: 4509334".
71
     *
72
     * @param Description $productDescription
73
     *
74
     * @return SaleRequest
75
     */
76
    public function setProductDescription(Description $productDescription): self
77
    {
78
        $this->payload['detail1_description'] = $productDescription->getSubject();
79
        $this->payload['detail1_text'] = $productDescription->getText();
80
81
        return $this;
82
    }
83
84
    /**
85
     * @param Url $url
86
     *
87
     * @return $this
88
     */
89
    public function setReturnUrl(Url $url): self
90
    {
91
        $this->payload['return_url'] = strval($url);
92
93
        return $this;
94
    }
95
96
    /**
97
     * @param Url $url
98
     *
99
     * @return $this
100
     */
101
    public function setCancelUrl(Url $url): self
102
    {
103
        $this->payload['cancel_url'] = strval($url);
104
105
        return $this;
106
    }
107
108
    /**
109
     * @param Url $url
110
     *
111
     * @return $this
112
     */
113
    public function setStatusUrl(Url $url): self
114
    {
115
        $this->payload['status_url'] = strval($url);
116
117
        return $this;
118
    }
119
120
    /**
121
     * @param RecurringBillingNote $note
122
     * @param Money                $money
123
     *
124
     * @return $this
125
     */
126
    public function enableRecurringBilling(RecurringBillingNote $note, Money $money): self
127
    {
128
        $this->payload['ondemand_max_amount'] = $this->formatToFloat($money);
129
        $this->payload['ondemand_max_currency'] = strval($money->getCurrency());
130
        $this->payload['ondemand_note'] = strval($note);
131
132
        return $this;
133
    }
134
}
135