Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Merge e6db20d into 78dd956
Browse files Browse the repository at this point in the history
  • Loading branch information
alexions committed Jul 2, 2019
2 parents 78dd956 + e6db20d commit f795e54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Klarna/Rest/Resource.php
Expand Up @@ -100,6 +100,24 @@ public function setLocation($url)
return $this;
}

/**
* Overrides: Stores the ID KEY field in order to restore it after exchanging the array without
* the ID field.
*
* @param array $array Data to be exchanged
*/
public function exchangeArray($array)
{
$id = $this->getId();

if (!is_null($array)) {
parent::exchangeArray($array);
}
if (is_null($this->getId()) && !is_null($id)) {
$this->setId($id);
}
}

/**
* Fetches the resource.
*
Expand All @@ -125,6 +143,19 @@ public function fetch()
return $this;
}

/**
* Sets new ID KEY field.
*
* @param mixed $id ID field
*
* @return self
*/
protected function setId($id)
{
$this[static::ID_FIELD] = $id;
return $this;
}

/**
* Sends a HTTP request to the specified url.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Component/Payments/SessionsTest.php
Expand Up @@ -119,7 +119,9 @@ public function testFetch()
$session = new Sessions($this->connector, '0b1d9815');
$session['status'] = 'incompleted';

$this->assertEquals('0b1d9815', $session->getId());
$session->fetch();
$this->assertEquals('0b1d9815', $session->getId()); // Check if the ID field still exists

$this->assertEquals('completed', $session['status']);
$this->assertEquals(123, $session['order_amount']);
Expand Down

0 comments on commit f795e54

Please sign in to comment.