Skip to content

Commit 99cbaae

Browse files
committed
Issue #4 default the errorUrl() to the returnUrl()
For card tokenisation, and authorize/purchase.
1 parent 5e24d8f commit 99cbaae

File tree

5 files changed

+117
-3
lines changed

5 files changed

+117
-3
lines changed

src/AbstractDatatransGateway.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getDefaultParameters()
4141
self::RETURN_METHOD_POST,
4242
self::RETURN_METHOD_GET,
4343
],
44-
'errorUrl' => '',
44+
'errorUrl' => null,
4545
'language' => [
4646
null, // account default
4747
'de', // German

src/Message/AbstractRedirectRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ public function getData()
218218
// These URLs are optional here, if set in the account.
219219

220220
if ($this->getReturnUrl() !== null) {
221+
// Default the errorUrl to the same returnURL.
222+
// It can be overridden later if required.
223+
221224
$data['successUrl'] = $this->getReturnUrl();
225+
$data['errorUrl'] = $this->getReturnUrl();
222226
}
223227

224228
if ($this->getCancelUrl() !== null) {

src/Message/TokenizeRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TokenizeRequest extends AbstractRedirectRequest
3131
*/
3232
public function getData()
3333
{
34-
$this->validate('merchantId', 'transactionId', 'sign', 'returnUrl', 'errorUrl', 'cancelUrl');
34+
$this->validate('merchantId', 'transactionId', 'sign', 'returnUrl', 'cancelUrl');
3535

3636
$data = array(
3737
'merchantId' => $this->getMerchantId(),
@@ -44,7 +44,7 @@ public function getData()
4444

4545
$data['successUrl'] = $this->getReturnUrl();
4646
$data['cancelUrl'] = $this->getCancelUrl();
47-
$data['errorUrl'] = $this->getErrorUrl();
47+
$data['errorUrl'] = $this->getErrorUrl() ?: $this->getReturnUrl();
4848
$data['cancelUrl'] = $this->getCancelUrl();
4949

5050
return $data;

tests/Message/PurchaseRequestTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,35 @@ public function testGetDataWithoutCard()
4747

4848
$this->assertEquals($expected, $this->request->getData());
4949
}
50+
51+
/**
52+
* No errorUrl set explicitly.
53+
*/
54+
public function testErrorUrlDefaults()
55+
{
56+
$this->request->initialize(array(
57+
'merchantId' => 'asdf',
58+
'sign' => '123',
59+
'testMode' => true,
60+
'amount' => '12.00',
61+
'currency' => 'CHF',
62+
'transactionId' => '123',
63+
'returnUrl' => 'https://www.example.com/return',
64+
'cancelUrl' => 'https://www.example.com/cancel'
65+
));
66+
67+
$expected = array(
68+
'merchantId' => 'asdf',
69+
'refno' => '123',
70+
'amount' => 1200,
71+
'currency' => 'CHF',
72+
'sign' => '123',
73+
'reqtype' => 'CAA',
74+
'successUrl' => 'https://www.example.com/return',
75+
'errorUrl' => 'https://www.example.com/return',
76+
'cancelUrl' => 'https://www.example.com/cancel'
77+
);
78+
79+
$this->assertEquals($expected, $this->request->getData());
80+
}
5081
}

tests/Message/TokenizeRequestTest.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Omnipay\Datatrans\Message;
4+
5+
use Omnipay\Common\CreditCard;
6+
use Omnipay\Tests\TestCase;
7+
8+
class TokenizeRequestTest extends TestCase
9+
{
10+
/**
11+
* @var PurchaseRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->request = new TokenizeRequest($this->getHttpClient(), $this->getHttpRequest());
20+
}
21+
22+
public function testGetDataWithoutCard()
23+
{
24+
$this->request->initialize(array(
25+
'merchantId' => 'asdf',
26+
'sign' => '123',
27+
'testMode' => true,
28+
'currency' => 'CHF',
29+
'transactionId' => '123',
30+
'returnUrl' => 'https://www.example.com/success',
31+
'errorUrl' => 'https://www.example.com/error',
32+
'cancelUrl' => 'https://www.example.com/cancel'
33+
));
34+
35+
$expected = array(
36+
'merchantId' => 'asdf',
37+
'refno' => '123',
38+
'amount' => 0,
39+
'currency' => 'CHF',
40+
'sign' => '123',
41+
'successUrl' => 'https://www.example.com/success',
42+
'errorUrl' => 'https://www.example.com/error',
43+
'cancelUrl' => 'https://www.example.com/cancel',
44+
'useAlias' => 'yes',
45+
);
46+
47+
$this->assertEquals($expected, $this->request->getData());
48+
}
49+
50+
/**
51+
* No errorUrl set explicitly.
52+
*/
53+
public function testErrorUrlDefaults()
54+
{
55+
$this->request->initialize(array(
56+
'merchantId' => 'asdfxxx',
57+
'sign' => '123',
58+
'testMode' => true,
59+
'currency' => 'CHF',
60+
'transactionId' => '123',
61+
'returnUrl' => 'https://www.example.com/return',
62+
'cancelUrl' => 'https://www.example.com/cancel'
63+
));
64+
65+
$expected = array(
66+
'merchantId' => 'asdfxxx',
67+
'refno' => '123',
68+
'amount' => 0,
69+
'currency' => 'CHF',
70+
'sign' => '123',
71+
'successUrl' => 'https://www.example.com/return',
72+
'errorUrl' => 'https://www.example.com/return',
73+
'cancelUrl' => 'https://www.example.com/cancel',
74+
'useAlias' => 'yes',
75+
);
76+
77+
$this->assertEquals($expected, $this->request->getData());
78+
}
79+
}

0 commit comments

Comments
 (0)