diff --git a/.gitignore b/.gitignore index 274656f..7417caa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -/.idea \ No newline at end of file +/.idea +.vscode diff --git a/README.md b/README.md index de96ef0..88b4245 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ if response.Approved() { ```go oldTransaction := AuthorizeCIM.PreviousTransaction{ Amount: "49.99", - RefId: "AUTHCODEHERE001", + RefID: "AUTHCODEHERE001", } response, err := oldTransaction.Capture() if response.Approved() { @@ -149,7 +149,7 @@ newTransaction := AuthorizeCIM.NewTransaction{ CardNumber: "4012888818888", ExpirationDate: "10/24", }, - RefTransId: "0392482938402", + RefTransID: "0392482938402", } response, err := newTransaction.Refund() if response.Approved() { @@ -161,7 +161,7 @@ if response.Approved() { :white_check_mark: voidTransaction ```go oldTransaction := AuthorizeCIM.PreviousTransaction{ - RefId: "3987324293834", + RefID: "3987324293834", } response, err := oldTransaction.Void() if response.Approved() { @@ -227,7 +227,7 @@ fmt.Println("Unsettled Count: ", transactions.Count) ```go oldTransaction := AuthorizeCIM.PreviousTransaction{ Amount: "49.99", - RefId: "39824723983", + RefID: "39824723983", } response, err := oldTransaction.Approve() @@ -718,7 +718,7 @@ for _, v := range batches { :white_check_mark: getTransactionDetails ```go oldTransaction := AuthorizeCIM.PreviousTransaction{ - RefId: "60019493304", + RefID: "60019493304", } response := oldTransaction.Info() diff --git a/_examples/new_transaction/main.go b/_examples/new_transaction/main.go index 5e682c8..a73eea7 100644 --- a/_examples/new_transaction/main.go +++ b/_examples/new_transaction/main.go @@ -1,9 +1,10 @@ package main import ( - auth "github.com/hunterlong/authorizecim" - "os" "fmt" + "os" + + auth "github.com/hunterlong/authorizecim" ) var newTransactionId string @@ -13,7 +14,7 @@ func main() { apiName := os.Getenv("apiName") apiKey := os.Getenv("apiKey") - auth.SetAPIInfo(apiName,apiKey,"test") + auth.SetAPIInfo(apiName, apiKey, "test") if auth.IsConnected() { fmt.Println("Connected to Authorize.net!") @@ -26,41 +27,40 @@ func main() { func ChargeCustomer() { - newTransaction := auth.NewTransaction{ - Amount: "13.75", - CreditCard: auth.CreditCard{ - CardNumber: "4012888818888", - ExpirationDate: "08/25", - CardCode: "393", - }, - BillTo: &auth.BillTo{ - FirstName: "Timmy", - LastName: "Jimmy", - Address: "1111 green ct", - City: "los angeles", - State: "CA", - Zip: "43534", - Country: "USA", - PhoneNumber: "8885555555", - }, - } - response := newTransaction.Charge() + newTransaction := auth.NewTransaction{ + Amount: "13.75", + CreditCard: auth.CreditCard{ + CardNumber: "4012888818888", + ExpirationDate: "08/25", + CardCode: "393", + }, + BillTo: &auth.BillTo{ + FirstName: "Timmy", + LastName: "Jimmy", + Address: "1111 green ct", + City: "los angeles", + State: "CA", + Zip: "43534", + Country: "USA", + PhoneNumber: "8885555555", + }, + } + response := newTransaction.Charge() - if response.Approved() { - newTransactionId = response.TransactionID() - fmt.Println("Transaction was Approved! #",response.TransactionID()) - } + if response.Approved() { + newTransactionId = response.TransactionID() + fmt.Println("Transaction was Approved! #", response.TransactionID()) + } } - func VoidTransaction() { newTransaction := auth.PreviousTransaction{ - RefId: newTransactionId, + RefID: newTransactionId, } response := newTransaction.Void() if response.Approved() { fmt.Println("Transaction was Voided!") } -} \ No newline at end of file +} diff --git a/authorizecim.go b/authorizecim.go index 4c08606..5a32f01 100644 --- a/authorizecim.go +++ b/authorizecim.go @@ -2,7 +2,6 @@ package AuthorizeCIM import ( "bytes" - "fmt" "io/ioutil" "net/http" ) @@ -58,9 +57,7 @@ func SendRequest(input []byte) ([]byte, error) { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf")) - if showLogs { - fmt.Println(string(body)) - } + return body, err } diff --git a/customer_profile.go b/customer_profile.go index 9f9310b..38a3a0d 100644 --- a/customer_profile.go +++ b/customer_profile.go @@ -125,7 +125,7 @@ func ValidatePaymentProfile(customer Customer) (*ValidateCustomerPaymentProfileR MerchantAuthentication: GetAuthentication(), CustomerProfileID: customer.ID, CustomerPaymentProfileID: customer.PaymentID, - ValidationMode: testMode, + ValidationMode: "testMode", }, } jsoned, err := json.Marshal(action) @@ -166,7 +166,7 @@ func CreateProfile(profile Profile) (*CustomProfileResponse, error) { CreateCustomerProfile: CreateCustomerProfile{ MerchantAuthentication: GetAuthentication(), Profile: profile, - ValidationMode: testMode, + ValidationMode: "testMode", }, } jsoned, err := json.Marshal(action) @@ -225,7 +225,7 @@ func UpdatePaymentProfile(profile Profile) (*MessagesResponse, error) { Payment: profile.PaymentProfiles.Payment, CustomerPaymentProfileID: profile.PaymentProfileId, }, - ValidationMode: testMode, + ValidationMode: "testMode", }, } dat, err := MessageResponder(action) diff --git a/customer_profile_test.go b/customer_profile_test.go index 7f14ed7..acb7b54 100644 --- a/customer_profile_test.go +++ b/customer_profile_test.go @@ -17,10 +17,12 @@ func init() { } func TestSetAPIInfo(t *testing.T) { - apiName := os.Getenv("apiName") - apiKey := os.Getenv("apiKey") - //apiMode := os.Getenv("mode") + apiName := os.Getenv("AUTHORIZE_ID") + apiKey := os.Getenv("AUTHORIZE_TRANSACTION_KEY") + // apiMode := os.Getenv("AUTHORIZE_API_ENVIRONMENT") + SetAPIInfo(apiName, apiKey, "test") + t.Log("API Info Set") } diff --git a/fraud_management.go b/fraud_management.go index a652274..eaebd4e 100644 --- a/fraud_management.go +++ b/fraud_management.go @@ -76,10 +76,10 @@ func SendTransactionUpdate(tranx PreviousTransaction, method string) (*Transacti action := UpdateHeldTransactionRequest{ UpdateHeldTransaction: UpdateHeldTransaction{ MerchantAuthentication: GetAuthentication(), - RefID: tranx.RefId, + RefID: tranx.RefID, HeldTransactionRequest: HeldTransactionRequest{ Action: method, - RefTransID: tranx.RefId, + RefTransID: tranx.RefID, }, }, } diff --git a/fraud_management_test.go b/fraud_management_test.go index e838bfd..f8abf6b 100644 --- a/fraud_management_test.go +++ b/fraud_management_test.go @@ -10,14 +10,14 @@ func TestGetUnsettledTransactions(t *testing.T) { t.Fail() } - t.Log("Count Unsettled: ", transactions.Count) + // t.Log("Count Unsettled: ", transactions.Count) t.Log(transactions.List()) } func TestApproveTransaction(t *testing.T) { oldTransaction := PreviousTransaction{ Amount: "49.99", - RefId: "39824723983", + RefID: "39824723983", } response, err := oldTransaction.Approve() @@ -35,7 +35,7 @@ func TestApproveTransaction(t *testing.T) { func TestDeclineTransaction2(t *testing.T) { oldTransaction := PreviousTransaction{ Amount: "49.99", - RefId: "39824723983", + RefID: "39824723983", } response, err := oldTransaction.Decline() diff --git a/payment_transactions.go b/payment_transactions.go index 6631d58..0b7de64 100644 --- a/payment_transactions.go +++ b/payment_transactions.go @@ -24,6 +24,7 @@ func (tranx NewTransaction) ChargeProfile(profile Customer) (*TransactionRespons new = TransactionRequest{ TransactionType: "authCaptureTransaction", Amount: tranx.Amount, + LineItems: tranx.LineItems, Profile: &Profile{ CustomerProfileId: profile.ID, PaymentProfile: &PaymentProfile{ @@ -53,7 +54,7 @@ func (tranx NewTransaction) Refund() (*TransactionResponse, error) { new = TransactionRequest{ TransactionType: "refundTransaction", Amount: tranx.Amount, - RefTransId: tranx.RefTransId, + RefTransID: tranx.RefTransID, } response, err := SendTransactionRequest(new) return response, err @@ -63,7 +64,7 @@ func (tranx PreviousTransaction) Void() (*TransactionResponse, error) { var new TransactionRequest new = TransactionRequest{ TransactionType: "voidTransaction", - RefTransId: tranx.RefId, + RefTransID: tranx.RefID, } response, err := SendTransactionRequest(new) return response, err @@ -73,7 +74,7 @@ func (tranx PreviousTransaction) Capture() (*TransactionResponse, error) { var new TransactionRequest new = TransactionRequest{ TransactionType: "priorAuthCaptureTransaction", - RefTransId: tranx.RefId, + RefTransID: tranx.RefID, } response, err := SendTransactionRequest(new) return response, err @@ -128,16 +129,16 @@ func SendTransactionRequest(input TransactionRequest) (*TransactionResponse, err } type NewTransaction struct { - Amount string `json:"amount,omitempty"` - InvoiceId string `json:"invoiceId,omitempty"` - RefTransId string `json:"refTransId,omitempty"` - CreditCard CreditCard `json:"payment,omitempty"` - AuthCode string `json:"authCode,omitempty"` - BillTo *BillTo `json:"omitempty"` + Amount string `json:"amount,omitempty"` + RefTransID string `json:"refTransId,omitempty"` + CreditCard CreditCard `json:"payment,omitempty"` + AuthCode string `json:"authCode,omitempty"` + BillTo *BillTo `json:"billTo,omitempty"` + LineItems map[string]*LineItem `json:"lineItems,omitempty"` } type PreviousTransaction struct { - RefId string `json:"refTransId,omitempty"` + RefID string `json:"refTransId,omitempty"` Amount string `json:"amount,omitempty"` } @@ -204,10 +205,6 @@ type CreditCard struct { CardCode string `json:"cardCode,omitempty"` } -type LineItems struct { - LineItem []LineItem `json:"lineItem,omitempty"` -} - type LineItem struct { ItemID string `json:"itemId,omitempty"` Name string `json:"name,omitempty"` @@ -261,13 +258,14 @@ type UserField struct { } type TransactionRequest struct { - TransactionType string `json:"transactionType,omitempty"` - Amount string `json:"amount,omitempty"` - Payment *Payment `json:"payment,omitempty"` - RefTransId string `json:"refTransId,omitempty"` - AuthCode string `json:"authCode,omitempty"` - Profile *Profile `json:"profile,omitempty"` - LineItems *LineItems `json:"lineItems,omitempty"` + TransactionType string `json:"transactionType,omitempty"` + Amount string `json:"amount,omitempty"` + Payment *Payment `json:"payment,omitempty"` + RefTransID string `json:"refTransId,omitempty"` + InvoiceNumber string `json:"invoiseNumber,omitempty"` + AuthCode string `json:"authCode,omitempty"` + Profile *Profile `json:"profile,omitempty"` + LineItems map[string]*LineItem `json:"lineItems,omitempty"` //Tax Tax `json:"tax,omitempty"` //Duty Duty `json:"duty,omitempty"` //Shipping Shipping `json:"shipping,omitempty"` diff --git a/payment_transactions_test.go b/payment_transactions_test.go index 3533b68..e16ab40 100644 --- a/payment_transactions_test.go +++ b/payment_transactions_test.go @@ -170,7 +170,7 @@ func TestAuthOnlyCard(t *testing.T) { func TestCaptureAuth(t *testing.T) { oldTransaction := PreviousTransaction{ Amount: "49.99", - RefId: previousAuth, + RefID: previousAuth, } response, err := oldTransaction.Capture() if err != nil { @@ -212,7 +212,7 @@ func TestRefundCard(t *testing.T) { CardNumber: "4012888818888", ExpirationDate: "10/24", }, - RefTransId: "0392482938402", + RefTransID: "0392482938402", } response, err := newTransaction.Refund() if err != nil { @@ -227,7 +227,7 @@ func TestRefundCard(t *testing.T) { func TestVoidCard(t *testing.T) { newTransaction := PreviousTransaction{ - RefId: previousCharged, + RefID: previousCharged, } response, err := newTransaction.Void() if err != nil { diff --git a/transaction_reporting.go b/transaction_reporting.go index 2b1b8a3..5cb0dda 100644 --- a/transaction_reporting.go +++ b/transaction_reporting.go @@ -118,7 +118,7 @@ func (tranx PreviousTransaction) Info() (*FullTransaction, error) { new := GetTransactionDetailsRequest{ GetTransactionDetails: GetTransactionDetails{ MerchantAuthentication: GetAuthentication(), - TransID: tranx.RefId, + TransID: tranx.RefID, }, } jsoned, err := json.Marshal(new) diff --git a/transaction_reporting_test.go b/transaction_reporting_test.go index c334778..1206e75 100644 --- a/transaction_reporting_test.go +++ b/transaction_reporting_test.go @@ -50,7 +50,7 @@ func TestGetTransactionList(t *testing.T) { func TestGetTransactionDetails(t *testing.T) { newTransaction := PreviousTransaction{ - RefId: "60019493304", + RefID: "60019493304", } response, err := newTransaction.Info() if err != nil { diff --git a/xcleanup_test.go b/xcleanup_test.go index fca791e..2eb1444 100644 --- a/xcleanup_test.go +++ b/xcleanup_test.go @@ -134,7 +134,7 @@ func TestDeleteSecondCustomerProfile(t *testing.T) { func TestDeclineTransaction(t *testing.T) { oldTransaction := PreviousTransaction{ //Amount: "49.99", - RefId: heldTransactionId, + RefID: heldTransactionId, } response, err := oldTransaction.Decline() @@ -144,7 +144,7 @@ func TestDeclineTransaction(t *testing.T) { } if response.Approved() { - t.Log("DECLINED the previous transasction that was on Hold. ID #", oldTransaction.RefId) + t.Log("DECLINED the previous transasction that was on Hold. ID #", oldTransaction.RefID) t.Log(response.TransactionID()) } else { t.Log(response.ErrorMessage())