Completed
Branch webservice-support (1bfa77)
by John
02:37
created

WebservicePurchaseRequest::getData()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 44
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 32
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 26
nc 4
nop 0
crap 12
1
<?php
2
3
namespace Omnipay\Redsys\Message;
4
5
use SimpleXMLElement;
6
7
/**
8
 * Redsys Webservice Purchase Request
9
 */
10
class WebservicePurchaseRequest extends PurchaseRequest
11
{
12
    /** @var string */
13
    protected $liveWsdl = __DIR__ . "/redsys-webservice-live.wsdl";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /redsys-webservice-live.wsdl does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
14
    /** @var string */
15
    protected $testWsdl = __DIR__ . "/redsys-webservice-test.wsdl";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal /redsys-webservice-test.wsdl does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
16
    /** @var string */
17
    protected $liveEndpoint = "https://sis.redsys.es/sis/services/SerClsWSEntrada";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal https://sis.redsys.es/sis/services/SerClsWSEntrada does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
18
    /** @var string */
19
    protected $testEndpoint = "https://sis-t.redsys.es:25443/sis/services/SerClsWSEntrada";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal https://sis-t.redsys.es:...ervices/SerClsWSEntrada does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
20
 
21
    public function getData()
22
    {
23
        $this->validate('merchantId', 'terminalId', 'amount', 'currency', 'card');
24
        $card = $this->getCard();
25
        // @todo given test card doesn't validate?
26
        if (!$this->getTestMode()) {
27
            $card->validate();
28
        }
29
30
        $data = array(
31
            'DS_MERCHANT_AMOUNT'          => $this->getAmountInteger(),
32
            'DS_MERCHANT_ORDER'           => $this->getTransactionId(),
33
            'DS_MERCHANT_MERCHANTCODE'    => $this->getMerchantId(),
34
            'DS_MERCHANT_CURRENCY'        => $this->getCurrencyNumeric(),  // uses ISO-4217 codes
35
            'DS_MERCHANT_PAN'             => $card->getNumber(),
36
            'DS_MERCHANT_CVV2'            => $card->getCvv(),
37
            'DS_MERCHANT_TRANSACTIONTYPE' => 'A',                          // 'Traditional payment'
38
            'DS_MERCHANT_TERMINAL'        => $this->getTerminalId(),
39
            'DS_MERCHANT_EXPIRYDATE'      => $card->getExpiryDate('ym'),
40
        );
41
42
43
        $request = new SimpleXMLElement('<REQUEST/>');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44
        $requestData = $request->addChild('DATOSENTRADA');
45
        foreach ($data as $tag => $value) {
46
            $requestData->addChild($tag, $value);
47
        }
48
49
        $security = new Security;
50
51
        $request->addChild('DS_SIGNATUREVERSION', Security::VERSION);
52
        $request->addChild('DS_SIGNATURE', $security->createSignature(
53
            $requestData->asXML(),
54
            $data['DS_MERCHANT_ORDER'],
55
            base64_decode($this->getHmacKey())
56
        ));
57
58
        return $request;
59
        // array(
60
        //     'DATOSENTRADA'        => $data,
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
        //     'DS_SIGNATUREVERSION' => $request->DS_SIGNATUREVERSION,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
62
        //     'DS_SIGNATURE'        => $request->DS_SIGNATURE,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
        // );
64
    }
65
66
    public function sendData($data)
67
    {
68
69
        // @todo either use SOAP client here, or wrap in soap yourself and just guzzle it
70
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
            use SoapClient;
72
            $s = new SoapClient($fs, array('trace' => $this->debug, 'exceptions' => true));
73
            $result = $s->trataPeticion(
74
                // $data   as nested array rather than XML?
75
            );
76
77
        */
78
79
        // DIY SOAP WRAPPER
80
        $envelope = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
81
              <soapenv:Header/>
82
              <soapenv:Body>
83
                <impl:trataPeticion xmlns:impl='http://webservice.sis.sermepa.es'>
84
                  <impl:datosEntrada>
85
                    ".htmlspecialchars($data->asXML())."
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n </im... </soapenv:Envelope> does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
86
                  </impl:datosEntrada>
87
                </impl:trataPeticion>
88
              </soapenv:Body>
89
            </soapenv:Envelope>";
90
91
        $httpResponse = $this->httpClient->post(
92
            $this->getEndpoint(),
93
            array('SOAPAction' => 'trataPeticion'),
94
            $envelope
95
        )->send();
96
97
        // unwrap httpResponse into actual data as SimpleXMLElement tree
98
        $envelope = $httpResponse->xml();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
99
        $response_data = new SimpleXMLElement(htmlspecialchars_decode(
100
            $envelope->children("http://schemas.xmlsoap.org/soap/envelope/")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal http://schemas.xmlsoap.org/soap/envelope/ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
101
            ->Body->children("http://webservice.sis.sermepa.es")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal http://webservice.sis.sermepa.es does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
102
            ->trataPeticionResponse
103
            ->trataPeticionReturn
104
        ));
105
106
        // remove any reflected request data (this happens on error, including card number)
107
        // if (isset($response_data->RECIBIDO)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
        //     unset($response_data->RECIBIDO);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
        // }
110
111
112
        return $this->response = new WebservicePurchaseResponse($this, $response_data);
113
    }
114
}
115