-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
2,055 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
# Ignore IDEA folder | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Auth-Only request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".AuthOnlyTest") | ||
// | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Auth-Only transaction. | ||
if gatewayService.PerformAuthOnly(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Auth-Only succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Transaction time: " + gatewayResponse.Get(response.TRANSACTION_TIME)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} else { | ||
fmt.Println("Auth-Only failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Transaction time: " + gatewayResponse.Get(response.TRANSACTION_TIME)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Auth-Only request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".AuthTicketTest") | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Auth-Only transaction. | ||
if gatewayService.PerformAuthOnly(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Auth-Only succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} else { | ||
fmt.Println("Auth-Only failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
return | ||
} | ||
// Setup the ticket request. | ||
gatewayRequest.Set(request.TRANSACT_ID, gatewayResponse.Get(response.TRANSACT_ID)) | ||
// Perform the Ticket transaction. | ||
if gatewayService.PerformTicket(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Ticket succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
} else { | ||
fmt.Println("Ticket failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Auth-Only request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".AuthVoidTest") | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Auth-Only transaction. | ||
if gatewayService.PerformAuthOnly(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Auth-Only succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} else { | ||
fmt.Println("Auth-Only failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
return | ||
} | ||
// Setup the void request. | ||
gatewayRequest.Set(request.TRANSACT_ID, gatewayResponse.Get(response.TRANSACT_ID)) | ||
// Perform the void transaction. | ||
if gatewayService.PerformVoid(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Void succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
} else { | ||
fmt.Println("Void failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
|
||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// TODO Add time prefix | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, "Go Test") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, "Sale Test") | ||
// | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Purchase request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".SaleTest") | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Purchase transaction. | ||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Card Issuer: " + gatewayResponse.Get(response.CARD_ISSUER_NAME)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Purchase request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".SaleTest") | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Purchase transaction. | ||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
|
||
// Set the transaction we want to credit. | ||
gatewayRequest.Set(request.TRANSACT_ID, gatewayResponse.Get(response.TRANSACT_ID)) | ||
// Perform the credit transaction. | ||
if gatewayService.PerformCredit(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Credit succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
} else { | ||
fmt.Println("Credit failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Purchase request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, fmt.Sprint(time)+".GoTest") | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, fmt.Sprint(time)+".SaleTest") | ||
// $1.99 3-day trial which renews to $9.99/month | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "1.99") | ||
gatewayRequest.Set(request.REBILL_START, "3") | ||
gatewayRequest.Set(request.REBILL_FREQUENCY, "MONTHLY") | ||
gatewayRequest.Set(request.REBILL_AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4111111111111111") | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Perform the Purchase transaction. | ||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Auth No: " + gatewayResponse.Get(response.AUTH_NO)) | ||
fmt.Println("AVS: " + gatewayResponse.Get(response.AVS_RESPONSE)) | ||
fmt.Println("CVV2: " + gatewayResponse.Get(response.CVV2_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
fmt.Println("Scrub: " + gatewayResponse.Get(response.SCRUB_RESULTS)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/rocketgate/rocketgate-go-sdk/request" | ||
"github.com/rocketgate/rocketgate-go-sdk/response" | ||
"github.com/rocketgate/rocketgate-go-sdk/service" | ||
) | ||
|
||
func main() { | ||
// Create gateway objects | ||
gatewayRequest := request.NewGatewayRequest() | ||
gatewayResponse := response.NewGatewayResponse() | ||
gatewayService := service.NewGatewayService() | ||
// Setup the Purchase request. | ||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
// For example/testing, we set the order id and customer as the unix timestamp as a convienent sequencing value | ||
// appending a test name to the order id to facilitate some clarity when reviewing the tests | ||
time := time.Now().Unix() | ||
cust_id := fmt.Sprint(time) + ".GoTest" | ||
inv_id := fmt.Sprint(time) + ".3DSTest" | ||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, cust_id) | ||
gatewayRequest.Set(request.MERCHANT_INVOICE_ID, inv_id) | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
|
||
gatewayRequest.Set(request.CARDNO, "4000000000001091") // This card will trigger a 3DS 2.0 stepUp in the TestProcessor | ||
gatewayRequest.Set(request.EXPIRE_MONTH, "02") | ||
gatewayRequest.Set(request.EXPIRE_YEAR, "2023") | ||
gatewayRequest.Set(request.CVV2, "999") | ||
|
||
gatewayRequest.Set(request.CUSTOMER_FIRSTNAME, "Joe") | ||
gatewayRequest.Set(request.CUSTOMER_LASTNAME, "GO Tester") | ||
gatewayRequest.Set(request.EMAIL, "gotest@fakedomain.com") | ||
gatewayRequest.Set(request.IPADDRESS, "192.168.1.1") | ||
// | ||
gatewayRequest.Set(request.BILLING_ADDRESS, "123 Main St") | ||
gatewayRequest.Set(request.BILLING_CITY, "Las Vegas") | ||
gatewayRequest.Set(request.BILLING_STATE, "NV") | ||
gatewayRequest.Set(request.BILLING_ZIPCODE, "89141") | ||
gatewayRequest.Set(request.BILLING_COUNTRY, "US") | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
// Request 3DS | ||
gatewayRequest.Set(request.USE_3D_SECURE, "TRUE") | ||
gatewayRequest.Set(request.BROWSER_USER_AGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36") | ||
gatewayRequest.Set(request.BROWSER_ACCEPT_HEADER, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") | ||
|
||
// Setup test parameters in the service and request. | ||
gatewayService.SetTestMode(true) | ||
|
||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Step 1: Perform the BIN intelligence transaction. | ||
gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) | ||
response_code := gatewayResponse.Get(response.RESPONSE_CODE) | ||
reason_code := gatewayResponse.Get(response.REASON_CODE) | ||
if response_code != fmt.Sprint(2) && reason_code != fmt.Sprint(225) { // RESPONSE_RISK_FAIL, REASON_3DSECURE_INITIATION | ||
fmt.Println("Response Code: " + response_code) | ||
fmt.Println("Reason Code: " + reason_code) | ||
return | ||
} | ||
|
||
fmt.Println("3DS 2.0 Device Fingerprinting Succeeded!") | ||
fmt.Println("Response Code: " + response_code) | ||
fmt.Println("Reason Code: " + reason_code) | ||
fmt.Println("Device Fingerprinting URL: " + gatewayResponse.Get(response.V_3DSECURE_DEVICE_COLLECTION_URL)) | ||
fmt.Println("Device Fingerprinting JWT: " + gatewayResponse.Get(response.V_3DSECURE_DEVICE_COLLECTION_JWT)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
|
||
// Recycle the first request and add two new fields | ||
gatewayRequest.Set(request.V_3DSECURE_DF_REFERENCE_ID, "fake") | ||
gatewayRequest.Set(request.V_3DSECURE_REDIRECT_URL, "fake") | ||
|
||
gatewayRequest.Set(request.BROWSER_JAVA_ENABLED, "TRUE") | ||
gatewayRequest.Set(request.BROWSER_LANGUAGE, "en-CA") | ||
gatewayRequest.Set(request.BROWSER_COLOR_DEPTH, "32") | ||
gatewayRequest.Set(request.BROWSER_SCREEN_HEIGHT, "1080") | ||
gatewayRequest.Set(request.BROWSER_SCREEN_WIDTH, "1920") | ||
gatewayRequest.Set(request.BROWSER_TIME_ZONE, "-240") | ||
|
||
// Step 2: Perform the Lookup transaction. | ||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Card Issuer: " + gatewayResponse.Get(response.CARD_ISSUER_NAME)) | ||
fmt.Println("Account: " + gatewayResponse.Get(response.MERCHANT_ACCOUNT)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} else if gatewayResponse.Get(response.REASON_CODE) == fmt.Sprint(202) { | ||
fmt.Println("3DS Lookup succeeded") | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("3DS Version: " + gatewayResponse.Get(response.V_3DSECURE_VERSION)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("PAREQ: " + gatewayResponse.Get(response.PAREQ)) | ||
fmt.Println("ACS URL: " + gatewayResponse.Get(response.ACS_URL)) | ||
fmt.Println("STEP-UP URL: " + gatewayResponse.Get(response.V_3DSECURE_STEP_UP_URL)) | ||
fmt.Println("STEP-UP JWT: " + gatewayResponse.Get(response.V_3DSECURE_STEP_UP_JWT)) | ||
// Setup the 3rd request. | ||
gatewayRequest := request.NewGatewayRequest() | ||
|
||
gatewayRequest.Set(request.MERCHANT_ID, "1") | ||
gatewayRequest.Set(request.MERCHANT_PASSWORD, "testpassword") | ||
|
||
gatewayRequest.Set(request.CVV2, "999") | ||
gatewayRequest.Set(request.REFERENCE_GUID, gatewayResponse.Get(response.TRANSACT_ID)) | ||
// In a real transaction this would include the PARES returned from the Authentication | ||
// On dev we send through the SimulatedPARES + TRANSACT_ID | ||
pares := "SimulatedPARES" + gatewayResponse.Get(response.TRANSACT_ID) | ||
gatewayRequest.Set(request.PARES, pares) | ||
// Risk/Scrub Request Setting | ||
gatewayRequest.Set(request.SCRUB, "IGNORE") | ||
gatewayRequest.Set(request.CVV2_CHECK, "IGNORE") | ||
gatewayRequest.Set(request.AVS_CHECK, "IGNORE") | ||
|
||
gatewayRequest.Set(request.MERCHANT_CUSTOMER_ID, cust_id) | ||
// | ||
gatewayRequest.Set(request.CURRENCY, "USD") | ||
gatewayRequest.Set(request.AMOUNT, "9.99") | ||
// Optional manual gateway | ||
gatewayRequest.Set(request.GATEWAY_SERVER, "local.rocketgate.com") | ||
gatewayRequest.Set(request.GATEWAY_PORTNO, "8443") | ||
gatewayRequest.Set(request.GATEWAY_PROTOCOL, "https") | ||
|
||
// Step 3: Perform the Purchase transaction. | ||
if gatewayService.PerformPurchase(gatewayRequest, gatewayResponse) { | ||
fmt.Println("Purchase succeeded") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} | ||
} else { | ||
fmt.Println("Purchase failed") | ||
fmt.Println("Response Code: " + gatewayResponse.Get(response.RESPONSE_CODE)) | ||
fmt.Println("Reason Code: " + gatewayResponse.Get(response.REASON_CODE)) | ||
fmt.Println("GUID: " + gatewayResponse.Get(response.TRANSACT_ID)) | ||
fmt.Println("Exception: " + gatewayResponse.Get(response.EXCEPTION)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module github.com/rocketgate/rocketgate-go-sdk | ||
|
||
go 1.17 | ||
|
||
require github.com/stretchr/testify v1.7.0 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
package request | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
/* Private constants */ | ||
const ( | ||
// GatewayRequest root XML element | ||
document_base string = "gatewayRequest" | ||
// Request parameter name for go sdk version | ||
version GatewayRequestParamType = "version" | ||
// GO SDK version | ||
version_no string = "GO5.10" | ||
) | ||
|
||
// GatewayRequestParamType is the list of allowed values for GatewayRequest parameters name | ||
type GatewayRequestParamType string | ||
|
||
// GatewayRequest Wrapper type for rocketgate gateway request | ||
type GatewayRequest map[string]string | ||
|
||
// NewGatewayRequest New GatewayRequest | ||
func NewGatewayRequest() *GatewayRequest { | ||
request := GatewayRequest{} | ||
request.Set(version, version_no) | ||
return &request | ||
} | ||
|
||
// Set request parameter value for key | ||
func (r GatewayRequest) Set(key GatewayRequestParamType, value string) { | ||
if r == nil { | ||
return | ||
} | ||
if len(strings.TrimSpace(value)) == 0 { | ||
delete(r, string(key)) | ||
} else { | ||
r[string(key)] = value | ||
} | ||
} | ||
|
||
// SetInt set request parameter int value for key | ||
func (r GatewayRequest) SetInt(key GatewayRequestParamType, value int) { | ||
r.Set(key, fmt.Sprint(value)) | ||
} | ||
|
||
func (r GatewayRequest) Get(key GatewayRequestParamType) string { | ||
return strings.TrimSpace(r[string(key)]) | ||
} | ||
|
||
func (r GatewayRequest) GetIntOrDefault(key GatewayRequestParamType, defaultValue int) int { | ||
value := r.Get(key) | ||
value = strings.TrimSpace(value) | ||
if value == "" { | ||
return defaultValue | ||
} | ||
intValue, err := strconv.Atoi(value) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return intValue | ||
} | ||
|
||
func (r GatewayRequest) GetInt(key GatewayRequestParamType) int { | ||
return r.GetIntOrDefault(key, -1) | ||
} | ||
|
||
func (r GatewayRequest) GetFloatOrDefault(key GatewayRequestParamType, defaultValue float64) float64 { | ||
value := r.Get(key) | ||
if value == "" { | ||
return defaultValue | ||
} | ||
floatValue, err := strconv.ParseFloat(value, 64) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return floatValue | ||
} | ||
|
||
func (r GatewayRequest) GetFloat(key GatewayRequestParamType) float64 { | ||
return r.GetFloatOrDefault(key, 0.0) | ||
} | ||
|
||
func (r GatewayRequest) GetReferenceGUID() int64 { | ||
value := r.Get(REFERENCE_GUID) | ||
if value == "" { | ||
return 0 | ||
} | ||
guid, err := strconv.ParseInt(value, 16, 64) | ||
if err != nil { | ||
return 0 | ||
} | ||
return guid | ||
} | ||
|
||
// ToXMLString return gateway XML request | ||
func (r GatewayRequest) ToXMLString() string { | ||
var xmlSb strings.Builder | ||
xmlSb.WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") | ||
xmlSb.WriteString("<" + document_base + ">\n") | ||
// TODO ensure version | ||
// Add key val parameters | ||
for key, val := range r { | ||
xmlSb.WriteString("<" + key + ">" + xmlEscape(val) + "</" + key + ">\n") | ||
} | ||
xmlSb.WriteString("</" + document_base + ">") | ||
return xmlSb.String() | ||
} | ||
|
||
// Escape XML value for request parameter | ||
func xmlEscape(value string) string { | ||
var buf bytes.Buffer | ||
xml.Escape(&buf, []byte(value)) | ||
return buf.String() | ||
} | ||
|
||
/* Public constants */ | ||
const ( | ||
AMOUNT GatewayRequestParamType = "amount" | ||
AVS_CHECK GatewayRequestParamType = "avsCheck" | ||
BILLING_ADDRESS GatewayRequestParamType = "billingAddress" | ||
BILLING_CITY GatewayRequestParamType = "billingCity" | ||
BILLING_COUNTRY GatewayRequestParamType = "billingCountry" | ||
BILLING_STATE GatewayRequestParamType = "billingState" | ||
BILLING_ZIPCODE GatewayRequestParamType = "billingZipCode" | ||
CARDNO GatewayRequestParamType = "cardNo" | ||
CURRENCY GatewayRequestParamType = "currency" | ||
CUSTOMER_FIRSTNAME GatewayRequestParamType = "customerFirstName" | ||
CUSTOMER_LASTNAME GatewayRequestParamType = "customerLastName" | ||
SSNUMBER GatewayRequestParamType = "ssnumber" | ||
CVV2 GatewayRequestParamType = "cvv2" | ||
CVV2_CHECK GatewayRequestParamType = "cvv2Check" | ||
EMAIL GatewayRequestParamType = "email" | ||
EXPIRE_MONTH GatewayRequestParamType = "expireMonth" | ||
EXPIRE_YEAR GatewayRequestParamType = "expireYear" | ||
IPADDRESS GatewayRequestParamType = "ipAddress" | ||
MERCHANT_ACCOUNT GatewayRequestParamType = "merchantAccount" | ||
MERCHANT_CUSTOMER_ID GatewayRequestParamType = "merchantCustomerID" | ||
MERCHANT_INVOICE_ID GatewayRequestParamType = "merchantInvoiceID" | ||
MERCHANT_ID GatewayRequestParamType = "merchantID" | ||
MERCHANT_PASSWORD GatewayRequestParamType = "merchantPassword" | ||
PREFERRED_MERCHANT_ACCOUNT GatewayRequestParamType = "preferredMerchantAccount" | ||
REFERENCE_GUID GatewayRequestParamType = "referenceGUID" | ||
TRANSACT_ID GatewayRequestParamType = REFERENCE_GUID | ||
TRANSACTION_TYPE GatewayRequestParamType = "transactionType" | ||
UDF01 GatewayRequestParamType = "udf01" | ||
UDF02 GatewayRequestParamType = "udf02" | ||
COF_FRAMEWORK GatewayRequestParamType = "cofFramework" | ||
// SCRUB parameter that enables scrubbing on server. | ||
SCRUB GatewayRequestParamType = "scrub" | ||
// Enhanced granularity of scrubs. | ||
SCRUB_PROFILE GatewayRequestParamType = "scrubProfile" | ||
SCRUB_ACTIVITY GatewayRequestParamType = "scrubActivity" | ||
SCRUB_NEGDB GatewayRequestParamType = "scrubNegDB" | ||
// CARD_HASH card hash value | ||
CARD_HASH GatewayRequestParamType = "cardHash" | ||
// PAY_HASH alias for CARD_HASH | ||
PAY_HASH GatewayRequestParamType = CARD_HASH | ||
// USERNAME parameter to allow passing of username. | ||
USERNAME GatewayRequestParamType = "username" | ||
// AFFILIATE parameter to allow passing of affiliate code. | ||
AFFILIATE GatewayRequestParamType = "affiliate" | ||
// MERCHANT_DESCRIPTOR parameter for dynamic descriptors | ||
MERCHANT_DESCRIPTOR GatewayRequestParamType = "merchantDescriptor" | ||
MERCHANT_DESCRIPTOR_TRIAL GatewayRequestParamType = "merchantDescriptorTrial" | ||
// MERCHANT_DESCRIPTOR_CITY parameter for dynamic descriptors city/phone | ||
MERCHANT_DESCRIPTOR_CITY GatewayRequestParamType = "merchantDescriptorCity" | ||
// MERCHANT_SITE_ID parameter for site ID | ||
MERCHANT_SITE_ID GatewayRequestParamType = "merchantSiteID" | ||
// BILLING_TYPE parameter for billing type. | ||
BILLING_TYPE GatewayRequestParamType = "billingType" | ||
// MERCHANT_PRODUCT_ID parameter for merchant product ID. | ||
MERCHANT_PRODUCT_ID GatewayRequestParamType = "merchantProductID" | ||
// REBILL_FREQUENCY elements for recurring billing. | ||
REBILL_FREQUENCY GatewayRequestParamType = "rebillFrequency" | ||
REBILL_AMOUNT GatewayRequestParamType = "rebillAmount" | ||
REBILL_START GatewayRequestParamType = "rebillStart" | ||
// REBILL_END_DATE element for automatic termination of rebilling. | ||
REBILL_END_DATE GatewayRequestParamType = "rebillEndDate" | ||
// REBILL_COUNT element for rebill count. | ||
REBILL_COUNT GatewayRequestParamType = "rebillCount" | ||
// TODO For internal use only | ||
// REBILL_TRANS_NUMBER For internal use only This comes from rec_transCount | ||
REBILL_TRANS_NUMBER GatewayRequestParamType = "rebillTransNumber" | ||
// REBILL_SUSPEND Added new elements for suspending and resuming memberships. | ||
REBILL_SUSPEND GatewayRequestParamType = "rebillSuspend" | ||
REBILL_RESUME GatewayRequestParamType = "rebillResume" | ||
// REFERRING_MERCHANT_ID added elements for 1-click referrals. | ||
REFERRING_MERCHANT_ID GatewayRequestParamType = "referringMerchantID" | ||
REFERRED_CUSTOMER_ID GatewayRequestParamType = "referredCustomerID" | ||
REFERRAL_NO GatewayRequestParamType = "referralNo" | ||
// CLONE_CUSTOMER_RECORD Added elements for cloning customer records. | ||
CLONE_CUSTOMER_RECORD GatewayRequestParamType = "cloneCustomerRecord" | ||
CLONE_TO_CUSTOMER_ID GatewayRequestParamType = "cloneToCustomerID" | ||
// PARTIAL_AUTH_FLAG Added PARTIAL_AUTH_FLAG to indicate desire to use partial authorization feature. | ||
PARTIAL_AUTH_FLAG GatewayRequestParamType = "partialAuthFlag" | ||
// IOVATION_BLACK_BOX Added parameters for Iovation. | ||
IOVATION_BLACK_BOX GatewayRequestParamType = "iovationBlackBox" | ||
IOVATION_RULE GatewayRequestParamType = "iovationRule" | ||
// THREATMETRIX_SESSION_ID Added parameter for ThreatMetrix. | ||
THREATMETRIX_SESSION_ID GatewayRequestParamType = "threatMetrixSessionID" | ||
// REFERRER_URL Added parameter REFERRER_URL parameter for eMerchantPay. | ||
REFERRER_URL GatewayRequestParamType = "referrerURL" | ||
// GENERATE_POSTBACK Added parameters for postback request. | ||
GENERATE_POSTBACK GatewayRequestParamType = "generatePostback" | ||
CUSTOMER_PASSWORD GatewayRequestParamType = "customerPassword" | ||
PARES GatewayRequestParamType = "PARES" | ||
USE_3D_SECURE GatewayRequestParamType = "use3DSecure" | ||
// OMIT_RECEIPT Added field to omit receipts. | ||
OMIT_RECEIPT GatewayRequestParamType = "omitReceipt" | ||
// ACCT_COMPROMISED_SCRUB Added flag to enable Account Compromised scrub. | ||
ACCT_COMPROMISED_SCRUB GatewayRequestParamType = "AcctCompromisedScrub" | ||
// PAYINFO_TRANSACT_ID Added element to pass PAYINFO_TRANSACT_ID in place of card hash. | ||
PAYINFO_TRANSACT_ID GatewayRequestParamType = "payInfoTransactID" | ||
// Added SUB_MERCHANT_ID for Credorax 'h3' parameter. | ||
// SUB_MERCHANT_ID | ||
SUB_MERCHANT_ID GatewayRequestParamType = "subMerchantID" | ||
// CAPTURE_DAYS Added CAPTURE_DAYS for delayed capture operations. | ||
CAPTURE_DAYS GatewayRequestParamType = "captureDays" | ||
// SS_NUMBER Added fields for SBW ACH implementation. | ||
SS_NUMBER GatewayRequestParamType = "SSNUMBER" | ||
SAVINGS_ACCOUNT GatewayRequestParamType = "SAVINGSACCOUNT" | ||
// BILLING_MODE Added cellphone parameters. | ||
BILLING_MODE GatewayRequestParamType = "billingMode" | ||
BILLING_WINDOW GatewayRequestParamType = "billingWindow" | ||
CARRIER_CODE GatewayRequestParamType = "carrierCode" | ||
CELLPHONE_NUMBER GatewayRequestParamType = "cellPhoneNumber" | ||
COUNTRY_CODE GatewayRequestParamType = "countryCode" | ||
PROMPT_TIMEOUT GatewayRequestParamType = "promptTimeout" | ||
// ACCOUNT_HOLDER Added Euro-Debit parameters. | ||
ACCOUNT_HOLDER GatewayRequestParamType = "accountHolder" | ||
ACCOUNT_NO GatewayRequestParamType = "accountNo" | ||
BANK_CITY GatewayRequestParamType = "bankCity" | ||
BANK_NAME GatewayRequestParamType = "bankName" | ||
CUSTOMER_PHONE_NO GatewayRequestParamType = "customerPhoneNo" | ||
LANGUAGE_CODE GatewayRequestParamType = "languageCode" | ||
PIN_FLAG GatewayRequestParamType = "pinFlag" | ||
PIN_NO GatewayRequestParamType = "pinNo" | ||
ROUTING_NO GatewayRequestParamType = "routingNo" | ||
// Added fields to support Verified-by-Visa and MasterCard SecureCode. | ||
// TODO public vars | ||
V_3D_CHECK GatewayRequestParamType = "ThreeDCheck" | ||
V_3D_ECI GatewayRequestParamType = "ThreeDECI" | ||
V_3D_CAVV_UCAF GatewayRequestParamType = "ThreeDCavvUcaf" | ||
V_3D_XID GatewayRequestParamType = "ThreeDXID" | ||
// Additional 3DS 1.0/2.0 fields for merchants using external 3DS servers | ||
V_3D_VERSION GatewayRequestParamType = "THREEDVERSION" | ||
V_3D_VERSTATUS GatewayRequestParamType = "THREEDVERSTATUS" | ||
V_3D_PARESSTATUS GatewayRequestParamType = "THREEDPARESSTATUS" | ||
V_3D_CAVV_ALGORITHM GatewayRequestParamType = "THREEDCAVVALGORITHM" | ||
// More 3DS parameters | ||
V_3DSECURE_THREE_DS_SERVER_TRANSACTION_ID GatewayRequestParamType = "_3DSECURE_THREE_DS_SERVER_TRANSACTION_ID" | ||
V_3DSECURE_DS_TRANSACTION_ID GatewayRequestParamType = "_3DSECURE_DS_TRANSACTION_ID" | ||
V_3DSECURE_ACS_TRANSACTION_ID GatewayRequestParamType = "_3DSECURE_ACS_TRANSACTION_ID" | ||
V_3DSECURE_DF_REFERENCE_ID GatewayRequestParamType = "_3DSECURE_DF_REFERENCE_ID" | ||
V_3DSECURE_REDIRECT_URL GatewayRequestParamType = "_3DSECURE_REDIRECT_URL" | ||
V_3DSECURE_CHALLENGE_MANDATED_INDICATOR GatewayRequestParamType = "_3DSECURE_CHALLENGE_MANDATED_INDICATOR" | ||
|
||
BROWSER_JAVA_ENABLED GatewayRequestParamType = "BROWSERJAVAENABLED" | ||
BROWSER_LANGUAGE GatewayRequestParamType = "BROWSERLANGUAGE" | ||
BROWSER_COLOR_DEPTH GatewayRequestParamType = "BROWSERCOLORDEPTH" | ||
BROWSER_SCREEN_HEIGHT GatewayRequestParamType = "BROWSERSCREENHEIGHT" | ||
BROWSER_SCREEN_WIDTH GatewayRequestParamType = "BROWSERSCREENWIDTH" | ||
BROWSER_TIME_ZONE GatewayRequestParamType = "BROWSERTIMEZONE" | ||
|
||
// BROWSER_USER_AGENT Added browser details for Cardinal3DS bypass. | ||
BROWSER_USER_AGENT GatewayRequestParamType = "browserUserAgent" | ||
BROWSER_ACCEPT_HEADER GatewayRequestParamType = "browserAcceptHeader" | ||
|
||
// EMBEDDED_FIELDS_TOKEN Added support for EmbeddedFieldsProxy service. | ||
EMBEDDED_FIELDS_TOKEN GatewayRequestParamType = "embeddedFieldsToken" | ||
|
||
// XSELL_MERCHANT_ID Added hosted page style cross-sells. | ||
XSELL_MERCHANT_ID GatewayRequestParamType = "xsellMerchantID" | ||
XSELL_CUSTOMER_ID GatewayRequestParamType = "xsellCustomerID" | ||
XSELL_REFERENCE_XACT GatewayRequestParamType = "xsellReferenceXact" | ||
|
||
// Definition of key constants that carry failure information to the servers. | ||
|
||
FAILED_SERVER GatewayRequestParamType = "failedServer" | ||
FAILED_GUID GatewayRequestParamType = "failedGUID" | ||
FAILED_RESPONSE_CODE GatewayRequestParamType = "failedResponseCode" | ||
FAILED_REASON_CODE GatewayRequestParamType = "failedReasonCode" | ||
|
||
// Definition of key values used to override gateway service URL. | ||
|
||
GATEWAY_SERVER GatewayRequestParamType = "gatewayServer" | ||
GATEWAY_PROTOCOL GatewayRequestParamType = "gatewayProtocol" | ||
GATEWAY_PORTNO GatewayRequestParamType = "gatewayPortNo" | ||
GATEWAY_SERVLET GatewayRequestParamType = "gatewayServlet" | ||
GATEWAY_CONNECT_TIMEOUT GatewayRequestParamType = "gatewayConnectTimeout" | ||
GATEWAY_READ_TIMEOUT GatewayRequestParamType = "gatewayReadTimeout" | ||
|
||
// GATEWAY_URL Added support for full URL override. | ||
GATEWAY_URL GatewayRequestParamType = "gatewayURL" | ||
|
||
// Definition of constant transaction types. | ||
|
||
TRANSACTION_AUTH_ONLY GatewayRequestParamType = "AUTH" | ||
TRANSACTION_TICKET GatewayRequestParamType = "TICKET" | ||
TRANSACTION_SALE GatewayRequestParamType = "PURCHASE" | ||
TRANSACTION_CREDIT GatewayRequestParamType = "CREDIT" | ||
TRANSACTION_VOID GatewayRequestParamType = "VOID" | ||
|
||
// TRANSACTION_CONFIRM Implemented confirmation as a separate transaction type. | ||
TRANSACTION_CONFIRM GatewayRequestParamType = "CONFIRM" | ||
|
||
// TRANSACTION_ABORT Added new transaction types for cellphones. | ||
TRANSACTION_ABORT GatewayRequestParamType = "ABORT" | ||
TRANSACTION_PRICE_CHECK GatewayRequestParamType = "PRICECHECK" | ||
|
||
// TRANSACTION_PIN_DATA Added new transaction type for Euro-Debit PIN call. | ||
TRANSACTION_PIN_DATA GatewayRequestParamType = "PINDATA" | ||
|
||
REFERENCE_SCHEME_TRANSACTION_ID GatewayRequestParamType = "SCHEMETRANID" | ||
REFERENCE_SCHEME_SETTLEMENT_DATE GatewayRequestParamType = "SCHEMESETTLEDATE" | ||
|
||
FAILURE_URL GatewayRequestParamType = "FAILUREURL" | ||
SUCCESS_URL GatewayRequestParamType = "SUCCESSURL" | ||
|
||
PROCESSOR_3DS GatewayRequestParamType = "PROCESSOR3DS" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package request | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const xmlHeader string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | ||
const gatewayRequestElem string = document_base // "<gatewayRequest>" | ||
|
||
func TestNewGatewayRequest(t *testing.T) { | ||
request := NewGatewayRequest() | ||
|
||
request2 := GatewayRequest{} | ||
request2.ToXMLString() | ||
|
||
xml := request.ToXMLString() | ||
assert.True(t, strings.HasPrefix(xml, xmlHeader), "Expect xml header") | ||
assert.True(t, strings.HasPrefix(xml, xmlHeader+"\n<"+gatewayRequestElem+">"), "Expect xml header and start root element") | ||
assert.True(t, strings.HasSuffix(xml, "</"+gatewayRequestElem+">"), "Expect end root element") | ||
assert.True(t, strings.Contains(xml, "<version>"+version_no+"</version>")) | ||
} | ||
|
||
func TestGatewayRequestSet(t *testing.T) { | ||
request := NewGatewayRequest() | ||
request.Set("a", "1") | ||
request.SetInt("b", 2) | ||
xml := request.ToXMLString() | ||
assert.True(t, strings.Contains(xml, "<a>1</a>"), "Expect a=1 value") | ||
assert.True(t, strings.Contains(xml, "<b>2</b>"), "Expect b=2 value") | ||
} | ||
|
||
func TestGatewayRequestGet(t *testing.T) { | ||
request := NewGatewayRequest() | ||
request.Set("a", "1") | ||
assert.Equal(t, "1", request.Get("a"), "Expect 1 for key a") | ||
request.SetInt("b", 2) | ||
assert.Equal(t, "2", request.Get("b"), "Expect 2 for key b") | ||
// Get value for invalid key | ||
assert.Equal(t, "", request.Get("invalid_key"), "Expect empty for invalid_key") | ||
// Test GetInt values | ||
assert.Equal(t, -1, request.GetInt("invalid_key"), "Expect -1") | ||
assert.Equal(t, 0, request.GetIntOrDefault("invalid_key", 0), "Expect 0") | ||
assert.Equal(t, 3, request.GetIntOrDefault("invalid_key", 3), "Expect 3") | ||
// Valid int | ||
request.Set("nr", "1") | ||
assert.Equal(t, 1, request.GetInt("nr"), "Expect 1") | ||
request.Set("nr", " 1") | ||
assert.Equal(t, 1, request.GetInt("nr"), "Expect 1") | ||
request.Set("nr", "1 ") | ||
assert.Equal(t, 1, request.GetInt("nr"), "Expect 1") | ||
// Invalid int | ||
request.Set("nr", "x") | ||
assert.Equal(t, -1, request.GetInt("nr"), "Expect -1") | ||
assert.Equal(t, 5, request.GetIntOrDefault("nr", 5), "Expect 5") | ||
// GetFloat | ||
request.Set("f", "1") | ||
assert.Equal(t, 1.0, request.GetFloat("f"), "Expect 1.0") | ||
request.Set("f", "2.00") | ||
assert.Equal(t, 2.0, request.GetFloat("f"), "Expect 2.0") | ||
request.Set("f", "") | ||
assert.Equal(t, 0.0, request.GetFloat("f"), "Expect 0.0") | ||
request.Set("f", "invalid") | ||
assert.Equal(t, 0.0, request.GetFloat("f"), "Expect 0.0") | ||
assert.Equal(t, 5.0, request.GetFloatOrDefault("f", 5.0), "Expect 5.0") | ||
} | ||
|
||
func TestGatewayRequestXmlEscape(t *testing.T) { | ||
request := NewGatewayRequest() | ||
request.Set("a", "<") | ||
request.Set("b", ">") | ||
request.Set("c", "'") | ||
request.Set("d", "\"") | ||
request.Set("e", "&") | ||
xml := request.ToXMLString() | ||
assert.True(t, strings.Contains(xml, "<a><</a>"), "Expect a=< value") | ||
assert.True(t, strings.Contains(xml, "<b>></b>"), "Expect b=> value") | ||
assert.True(t, strings.Contains(xml, "<c>'</c>"), "Expect c=' value") | ||
assert.True(t, strings.Contains(xml, "<d>"</d>"), "Expect d=" value") | ||
assert.True(t, strings.Contains(xml, "<e>&</e>"), "Expect e=& value") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package response | ||
|
||
/* Declaration of static codes returned to clients in response documents. */ | ||
const ( | ||
// RESPONSE_SUCCESS Function succeeded | ||
RESPONSE_SUCCESS int = 0 | ||
// RESPONSE_BANK_FAIL Bank decline/failure | ||
RESPONSE_BANK_FAIL int = 1 | ||
// RESPONSE_RISK_FAIL Risk failure | ||
RESPONSE_RISK_FAIL int = 2 | ||
// RESPONSE_SYSTEM_ERROR Hosting system error | ||
RESPONSE_SYSTEM_ERROR int = 3 | ||
// RESPONSE_REQUEST_ERROR Invalid request | ||
RESPONSE_REQUEST_ERROR int = 4 | ||
|
||
/* Declaration of static reason codes. */ | ||
|
||
// REASON_SUCCESS Function succeeded | ||
REASON_SUCCESS int = 0 | ||
REASON_NOMATCHING_XACT int = 100 | ||
REASON_CANNOT_VOID int = 101 | ||
REASON_CANNOT_CREDIT int = 102 | ||
REASON_CANNOT_TICKET int = 103 | ||
REASON_DECLINED int = 104 | ||
REASON_DECLINED_OVERLIMIT int = 105 | ||
REASON_DECLINED_CVV2 int = 106 | ||
REASON_DECLINED_EXPIRED int = 107 | ||
REASON_DECLINED_CALL int = 108 | ||
REASON_DECLINED_PICKUP int = 109 | ||
REASON_DECLINED_EXCESSIVEUSE int = 110 | ||
REASON_DECLINE_INVALID_CARDNO int = 111 | ||
REASON_DECLINE_INVALID_EXPIRATION int = 112 | ||
REASON_BANK_UNAVAILABLE int = 113 | ||
REASON_DECLINED_AVS int = 117 | ||
// REASON_USER_DECLINED Re-use declined for terminated rebilling. | ||
REASON_USER_DECLINED int = 123 | ||
// REASON_CELLPHONE_BLACKLISTED Added codes returned by CellPhone API. | ||
REASON_CELLPHONE_BLACKLISTED int = 126 | ||
REASON_INTEGRATION_ERROR int = 154 | ||
// REASON_DECLINED_RISK Add definition of DECLINED_RISK for use by rebilling utility. | ||
REASON_DECLINED_RISK int = 157 | ||
REASON_PREVIOUS_HARD_DECLINE int = 161 | ||
// REASON_MERCHACCT_LIMIT Add definition of MERCHACCT_LIMIT for use by rebilling utility. | ||
REASON_MERCHACCT_LIMIT int = 162 | ||
REASON_DECLINED_STOLEN int = 164 | ||
REASON_BANK_INVALID_TRANSACTION int = 165 | ||
REASON_CVV2_REQUIRED int = 167 | ||
REASON_RISK_FAIL int = 200 | ||
REASON_CUSTOMER_BLOCKED int = 201 | ||
REASON_3DSECURE_INITIATION int = 225 | ||
REASON_3DSECURE_SCA_REQUIRED int = 228 | ||
REASON_DNS_FAILURE int = 300 | ||
REASON_UNABLE_TO_CONNECT int = 301 | ||
REASON_REQUEST_XMIT_ERROR int = 302 | ||
REASON_RESPONSE_READ_TIMEOUT int = 303 | ||
REASON_RESPONSE_READ_ERROR int = 304 | ||
REASON_SERVICE_UNAVAILABLE int = 305 | ||
REASON_CONNECTION_UNAVAILABLE int = 306 | ||
REASON_BUGCHECK int = 307 | ||
REASON_UNHANDLED_EXCEPTION int = 308 | ||
REASON_SQL_EXCEPTION int = 309 | ||
REASON_SQL_INSERT_ERROR int = 310 | ||
REASON_BANK_CONNECT_ERROR int = 311 | ||
REASON_BANK_XMIT_ERROR int = 312 | ||
REASON_BANK_READ_ERROR int = 313 | ||
REASON_BANK_DISCONNECT_ERROR int = 314 | ||
REASON_BANK_TIMEOUT_ERROR int = 315 | ||
REASON_BANK_PROTOCOL_ERROR int = 316 | ||
REASON_ENCRYPTION_ERROR int = 317 | ||
REASON_BANK_XMIT_RETRIES int = 318 | ||
REASON_BANK_RESPONSE_RETRIES int = 319 | ||
REASON_BANK_REDUNDANT_RESPONSESint = 320 | ||
REASON_XML_ERROR int = 400 | ||
REASON_INVALID_URL int = 401 | ||
REASON_INVALID_TRANSACTION int = 402 | ||
REASON_INVALID_CARDNO int = 403 | ||
REASON_INVALID_EXPIRATION int = 404 | ||
REASON_INVALID_AMOUNT int = 405 | ||
REASON_INVALID_MERCHANT_ID int = 406 | ||
REASON_INVALID_MERCHANT_ACCOUNT int = 407 | ||
REASON_INCOMPATABLE_CARDTYPE int = 408 | ||
REASON_NO_SUITABLE_ACCOUNT int = 409 | ||
REASON_INVALID_REFGUID int = 410 | ||
REASON_INVALID_ACCESS_CODE int = 411 | ||
REASON_INVALID_CUSTDATA_LENGTH int = 412 | ||
REASON_INVALID_EXTDATA_LENGTH int = 413 | ||
REASON_INVALID_COF_FRAMEWORK int = 458 | ||
REASON_INVALID_REFERENCE_SCHEME_TRANSACTION int = 459 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
package response | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
"io" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type GatewayResponseParamType string | ||
|
||
type GatewayResponse map[string]string | ||
|
||
func NewGatewayResponse() *GatewayResponse { | ||
response := GatewayResponse{} | ||
return &response | ||
} | ||
|
||
// Reset the response parameters so that the object response can be reused. | ||
func (r GatewayResponse) Reset() { | ||
for k := range r { | ||
delete(r, k) | ||
} | ||
} | ||
|
||
// Set a value in the parameters | ||
func (r GatewayResponse) Set(key GatewayResponseParamType, value string) { | ||
if r == nil { | ||
return | ||
} | ||
if len(strings.TrimSpace(value)) == 0 { | ||
delete(r, string(key)) | ||
} else { | ||
r[string(key)] = value | ||
} | ||
} | ||
|
||
// SetInt set request parameter int value for key | ||
func (r GatewayResponse) SetInt(key GatewayResponseParamType, value int) { | ||
r.Set(key, fmt.Sprint(value)) | ||
} | ||
|
||
// SetResults set RESPONSE_CODE and REASON_CODE values | ||
func (r GatewayResponse) SetResults(response int, reason int) { | ||
r.SetInt(RESPONSE_CODE, response) | ||
r.SetInt(REASON_CODE, reason) | ||
} | ||
|
||
func (r GatewayResponse) SetFromXML(xmlData string) { | ||
decoder := xml.NewDecoder(strings.NewReader(xmlData)) | ||
key := "" | ||
value := "" | ||
for { | ||
token, err := decoder.Token() | ||
if err == io.EOF { | ||
break | ||
} else if err != nil { | ||
r.setXmlError("invalid xml: " + err.Error()) | ||
return | ||
} | ||
|
||
switch token := token.(type) { | ||
case xml.StartElement: | ||
if token.Name.Local == DOCUMENT_BASE { | ||
// Start root element | ||
continue | ||
} | ||
if key == "" { | ||
// Start response parameter element | ||
key = token.Name.Local | ||
value = "" | ||
continue | ||
} | ||
r.setXmlError("invalid xml") | ||
return | ||
case xml.EndElement: | ||
if token.Name.Local == DOCUMENT_BASE { | ||
// End root element | ||
return | ||
} | ||
if key == token.Name.Local { | ||
// End response parameter element | ||
r[key] = strings.TrimSpace(value) | ||
key = "" | ||
value = "" | ||
} | ||
case xml.CharData: | ||
value = string([]byte(token)) | ||
} | ||
} | ||
|
||
} | ||
|
||
func (r GatewayResponse) setXmlError(exception string) { | ||
r.SetResults(RESPONSE_REQUEST_ERROR, REASON_XML_ERROR) | ||
r.Set(EXCEPTION, exception) | ||
} | ||
|
||
func (r GatewayResponse) Get(key GatewayResponseParamType) string { | ||
return strings.TrimSpace(r[string(key)]) | ||
} | ||
|
||
func (r GatewayResponse) GetIntOrDefault(key GatewayResponseParamType, defaultValue int) int { | ||
value := r.Get(key) | ||
value = strings.TrimSpace(value) | ||
if value == "" { | ||
return defaultValue | ||
} | ||
intValue, err := strconv.Atoi(value) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return intValue | ||
} | ||
|
||
func (r GatewayResponse) GetInt(key GatewayResponseParamType) int { | ||
return r.GetIntOrDefault(key, -1) | ||
} | ||
|
||
func (r GatewayResponse) GetResponseCode() int { | ||
return r.GetInt(RESPONSE_CODE) | ||
} | ||
|
||
/* Public constants */ | ||
const ( | ||
DOCUMENT_BASE string = "gatewayResponse" | ||
VERSION GatewayResponseParamType = "version" | ||
VERSION_NO GatewayResponseParamType = "1.0" | ||
AUTH_NO GatewayResponseParamType = "authNo" | ||
AVS_RESPONSE GatewayResponseParamType = "avsResponse" | ||
CVV2_CODE GatewayResponseParamType = "cvv2Code" | ||
EXCEPTION GatewayResponseParamType = "exception" | ||
MERCHANT_ACCOUNT GatewayResponseParamType = "merchantAccount" | ||
REASON_CODE GatewayResponseParamType = "reasonCode" | ||
RESPONSE_CODE GatewayResponseParamType = "responseCode" | ||
TRANSACT_ID GatewayResponseParamType = "guidNo" | ||
// Transaction time using Gateway localtime "yyyy-MM-dd HH:mm:ss" | ||
TRANSACTION_TIME GatewayResponseParamType = "transactionTime" | ||
// SCRUB_RESULTS Added SCRUB_RESULTS to list of values returned in | ||
SCRUB_RESULTS GatewayResponseParamType = "scrubResults" | ||
// SETTLED_AMOUNT Added SETTLED_AMOUNT and SETTLED_CURRENCY for foreign currency support. | ||
SETTLED_AMOUNT GatewayResponseParamType = "approvedAmount" | ||
SETTLED_CURRENCY GatewayResponseParamType = "approvedCurrency" | ||
// CARD_TYPE Added keys for new ServiceDispatcher. | ||
CARD_TYPE GatewayResponseParamType = "cardType" | ||
CARD_HASH GatewayResponseParamType = "cardHash" | ||
CARD_LAST_FOUR GatewayResponseParamType = "cardLastFour" | ||
CARD_EXPIRATION GatewayResponseParamType = "cardExpiration" | ||
CARD_COUNTRY GatewayResponseParamType = "cardCountry" | ||
// CARD_ISSUER_NAME Added keys for issuer data. | ||
CARD_ISSUER_NAME GatewayResponseParamType = "cardIssuerName" | ||
CARD_ISSUER_PHONE GatewayResponseParamType = "cardIssuerPhone" | ||
CARD_ISSUER_URL GatewayResponseParamType = "cardIssuerURL" | ||
// CARD_REGION Added keys for additional card information. | ||
CARD_REGION GatewayResponseParamType = "cardRegion" | ||
CARD_DESCRIPTION GatewayResponseParamType = "cardDescription" | ||
CARD_DEBIT_CREDIT GatewayResponseParamType = "cardDebitCredit" | ||
// CARD_BIN Added CARD_BIN for Embedded Fields 'Lookup'. | ||
CARD_BIN GatewayResponseParamType = "cardBin" | ||
BILLING_ADDRESS GatewayResponseParamType = "billingAddress" | ||
BILLING_CITY GatewayResponseParamType = "billingCity" | ||
BILLING_COUNTRY GatewayResponseParamType = "billingCountry" | ||
BILLING_STATE GatewayResponseParamType = "billingState" | ||
BILLING_ZIPCODE GatewayResponseParamType = "billingZipCode" | ||
CUSTOMER_FIRSTNAME GatewayResponseParamType = "customerFirstName" | ||
CUSTOMER_LASTNAME GatewayResponseParamType = "customerLastName" | ||
EMAIL GatewayResponseParamType = "email" | ||
ROCKETPAY_INDICATOR GatewayResponseParamType = "rocketPayIndicator" | ||
// PAY_TYPE Added payment type and aliases for card hash and card last four. | ||
PAY_TYPE GatewayResponseParamType = "payType" | ||
PAY_HASH GatewayResponseParamType = CARD_HASH | ||
PAY_LAST_FOUR GatewayResponseParamType = CARD_LAST_FOUR | ||
// ACS_URL Added fields for 3D-Secure. | ||
ACS_URL GatewayResponseParamType = "acsURL" | ||
PAREQ GatewayResponseParamType = "PAREQ" | ||
// CAVV_RESPONSE Added field to return CAVV results. | ||
CAVV_RESPONSE GatewayResponseParamType = "cavvResponse" | ||
// REBILL_END_DATE Added cancellation date return value. | ||
REBILL_END_DATE GatewayResponseParamType = "rebillEndDate" | ||
// REBILL_DATE Added rebill parameters for rebill update response. | ||
REBILL_DATE GatewayResponseParamType = "rebillDate" | ||
REBILL_AMOUNT GatewayResponseParamType = "rebillAmount" | ||
// REBILL_FREQUENCY Added more parameters for rebill update response. | ||
REBILL_FREQUENCY GatewayResponseParamType = "rebillFrequency" | ||
LAST_BILLING_DATE GatewayResponseParamType = "lastBillingDate" | ||
LAST_BILLING_AMOUNT GatewayResponseParamType = "lastBillingAmount" | ||
JOIN_DATE GatewayResponseParamType = "joinDate" | ||
JOIN_AMOUNT GatewayResponseParamType = "joinAmount" | ||
// REBILL_STATUS Added REBILL_STATUS to return ACTIVE or SUSPENDED state. | ||
REBILL_STATUS GatewayResponseParamType = "rebillStatus" | ||
// LAST_REASON_CODE Added last reason code to rebill update response. | ||
LAST_REASON_CODE GatewayResponseParamType = "lastReasonCode" | ||
// BALANCE_AMOUNT Added return values for balance remaining on prepaid cards. | ||
BALANCE_AMOUNT GatewayResponseParamType = "balanceAmount" | ||
BALANCE_CURRENCY GatewayResponseParamType = "balanceCurrency" | ||
// MERCHANT_SITE_ID Added merchant site ID and product ID to rebill update response. | ||
MERCHANT_SITE_ID GatewayResponseParamType = "merchantSiteID" | ||
MERCHANT_PRODUCT_ID GatewayResponseParamType = "merchantProductID" | ||
// MERCHANT_CUSTOMER_ID Added customer ID and invoice ID. | ||
MERCHANT_CUSTOMER_ID GatewayResponseParamType = "merchantCustomerID" | ||
MERCHANT_INVOICE_ID GatewayResponseParamType = "merchantInvoiceID" | ||
SCHEME_TRANSACTION_ID GatewayResponseParamType = "schemeTransactionID" | ||
SCHEME_SETTLEMENT_DATE GatewayResponseParamType = "schemeSettlementDate" | ||
// IOVATION_TRACKING_NO Added return values for Iovation. | ||
IOVATION_TRACKING_NO GatewayResponseParamType = "IOVATIONTRACKINGNO" | ||
IOVATION_DEVICE GatewayResponseParamType = "IOVATIONDEVICE" | ||
IOVATION_RESULTS GatewayResponseParamType = "IOVATIONRESULTS" | ||
IOVATION_SCORE GatewayResponseParamType = "IOVATIONSCORE" | ||
IOVATION_RULE_COUNT GatewayResponseParamType = "IOVATIONRULECOUNT" | ||
IOVATION_RULE_TYPE_ GatewayResponseParamType = "IOVATIONRULETYPE_" | ||
IOVATION_RULE_REASON_ GatewayResponseParamType = "IOVATIONRULEREASON_" | ||
IOVATION_RULE_SCORE_ GatewayResponseParamType = "IOVATIONRULESCORE_" | ||
|
||
BILLING_DURATION GatewayResponseParamType = "billingDuration" | ||
BILLING_METHOD GatewayResponseParamType = "billingMethod" | ||
BILLING_WINDOW GatewayResponseParamType = "billingWindow" | ||
CARRIER_LIST GatewayResponseParamType = "carrierList" | ||
CARRIER_NETWORK GatewayResponseParamType = "carrierNetwork" | ||
MESSAGE_COUNT GatewayResponseParamType = "messageCount" | ||
MSISDN GatewayResponseParamType = "msisdn" | ||
PROMPT_TIMEOUT GatewayResponseParamType = "promptTimeout" | ||
SHORT_CODE GatewayResponseParamType = "shortCode" | ||
USER_AMOUNT GatewayResponseParamType = "userAmount" | ||
USER_CURRENCY GatewayResponseParamType = "userCurrency" | ||
|
||
// Adding 3DS response fields | ||
V_3DSECURE_DEVICE_COLLECTION_JWT GatewayResponseParamType = "_3DSECURE_DEVICE_COLLECTION_JWT" | ||
V_3DSECURE_DEVICE_COLLECTION_URL GatewayResponseParamType = "_3DSECURE_DEVICE_COLLECTION_URL" | ||
V_3DSECURE_STEP_UP_URL GatewayResponseParamType = "_3DSECURE_STEP_UP_URL" | ||
V_3DSECURE_STEP_UP_JWT GatewayResponseParamType = "_3DSECURE_STEP_UP_JWT" | ||
V_3DSECURE_VERSION GatewayResponseParamType = "_3DSECURE_VERSION" | ||
V_3DSECURE_CHALLENGE_INDICATOR GatewayResponseParamType = "_3DSECURE_CHALLENGE_INDICATOR" | ||
|
||
PAYMENT_LINK_URL GatewayResponseParamType = "PAYMENT_LINK_URL" | ||
|
||
PROCESSOR_3DS GatewayResponseParamType = "PROCESSOR3DS" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package response | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const xmlHeader string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | ||
|
||
func TestNewGatewayResponse(t *testing.T) { | ||
response := NewGatewayResponse() | ||
fmt.Println(response) | ||
assert.Equal(t, "", response.Get("invalid_key"), "Expect empty for invalid_key") | ||
assert.Equal(t, 2, response.GetIntOrDefault("invalid_key", 2), "Expect 2 value ") | ||
assert.Equal(t, -1, response.GetInt("invalid_key"), "Expect -1 value ") | ||
assert.Equal(t, -1, response.GetResponseCode(), "Expect -1 value ") | ||
} | ||
|
||
func TestParseResponse(t *testing.T) { | ||
testInput := "<gatewayResponse><par1>a</par1><par2>b</par2><par3></par3></gatewayResponse>" | ||
response := NewGatewayResponse() | ||
response.SetFromXML(testInput) | ||
assert.Equal(t, "a", response.Get("par1"), "Expect a for par1") | ||
assert.Equal(t, "b", response.Get("par2"), "Expect b for par2") | ||
assert.Equal(t, "", response.Get("par3"), "Expect par3 empty") | ||
assert.Equal(t, "", response.Get("par4"), "Expect par4 empty") | ||
} | ||
|
||
func TestParseInvalidResponseRoot(t *testing.T) { | ||
testInput := "<root><par1>a</par1></root>" | ||
response := NewGatewayResponse() | ||
response.SetFromXML(testInput) | ||
fmt.Println(response) | ||
assert.Equal(t, "4", response.Get(RESPONSE_CODE), "Expect responseCode: 4") | ||
assert.Equal(t, "400", response.Get(REASON_CODE), "Expect reasonCode: 400") | ||
assert.Equal(t, "invalid xml", response.Get(EXCEPTION), "Expect exception: invalid xml") | ||
} | ||
|
||
func TestParseInvalidResponseParElement(t *testing.T) { | ||
testInput := "<gatewayResponse><par1>a</par2></gatewayResponse>" | ||
response := NewGatewayResponse() | ||
response.SetFromXML(testInput) | ||
fmt.Println(response) | ||
assert.Equal(t, "4", response.Get(RESPONSE_CODE), "Expect responseCode: 4") | ||
assert.Equal(t, "400", response.Get(REASON_CODE), "Expect reasonCode: 400") | ||
assert.True(t, strings.HasPrefix(response.Get(EXCEPTION), "invalid xml"), "Expect invalid xml prefix") | ||
} | ||
|
||
func TestParseXMLHeader(t *testing.T) { | ||
testInput := xmlHeader + "\n<gatewayResponse><par1>x</par1></gatewayResponse>" | ||
response := NewGatewayResponse() | ||
response.SetFromXML(testInput) | ||
fmt.Println(response) | ||
assert.Equal(t, "x", response.Get("par1"), "Expect x for par1") | ||
} | ||
|
||
func TestParseXMLWithSpaces(t *testing.T) { | ||
testInput := xmlHeader + " \n <gatewayResponse>\n\n<par1> s \t</par1>\n <par2> 5\t \n </par2> </gatewayResponse> \n\n" | ||
response := NewGatewayResponse() | ||
response.SetFromXML(testInput) | ||
fmt.Println(response) | ||
assert.Equal(t, "s", response.Get("par1"), "Expect s for par1") | ||
assert.Equal(t, 5, response.GetInt("par2"), "Expect 5 for par2") | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestNewGatewayResponse(t *testing.T) { | ||
service := NewGatewayService() | ||
fmt.Println(service) | ||
} |