forked from blacklightcms/recurly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credit_payments.go
58 lines (53 loc) · 2.29 KB
/
credit_payments.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
package recurly
import "encoding/xml"
// Credit payment action constants.
const (
CreditPaymentActionPayment = "payment" // applying the credit
CreditPaymentActionGiftCard = "gift_card"
CreditPaymentActionRefund = "refund"
CreditPaymentActionReduction = "reduction" // reducing the amount of the credit without applying it
CreditPaymentActionWriteOff = "write_off" // used for voiding invoices
)
// CreditPayment is a credit that has been applied to an invoice.
// This is a read-only object.
// Unmarshaling an invoice is handled by the custom UnmarshalXML function.
type CreditPayment struct {
XMLName xml.Name `xml:"credit_payment"`
AccountCode string `xml:"-"`
UUID string `xml:"uuid"`
Action string `xml:"action"`
Currency string `xml:"currency"`
AmountInCents int `xml:"amount_in_cents"`
OriginalInvoiceNumber int `xml:"-"`
AppliedToInvoice int `xml:"-"`
OriginalCreditPaymentUUID string `xml:"-"`
RefundTransactionUUID string `xml:"-"`
CreatedAt NullTime `xml:"created_at"`
UpdatedAt NullTime `xml:"updated_at,omitempty"`
VoidedAt NullTime `xml:"voided_at,omitempty"`
}
// UnmarshalXML unmarshals invoices and handles intermediary state during unmarshaling
// for types like href.
func (c *CreditPayment) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type creditPaymentAlias CreditPayment
var v struct {
XMLName xml.Name `xml:"credit_payment"`
creditPaymentAlias
AccountCode hrefString `xml:"account"`
OriginalInvoiceNumber hrefInt `xml:"original_invoice"`
AppliedToInvoice hrefInt `xml:"applied_to_invoice"`
OriginalCreditPayment hrefString `xml:"original_credit_payment,omitempty"`
RefundTransaction hrefString `xml:"refund_transaction,omitempty"`
}
if err := d.DecodeElement(&v, &start); err != nil {
return err
}
*c = CreditPayment(v.creditPaymentAlias)
c.XMLName = v.XMLName
c.AccountCode = string(v.AccountCode)
c.OriginalInvoiceNumber = int(v.OriginalInvoiceNumber)
c.AppliedToInvoice = int(v.AppliedToInvoice)
c.OriginalCreditPaymentUUID = string(v.OriginalCreditPayment)
c.RefundTransactionUUID = string(v.RefundTransaction)
return nil
}