Skip to content

Commit

Permalink
Added Submit For Settlement functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesflynn committed Jan 8, 2016
1 parent 01bf0b7 commit a2b69e6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
8 changes: 8 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func (r *Response) subscription() (*Subscription, error) {
return &b, nil
}

func (r *Response) settlement() (*SettlementBatchSummary, error) {
var b SettlementBatchSummary
if err := xml.Unmarshal(r.Body, &b); err != nil {
return nil, err
}
return &b, nil
}

func (r *Response) address() (*Address, error) {
var b Address
if err := xml.Unmarshal(r.Body, &b); err != nil {
Expand Down
25 changes: 25 additions & 0 deletions settlement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package braintree

type Record struct {
XMLName string `xml:"record"`
CardType string `xml:"card-type"`
Count int `xml:"count"`
MerchantAccountId string `xml:"merchant-account_id"`
Kind string `xml:"kind"`
AmountSettled *Decimal `xml:"amount-settled"`
}

type XMLRecords struct {
XMLName string `xml:"records"`
Type []Record `xml:"record"`
}
type SettlementBatchSummary struct {
XMLName string `xml:"settlement-batch-summary"`
Records XMLRecords `xml:"records"`
}

type Settlement struct {
XMLName string `xml:"settlement_batch_summary"`
Date string `xml:"settlement_date"`
//CustomField string `xml:group_by_custom_field"`
}
17 changes: 17 additions & 0 deletions settlement_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package braintree

type SettlementGateway struct {
*Braintree
}

func (sg *SettlementGateway) Generate(s *Settlement) (*SettlementBatchSummary, error) {
resp, err := sg.execute("POST", "settlement_batch_summary", s)
if err != nil {
return nil, err
}
switch resp.StatusCode {
case 200:
return resp.settlement()
}
return nil, &invalidResponseError{resp}
}
11 changes: 3 additions & 8 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,26 @@ type Transaction struct {
CreatedAt *time.Time `xml:"created-at,omitempty"`
UpdatedAt *time.Time `xml:"updated-at,omitempty"`
DisbursementDetails *DisbursementDetails `xml:"disbursement-details,omitempty"`
RefundIds *[]string `xml:"refund-ids>item,omitempty"`
RefundId string `xml:"refund-id,omitempty"`
RefundIds *[]string `xml:"refund-ids,omitempty"`
RefundedTransactionId *string `xml:"refunded-transaction-id,omitempty"`
ProcessorResponseCode int `xml:"processor-response-code,omitempty"`
ProcessorResponseText string `xml:"processor-response-text,omitempty"`
ProcessorAuthorizationCode string `xml:"processor-authorization-code,omitempty"`
SettlementBatchId string `xml:"settlement-batch-id,omitempty"`
}

// TODO: not all transaction fields are implemented yet, here are the missing fields (add on demand)
//
// <transaction>
// <currency-iso-code>USD</currency-iso-code>
// <refund-id nil="true"></refund-id>
// <refund-ids type="array"/>
// <refunded-transaction-id nil="true"></refunded-transaction-id>
// <settlement-batch-id>2013-10-08_49grybq7pbtsnvsr</settlement-batch-id>
// <custom-fields>
// </custom-fields>
// <avs-error-response-code nil="true"></avs-error-response-code>
// <avs-postal-code-response-code>I</avs-postal-code-response-code>
// <avs-street-address-response-code>I</avs-street-address-response-code>
// <cvv-response-code>I</cvv-response-code>
// <gateway-rejection-reason nil="true"></gateway-rejection-reason>
// <processor-authorization-code>YCSBWR</processor-authorization-code>
// <processor-response-code>1000</processor-response-code>
// <processor-response-text>Approved</processor-response-text>
// <voice-referral-number nil="true"></voice-referral-number>
// <purchase-order-number nil="true"></purchase-order-number>
// <tax-amount nil="true"></tax-amount>
Expand Down

0 comments on commit a2b69e6

Please sign in to comment.