Skip to content

Commit

Permalink
Merge pull request #31 from ingrammicro/bug-fix-message-send
Browse files Browse the repository at this point in the history
BugFix:

* Usage Acceptance and Reject is consistent with all the other exceptions for transitioning usage file over workflow
* Moved away from strings to json_encode
  • Loading branch information
marcserrat authored Jun 6, 2019
2 parents 36c77b9 + a85a3ee commit 7eb8b72
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 160 deletions.
12 changes: 6 additions & 6 deletions src/FulfillmentAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ protected function dispatchTierConfig($tierConfigRequest)
$this->tierConfiguration->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"id": "' . $msg->templateid . '"}}'
json_encode(['template' => ['id' => $msg->templateid ]])
);
$processingResult = 'succeed (Activated using template ' . $msg->templateid . ')';
} else {
$this->tierConfiguration->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/approve',
'{"template": {"representation": "' . $msg->activationTile . '"}}'
json_encode(['template' => ['representation' => $msg->activationTile ]])
);
$processingResult = 'succeed (' . $msg->activationTile . ')';
}
Expand All @@ -84,7 +84,7 @@ protected function dispatchTierConfig($tierConfigRequest)
$this->tierConfiguration->sendRequest(
'POST',
'/tier/config-requests/' . $tierConfigRequest->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}'
json_encode(['reason' => $e->getMessage()])
);
$processingResult = 'fail';
} catch (Skip $e) {
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function dispatch($request)
$this->fulfillment->sendRequest(
'POST',
'/requests/' . $request->id . '/approve',
'{"template_id": "' . $msg->templateid . '"}'
json_encode(['template_id' => $msg->templateid])
);
try {
$request->conversation()->addMessage('Activated using template ' . $msg->templateid);
Expand All @@ -132,7 +132,7 @@ protected function dispatch($request)
$this->fulfillment->sendRequest(
'POST',
'/requests/' . $request->id . '/approve',
'{"activation_tile": "' . $msg->activationTile . '"}'
json_encode(['activation_tile' => $msg->activationTile])
);
try {
$request->conversation()->addMessage('Activated using Custom ActivationTile');
Expand All @@ -156,7 +156,7 @@ protected function dispatch($request)
$this->fulfillment->sendRequest(
'POST',
'/requests/' . $request->id . '/fail',
'{"reason": "' . $e->getMessage() . '"}'
json_encode(['reason' => $e->getMessage()])
);
try {
$request->conversation()->addMessage($e->getMessage());
Expand Down
11 changes: 4 additions & 7 deletions src/Usage/Accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
*/
class Accept extends \Connect\Message
{
public $response;

/**
* Accept constructor
* @param AcceptResponse $response
* Accept constructor.
* @param $message
*/
public function __construct($response)
public function __construct($message = null)
{
$this->response = $response;
parent::__construct('Accept Response is required', 'response');
parent::__construct($message ? $message : 'Usage data is correct', "accept");
}
}
33 changes: 0 additions & 33 deletions src/Usage/AcceptResponse.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Usage/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class File extends \Connect\Model
*/

public $note;
/**
* @var
*/

/**
* @var
*/
public $status;

/**
Expand Down
11 changes: 2 additions & 9 deletions src/Usage/Reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@
*/
class Reject extends \Connect\Message
{
public $response;

/**
* Accept constructor
* @param RejectResponse $response
*/
public function __construct($response)
public function __construct($message = null)
{
$this->response = $response;
parent::__construct('Accept Response is required', 'rejectresponse');
parent::__construct($message ? $message : 'Usage data is not correct', "reject");
}
}
33 changes: 0 additions & 33 deletions src/Usage/RejectResponse.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/UsageFileAutomation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function dispatchUsageFileProcessing($usageFile)
$this->usage->sendRequest(
'POST',
'/usage/files/' . $usageFile->id . '/accept/',
'{"acceptance_note": "' . $e->getMessage() . '""}'
json_encode(['acceptance_note' => $e->getMessage()])
);
$processingResult = 'accept';
} catch (Close $e) {
Expand All @@ -91,7 +91,7 @@ protected function dispatchUsageFileProcessing($usageFile)
$this->usage->sendRequest(
'POST',
'/usage/files/' . $usageFile->id . '/reject/',
'{"rejection_note": "' . $e->getMessage() . '""}'
json_encode(['rejection_note' => $e->getMessage()])
);
$processingResult = 'reject';
} catch (Submit $e) {
Expand Down
32 changes: 0 additions & 32 deletions tests/Unit/AcceptResponseTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Unit/AcceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testUsageInstantiation()

$this->assertInstanceOf('\Connect\Usage\Accept', $responseAccept);

$this->assertEquals("TD-123", $responseAccept->response);
$this->assertEquals("TD-123", $responseAccept->getMessage());
return $responseAccept;
}
}
32 changes: 0 additions & 32 deletions tests/Unit/RejectResponseTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Unit/RejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testInstantiation()

$this->assertInstanceOf('\Connect\Usage\Reject', $responseReject);

$this->assertEquals("TD-123", $responseReject->response);
$this->assertEquals("TD-123", $responseReject->getMessage());
return $responseReject;
}
}

0 comments on commit 7eb8b72

Please sign in to comment.