Skip to content

Commit 9fc8862

Browse files
ianchambaclaude
andcommitted
fix: update webhook endpoints to company-scoped /webhooks
- Change webhook URI from `/hooks` to `/webhooks` in APIResource - Make NFe_Webhook methods company-scoped (matching ServiceInvoice pattern) - `create($companyId, $attributes)` instead of `create($attributes)` - `fetch($companyId, $webhookId)` instead of `fetch($key)` - `search($companyId, $options)` instead of `search($options)` This aligns the PHP SDK with the Node.js SDK v3 where webhooks are scoped under `/companies/{companyId}/webhooks/{webhookId}`. The old global `/hooks/{id}` endpoint returns 404, causing webhook operations to fail silently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3890f79 commit 9fc8862

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

lib/NFe/APIResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function objectBaseURI() {
2323
case 'service_invoice':
2424
return 'serviceInvoices';
2525
case 'webhook':
26-
return 'hooks';
26+
return 'webhooks';
2727
default:
2828
return $object_type . 's';
2929
}

lib/NFe/Webhook.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
<?php
22

33
class NFe_Webhook extends NFe_APIResource {
4-
public static function create( $attributes = array() ) {
4+
5+
/**
6+
* Create a new webhook for a company.
7+
*
8+
* @param string $companyId Company ID
9+
* @param array $attributes Webhook attributes (url, secret, events, status, contentType)
10+
* @return NFe_Webhook|null
11+
*/
12+
public static function create( $companyId, $attributes = array() ) {
13+
$attributes['company_id'] = $companyId;
514
return self::createAPI($attributes);
615
}
716

8-
public static function fetch( $key ) {
9-
return self::fetchAPI($key);
17+
/**
18+
* Fetch a specific webhook by company and webhook ID.
19+
*
20+
* @param string $companyId Company ID
21+
* @param string $webhookId Webhook ID
22+
* @return NFe_Webhook|null
23+
*/
24+
public static function fetch( $companyId, $webhookId ) {
25+
return self::fetchAPI( array( 'company_id' => $companyId, 'id' => $webhookId ) );
1026
}
1127

12-
public function save() {
13-
return $this->saveAPI();
28+
/**
29+
* List all webhooks for a company.
30+
*
31+
* @param string $companyId Company ID
32+
* @param array $options Search options
33+
* @return NFe_SearchResult|array
34+
*/
35+
public static function search( $companyId, $options = array() ) {
36+
return self::searchAPI( array_merge( $options, array( 'company_id' => $companyId ) ) );
1437
}
1538

16-
public function delete() {
17-
return $this->deleteAPI();
39+
public function save() {
40+
return $this->saveAPI();
1841
}
1942

20-
public function refresh() {
21-
return $this->refreshAPI();
43+
public function delete() {
44+
return $this->deleteAPI();
2245
}
2346

24-
public static function search( $options = array() ) {
25-
return self::searchAPI($options);
47+
public function refresh() {
48+
return $this->refreshAPI();
2649
}
2750
}

0 commit comments

Comments
 (0)