GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#62)
by Jelte
04:52
created

OgoneTest::AliasIsCreatedByOgone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 11
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Marlon Ogone package.
4
 *
5
 * (c) Marlon BVBA <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Ogone\Tests;
12
13
use Guzzle\Http\Client;
14
use Ogone\DirectLink\Eci;
15
use Ogone\Passphrase;
16
use Ogone\DirectLink\Alias;
17
use Ogone\DirectLink\CreateAliasRequest;
18
use Ogone\DirectLink\CreateAliasResponse;
19
use Ogone\ShaComposer\AllParametersShaComposer;
20
use Ogone\ParameterFilter\ShaOutParameterFilter;
21
use Ogone\DirectLink\DirectLinkPaymentRequest;
22
use Ogone\DirectLink\DirectLinkPaymentResponse;
23
24
/**
25
 * @group integration
26
 */
27
class OgoneTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @test
31
     */
32
    public function AliasCreationIsSuccessful()
33
    {
34
        $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT);
35
        $shaOutComposer = new AllParametersShaComposer($passphraseOut);
36
        $shaOutComposer->addParameterFilter(new ShaOutParameterFilter());
37
38
        $createAliasResponse = $this->provideAliasResponse();
39
40
        $this->assertTrue($createAliasResponse->isValid($shaOutComposer));
41
        $this->assertTrue($createAliasResponse->isSuccessful());
42
43
        return (string) $createAliasResponse->getAlias();
44
    }
45
46
    /**
47
     * @test
48
     * @depends AliasCreationIsSuccessful
49
     */
50
    public function DirectLinkPaymentIsSuccessful($alias)
51
    {
52
        $passphrase = new Passphrase(PASSPHRASE_SHA_IN);
53
        $shaComposer = new AllParametersShaComposer($passphrase);
54
        $directLinkRequest = new DirectLinkPaymentRequest($shaComposer);
55
56
        $orderId = uniqid('order_'); // create a unique order id
57
        $directLinkRequest->setOrderid($orderId);
58
59
        $alias = new Alias($alias);
60
        $directLinkRequest->setPspid(PSPID);
61
        $directLinkRequest->setUserId(USERID);
62
        $directLinkRequest->setPassword(PASSWORD);
63
        $directLinkRequest->setAlias($alias);
64
        $directLinkRequest->setAmount(100);
65
        $directLinkRequest->setCurrency('EUR');
66
        $directLinkRequest->setEci(new Eci(Eci::ECOMMERCE_RECURRING));
67
        $directLinkRequest->validate();
68
69
        $body = array();
70
        foreach ($directLinkRequest->toArray() as $key => $value) {
71
            $body[strtoupper($key)] = $value;
72
        }
73
74
        $body['SHASIGN'] = $directLinkRequest->getShaSign();
75
76
        $client = new Client($directLinkRequest->getOgoneUri());
77
        $request = $client->post(null, null, $body);
78
        $response = $request->send();
79
80
        $directLinkResponse = new DirectLinkPaymentResponse($response->getBody(true));
81
82
        $this->assertTrue($directLinkResponse->isSuccessful());
83
84
        return $alias;
85
    }
86
87
    /**
88
     * @test
89
     */
90 View Code Duplication
    public function AliasIsCreatedByOgone()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT);
93
        $shaOutComposer = new AllParametersShaComposer($passphraseOut);
94
        $shaOutComposer->addParameterFilter(new ShaOutParameterFilter());
95
96
        $createAliasResponse = $this->provideAliasResponse(false);
97
98
        $this->assertTrue($createAliasResponse->isValid($shaOutComposer));
99
        $this->assertTrue($createAliasResponse->isSuccessful());
100
    }
101
102
    /**
103
     * @test
104
     */
105 View Code Duplication
    public function CreateAliasInvalid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    {
107
        $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT);
108
        $shaOutComposer = new AllParametersShaComposer($passphraseOut);
109
        $shaOutComposer->addParameterFilter(new ShaOutParameterFilter());
110
111
        $createAliasResponse = $this->provideAliasResponse(true, true);
112
113
        $this->assertTrue($createAliasResponse->isValid($shaOutComposer));
114
        $this->assertFalse($createAliasResponse->isSuccessful());
115
    }
116
117
118
    public function provideAliasResponse($createAlias = true, $noValidCardnumber = false)
119
    {
120
        /*
121
         *  Create an alias request to Ogone
122
         */
123
        $passphrase = new Passphrase(PASSPHRASE_SHA_IN);
124
        $shaComposer = new AllParametersShaComposer($passphrase);
125
126
        $createAliasRequest = new CreateAliasRequest($shaComposer);
127
        $createAliasRequest->setPspid(PSPID);
128
        $createAliasRequest->setAccepturl('http://www.example.com');
129
        $createAliasRequest->setExceptionurl('http://www.example.com');
130
131
        if ($createAlias == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
132
            $unique_alias = uniqid('customer_'); // create a unique alias
133
            $alias = new Alias($unique_alias);
134
            $createAliasRequest->setAlias($alias);
135
        }
136
137
        $createAliasRequest->validate();
138
139
        $body = array();
140
        foreach ($createAliasRequest->toArray() as $key => $value) {
141
            $body[strtoupper($key)] = $value;
142
        }
143
144
        $body['SHASIGN'] = $createAliasRequest->getShaSign();
145
        $body['CN'] = 'Don Corleone';
146
        $body['CARDNO'] = ($noValidCardnumber) ? '' : '4111111111111111'; // Ogone Visa test cardnumber
147
        $body['CVC'] = '777';
148
        $body['ED'] = date('my', strtotime('+1 year')); // test-date should be in the future
149
150
        $client = new Client($createAliasRequest->getOgoneUri());
151
        $request = $client->post(null, null, $body);
152
        $response = $request->send();
153
154
        $url = parse_url($response->getInfo('url'));
155
        $params = array();
156
        parse_str($url['query'], $params);
157
158
        /*
159
         * Validate alias response from Ogone
160
         */
161
162
        $createAliasResponse = new CreateAliasResponse($params);
0 ignored issues
show
Bug introduced by
It seems like $params can also be of type null; however, Ogone\AbstractResponse::__construct() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
163
164
        return $createAliasResponse;
165
    }
166
}
167