Skip to content

Commit

Permalink
Add ProcessorResponseType to Transaction (#273)
Browse files Browse the repository at this point in the history
What
===
Add ProcessorResponseType to Transaction.

Why
===
The official SDKs now expose a ProcessorResponseType field on
Transactions that indicates of a processor response is approved, soft
declined or hard declined.

https://developers.braintreepayments.com/reference/response/transaction#processor_response_type

Fixes #227
  • Loading branch information
leighmcculloch committed Nov 9, 2018
1 parent e642978 commit 3242ad9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions processor_response_type.go
@@ -0,0 +1,9 @@
package braintree

type ProcessorResponseType string

const (
ProcessorResponseTypeApproved ProcessorResponseType = "approved"
ProcessorResponseTypeSoftDeclined ProcessorResponseType = "soft_declined"
ProcessorResponseTypeHardDeclined ProcessorResponseType = "hard_declined"
)
1 change: 1 addition & 0 deletions transaction.go
Expand Up @@ -77,6 +77,7 @@ type Transaction struct {
RefundedTransactionId *string `xml:"refunded-transaction-id"`
ProcessorResponseCode ProcessorResponseCode `xml:"processor-response-code"`
ProcessorResponseText string `xml:"processor-response-text"`
ProcessorResponseType ProcessorResponseType `xml:"processor-response-type"`
ProcessorAuthorizationCode string `xml:"processor-authorization-code"`
SettlementBatchId string `xml:"settlement-batch-id"`
EscrowStatus EscrowStatus `xml:"escrow-status"`
Expand Down
7 changes: 7 additions & 0 deletions transaction_integration_test.go
Expand Up @@ -428,6 +428,9 @@ func TestTransactionCreateWhenGatewayRejected(t *testing.T) {
if err.(*BraintreeError).Transaction.ProcessorResponseCode != 2010 {
t.Fatalf("expected err.Transaction.ProcessorResponseCode to be 2010, but got %d", err.(*BraintreeError).Transaction.ProcessorResponseCode)
}
if err.(*BraintreeError).Transaction.ProcessorResponseType != ProcessorResponseTypeHardDeclined {
t.Fatalf("expected err.Transaction.ProcessorResponseType to be %s, but got %s", ProcessorResponseTypeHardDeclined, err.(*BraintreeError).Transaction.ProcessorResponseType)
}

if err.(*BraintreeError).Transaction.AdditionalProcessorResponse != "2010 : Card Issuer Declined CVV" {
t.Fatalf("expected err.Transaction.ProcessorResponseCode to be `2010 : Card Issuer Declined CVV`, but got %s", err.(*BraintreeError).Transaction.AdditionalProcessorResponse)
Expand Down Expand Up @@ -965,6 +968,10 @@ func TestAllTransactionFields(t *testing.T) {
if tx2.AdditionalProcessorResponse != "" {
t.Fatalf("expected tx2.AdditionalProcessorResponse to be empty, but got %s", tx2.AdditionalProcessorResponse)
}
if tx2.ProcessorResponseType != ProcessorResponseTypeApproved {
t.Fatalf("expected tx2.ProcessorResponseType to be %s, but got %s", ProcessorResponseTypeApproved, tx2.ProcessorResponseType)
}

if tx2.RiskData == nil {
t.Fatal("expected tx2.RiskData not to be empty")
}
Expand Down

0 comments on commit 3242ad9

Please sign in to comment.