Skip to content

Commit

Permalink
Issue #4 default the errorUrl() to the returnUrl()
Browse files Browse the repository at this point in the history
For card tokenisation, and authorize/purchase.
  • Loading branch information
judgej committed Aug 22, 2018
1 parent 5e24d8f commit 99cbaae
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/AbstractDatatransGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getDefaultParameters()
self::RETURN_METHOD_POST,
self::RETURN_METHOD_GET,
],
'errorUrl' => '',
'errorUrl' => null,
'language' => [
null, // account default
'de', // German
Expand Down
4 changes: 4 additions & 0 deletions src/Message/AbstractRedirectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ public function getData()
// These URLs are optional here, if set in the account.

if ($this->getReturnUrl() !== null) {
// Default the errorUrl to the same returnURL.
// It can be overridden later if required.

$data['successUrl'] = $this->getReturnUrl();
$data['errorUrl'] = $this->getReturnUrl();
}

if ($this->getCancelUrl() !== null) {
Expand Down
4 changes: 2 additions & 2 deletions src/Message/TokenizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TokenizeRequest extends AbstractRedirectRequest
*/
public function getData()
{
$this->validate('merchantId', 'transactionId', 'sign', 'returnUrl', 'errorUrl', 'cancelUrl');
$this->validate('merchantId', 'transactionId', 'sign', 'returnUrl', 'cancelUrl');

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

$data['successUrl'] = $this->getReturnUrl();
$data['cancelUrl'] = $this->getCancelUrl();
$data['errorUrl'] = $this->getErrorUrl();
$data['errorUrl'] = $this->getErrorUrl() ?: $this->getReturnUrl();
$data['cancelUrl'] = $this->getCancelUrl();

return $data;
Expand Down
31 changes: 31 additions & 0 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,35 @@ public function testGetDataWithoutCard()

$this->assertEquals($expected, $this->request->getData());
}

/**
* No errorUrl set explicitly.
*/
public function testErrorUrlDefaults()
{
$this->request->initialize(array(
'merchantId' => 'asdf',
'sign' => '123',
'testMode' => true,
'amount' => '12.00',
'currency' => 'CHF',
'transactionId' => '123',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel'
));

$expected = array(
'merchantId' => 'asdf',
'refno' => '123',
'amount' => 1200,
'currency' => 'CHF',
'sign' => '123',
'reqtype' => 'CAA',
'successUrl' => 'https://www.example.com/return',
'errorUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel'
);

$this->assertEquals($expected, $this->request->getData());
}
}
79 changes: 79 additions & 0 deletions tests/Message/TokenizeRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Omnipay\Datatrans\Message;

use Omnipay\Common\CreditCard;
use Omnipay\Tests\TestCase;

class TokenizeRequestTest extends TestCase
{
/**
* @var PurchaseRequest
*/
private $request;

public function setUp()
{
parent::setUp();

$this->request = new TokenizeRequest($this->getHttpClient(), $this->getHttpRequest());
}

public function testGetDataWithoutCard()
{
$this->request->initialize(array(
'merchantId' => 'asdf',
'sign' => '123',
'testMode' => true,
'currency' => 'CHF',
'transactionId' => '123',
'returnUrl' => 'https://www.example.com/success',
'errorUrl' => 'https://www.example.com/error',
'cancelUrl' => 'https://www.example.com/cancel'
));

$expected = array(
'merchantId' => 'asdf',
'refno' => '123',
'amount' => 0,
'currency' => 'CHF',
'sign' => '123',
'successUrl' => 'https://www.example.com/success',
'errorUrl' => 'https://www.example.com/error',
'cancelUrl' => 'https://www.example.com/cancel',
'useAlias' => 'yes',
);

$this->assertEquals($expected, $this->request->getData());
}

/**
* No errorUrl set explicitly.
*/
public function testErrorUrlDefaults()
{
$this->request->initialize(array(
'merchantId' => 'asdfxxx',
'sign' => '123',
'testMode' => true,
'currency' => 'CHF',
'transactionId' => '123',
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel'
));

$expected = array(
'merchantId' => 'asdfxxx',
'refno' => '123',
'amount' => 0,
'currency' => 'CHF',
'sign' => '123',
'successUrl' => 'https://www.example.com/return',
'errorUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'useAlias' => 'yes',
);

$this->assertEquals($expected, $this->request->getData());
}
}

0 comments on commit 99cbaae

Please sign in to comment.