Skip to content

Commit

Permalink
Merge branch 'feature/v3' of https://github.com/HubSpot/hubspot-php i…
Browse files Browse the repository at this point in the history
…nto feature/v3
  • Loading branch information
ksvirkou-hubspot committed Oct 13, 2020
2 parents 2cf3e8c + 9f552ed commit 0ab3b3b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
23 changes: 19 additions & 4 deletions src/Resources/Deals.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@ class Deals extends Resource
/**
* Create a deal.
*
* @param array $properties array of deal properties
* @param array $properties array of deal properties
* @param array $associations array of IDs for records that the new deal should be associated with
*
* @see https://developers.hubspot.com/docs/methods/deals/create_deal
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create(array $properties)
public function create(array $properties, array $associations = [])
{
$endpoint = 'https://api.hubapi.com/deals/v1/deal';

return $this->client->request('post', $endpoint, ['json' => $properties]);
$data = ['properties' => $properties];

if (!empty($associations)) {
$data['associations'] = $associations;
}

return $this->client->request(
'post',
$endpoint,
['json' => $data]
);
}

/**
Expand All @@ -37,7 +48,11 @@ public function update($id, array $properties)
{
$endpoint = "https://api.hubapi.com/deals/v1/deal/{$id}";

return $this->client->request('put', $endpoint, ['json' => $properties]);
return $this->client->request(
'put',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
Expand Down
37 changes: 18 additions & 19 deletions tests/Integration/Resources/DealsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
class DealsTest extends EntityTestCase
{
/**
* @var Deals
*/
protected $resource;

/**
* @var Deals::class
*/
Expand Down Expand Up @@ -49,11 +54,9 @@ public function create()
public function update()
{
$response = $this->resource->update($this->entity->dealId, [
'properties' => [
[
'name' => 'amount',
'value' => '70000',
],
[
'name' => 'amount',
'value' => '70000',
],
]);

Expand Down Expand Up @@ -109,11 +112,9 @@ public function all()
public function getRecentlyModified()
{
$this->resource->update($this->entity->dealId, [
'properties' => [
[
'name' => 'amount',
'value' => '70000',
],
[
'name' => 'amount',
'value' => '70000',
],
]);

Expand Down Expand Up @@ -317,15 +318,13 @@ protected function deleteContact($id)
protected function createEntity()
{
return $this->resource->create([
'properties' => [
[
'value' => 'Cool Deal',
'name' => 'dealname',
],
[
'value' => '60000',
'name' => 'amount',
],
[
'value' => 'Cool Deal',
'name' => 'dealname',
],
[
'value' => '60000',
'name' => 'amount',
],
]);
}
Expand Down

0 comments on commit 0ab3b3b

Please sign in to comment.