Skip to content

Commit

Permalink
Merge pull request #93 from alma/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Benjamin-Freoua-Alma authored Mar 6, 2024
2 parents ce024b0 + 34a20b2 commit 80ed0ec
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
=========

v2.0.5
-------
* Fix endpoint customer-carts

v2.0.4
-------
* Fix json_decode in getSubscriptionDetails
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alma/alma-php-client",
"description": "PHP API client for the Alma payments API",
"version": "2.0.4",
"version": "2.0.5",
"type": "library",
"require": {
"php": "^5.6 || ~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Client
{
const VERSION = '2.0.4';
const VERSION = '2.0.5';

const LIVE_MODE = 'live';
const TEST_MODE = 'test';
Expand Down
7 changes: 6 additions & 1 deletion src/Endpoints/Insurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Alma\API\Entities\Insurance\Contract;
use Alma\API\Entities\Insurance\File;
use Alma\API\Entities\Insurance\Subscription;
use Alma\API\Exceptions\InsuranceCancelPendingException;
use Alma\API\Exceptions\MissingKeyException;
use Alma\API\Exceptions\ParametersException;
use Alma\API\Exceptions\RequestException;
Expand Down Expand Up @@ -182,7 +183,7 @@ public function sendCustomerCart($cmsReferenceArray, $cartId)
{
try {
$this->insuranceValidator->checkCmsReference($cmsReferenceArray);
$request = $this->request(self::INSURANCE_PATH . 'customer-cart')
$request = $this->request(self::INSURANCE_PATH . 'customer-carts')
->setRequestBody(
[
'cms_references' => $cmsReferenceArray
Expand Down Expand Up @@ -317,6 +318,7 @@ public function addCustomerSessionToRequest($request, $customerSessionId = null,
/**
* @param string $subscriptionId
* @return void
* @throws InsuranceCancelPendingException
* @throws ParametersException
* @throws RequestError
* @throws RequestException
Expand All @@ -329,6 +331,9 @@ public function cancelSubscription($subscriptionId)
$request = $this->request(self::INSURANCE_PATH . 'subscriptions/' . $subscriptionId . '/void');
$response = $request->post();

if ($response->responseCode === 410) {
throw new InsuranceCancelPendingException('Subscription can not be cancelled at this time');
}
if ($response->isError()) {
throw new RequestException($response->errorMessage, $request, $response);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Exceptions/InsuranceCancelPendingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Alma\API\Exceptions;


class InsuranceCancelPendingException extends AlmaException
{
}
30 changes: 28 additions & 2 deletions tests/Unit/Legacy/Endpoints/InsuranceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Alma\API\Entities\Insurance\File;
use Alma\API\Entities\Insurance\Subscriber;
use Alma\API\Entities\Insurance\Subscription;
use Alma\API\Exceptions\InsuranceCancelPendingException;
use Alma\API\Exceptions\MissingKeyException;
use Alma\API\Exceptions\ParametersException;
use Alma\API\Exceptions\RequestException;
Expand All @@ -29,7 +30,7 @@ class InsuranceTest extends TestCase
const TEST_EMAIL = '[email protected]';
const TEST_CMSREFERENCE = '17-35';
const TEST_BIRTHDATE = '1988-08-22';
const INSURANCE_CUSTOMER_CART_PATH = '/v1/insurance/customer-cart';
const INSURANCE_CUSTOMER_CART_PATH = '/v1/insurance/customer-carts';
/**
* @var ClientContext
*/
Expand Down Expand Up @@ -897,14 +898,16 @@ public function testSendCustomerCartCallApiPostCustomerCartWithCmsReferencesArra

/**
* @return void
* @throws InsuranceCancelPendingException
* @throws ParametersException
* @throws RequestError
* @throws RequestException
*/
public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowExceptionForResponseUpperThan400()
public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowExceptionForResponseUpperThan400ButNo410()
{
$this->expectException(RequestException::class);
$subscriptionCancelPayload = 'subscriptionId1';

$this->responseMock->shouldReceive('isError')->once()->andReturn(true);
$this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock);
$this->insuranceMock->shouldReceive('request')
Expand All @@ -914,6 +917,26 @@ public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAnd
$this->insuranceMock->cancelSubscription($subscriptionCancelPayload);
}

/**
* @return void
* @throws InsuranceCancelPendingException
* @throws ParametersException
* @throws RequestError
* @throws RequestException
*/
public function testCancelSubscriptionCallRequestWithSubscriptionArrayPayloadAndThrowInsuranceCancelPendingExceptionForResponse410()
{
$this->expectException(InsuranceCancelPendingException::class);
$subscriptionCancelPayload = 'subscriptionId1';
$this->responseMock->responseCode = 410;
$this->requestObject->shouldReceive('post')->once()->andReturn($this->responseMock);
$this->insuranceMock->shouldReceive('request')
->with(self::INSURANCE_SUBSCRIPTIONS_PATH . '/subscriptionId1/void')
->once()
->andReturn($this->requestObject);
$this->insuranceMock->cancelSubscription($subscriptionCancelPayload);
}

/**
* @dataProvider cancelSubscriptionErrorPayloadDataProvider
* @param $payload
Expand All @@ -926,6 +949,9 @@ public function testCheckSubscriptionIdFormatThrowParamsErrorForBadPayload($payl
$this->insuranceMock->checkSubscriptionIdFormat($payload);
}

/**
* @return array
*/
public function cancelSubscriptionErrorPayloadDataProvider()
{
return [
Expand Down

0 comments on commit 80ed0ec

Please sign in to comment.