-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ad04bb
commit 8585943
Showing
7 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hyperse/paypal-node-sdk": patch | ||
--- | ||
|
||
Add `webhooks` apis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import querystring from 'querystring'; | ||
import { HttpRequestBase } from '../core/HttpRequestBase.js'; | ||
import { type BaseWebhookHeaders } from '../types/type-webhook.js'; | ||
|
||
type WebhookCreateRequestBody = { | ||
/** | ||
* The URL that is configured to listen on localhost for incoming POST notification messages that contain event information. | ||
* https://example.com/example_webhook | ||
*/ | ||
url: string; | ||
/** | ||
* An array of events to which to subscribe your webhook. To subscribe to all events, including events as they are added, specify the asterisk wild card. | ||
* To replace the event_types array, specify the asterisk wild card. To list all supported events: @link https://developer.paypal.com/docs/api/webhooks/v1/#event-type_list | ||
* [ { "name": "PAYMENT.AUTHORIZATION.CREATED" }, { "name": "PAYMENT.AUTHORIZATION.VOIDED" } ] | ||
*/ | ||
event_types: Array<{ name: string }>; | ||
}; | ||
|
||
/** | ||
* Subscribes your webhook listener to events. | ||
* @see {@link https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post} | ||
*/ | ||
export class WebhookCreateRequest extends HttpRequestBase< | ||
BaseWebhookHeaders, | ||
WebhookCreateRequestBody | ||
> { | ||
constructor(webhookId: string) { | ||
super(); | ||
this.verb = 'POST'; | ||
this.path = '/v1/notifications/webhooks/{webhook_id}?'; | ||
this.path = this.path.replace( | ||
'{webhook_id}', | ||
querystring.escape(webhookId) | ||
); | ||
this.headers = { | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
|
||
requestBody(createRequest: WebhookCreateRequestBody) { | ||
this.body = createRequest; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import querystring from 'querystring'; | ||
import { HttpRequestBase } from '../core/HttpRequestBase.js'; | ||
import { type BaseWebhookHeaders } from '../types/type-webhook.js'; | ||
|
||
/** | ||
* Delete webhook, Deletes a webhook, by ID. | ||
* @see {@link https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_delete} | ||
* | ||
*/ | ||
export class WebhookDeleteRequest extends HttpRequestBase<BaseWebhookHeaders> { | ||
constructor(webhookId: string) { | ||
super(); | ||
this.verb = 'DELETE'; | ||
this.path = '/v1/notifications/webhooks/{webhook_id}?'; | ||
this.path = this.path.replace( | ||
'{webhook_id}', | ||
querystring.escape(webhookId) | ||
); | ||
this.headers = { | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import querystring from 'querystring'; | ||
import { HttpRequestBase } from '../core/HttpRequestBase.js'; | ||
import { type BaseWebhookHeaders } from '../types/type-webhook.js'; | ||
|
||
/** | ||
* Lists webhooks for an app. | ||
* @see {@link https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_list} | ||
* | ||
*/ | ||
export class WebhookListRequest extends HttpRequestBase<BaseWebhookHeaders> { | ||
constructor(anchorType: 'APPLICATION' | 'ACCOUNT' = 'APPLICATION') { | ||
super(); | ||
this.verb = 'GET'; | ||
this.path = '/v1/notifications/webhooks?anchor_type={anchor_type}'; | ||
this.path = this.path.replace( | ||
'{anchor_type}', | ||
querystring.escape(anchorType) | ||
); | ||
this.headers = { | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import querystring from 'querystring'; | ||
import { HttpRequestBase } from '../core/HttpRequestBase.js'; | ||
import { type BaseWebhookHeaders } from '../types/type-webhook.js'; | ||
|
||
type WebhookUpdateRequestBody = { | ||
/** | ||
* The operation. | ||
*/ | ||
op: 'add' | 'replace' | 'remove' | 'move' | 'copy'; | ||
/** | ||
* The JSON Pointer to the target document location at which to complete the operation. | ||
* @example `/event_types` | ||
*/ | ||
path: string; | ||
/** | ||
* The value to apply. The remove operation does not require a value. | ||
* [ { "name": "PAYMENT.SALE.REFUNDED" } ] | ||
*/ | ||
value: string | Array<{ name: string }>; | ||
/** | ||
* The JSON Pointer to the target document location from which to move the value. Required for the move operation. | ||
*/ | ||
from: string; | ||
}; | ||
|
||
/** | ||
* Updates a webhook to replace webhook fields with new values. Supports only the replace operation. | ||
* Pass a json_patch object with replace operation and path, which is /url for a URL or /event_types for events. The value is either the URL or a list of events. | ||
* @see {@link https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_update} | ||
* | ||
*/ | ||
export class WebhookUpdateRequest extends HttpRequestBase< | ||
BaseWebhookHeaders, | ||
WebhookUpdateRequestBody | ||
> { | ||
constructor(webhookId: string) { | ||
super(); | ||
this.verb = 'POST'; | ||
this.path = '/v1/notifications/webhooks/{webhook_id}?'; | ||
this.path = this.path.replace( | ||
'{webhook_id}', | ||
querystring.escape(webhookId) | ||
); | ||
this.headers = { | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
|
||
requestBody(updateRequest: WebhookUpdateRequestBody) { | ||
this.body = updateRequest; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters