Skip to content

Commit

Permalink
Add risk data request to transaction
Browse files Browse the repository at this point in the history
What
===
Add transaction request fields for risk data for customer browser and
customer ID.

Why
===
The fields aren't settable, and requested in #127.
  • Loading branch information
leighmcculloch committed Apr 19, 2017
1 parent 087a5fe commit 371a3c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions transaction.go
Expand Up @@ -61,6 +61,7 @@ type TransactionRequest struct {
DeviceData string `xml:"device-data,omitempty"`
Options *TransactionOptions `xml:"options,omitempty"`
ServiceFeeAmount *Decimal `xml:"service-fee-amount,attr,omitempty"`
RiskData *RiskDataRequest `xml:"risk-data,omitempty"`
Descriptor *Descriptor `xml:"descriptor,omitempty"`
CustomFields customfields.CustomFields `xml:"custom-fields,omitempty"`
}
Expand Down Expand Up @@ -142,3 +143,8 @@ type RiskData struct {
ID string `xml:"id"`
Decision string `xml:"decision"`
}

type RiskDataRequest struct {
CustomerBrowser string `xml:"customer-browser"`
CustomerIP string `xml:"customer-ip"`
}
26 changes: 26 additions & 0 deletions transaction_integration_test.go
Expand Up @@ -329,6 +329,32 @@ func TestTransactionDescriptorFields(t *testing.T) {
}
}

func TestTransactionRiskDataFields(t *testing.T) {
t.Parallel()

tx := &TransactionRequest{
Type: "sale",
Amount: randomAmount(),
PaymentMethodNonce: FakeNonceTransactable,
RiskData: &RiskDataRequest{
CustomerBrowser: "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/540.0 (KHTML,like Gecko) Chrome/9.1.0.0 Safari/540.0",
CustomerIP: "127.0.0.1",
},
}

tx2, err := testGateway.Transaction().Create(tx)
if err != nil {
t.Fatal(err)
}

if tx2.Type != tx.Type {
t.Fatalf("expected Type to be equal, but %s was not %s", tx2.Type, tx.Type)
}
if tx2.Amount.Cmp(tx.Amount) != 0 {
t.Fatalf("expected Amount to be equal, but %s was not %s", tx2.Amount, tx.Amount)
}
}

func TestAllTransactionFields(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 371a3c2

Please sign in to comment.