Skip to content

Commit

Permalink
Merge pull request #52 from BrandonKerr/fix-updateCustomerAddress
Browse files Browse the repository at this point in the history
Add optional responseKey to updateResource and fix updateCustomerAddress
  • Loading branch information
emilhorlyck authored Sep 22, 2024
2 parents a6ce873 + 43d6b1c commit 9a2496f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/REST/Actions/ManagesCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getCustomerAddress($customerId, $addressId): ApiResource

public function updateCustomerAddress($customerId, $addressId, $data): ApiResource
{
return $this->updateResource('addresses', $addressId, $data, ['customers', $customerId]);
return $this->updateResource('addresses', $addressId, $data, ['customers', $customerId], 'customer_address');
}

public function deleteCustomerAddress($customerId, $addressId): void
Expand Down
6 changes: 5 additions & 1 deletion src/Support/MakesHttpRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ protected function getResource(string $resource, $resourceId, array $uriPrefix =
return new $resourceClass($response[$key], $this);
}

protected function updateResource(string $resource, $resourceId, array $data, array $uriPrefix = []): ApiResource
protected function updateResource(string $resource, $resourceId, array $data, array $uriPrefix = [], string $responseKey = null): ApiResource
{
$key = Str::singular($resource);
$resourceClass = $this->resourceClassFor($resource);

$response = $this->put(implode('/', [...$uriPrefix, "{$resource}/{$resourceId}.json"]), [$key => $data]);

if (! empty($responseKey)) {
$key = $responseKey;
}

return new $resourceClass($response[$key], $this);
}

Expand Down

0 comments on commit 9a2496f

Please sign in to comment.