Passed
Push — master ( 56e3ba...d2a4fa )
by İbrahim
03:24
created

CancelRequestBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
namespace Paranoia\Builder\Posnet;
3
4
use Paranoia\Common\Serializer\Serializer;
5
use Paranoia\Request\Request;
6
7
class CancelRequestBuilder extends BaseRequestBuilder
8
{
9
    const TRANSACTION_TYPE = 'reverse';
10
    const ENVELOPE_NAME    = 'posnetRequest';
11
12
    const TEMPORARY_DEFAULT_TRANSACTION_TYPE ='sale'; //TODO: To be removed.
13
14
    public function build(Request $request)
15
    {
16
        //TODO: Normally, the bank can cancel any type of request
17
        // but we are going to be assumed we can just do 'cancel'
18
        // sale transactions for the first phase.
19
20
        $data = array_merge(
21
            $this->buildBaseRequest($request),
22
            [
23
                self::TRANSACTION_TYPE => [
24
                    'transaction' => self::TEMPORARY_DEFAULT_TRANSACTION_TYPE,
25
                    'hostLogKey' => $request->getTransactionId(),
26
                    //authCode just needed when VFT transaction performed
27
                    // For the other transaction types we can keep it as '000000'
28
                    'authCode' => '000000'
29
                ]
30
            ]
31
        );
32
33
        $serializer = new Serializer(Serializer::XML);
34
        return $serializer->serialize($data, ['root_name' => self::ENVELOPE_NAME]);
35
    }
36
}
37