This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\DirectLink\PaymentOperation; |
||
16 | use Ogone\Passphrase; |
||
17 | use Ogone\DirectLink\Alias; |
||
18 | use Ogone\DirectLink\CreateAliasRequest; |
||
19 | use Ogone\DirectLink\CreateAliasResponse; |
||
20 | use Ogone\ShaComposer\AllParametersShaComposer; |
||
21 | use Ogone\ParameterFilter\ShaOutParameterFilter; |
||
22 | use Ogone\DirectLink\DirectLinkPaymentRequest; |
||
23 | use Ogone\DirectLink\DirectLinkPaymentResponse; |
||
24 | |||
25 | /** |
||
26 | * @group integration |
||
27 | */ |
||
28 | class OgoneTest extends \PHPUnit_Framework_TestCase |
||
29 | { |
||
30 | /** |
||
31 | * @test |
||
32 | */ |
||
33 | public function AliasCreationIsSuccessful() |
||
34 | { |
||
35 | $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT); |
||
36 | $shaOutComposer = new AllParametersShaComposer($passphraseOut); |
||
37 | $shaOutComposer->addParameterFilter(new ShaOutParameterFilter()); |
||
38 | |||
39 | $createAliasResponse = $this->provideAliasResponse(); |
||
40 | |||
41 | $this->assertTrue($createAliasResponse->isValid($shaOutComposer)); |
||
42 | $this->assertTrue($createAliasResponse->isSuccessful()); |
||
43 | |||
44 | return (string) $createAliasResponse->getAlias(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @test |
||
49 | * @depends AliasCreationIsSuccessful |
||
50 | */ |
||
51 | public function DirectLinkPaymentIsSuccessful($alias) |
||
52 | { |
||
53 | $passphrase = new Passphrase(PASSPHRASE_SHA_IN); |
||
54 | $shaComposer = new AllParametersShaComposer($passphrase); |
||
55 | $directLinkRequest = new DirectLinkPaymentRequest($shaComposer); |
||
56 | |||
57 | $orderId = uniqid('order_'); // create a unique order id |
||
58 | $directLinkRequest->setOrderid($orderId); |
||
59 | |||
60 | $alias = new Alias($alias); |
||
61 | $directLinkRequest->setPspid(PSPID); |
||
62 | $directLinkRequest->setUserId(USERID); |
||
63 | $directLinkRequest->setPassword(PASSWORD); |
||
64 | $directLinkRequest->setAlias($alias); |
||
65 | $directLinkRequest->setAmount(100); |
||
66 | $directLinkRequest->setCurrency('EUR'); |
||
67 | $directLinkRequest->setEci(new Eci(Eci::ECOMMERCE_RECURRING)); |
||
68 | $directLinkRequest->setOperation(new PaymentOperation(PaymentOperation::REQUEST_FOR_DIRECT_SALE)); |
||
69 | $directLinkRequest->validate(); |
||
70 | |||
71 | $body = array(); |
||
72 | foreach ($directLinkRequest->toArray() as $key => $value) { |
||
73 | $body[strtoupper($key)] = $value; |
||
74 | } |
||
75 | |||
76 | $body['SHASIGN'] = $directLinkRequest->getShaSign(); |
||
77 | |||
78 | $client = new Client($directLinkRequest->getOgoneUri()); |
||
79 | $request = $client->post(null, null, $body); |
||
80 | $response = $request->send(); |
||
81 | |||
82 | $directLinkResponse = new DirectLinkPaymentResponse($response->getBody(true)); |
||
83 | |||
84 | $this->assertTrue($directLinkResponse->isSuccessful()); |
||
85 | |||
86 | return $alias; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @test |
||
91 | */ |
||
92 | View Code Duplication | public function AliasIsCreatedByOgone() |
|
0 ignored issues
–
show
|
|||
93 | { |
||
94 | $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT); |
||
95 | $shaOutComposer = new AllParametersShaComposer($passphraseOut); |
||
96 | $shaOutComposer->addParameterFilter(new ShaOutParameterFilter()); |
||
97 | |||
98 | $createAliasResponse = $this->provideAliasResponse(false); |
||
99 | |||
100 | $this->assertTrue($createAliasResponse->isValid($shaOutComposer)); |
||
101 | $this->assertTrue($createAliasResponse->isSuccessful()); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @test |
||
106 | */ |
||
107 | View Code Duplication | public function CreateAliasInvalid() |
|
0 ignored issues
–
show
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. ![]() |
|||
108 | { |
||
109 | $passphraseOut = new Passphrase(PASSPHRASE_SHA_OUT); |
||
110 | $shaOutComposer = new AllParametersShaComposer($passphraseOut); |
||
111 | $shaOutComposer->addParameterFilter(new ShaOutParameterFilter()); |
||
112 | |||
113 | $createAliasResponse = $this->provideAliasResponse(true, true); |
||
114 | |||
115 | $this->assertTrue($createAliasResponse->isValid($shaOutComposer)); |
||
116 | $this->assertFalse($createAliasResponse->isSuccessful()); |
||
117 | } |
||
118 | |||
119 | |||
120 | public function provideAliasResponse($createAlias = true, $noValidCardnumber = false) |
||
121 | { |
||
122 | /* |
||
123 | * Create an alias request to Ogone |
||
124 | */ |
||
125 | $passphrase = new Passphrase(PASSPHRASE_SHA_IN); |
||
126 | $shaComposer = new AllParametersShaComposer($passphrase); |
||
127 | |||
128 | $createAliasRequest = new CreateAliasRequest($shaComposer); |
||
129 | $createAliasRequest->setPspid(PSPID); |
||
130 | $createAliasRequest->setAccepturl('http://www.example.com'); |
||
131 | $createAliasRequest->setExceptionurl('http://www.example.com'); |
||
132 | |||
133 | if ($createAlias == true) { |
||
0 ignored issues
–
show
|
|||
134 | $unique_alias = uniqid('customer_'); // create a unique alias |
||
135 | $alias = new Alias($unique_alias); |
||
136 | $createAliasRequest->setAlias($alias); |
||
137 | } |
||
138 | |||
139 | $createAliasRequest->validate(); |
||
140 | |||
141 | $body = array(); |
||
142 | foreach ($createAliasRequest->toArray() as $key => $value) { |
||
143 | $body[strtoupper($key)] = $value; |
||
144 | } |
||
145 | |||
146 | $body['SHASIGN'] = $createAliasRequest->getShaSign(); |
||
147 | $body['CN'] = 'Don Corleone'; |
||
148 | $body['CARDNO'] = ($noValidCardnumber) ? '' : '4111111111111111'; // Ogone Visa test cardnumber |
||
149 | $body['CVC'] = '777'; |
||
150 | $body['ED'] = date('my', strtotime('+1 year')); // test-date should be in the future |
||
151 | |||
152 | $client = new Client($createAliasRequest->getOgoneUri()); |
||
153 | $request = $client->post(null, null, $body); |
||
154 | $response = $request->send(); |
||
155 | |||
156 | $url = parse_url($response->getInfo('url')); |
||
157 | $params = array(); |
||
158 | parse_str($url['query'], $params); |
||
159 | |||
160 | /* |
||
161 | * Validate alias response from Ogone |
||
162 | */ |
||
163 | |||
164 | $createAliasResponse = new CreateAliasResponse($params); |
||
0 ignored issues
–
show
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. ![]() |
|||
165 | |||
166 | return $createAliasResponse; |
||
167 | } |
||
168 | } |
||
169 |
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.