Gateway::purchase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace ByTIC\Omnipay\PlatiOnline;
4
5
use ByTIC\Omnipay\PlatiOnline\Message\AuthorizeRequest;
6
use ByTIC\Omnipay\PlatiOnline\Message\AuthorizeResponse;
7
use ByTIC\Omnipay\PlatiOnline\Message\CompletePurchaseRequest;
8
use ByTIC\Omnipay\PlatiOnline\Message\PurchaseRequest;
9
use ByTIC\Omnipay\PlatiOnline\Message\ServerCompletePurchaseRequest;
10
use ByTIC\Omnipay\PlatiOnline\Traits\HasSecurityParamsTrait;
11
use Omnipay\Common\AbstractGateway;
12
use Omnipay\Common\Message\NotificationInterface;
13
use Omnipay\Common\Message\RequestInterface;
14
15
/**
16
 * Class Gateway
17
 * @package ByTIC\Omnipay\PlatiOnline
18
 *
19
 * @method RequestInterface capture(array $options = [])
20
 * @method RequestInterface completeAuthorize(array $options = [])
21
 * @method RequestInterface refund(array $options = [])
22
 * @method RequestInterface void(array $options = [])
23
 * @method RequestInterface createCard(array $options = [])
24
 * @method RequestInterface updateCard(array $options = [])
25
 * @method RequestInterface deleteCard(array $options = [])
26
 * @method RequestInterface fetchTransaction(array $options = [])
27
 * @method NotificationInterface acceptNotification(array $options = [])
28
 */
29
class Gateway extends AbstractGateway
30
{
31
    use HasSecurityParamsTrait;
32
33
    public const VERSION = '1.0';
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function getName()
39
    {
40
        return 'PlatiOnline';
41
    }
42
43
    // ------------ REQUESTS ------------ //
44
45
    /**
46
     * @inheritdoc
47
     * @return PurchaseRequest
48
     */
49
    public function purchase(array $parameters = []): RequestInterface
50
    {
51
        $authorizeRequest = $this->authorize(array_merge($this->getDefaultParameters(), $parameters));
52
53
        return $this->createRequest(
54
            PurchaseRequest::class,
55
            ['authorizeResponse' => $authorizeRequest->send()]
56
        );
57
    }
58
59
    /**
60
     * @inheritdoc
61
     * //     * @return CompletePurchaseRequest
62
     */
63
    public function completePurchase(array $parameters = []): RequestInterface
64
    {
65
        return $this->createRequest(
66
            CompletePurchaseRequest::class,
67
            array_merge($this->getDefaultParameters(), $parameters)
68
        );
69
    }
70
71
    /**
72
     * @inheritdoc
73
     * @return AuthorizeResponse
74
     */
75
    public function authorize(array $parameters = []): RequestInterface
76
    {
77
        return $this->createRequest(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createRequ...meters(), $parameters)) returns the type ByTIC\Omnipay\PlatiOnline\Message\AuthorizeRequest which is incompatible with the documented return type ByTIC\Omnipay\PlatiOnlin...ssage\AuthorizeResponse.
Loading history...
78
            AuthorizeRequest::class,
79
            array_merge($this->getDefaultParameters(), $parameters)
80
        );
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public function serverCompletePurchase(array $parameters = []): RequestInterface
87
    {
88
        return $this->createRequest(
89
            ServerCompletePurchaseRequest::class,
90
            array_merge($this->getDefaultParameters(), $parameters)
91
        );
92
    }
93
94
    // ------------ PARAMETERS ------------ //
95
96
    /** @noinspection PhpMissingParentCallCommonInspection
97
     *
98
     * {@inheritdoc}
99
     */
100
    public function getDefaultParameters()
101
    {
102
        return [
103
            'testMode' => $this->getTestMode(),
104
            'loginId' => $this->getLoginId(),
105
            'publicKey' => $this->getPublicKey(),
106
            'privateKey' => $this->getPrivateKey(),
107
            'initialVector' => $this->getInitialVector(),
108
            'initialVectorItsn' => $this->getInitialVectorItsn(),
109
            'website' => $this->getWebsite(),
110
            'currency' => 'RON',
111
            'lang' => 'RO'
112
        ];
113
    }
114
115
    // ------------ Getter'n'Setters ------------ //
116
}
117