#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

@ -330,7 +330,7 @@ c.CreateWebhook(paypal.CreateWebhookRequest{
EventTypes: []paypal.WebhookEventType{ EventTypes: []paypal.WebhookEventType{
paypal.WebhookEventType{ paypal.WebhookEventType{
Name: "PAYMENT.AUTHORIZATION.CREATED", Name: "PAYMENT.AUTHORIZATION.CREATED",
}, },
}, },
}) })
@ -355,7 +355,6 @@ c.DeleteWebhook("WebhookID")
// List registered webhooks // List registered webhooks
c.ListWebhooks(paypal.AncorTypeApplication) c.ListWebhooks(paypal.AncorTypeApplication)
``` ```
## How to Contribute ## How to Contribute

View File

@ -1056,19 +1056,33 @@ type (
Links []Link `json:"links"` Links []Link `json:"links"`
} }
// WebhookEvent struct // Event struct
WebhookEvent struct { Event struct {
ID string `json:"id"` ID string `json:"id"`
CreateTime time.Time `json:"create_time"` CreateTime time.Time `json:"create_time"`
ResourceType string `json:"resource_type"` ResourceType string `json:"resource_type"`
EventType string `json:"event_type"` EventType string `json:"event_type"`
Summary string `json:"summary,omitempty"` Summary string `json:"summary,omitempty"`
Resource Resource `json:"resource"`
Links []Link `json:"links"` Links []Link `json:"links"`
EventVersion string `json:"event_version,omitempty"` EventVersion string `json:"event_version,omitempty"`
ResourceVersion string `json:"resource_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
WebhookEventType struct { WebhookEventType struct {
Name string `json:"name"` Name string `json:"name"`
@ -1107,15 +1121,12 @@ type (
SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"` SellerReceivableBreakdown *SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitempty"`
NoteToPayer string `json:"note_to_payer,omitempty"` NoteToPayer string `json:"note_to_payer,omitempty"`
CustomID string `json:"custom_id,omitempty"` CustomID string `json:"custom_id,omitempty"`
// merchant-onboarding Resource type PartnerClientID string `json:"partner_client_id,omitempty"`
PartnerClientID string `json:"partner_client_id,omitempty"` MerchantID string `json:"merchant_id,omitempty"`
MerchantID string `json:"merchant_id,omitempty"` Intent string `json:"intent,omitempty"`
// Checkout Resource type PurchaseUnits []*PurchaseUnitRequest `json:"purchase_units,omitempty"`
Intent string `json:"intent,omitempty"` Payer *PayerWithNameAndPhone `json:"payer,omitempty"`
PurchaseUnits []*PurchaseUnitRequest `json:"purchase_units,omitempty"` Links []Link `json:"links,omitempty"`
Payer *PayerWithNameAndPhone `json:"payer,omitempty"`
// Common
Links []Link `json:"links,omitempty"`
} }
CaptureSellerBreakdown struct { CaptureSellerBreakdown struct {

View File

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