Passed
Pull Request — main (#2)
by Leith
02:47
created

CreateCardRequest::setAuthorizationMode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Omnipay\Worldline\Message;
4
5
/**
6
 * Worldline (Hosted) Create Card Request
7
 *
8
 * Creates a card token via the hosted checkout by creating an Authorize Request and forcing the 'Tokenize' property.
9
 * This can still be used to make purchases if the authorizationMode is supplied as 'SALE' or it's captured separately.
10
 *
11
 * @see https://docs.direct.worldline-solutions.com/en/api-reference#tag/HostedCheckout/operation/CreateHostedCheckoutApi
12
 */
13
class CreateCardRequest extends PurchaseRequest
14
{
15
    protected $authorizationMode = 'PRE_AUTHORIZATION';
16
17
    public function getAuthorizationMode()
18
    {
19
        return $this->getParameter('authorizationMode');
20
    }
21
22
    public function setAuthorizationMode($value)
23
    {
24
        if (!in_array($value, ['FINAL_AUTHORIZATION', 'PRE_AUTHORIZATION', 'SALE'])) {
25
            $value = null;
26
        }
27
        return $this->setParameter('authorizationMode', $value);
28
    }
29
30
    public function getData()
31
    {
32
        $this->setAmount($this->getAmount() ?: '1.00');
33
        $this->setTokenize(true);
34
35
        if ($this->getAuthorizationMode()) {
36
            $this->authorizationMode = $this->getAuthorizationMode();
37
        }
38
39
        return parent::getData();
40
    }
41
}
42