Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ecom 2125 php client send endpoint url to alma #150

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class Client
*/
public $insurance;
/*************************/
/**
* @var Endpoints\Configuration
*/
public $configuration;
/*************************/

/**
* Alma client initialization.
Expand Down Expand Up @@ -150,6 +155,7 @@ private function initEndpoints()
$this->shareOfCheckout = new Endpoints\ShareOfCheckout($this->context);
$this->webhooks = new Endpoints\Webhooks($this->context);
$this->insurance = new Endpoints\Insurance($this->context);
$this->configuration = new Endpoints\Configuration($this->context);
}

private function initUserAgent()
Expand Down
50 changes: 50 additions & 0 deletions src/Endpoints/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* Copyright (c) 2018 Alma / Nabla SAS
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma / Nabla SAS <[email protected]>
* @copyright Copyright (c) 2018 Alma / Nabla SAS
* @license https://opensource.org/licenses/MIT The MIT License
*
*/

namespace Alma\API\Endpoints;

use Alma\API\Exceptions\RequestException;
use Alma\API\RequestError;

class Configuration extends Base
{
const CONFIGURATION_PATH = '/v1/integration-configuration';

/**
* @param string $url The URL to send to Alma for integrations configuration
* @throws RequestException
* @throws RequestError
*/
public function sendIntegrationsConfigurationsUrl($url)
{
$res = $this->request(self::CONFIGURATION_PATH . "/api")->setRequestBody(array(
"collect_data_url" => $url
))->put();

if ($res->isError()) {
throw new RequestException($res->errorMessage, null, $res);
}
}
}
18 changes: 0 additions & 18 deletions src/Endpoints/Merchants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

use Alma\API\Entities\FeePlan;
use Alma\API\Entities\Merchant;
use Alma\API\Entities\MerchantData\MerchantData;
use Alma\API\Exceptions\RequestException;
use Alma\API\RequestError;

class Merchants extends Base
Expand Down Expand Up @@ -82,20 +80,4 @@ public function feePlans($kind = FeePlan::KIND_GENERAL, $installmentsCounts = "a
return new FeePlan($val);
}, $res->json);
}

/**
* @param string $url The URL to send to Alma for integrations configuration
* @throws RequestException
* @throws RequestError
*/
public function sendIntegrationsConfigurationsUrl($url)
{
$res = $this->request(self::ME_PATH . "/configuration")->setRequestBody(array(
"endpoint_url" => $url
))->post();

if ($res->isError()) {
throw new RequestException($res->errorMessage, null, $res);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@

namespace Unit\Endpoints;

use Alma\API\Endpoints\Merchants;
use Alma\API\Endpoints\Configuration;
use Alma\API\Exceptions\RequestException;
use Alma\API\Request;
use Alma\API\Response;
use Mockery;
use PHPUnit\Framework\TestCase;

class MerchantsTest extends TestCase
class ConfigurationTest extends TestCase
{
const URL = "https://www.example.com/integrations/configurations";

private $configurationEndpoint;
private $responseMock;
private $requestObject;

public function setUp(): void
{
$this->merchantEndpoint = Mockery::mock(Merchants::class)->makePartial();
$this->configurationEndpoint = Mockery::mock(Configuration::class)->makePartial();
$this->responseMock = Mockery::mock(Response::class);
$this->requestObject = Mockery::mock(Request::class);
}

public function tearDown(): void
{
$this->merchantEndpoint = null;
$this->configurationEndpoint = null;
$this->responseMock = null;
$this->requestObject = null;
Mockery::close();
Expand All @@ -31,34 +35,32 @@ public function tearDown(): void
public function testSendIntegrationsConfigurationsUrlIsOk(){
$this->responseMock->shouldReceive('isError')->once()->andReturn(false);
$this->requestObject->shouldReceive('setRequestBody')
->with(['endpoint_url' => self::URL])
->with(['collect_data_url' => self::URL])
->andReturn($this->requestObject);

$this->merchantEndpoint->shouldReceive('request')
->with(Merchants::ME_PATH . "/configuration")
$this->configurationEndpoint->shouldReceive('request')
->with(Configuration::CONFIGURATION_PATH . "/api")
->once()
->andReturn($this->requestObject);
$this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock);
$this->requestObject->shouldReceive('put')->once()->andReturn($this->responseMock);

$url = self::URL;
$this->assertNull($this->merchantEndpoint->sendIntegrationsConfigurationsUrl($url));
$this->assertNull($this->configurationEndpoint->sendIntegrationsConfigurationsUrl(self::URL));
}

public function testSendIntegrationsConfigurationsUrlThrowRequestException(){
$this->responseMock->shouldReceive('isError')->once()->andReturn(true);
$this->requestObject->shouldReceive('setRequestBody')
->with(['endpoint_url' => self::URL])
->with(['collect_data_url' => self::URL])
->andReturn($this->requestObject);

$this->merchantEndpoint->shouldReceive('request')
->with(Merchants::ME_PATH . "/configuration")
$this->configurationEndpoint->shouldReceive('request')
->with(Configuration::CONFIGURATION_PATH . "/api")
->once()
->andReturn($this->requestObject);
$this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock);
$this->requestObject->shouldReceive('put')->once()->andReturn($this->responseMock);

$url = self::URL;
$this->expectException(RequestException::class);
$this->merchantEndpoint->sendIntegrationsConfigurationsUrl($url);
$this->configurationEndpoint->sendIntegrationsConfigurationsUrl(self::URL);

}
}