#192: refactor Event type

This commit is contained in:
Alex Pliutau 2021-04-10 17:56:52 +02:00
parent 1e23f8dd7d
commit 52acc61786
3 changed files with 26 additions and 16 deletions

View File

@ -355,7 +355,6 @@ c.DeleteWebhook("WebhookID")
// List registered webhooks
c.ListWebhooks(paypal.AncorTypeApplication)
```
## How to Contribute

View File

@ -1056,19 +1056,33 @@ type (
Links []Link `json:"links"`
}
// WebhookEvent struct
WebhookEvent struct {
// Event struct
Event struct {
ID string `json:"id"`
CreateTime time.Time `json:"create_time"`
ResourceType string `json:"resource_type"`
EventType string `json:"event_type"`
Summary string `json:"summary,omitempty"`
Resource Resource `json:"resource"`
Links []Link `json:"links"`
EventVersion string `json:"event_version,omitempty"`
ResourceVersion string `json:"resource_version,omitempty"`
}
AnyEvent struct {
Event
Resource json.RawMessage `json:"resource"`
}
PaymentPayoutsItemEvent struct {
Event
Resource PayoutItemResponse `json:"resource"`
}
PaymentPayoutsBatchEvent struct {
Event
Resource PayoutResponse `json:"resource"`
}
// WebhookEventType struct
WebhookEventType struct {
Name string `json:"name"`
@ -1107,14 +1121,11 @@ type (
SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"`
NoteToPayer string `json:"note_to_payer,omitempty"`
CustomID string `json:"custom_id,omitempty"`
// merchant-onboarding Resource type
PartnerClientID string `json:"partner_client_id,omitempty"`
MerchantID string `json:"merchant_id,omitempty"`
// Checkout Resource type
Intent string `json:"intent,omitempty"`
PurchaseUnits []*PurchaseUnitRequest `json:"purchase_units,omitempty"`
Payer *PayerWithNameAndPhone `json:"payer,omitempty"`
// Common
Links []Link `json:"links,omitempty"`
}

View File

@ -89,7 +89,7 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque
TransmissionSig string `json:"transmission_sig,omitempty"`
TransmissionTime string `json:"transmission_time,omitempty"`
WebhookID string `json:"webhook_id,omitempty"`
WebhookEvent json.RawMessage `json:"webhook_event"`
Event json.RawMessage `json:"webhook_event"`
}
// Read the content
@ -107,7 +107,7 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque
TransmissionSig: httpReq.Header.Get("PAYPAL-TRANSMISSION-SIG"),
TransmissionTime: httpReq.Header.Get("PAYPAL-TRANSMISSION-TIME"),
WebhookID: webhookID,
WebhookEvent: json.RawMessage(bodyBytes),
Event: json.RawMessage(bodyBytes),
}
response := &VerifyWebhookResponse{}