forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_notification.go
50 lines (43 loc) · 1.73 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
package braintree
import (
"encoding/xml"
"time"
)
const (
SubscriptionCanceled = "subscription_canceled"
SubscriptionChargedSuccessfully = "subscription_charged_successfully"
SubscriptionChargedUnsuccessfully = "subscription_charged_unsuccessfully"
SubscriptionExpired = "subscription_expired"
SubscriptionTrialEnded = "subscription_trial_ended"
SubscriptionWentActive = "subscription_went_active"
SubscriptionWentPastDue = "subscription_went_past_due"
SubMerchantAccountApproved = "sub_merchant_account_approved"
SubMerchantAccountDeclined = "sub_merchant_account_declined"
TransactionDisbursed = "transaction_disbursed"
PartnerMerchantConnected = "partner_merchant_connected"
PartnerMerchantDisconnected = "partner_merchant_disconnected"
PartnerMerchantDeclined = "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
}
type webhookSubject struct {
XMLName xml.Name `xml:"subject"`
APIErrorResponse *braintreeError `xml:",omitempty"`
Subscription *Subscription `xml:",omitempty"`
MerchantAccount *MerchantAccount `xml:"merchant-account,omitempty"`
Transaction *Transaction `xml:",omitempty"`
// Remaining Fields:
// partner_merchant
}