Skip to content

Commit

Permalink
Add optional responseKey to updateResource and fix updateCustomerAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Kerr committed Aug 30, 2023
1 parent 1ac02bb commit 43d6b1c
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 43d6b1c

Please sign in to comment.