Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Fix auth net request nil pointer (#245)
Browse files Browse the repository at this point in the history
Description: fixed an nil pointer panics in auth net request builder

TestPlan: unit tests
  • Loading branch information
linw50 authored Oct 19, 2022
1 parent ac34c99 commit ff18214
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
29 changes: 18 additions & 11 deletions gateways/authorizenet/request_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,28 @@ func buildAuthRequest(merchantName string, transactionKey string, authRequest *s
CreditCard: creditCard,
},
BillingAddress: &BillingAddress{
FirstName: authRequest.CreditCard.FirstName,
LastName: authRequest.CreditCard.LastName,
Address: billingAddress.StreetAddress1,
City: billingAddress.Locality,
State: billingAddress.RegionCode,
Zip: billingAddress.PostalCode,
Country: billingAddress.CountryCode,
PhoneNumber: billingAddress.PhoneNumber,
},
Customer: &Customer{
Email: common.SafeStr(billingAddress.Email),
FirstName: authRequest.CreditCard.FirstName,
LastName: authRequest.CreditCard.LastName,
},
},
}

if billingAddress != nil {
authorizeRequest.TransactionRequest.BillingAddress = &BillingAddress{
FirstName: authRequest.CreditCard.FirstName,
LastName: authRequest.CreditCard.LastName,
Address: billingAddress.StreetAddress1,
City: billingAddress.Locality,
State: billingAddress.RegionCode,
Zip: billingAddress.PostalCode,
Country: billingAddress.CountryCode,
PhoneNumber: billingAddress.PhoneNumber,
}
authorizeRequest.TransactionRequest.Customer = &Customer{
Email: common.SafeStr(billingAddress.Email),
}
}

if authRequest.MerchantOrderReference != "" {
invoiceNumber := sleet.TruncateString(authRequest.MerchantOrderReference, InvoiceNumberMaxLength)
authorizeRequest.TransactionRequest.Order = &Order{InvoiceNumber: invoiceNumber}
Expand Down
33 changes: 33 additions & 0 deletions gateways/authorizenet/request_builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,39 @@ func TestBuildAuthRequest(t *testing.T) {
},
},
},
{
"Basic Auth Request with nil Billing Address",
&sleet.AuthorizationRequest{
Amount: base.Amount,
CreditCard: base.CreditCard,
ClientTransactionReference: base.ClientTransactionReference,
ShopperReference: "test",
MerchantOrderReference: base.MerchantOrderReference,
},
&Request{
CreateTransactionRequest: CreateTransactionRequest{
MerchantAuthentication: MerchantAuthentication{Name: "MerchantName", TransactionKey: "Key"},
TransactionRequest: TransactionRequest{
TransactionType: TransactionTypeAuthOnly,
Amount: &amount,
Payment: &Payment{
CreditCard: CreditCard{
CardNumber: "4111111111111111",
ExpirationDate: "2023-10",
CardCode: base.CreditCard.CVV,
},
},
BillingAddress: &BillingAddress{
FirstName: "Bolt",
LastName: "Checkout",
},
Order: &Order{
InvoiceNumber: base.MerchantOrderReference[:InvoiceNumberMaxLength],
},
},
},
},
},
}

for _, c := range cases {
Expand Down

0 comments on commit ff18214

Please sign in to comment.