Skip to content

Commit

Permalink
changed standard from Approved() to Ok() - cleaning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Mar 13, 2017
1 parent fcbf7e1 commit 0709cc9
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 112 deletions.
2 changes: 1 addition & 1 deletion authorizecim.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func SetAPIInfo(name string, key string, mode string) {

func IsConnected() bool {
info := GetMerchantDetails()
if info.Approved() {
if info.Ok() {
return true
}
return false
Expand Down
36 changes: 23 additions & 13 deletions customer_profile_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package AuthorizeCIM

import (
"math/rand"
"os"
"testing"
"time"
)

var newCustomerProfileId string
var newCustomerPaymentId string
var newCustomerShippingId string
var newSecondCustomerProfileId string

func init() {
rand.Seed(time.Now().UnixNano())
}

func TestSetAPIInfo(t *testing.T) {
apiName := os.Getenv("apiName")
Expand All @@ -27,8 +34,8 @@ func TestIsConnected(t *testing.T) {
func TestCreateCustomerProfile(t *testing.T) {

customer := Profile{
MerchantCustomerID: "21232",
Email: "info@brandnewuser.com",
MerchantCustomerID: RandomNumber(1000, 9999),
Email: "info@" + RandomString(8) + ".com",
PaymentProfiles: &PaymentProfiles{
CustomerType: "individual",
Payment: Payment{
Expand All @@ -43,7 +50,7 @@ func TestCreateCustomerProfile(t *testing.T) {

response := customer.CreateProfile()

if response.Approved() {
if response.Ok() {
newCustomerProfileId = response.CustomerProfileID
t.Log("New Customer Profile Created #", response.CustomerProfileID)
} else {
Expand Down Expand Up @@ -78,7 +85,7 @@ func TestUpdateCustomerProfile(t *testing.T) {

response := customer.UpdateProfile()

if response.Approved() {
if response.Ok() {
t.Log("Customer Profile was Updated")
} else {
t.Log(response.ErrorMessage())
Expand Down Expand Up @@ -112,7 +119,7 @@ func TestCreateCustomerPaymentProfile(t *testing.T) {

response := paymentProfile.Add()

if response.Approved() {
if response.Ok() {
newCustomerPaymentId = response.CustomerPaymentProfileID
t.Log("Created new Payment Profile #", response.CustomerPaymentProfileID, "for Customer ID: ", response.CustomerProfileId)
} else {
Expand Down Expand Up @@ -156,7 +163,7 @@ func TestValidateCustomerPaymentProfile(t *testing.T) {

response := customerProfile.Validate()

if response.Approved() {
if response.Ok() {
t.Log("Customer Payment Profile is VALID")
} else {
t.Log(response.ErrorMessage())
Expand All @@ -171,7 +178,7 @@ func TestUpdateCustomerPaymentProfile(t *testing.T) {
CustomerProfileId: newCustomerProfileId,
PaymentProfileId: newCustomerPaymentId,
Description: "Updated Account",
Email: "info@updatedemail.com",
Email: "info@" + RandomString(8) + ".com",
PaymentProfiles: &PaymentProfiles{
Payment: Payment{
CreditCard: CreditCard{
Expand All @@ -193,7 +200,7 @@ func TestUpdateCustomerPaymentProfile(t *testing.T) {

response := customer.UpdatePaymentProfile()

if response.Approved() {
if response.Ok() {
t.Log("Customer Payment Profile was Updated")
} else {
t.Log(response.ErrorMessage())
Expand All @@ -207,7 +214,7 @@ func TestCreateCustomerShippingProfile(t *testing.T) {
customer := Profile{
MerchantCustomerID: "86437",
CustomerProfileId: newCustomerProfileId,
Email: "info@emailhereooooo.com",
Email: "info@" + RandomString(8) + ".com",
Shipping: &Address{
FirstName: "My",
LastName: "Name",
Expand All @@ -223,7 +230,7 @@ func TestCreateCustomerShippingProfile(t *testing.T) {

response := customer.CreateShipping()

if response.Approved() {
if response.Ok() {
newCustomerShippingId = response.CustomerAddressID
t.Log("New Shipping Added: #", response.CustomerAddressID)
} else {
Expand Down Expand Up @@ -270,7 +277,7 @@ func TestUpdateCustomerShippingProfile(t *testing.T) {

response := customer.UpdateShippingProfile()

if response.Approved() {
if response.Ok() {
t.Log("Shipping Address Profile was updated")
} else {
t.Log(response.ErrorMessage())
Expand All @@ -288,9 +295,12 @@ func TestCreateCustomerProfileFromTransaction(t *testing.T) {
}

func TestCreateSubscriptionCustomerProfile(t *testing.T) {

amount := RandomNumber(5, 99) + "." + RandomNumber(10, 99)

subscription := Subscription{
Name: "New Customer Subscription",
Amount: "7.00",
Name: "New Customer Profile Subscription",
Amount: amount,
//TrialAmount: "0.00",
PaymentSchedule: &PaymentSchedule{
StartDate: CurrentDate(),
Expand Down
4 changes: 2 additions & 2 deletions fraud_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestApproveTransaction(t *testing.T) {

response := oldTransaction.Approve()

if response.Approved() {
if response.Ok() {
t.Log(response.ErrorMessage())
} else {
t.Log(response.ErrorMessage())
Expand All @@ -34,7 +34,7 @@ func TestDeclineTransaction(t *testing.T) {

response := oldTransaction.Decline()

if response.Approved() {
if response.Ok() {
t.Log(response.ErrorMessage())
} else {
t.Log(response.ErrorMessage())
Expand Down
50 changes: 30 additions & 20 deletions payment_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func (tranx NewTransaction) Charge() TransactionResponse {
Payment: &Payment{
CreditCard: tranx.CreditCard,
},
BillTo: tranx.BillTo,
AuthCode: tranx.AuthCode,
}
response, _ := SendTransactionRequest(new)
Expand Down Expand Up @@ -132,6 +133,7 @@ type NewTransaction struct {
RefTransId string `json:"refTransId,omitempty"`
CreditCard CreditCard `json:"payment,omitempty"`
AuthCode string `json:"authCode,omitempty"`
BillTo *BillTo `json:"omitempty"`
}

type PreviousTransaction struct {
Expand All @@ -140,28 +142,36 @@ type PreviousTransaction struct {
}

type TransactionResponse struct {
Response struct {
ResponseCode string `json:"responseCode"`
AuthCode string `json:"authCode"`
AvsResultCode string `json:"avsResultCode"`
CvvResultCode string `json:"cvvResultCode"`
CavvResultCode string `json:"cavvResultCode"`
TransID string `json:"transId"`
RefTransID string `json:"refTransID"`
TransHash string `json:"transHash"`
TestRequest string `json:"testRequest"`
AccountNumber string `json:"accountNumber"`
AccountType string `json:"accountType"`
Errors []AuthNetErrors `json:"errors"`
TransHashSha2 string `json:"transHashSha2"`
Message MessagesResponse
} `json:"transactionResponse"`
Response TranxResponse `json:"transactionResponse"`
MessagesResponse
}

type AuthNetErrors struct {
ErrorCode string `json:"errorCode"`
ErrorText string `json:"errorText"`
type TranxResponse struct {
ResponseCode string `json:"responseCode"`
AuthCode string `json:"authCode"`
AvsResultCode string `json:"avsResultCode"`
CvvResultCode string `json:"cvvResultCode"`
CavvResultCode string `json:"cavvResultCode"`
TransID string `json:"transId"`
RefTransID string `json:"refTransID"`
TransHash string `json:"transHash"`
TestRequest string `json:"testRequest"`
AccountNumber string `json:"accountNumber"`
AccountType string `json:"accountType"`
Errors []struct {
ErrorCode string `json:"errorCode"`
ErrorText string `json:"errorText"`
} `json:"errors"`
TransactionMessages
TransHashSha2 string `json:"transHashSha2"`
Message TransactionMessages
}

type TransactionMessages struct {
Message []struct {
Code string `json:"code"`
Description string `json:"description"`
} `json:"messages"`
}

type Message struct {
Expand Down Expand Up @@ -263,7 +273,7 @@ type TransactionRequest struct {
//Shipping Shipping `json:"shipping,omitempty"`
//PoNumber string `json:"poNumber,omitempty"`
//Customer Customer `json:"customer,omitempty"`
BillTo *Address `json:"billTo,omitempty"`
BillTo *BillTo `json:"billTo,omitempty"`
ShipTo *Address `json:"shipTo,omitempty"`
CustomerIP string `json:"customerIP,omitempty"`
//TransactionSettings TransactionSettings `json:"transactionSettings,omitempty"`
Expand Down
50 changes: 45 additions & 5 deletions payment_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ var previousCharged string

func TestChargeCard(t *testing.T) {
newTransaction := NewTransaction{
Amount: "15.90",
Amount: RandomNumber(5, 99) + ".90",
CreditCard: CreditCard{
CardNumber: "4007000000027",
ExpirationDate: "10/23",
},
BillTo: &BillTo{
FirstName: "okokk",
LastName: "okok",
Address: "1111 white ct",
City: "los angeles",
Country: "USA",
Zip: "29292",
PhoneNumber: "8885555555",
},
}
response := newTransaction.Charge()
if response.Approved() {
Expand All @@ -28,9 +37,39 @@ func TestChargeCard(t *testing.T) {
}
}

func TestDeclinedChargeCard(t *testing.T) {
newTransaction := NewTransaction{
Amount: RandomNumber(5, 99) + ".90",
CreditCard: CreditCard{
CardNumber: "4007000000027",
ExpirationDate: "10/23",
},
BillTo: &BillTo{
FirstName: "Fraud",
LastName: "User",
Address: "1337 Yolo Ln.",
City: "Beverly Hills",
State: "CA",
Country: "USA",
Zip: "46282",
PhoneNumber: "8885555555",
},
}
response := newTransaction.Charge()
if response.Approved() {
t.Fail()
} else {
previousCharged = response.TransactionID()
t.Log("#", response.TransactionID(), "Transaction was CHARGED $", newTransaction.Amount, "\n")
t.Log("AVS Result Code: ", response.AVS().avsResultCode+"\n")
t.Log("AVS ACVV Result Code: ", response.AVS().cavvResultCode+"\n")
t.Log("AVS CVV Result Code: ", response.AVS().cvvResultCode+"\n")
}
}

func TestAuthOnlyCard(t *testing.T) {
newTransaction := NewTransaction{
Amount: "100.00",
Amount: RandomNumber(5, 99) + ".00",
CreditCard: CreditCard{
CardNumber: "4012888818888",
ExpirationDate: "10/27",
Expand All @@ -49,7 +88,7 @@ func TestAuthOnlyCard(t *testing.T) {

func TestCaptureAuth(t *testing.T) {
oldTransaction := PreviousTransaction{
Amount: "49.99",
Amount: RandomNumber(5, 99) + ".99",
RefId: previousAuth,
}
response := oldTransaction.Capture()
Expand All @@ -64,7 +103,7 @@ func TestCaptureAuth(t *testing.T) {

func TestChargeCardChannel(t *testing.T) {
newTransaction := NewTransaction{
Amount: "38.00",
Amount: RandomNumber(5, 99) + ".00",
CreditCard: CreditCard{
CardNumber: "4012888818888",
ExpirationDate: "10/24",
Expand Down Expand Up @@ -111,6 +150,7 @@ func TestVoidCard(t *testing.T) {
t.Log("#", response.TransactionID(), "Transaction was VOIDED $", newTransaction.Amount, "\n")
} else {
t.Log(response.ErrorMessage(), "\n")
t.Log(response.Message(), "\n")
t.SkipNow()
}
}
Expand All @@ -126,7 +166,7 @@ func TestChargeCustomerProfile(t *testing.T) {
}

newTransaction := NewTransaction{
Amount: "35.00",
Amount: RandomNumber(5, 99) + ".00",
}

response := newTransaction.ChargeProfile(customer)
Expand Down
Loading

0 comments on commit 0709cc9

Please sign in to comment.