forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook_notification.go
61 lines (53 loc) · 2.17 KB
/
webhook_notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package braintree
import (
"encoding/xml"
"time"
)
const (
DisbursementWebhook = "disbursement"
DisbursementExceptionWebhook = "disbursement_exception"
SubscriptionCanceledWebhook = "subscription_canceled"
SubscriptionChargedSuccessfullyWebhook = "subscription_charged_successfully"
SubscriptionChargedUnsuccessfullyWebhook = "subscription_charged_unsuccessfully"
SubscriptionExpiredWebhook = "subscription_expired"
SubscriptionTrialEndedWebhook = "subscription_trial_ended"
SubscriptionWentActiveWebhook = "subscription_went_active"
SubscriptionWentPastDueWebhook = "subscription_went_past_due"
SubMerchantAccountApprovedWebhook = "sub_merchant_account_approved"
SubMerchantAccountDeclinedWebhook = "sub_merchant_account_declined"
TransactionDisbursedWebhook = "transaction_disbursed"
PartnerMerchantConnectedWebhook = "partner_merchant_connected"
PartnerMerchantDisconnectedWebhook = "partner_merchant_disconnected"
PartnerMerchantDeclinedWebhook = "partner_merchant_declined"
)
type WebhookNotification struct {
XMLName xml.Name `xml:"notification"`
Timestamp time.Time `xml:"timestamp"`
Kind string `xml:"kind"`
Subject *WebhookSubject `xml:"subject"`
}
func (n *WebhookNotification) MerchantAccount() *MerchantAccount {
if n.Subject.APIErrorResponse != nil && n.Subject.APIErrorResponse.MerchantAccount != nil {
return n.Subject.APIErrorResponse.MerchantAccount
} else if n.Subject.MerchantAccount != nil {
return n.Subject.MerchantAccount
}
return nil
}
func (n *WebhookNotification) Disbursement() *Disbursement {
if n.Subject.Disbursement != nil {
return n.Subject.Disbursement
} else {
return nil
}
}
type WebhookSubject struct {
XMLName xml.Name `xml:"subject"`
APIErrorResponse *BraintreeError `xml:",omitempty"`
Disbursement *Disbursement `xml:"disbursement,omitempty"`
Subscription *Subscription `xml:",omitempty"`
MerchantAccount *MerchantAccount `xml:"merchant-account,omitempty"`
Transaction *Transaction `xml:",omitempty"`
// Remaining Fields:
// partner_merchant
}