Skip to content

Commit

Permalink
Merge pull request Adyen#55 from georgegg/add-modification-adjust-aut…
Browse files Browse the repository at this point in the history
…horisation

Add adjustAuthorisation to modification models
  • Loading branch information
rikterbeek authored Mar 7, 2018
2 parents 9fc5b05 + 2965e62 commit ede8a6b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Adyen/Service/Modification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Modification extends \Adyen\Service
protected $_cancelOrRefund;
protected $_capture;
protected $_refund;
protected $_adjustAuthorisation;

public function __construct(\Adyen\Client $client)
{
Expand All @@ -18,6 +19,7 @@ public function __construct(\Adyen\Client $client)
$this->_cancelOrRefund = new \Adyen\Service\ResourceModel\Modification\CancelOrRefund($this);
$this->_capture = new \Adyen\Service\ResourceModel\Modification\Capture($this);
$this->_refund = new \Adyen\Service\ResourceModel\Modification\Refund($this);
$this->_adjustAuthorisation = new \Adyen\Service\ResourceModel\Modification\AdjustAuthorisation($this);
}

public function cancel($params)
Expand All @@ -44,4 +46,9 @@ public function refund($params)
return $result;
}

public function adjustAuthorisation($params)
{
$result = $this->_adjustAuthorisation->request($params);
return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Adyen\Service\ResourceModel\Modification;

class AdjustAuthorisation extends \Adyen\Service\AbstractResource
{
protected $_requiredFields = array(
'merchantAccount',
'originalReference',
'modificationAmount.value',
'modificationAmount.currency',
);

protected $_endpoint;

public function __construct($service)
{
$this->_endpoint = $service->getClient()->getConfig()->get('endpoint').'/pal/servlet/Payment/'.$service->getClient()->getApiVersion().'/adjustAuthorisation';
parent::__construct($service, $this->_endpoint, $this->_requiredFields);
}

}
63 changes: 60 additions & 3 deletions tests/ModificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModificationTest extends TestCase
public function testCancelModification()
{
// create a payment
require_once __DIR__ . '/CreatePaymentRequestTest.php';
require_once __DIR__.'/CreatePaymentRequestTest.php';
$test = new CreatePaymentRequestTest();
$result = $test->testCreatePaymentSuccess();

Expand All @@ -36,7 +36,7 @@ public function testCancelModification()
public function testRefundModification()
{
// create a payment
require_once __DIR__ . '/CreatePaymentRequestTest.php';
require_once __DIR__.'/CreatePaymentRequestTest.php';
$test = new CreatePaymentRequestTest();
$result = $test->testCreatePaymentSuccess();

Expand All @@ -53,7 +53,7 @@ public function testRefundModification()
$params = array(
"merchantAccount" => $this->_merchantAccount,
"modificationAmount" => $modificationAmount,
"reference" => $pspReference . '_refund',
"reference" => $pspReference.'_refund',
"originalReference" => $pspReference
);

Expand All @@ -64,4 +64,61 @@ public function testRefundModification()
}


public function testAdjustDecreaseModification()
{
// create a payment
require_once __DIR__.'/CreatePaymentRequestTest.php';
$test = new CreatePaymentRequestTest();
$result = $test->testCreatePaymentSuccess();

$pspReference = $result['pspReference'];

// create modification
$client = $this->createClient();

// initialize service
$service = new Service\Modification($client);

$params = array(
"merchantAccount" => $this->_merchantAccount,
"modificationAmount" => array('currency' => 'EUR', 'value' => '750'),
"reference" => $pspReference.'_adjustAuthorisation',
"originalReference" => $pspReference
);

$result = $service->adjustAuthorisation($params);

$this->assertEquals('[adjustAuthorisation-received]', $result['response']);

}

public function testAdjustIncreaseModification()
{
// create a payment
require_once __DIR__.'/CreatePaymentRequestTest.php';
$test = new CreatePaymentRequestTest();
$result = $test->testCreatePaymentSuccess();

$pspReference = $result['pspReference'];

// create modification
$client = $this->createClient();

// initialize service
$service = new Service\Modification($client);

$params = array(
"merchantAccount" => $this->_merchantAccount,
"modificationAmount" => array('currency' => 'EUR', 'value' => '1600'),
"reference" => $pspReference.'_adjustAuthorisation',
"originalReference" => $pspReference
);

$result = $service->adjustAuthorisation($params);

$this->assertEquals('[adjustAuthorisation-received]', $result['response']);

}


}

0 comments on commit ede8a6b

Please sign in to comment.