diff --git a/.gitignore b/.gitignore index 57a1574..d06926c 100644 --- a/.gitignore +++ b/.gitignore @@ -194,3 +194,6 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt + +# Filesystem +*.DS_Store \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a019294..ab47a22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: csharp +dist: trusty + install: - nuget restore SampleCode.sln - sudo apt-get install nunit-console diff --git a/AcceptSuite/CreateAnAcceptPaymentTransaction.cs b/AcceptSuite/CreateAnAcceptPaymentTransaction.cs new file mode 100644 index 0000000..90a855b --- /dev/null +++ b/AcceptSuite/CreateAnAcceptPaymentTransaction.cs @@ -0,0 +1,117 @@ +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.Generic; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + public class CreateAnAcceptPaymentTransaction + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) + { + Console.WriteLine("Create an Accept Payment Transaction Sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + var opaqueData = new opaqueDataType + { + dataDescriptor = "COMMON.ACCEPT.INAPP.PAYMENT", + dataValue = "119eyJjb2RlIjoiNTBfMl8wNjAwMDUyN0JEODE4RjQxOUEyRjhGQkIxMkY0MzdGQjAxQUIwRTY2NjhFNEFCN0VENzE4NTUwMjlGRUU0M0JFMENERUIwQzM2M0ExOUEwMDAzNzlGRDNFMjBCODJEMDFCQjkyNEJDIiwidG9rZW4iOiI5NDkwMjMyMTAyOTQwOTk5NDA0NjAzIiwidiI6IjEuMSJ9" + + }; + + var billingAddress = new customerAddressType + { + firstName = "John", + lastName = "Doe", + address = "123 My St", + city = "OurTown", + zip = "98004" + }; + + //standard api call to retrieve response + var paymentType = new paymentType { Item = opaqueData }; + + // Add line Items + var lineItems = new lineItemType[2]; + lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; + lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; + + var transactionRequest = new transactionRequestType + { + transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card + + amount = amount, + payment = paymentType, + billTo = billingAddress, + lineItems = lineItems + }; + + var request = new createTransactionRequest { transactionRequest = transactionRequest }; + + // instantiate the controller that will call the service + var controller = new createTransactionController(request); + controller.Execute(); + + // get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + + // validate response + if (response != null) + { + if (response.messages.resultCode == messageTypeEnum.Ok) + { + if(response.transactionResponse.messages != null) + { + Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); + Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); + Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); + Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); + Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode); + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + } + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse != null && response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + else + { + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + } + } + } + else + { + Console.WriteLine("Null Response."); + } + + return response; + } + } +} diff --git a/CustomerProfiles/GetAcceptCustomerProfilePage.cs b/AcceptSuite/GetAcceptCustomerProfilePage.cs similarity index 100% rename from CustomerProfiles/GetAcceptCustomerProfilePage.cs rename to AcceptSuite/GetAcceptCustomerProfilePage.cs diff --git a/PaymentTransactions/GetHostedPaymentPage.cs b/AcceptSuite/GetAnAcceptPaymentPage.cs similarity index 86% rename from PaymentTransactions/GetHostedPaymentPage.cs rename to AcceptSuite/GetAnAcceptPaymentPage.cs index a52ae53..ac05920 100644 --- a/PaymentTransactions/GetHostedPaymentPage.cs +++ b/AcceptSuite/GetAnAcceptPaymentPage.cs @@ -8,11 +8,11 @@ namespace net.authorize.sample.CustomerProfiles { - public class GetHostedPaymentPage + public class GetAnAcceptPaymentPage { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, decimal amount) { - Console.WriteLine("GetHostedPaymentPage Sample"); + Console.WriteLine("GetAnAcceptPaymentPage Sample"); ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() { @@ -34,21 +34,26 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize capture only - amount = amount + amount = amount, + order = new orderType + { + invoiceNumber = "INV-123456", + description = "TEST INVOICE" + } }; var request = new getHostedPaymentPageRequest(); request.transactionRequest = transactionRequest; request.hostedPaymentSettings = settings; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new getHostedPaymentPageController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine("Message code : " + response.messages.message[0].code); diff --git a/CustomerProfiles/CreateCustomerPaymentProfile.cs b/CustomerProfiles/CreateCustomerPaymentProfile.cs index cfe86cd..1e21334 100644 --- a/CustomerProfiles/CreateCustomerPaymentProfile.cs +++ b/CustomerProfiles/CreateCustomerPaymentProfile.cs @@ -8,10 +8,14 @@ namespace net.authorize.sample { public class CreateCustomerPaymentProfile { - public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId) + public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string customerProfileId) { - Console.WriteLine("CreateCustomerPaymentProfile Sample"); + Console.WriteLine("Create Customer Payment Profile Sample"); + + // set whether to use the sandbox environment, or production enviornment ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + + // define the merchant information (authentication / transaction id) ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, @@ -44,28 +48,48 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s { customerProfileId = customerProfileId, paymentProfile = echeckPaymentProfile, - validationMode = validationModeEnum.none + validationMode = validationModeEnum.testMode }; - //Prepare Request + // instantiate the controller that will call the service var controller = new createCustomerPaymentProfileController(request); controller.Execute(); - //Send Request to EndPoint - createCustomerPaymentProfileResponse response = controller.GetApiResponse(); - if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + // get the response from the service (errors contained if any) + createCustomerPaymentProfileResponse response = controller.GetApiResponse(); + + // validate response + if (response != null) { - if (response != null && response.messages.message != null) + if (response.messages.resultCode == messageTypeEnum.Ok) { - Console.WriteLine("Success, createCustomerPaymentProfileID : " + response.customerPaymentProfileId); + if(response.messages.message != null) + { + Console.WriteLine("Success! Customer Payment Profile ID: " + response.customerPaymentProfileId); + } + } + else + { + Console.WriteLine("Customer Payment Profile Creation Failed."); + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + if (response.messages.message[0].code == "E00039") + { + Console.WriteLine("Duplicate Payment Profile ID: " + response.customerPaymentProfileId); + } } } else { - Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); - if (response.messages.message[0].code == "E00039") + if (controller.GetErrorResponse().messages.message.Length > 0) + { + Console.WriteLine("Customer Payment Profile Creation Failed."); + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + } + else { - Console.WriteLine("Duplicate ID: " + response.customerPaymentProfileId); + Console.WriteLine("Null Response."); } } @@ -73,4 +97,4 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s } } -} +} \ No newline at end of file diff --git a/CustomerProfiles/CreateCustomerProfile.cs b/CustomerProfiles/CreateCustomerProfile.cs index abdf287..ea1c2f1 100644 --- a/CustomerProfiles/CreateCustomerProfile.cs +++ b/CustomerProfiles/CreateCustomerProfile.cs @@ -10,9 +10,12 @@ public class CreateCustomerProfile { public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string emailId) { - Console.WriteLine("CreateCustomerProfile Sample"); + Console.WriteLine("Create Customer Profile Sample"); + // set whether to use the sandbox environment, or production enviornment ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + + // define the merchant information (authentication / transaction id) ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() { name = ApiLoginID, @@ -20,11 +23,10 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s Item = ApiTransactionKey, }; - var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; var bankAccount = new bankAccountType @@ -37,7 +39,7 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s bankName = "Bank Of America" }; - //standard api call to retrieve response + // standard api call to retrieve response paymentType cc = new paymentType { Item = creditCard }; paymentType echeck = new paymentType {Item = bankAccount}; @@ -75,24 +77,44 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s var request = new createCustomerProfileRequest{ profile = customerProfile, validationMode = validationModeEnum.none}; - var controller = new createCustomerProfileController(request); // instantiate the contoller that will call the service + // instantiate the controller that will call the service + var controller = new createCustomerProfileController(request); controller.Execute(); - createCustomerProfileResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) + // get the response from the service (errors contained if any) + createCustomerProfileResponse response = controller.GetApiResponse(); - //validate - if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + // validate response + if (response != null) { - if (response != null && response.messages.message != null) + if (response.messages.resultCode == messageTypeEnum.Ok) + { + if(response.messages.message != null) + { + Console.WriteLine("Success!"); + Console.WriteLine("Customer Profile ID: " + response.customerProfileId); + Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]); + Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]); } + } + else { - Console.WriteLine("Success, CustomerProfileID : " + response.customerProfileId); - Console.WriteLine("Success, CustomerPaymentProfileID : " + response.customerPaymentProfileIdList[0]); - Console.WriteLine("Success, CustomerShippingProfileID : " + response.customerShippingAddressIdList[0]); + Console.WriteLine("Customer Profile Creation Failed."); + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); } } - else if(response != null ) + else { - Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text); + if (controller.GetErrorResponse().messages.message.Length > 0) + { + Console.WriteLine("Customer Profile Creation Failed."); + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + } + else + { + Console.WriteLine("Null Response."); + } } return response; diff --git a/CustomerProfiles/CreateCustomerProfileFromTransaction.cs b/CustomerProfiles/CreateCustomerProfileFromTransaction.cs index 986bffc..0af574c 100644 --- a/CustomerProfiles/CreateCustomerProfileFromTransaction.cs +++ b/CustomerProfiles/CreateCustomerProfileFromTransaction.cs @@ -42,7 +42,7 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s createCustomerProfileResponse response = controller.GetApiResponse(); - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/CustomerProfiles/GetCustomerProfile.cs b/CustomerProfiles/GetCustomerProfile.cs index 496fc10..4faf040 100644 --- a/CustomerProfiles/GetCustomerProfile.cs +++ b/CustomerProfiles/GetCustomerProfile.cs @@ -25,12 +25,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s Item = ApiTransactionKey, }; - var request = new getCustomerProfileRequest(); + var request = new getCustomerProfileRequest(); request.customerProfileId = customerProfileId; // instantiate the controller that will call the service var controller = new getCustomerProfileController(request); - controller.Execute(); + controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); diff --git a/CustomerProfiles/UpdateCustomerPaymentProfile.cs b/CustomerProfiles/UpdateCustomerPaymentProfile.cs index 6644c94..9be4e39 100644 --- a/CustomerProfiles/UpdateCustomerPaymentProfile.cs +++ b/CustomerProfiles/UpdateCustomerPaymentProfile.cs @@ -27,7 +27,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //=========================================================================== diff --git a/CustomerProfiles/UpdateCustomerProfile.cs b/CustomerProfiles/UpdateCustomerProfile.cs index f58b46e..13918b1 100644 --- a/CustomerProfiles/UpdateCustomerProfile.cs +++ b/CustomerProfiles/UpdateCustomerProfile.cs @@ -24,7 +24,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s Item = ApiTransactionKey, }; - var profile = new customerProfileExType + var profile = new customerProfileInfoExType { merchantCustomerId = "custId123", description = "some description", diff --git a/CustomerProfiles/UpdateCustomerShippingAddress.cs b/CustomerProfiles/UpdateCustomerShippingAddress.cs index 0fd3f64..49d9c0e 100644 --- a/CustomerProfiles/UpdateCustomerShippingAddress.cs +++ b/CustomerProfiles/UpdateCustomerShippingAddress.cs @@ -27,7 +27,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; var paymentType = new paymentType { Item = creditCard }; diff --git a/CustomerProfiles/ValidateCustomerPaymentProfile.cs b/CustomerProfiles/ValidateCustomerPaymentProfile.cs index b8eb602..7d39eb3 100644 --- a/CustomerProfiles/ValidateCustomerPaymentProfile.cs +++ b/CustomerProfiles/ValidateCustomerPaymentProfile.cs @@ -27,7 +27,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new validateCustomerPaymentProfileRequest(); request.customerProfileId = customerProfileId; request.customerPaymentProfileId = customerPaymentProfileId; - request.validationMode = validationModeEnum.liveMode; + request.validationMode = validationModeEnum.testMode; // instantiate the controller that will call the service diff --git a/DotNetCoreReleaseArtifacts/AuthorizeNET.dll b/DotNetCoreReleaseArtifacts/AuthorizeNET.dll new file mode 100644 index 0000000..2108b24 Binary files /dev/null and b/DotNetCoreReleaseArtifacts/AuthorizeNET.dll differ diff --git a/PaymentTransactions/UpdateHeldTransaction.cs b/FraudManagement/ApproveOrDeclineHeldTransaction.cs similarity index 86% rename from PaymentTransactions/UpdateHeldTransaction.cs rename to FraudManagement/ApproveOrDeclineHeldTransaction.cs index 092504a..d9bccaa 100644 --- a/PaymentTransactions/UpdateHeldTransaction.cs +++ b/FraudManagement/ApproveOrDeclineHeldTransaction.cs @@ -6,15 +6,15 @@ using AuthorizeNet; using AuthorizeNet.Api.Controllers; using AuthorizeNet.Api.Contracts.V1; -using AuthorizeNet.Api.Controllers.Bases; - -namespace net.authorize.sample.PaymentTransactions -{ - class UpdateHeldTransaction - { +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + class ApproveOrDeclineHeldTransaction + { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) { - Console.WriteLine("Update held transaction sample"); + Console.WriteLine("Approve held transaction sample"); ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; // define the merchant information (authentication / transaction id) @@ -28,8 +28,8 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var request = new updateHeldTransactionRequest(); request.heldTransactionRequest = new heldTransactionRequestType { - action = afdsTransactionEnum.approve, - refTransId = "12345" + action = afdsTransactionEnum.approve, + refTransId = "60108066607" }; // instantiate the controller that will call the service @@ -40,7 +40,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var response = controller.GetApiResponse(); if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { - Console.WriteLine(response.ToString()); + Console.WriteLine("Transaction Approved: "+response.transactionResponse.transId); } else if (response != null) { @@ -49,6 +49,6 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) } return response; - } - } -} + } + } +} diff --git a/FraudManagement/GetHeldTransactionList.cs b/FraudManagement/GetHeldTransactionList.cs new file mode 100644 index 0000000..07bc209 --- /dev/null +++ b/FraudManagement/GetHeldTransactionList.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AuthorizeNet; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + public class GetHeldTransactionList + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) + { + Console.WriteLine("Get suspicious transaction list sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + var request = new getUnsettledTransactionListRequest(); + request.status = TransactionGroupStatusEnum.pendingApproval; + request.statusSpecified = true; + request.paging = new Paging + { + limit = 10, + offset = 1 + }; + request.sorting = new TransactionListSorting + { + orderBy = TransactionListOrderFieldEnum.id, + orderDescending = true + }; + // instantiate the controller that will call the service + var controller = new getUnsettledTransactionListController(request); + controller.Execute(); + + // get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + { + if (response.transactions == null) + return response; + + foreach (var item in response.transactions) + { + Console.WriteLine("Transaction Id: {0} was submitted on {1}", item.transId, + item.submitTimeLocal); + } + } + else if(response != null) + { + Console.WriteLine("Error: " + response.messages.message[0].code + " " + + response.messages.message[0].text); + } + + return response; + } + } +} diff --git a/MobileInappTransactions/CreateAnAcceptTransaction.cs b/MobileInAppTransactions/CreateAnAcceptTransaction.cs similarity index 96% rename from MobileInappTransactions/CreateAnAcceptTransaction.cs rename to MobileInAppTransactions/CreateAnAcceptTransaction.cs index a0b64c3..12eb560 100644 --- a/MobileInappTransactions/CreateAnAcceptTransaction.cs +++ b/MobileInAppTransactions/CreateAnAcceptTransaction.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; -namespace net.authorize.sample.MobileInappTransactions +namespace net.authorize.sample { public class CreateAnAcceptTransaction { @@ -39,14 +39,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, D var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/MobileInappTransactions/CreateAnAndroidPayTransaction.cs b/MobileInAppTransactions/CreateAnAndroidPayTransaction.cs similarity index 98% rename from MobileInappTransactions/CreateAnAndroidPayTransaction.cs rename to MobileInAppTransactions/CreateAnAndroidPayTransaction.cs index 5d7e883..e046949 100644 --- a/MobileInappTransactions/CreateAnAndroidPayTransaction.cs +++ b/MobileInAppTransactions/CreateAnAndroidPayTransaction.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; -namespace net.authorize.sample.MobileInappTransactions +namespace net.authorize.sample { public class CreateAnAndroidPayTransaction { @@ -39,14 +39,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, D var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/MobileInappTransactions/CreateAnApplePayTransaction.cs b/MobileInAppTransactions/CreateAnApplePayTransaction.cs similarity index 98% rename from MobileInappTransactions/CreateAnApplePayTransaction.cs rename to MobileInAppTransactions/CreateAnApplePayTransaction.cs index ccb5367..ed94d5a 100644 --- a/MobileInappTransactions/CreateAnApplePayTransaction.cs +++ b/MobileInAppTransactions/CreateAnApplePayTransaction.cs @@ -6,7 +6,7 @@ using AuthorizeNet.Api.Contracts.V1; using AuthorizeNet.Api.Controllers.Bases; -namespace net.authorize.sample.MobileInappTransactions +namespace net.authorize.sample { public class CreateAnApplePayTransaction { @@ -39,14 +39,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, D var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/MobileInAppTransactions/CreateGooglePayTransaction.cs b/MobileInAppTransactions/CreateGooglePayTransaction.cs new file mode 100644 index 0000000..e07ee08 --- /dev/null +++ b/MobileInAppTransactions/CreateGooglePayTransaction.cs @@ -0,0 +1,132 @@ +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Controllers.Bases; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace net.authorize.sample +{ + public class CreateGooglePayTransaction + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, Decimal Amount) + { + Console.WriteLine("Create Google Pay Transaction Sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + var opaqueData = new opaqueDataType() + { + dataDescriptor = "COMMON.GOOGLE.INAPP.PAYMENT", + dataValue = "1234567890ABCDEF1111AAAA2222BBBB3333CCCC4444DDDD5555EEEE6666FFFF7777888899990000", + }; + + var paymentType = new paymentType() + { + Item = opaqueData + }; + + var lineItems = new lineItemType[] + { + new lineItemType() + { + itemId = "1", + name = "vase", + description = "Cannes logo", + quantity = 18, + unitPrice = 45.00M + } + }; + + var tax = new extendedAmountType() + { + amount = Amount, + name = "level2 tax name", + description = "level2 tax" + }; + + var userFields = new userField[] + { + new userField() + { + name = "UserDefinedFieldName1", + value = "UserDefinedFieldValue1" + }, + new userField() + { + name = "UserDefinedFieldName2", + value = "UserDefinedFieldName2" + } + }; + + var transactionRequest = new transactionRequestType() + { + transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), + amount = Amount, + payment = paymentType, + lineItems = lineItems, + tax = tax, + userFields = userFields + }; + + var request = new createTransactionRequest { transactionRequest = transactionRequest }; + + var controller = new createTransactionController(request); + controller.Execute(); + + var response = controller.GetApiResponse(); + + if (response != null) + { + if (response.messages.resultCode == messageTypeEnum.Ok) + { + if (response.transactionResponse.messages != null) + { + Console.WriteLine("Successfully created a Google Pay transaction with Transaction ID: " + response.transactionResponse.transId); + Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); + Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); + Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + } + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse != null && response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + else + { + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + } + } + } + else + { + Console.WriteLine("Null Response."); + } + + return response; + } + } +} diff --git a/PaypalExpressCheckout/AuthorizationAndCapture.cs b/PayPalExpressCheckout/AuthorizationAndCapture.cs similarity index 97% rename from PaypalExpressCheckout/AuthorizationAndCapture.cs rename to PayPalExpressCheckout/AuthorizationAndCapture.cs index 5218063..286d95f 100644 --- a/PaypalExpressCheckout/AuthorizationAndCapture.cs +++ b/PayPalExpressCheckout/AuthorizationAndCapture.cs @@ -42,14 +42,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/AuthorizationAndCaptureContinue.cs b/PayPalExpressCheckout/AuthorizationAndCaptureContinued.cs similarity index 94% rename from PaypalExpressCheckout/AuthorizationAndCaptureContinue.cs rename to PayPalExpressCheckout/AuthorizationAndCaptureContinued.cs index 32d2eae..69e0153 100644 --- a/PaypalExpressCheckout/AuthorizationAndCaptureContinue.cs +++ b/PayPalExpressCheckout/AuthorizationAndCaptureContinued.cs @@ -8,11 +8,11 @@ namespace net.authorize.sample { - public class PayPalAuthorizeCaptureContinue + public class PayPalAuthorizeCaptureContinued { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string TransactionID, string PayerID) { - Console.WriteLine("PayPal Authorize Capture-Continue Transaction"); + Console.WriteLine("PayPal Authorization and Capture, Continued Transaction"); ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; @@ -44,14 +44,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/AuthorizationOnly.cs b/PayPalExpressCheckout/AuthorizationOnly.cs similarity index 97% rename from PaypalExpressCheckout/AuthorizationOnly.cs rename to PayPalExpressCheckout/AuthorizationOnly.cs index b45668a..4af0ddc 100644 --- a/PaypalExpressCheckout/AuthorizationOnly.cs +++ b/PayPalExpressCheckout/AuthorizationOnly.cs @@ -42,14 +42,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/AuthorizationOnlyContinued.cs b/PayPalExpressCheckout/AuthorizationOnlyContinued.cs similarity index 94% rename from PaypalExpressCheckout/AuthorizationOnlyContinued.cs rename to PayPalExpressCheckout/AuthorizationOnlyContinued.cs index 65aae9d..5c2e29e 100644 --- a/PaypalExpressCheckout/AuthorizationOnlyContinued.cs +++ b/PayPalExpressCheckout/AuthorizationOnlyContinued.cs @@ -8,11 +8,11 @@ namespace net.authorize.sample { - public class PayPalAuthorizeOnlyContinue + public class PayPalAuthorizeOnlyContinued { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string TransactionID, string PayerID) { - Console.WriteLine("PayPal Authorize Only-Continue Transaction"); + Console.WriteLine("PayPal Authorize Only, Continued Transaction"); ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; @@ -44,14 +44,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/Credit.cs b/PayPalExpressCheckout/Credit.cs similarity index 97% rename from PaypalExpressCheckout/Credit.cs rename to PayPalExpressCheckout/Credit.cs index 9c1b761..301b6b0 100644 --- a/PaypalExpressCheckout/Credit.cs +++ b/PayPalExpressCheckout/Credit.cs @@ -43,14 +43,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/GetDetails.cs b/PayPalExpressCheckout/GetDetails.cs similarity index 97% rename from PaypalExpressCheckout/GetDetails.cs rename to PayPalExpressCheckout/GetDetails.cs index 2675c27..527c258 100644 --- a/PaypalExpressCheckout/GetDetails.cs +++ b/PayPalExpressCheckout/GetDetails.cs @@ -43,14 +43,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/PriorAuthorizationCapture.cs b/PayPalExpressCheckout/PriorAuthorizationCapture.cs similarity index 97% rename from PaypalExpressCheckout/PriorAuthorizationCapture.cs rename to PayPalExpressCheckout/PriorAuthorizationCapture.cs index b06c590..5b87db9 100644 --- a/PaypalExpressCheckout/PriorAuthorizationCapture.cs +++ b/PayPalExpressCheckout/PriorAuthorizationCapture.cs @@ -43,14 +43,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaypalExpressCheckout/Void.cs b/PayPalExpressCheckout/Void.cs similarity index 97% rename from PaypalExpressCheckout/Void.cs rename to PayPalExpressCheckout/Void.cs index 69776bb..69c6947 100644 --- a/PaypalExpressCheckout/Void.cs +++ b/PayPalExpressCheckout/Void.cs @@ -42,14 +42,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/AuthorizeCreditCard.cs b/PaymentTransactions/AuthorizeCreditCard.cs index 4f0d937..ccf631a 100644 --- a/PaymentTransactions/AuthorizeCreditCard.cs +++ b/PaymentTransactions/AuthorizeCreditCard.cs @@ -27,7 +27,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //standard api call to retrieve response @@ -42,14 +42,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if(response != null){ if(response.messages.resultCode == messageTypeEnum.Ok){ if(response.transactionResponse.messages != null) diff --git a/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.cs b/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.cs index 934c5f0..4d7f22c 100644 --- a/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.cs +++ b/PaymentTransactions/CaptureFundsAuthorizedThroughAnotherChannel.cs @@ -29,7 +29,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d { // Change the cardNumber and expiration Date as required cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //standard api call to retrieve response @@ -51,14 +51,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/CapturePreviouslyAuthorizedAmount.cs b/PaymentTransactions/CapturePreviouslyAuthorizedAmount.cs index 03ba769..5f1fd13 100644 --- a/PaymentTransactions/CapturePreviouslyAuthorizedAmount.cs +++ b/PaymentTransactions/CapturePreviouslyAuthorizedAmount.cs @@ -41,14 +41,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/ChargeCreditCard.cs b/PaymentTransactions/ChargeCreditCard.cs index b97d7b3..024b6a9 100644 --- a/PaymentTransactions/ChargeCreditCard.cs +++ b/PaymentTransactions/ChargeCreditCard.cs @@ -28,7 +28,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718", + expirationDate = "1035", cardCode = "123" }; @@ -61,14 +61,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/ChargeCustomerProfile.cs b/PaymentTransactions/ChargeCustomerProfile.cs index fc9d7cf..1146641 100644 --- a/PaymentTransactions/ChargeCustomerProfile.cs +++ b/PaymentTransactions/ChargeCustomerProfile.cs @@ -46,7 +46,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/ChargeEncryptedTrackData.cs b/PaymentTransactions/ChargeEncryptedTrackData.cs index 3c69966..cdd7152 100644 --- a/PaymentTransactions/ChargeEncryptedTrackData.cs +++ b/PaymentTransactions/ChargeEncryptedTrackData.cs @@ -72,14 +72,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/ChargeTokenizedCreditCard.cs b/PaymentTransactions/ChargeTokenizedCreditCard.cs index 1174786..6da78e9 100644 --- a/PaymentTransactions/ChargeTokenizedCreditCard.cs +++ b/PaymentTransactions/ChargeTokenizedCreditCard.cs @@ -28,8 +28,10 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718", - cryptogram = Guid.NewGuid().ToString() // Set this to the value of the cryptogram received from the token provide + expirationDate = "1035", + // Set the token specific info + isPaymentToken = true, + cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=" // Set this to the value of the cryptogram received from the token provide }; //standard api call to retrieve response @@ -44,14 +46,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/ChargeTrackData.cs b/PaymentTransactions/ChargeTrackData.cs index bd2a046..181837e 100644 --- a/PaymentTransactions/ChargeTrackData.cs +++ b/PaymentTransactions/ChargeTrackData.cs @@ -57,14 +57,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/CreateChasePayTransaction.cs b/PaymentTransactions/CreateChasePayTransaction.cs new file mode 100644 index 0000000..d14de16 --- /dev/null +++ b/PaymentTransactions/CreateChasePayTransaction.cs @@ -0,0 +1,115 @@ +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Controllers.Bases; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace net.authorize.sample.PaymentTransactions +{ + class CreateChasePayTransaction + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) + { + Console.WriteLine("Create a ChasePay Transaction Sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + var creditCard = new creditCardType + { + cardNumber = "4111111111111111", + expirationDate = "0735", + cardCode = "999", + // Set the token specific info + isPaymentToken = true, + // Set this to the value of the cryptogram received from the token provide + cryptogram = "EjRWeJASNFZ4kBI0VniQEjRWeJA=", + tokenRequestorName = "CHASE_PAY", + tokenRequestorId = "12345678901", + tokenRequestorEci = "07" + }; + + //standard api call to retrieve response + var paymentType = new paymentType { Item = creditCard }; + + var transactionRequest = new transactionRequestType + { + transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), + amount = 133.45m, + payment = paymentType + }; + + var request = new createTransactionRequest { transactionRequest = transactionRequest }; + + // instantiate the controller that will call the service + var controller = new createTransactionController(request); + controller.Execute(); + + // get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + + // validate response + if (response != null) + { + if (response.messages.resultCode == messageTypeEnum.Ok) + { + if (response.transactionResponse.messages != null) + { + Console.WriteLine("Successfully created transaction with Transaction ID: " + response.transactionResponse.transId); + Console.WriteLine("Response Code: " + response.transactionResponse.responseCode); + Console.WriteLine("Message Code: " + response.transactionResponse.messages[0].code); + Console.WriteLine("Description: " + response.transactionResponse.messages[0].description); + Console.WriteLine("Hash Code: " + response.transactionResponse.transHash); + Console.WriteLine("Success, Auth Code : " + response.transactionResponse.authCode); + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + } + } + else + { + Console.WriteLine("Failed Transaction."); + if (response.transactionResponse != null && response.transactionResponse.errors != null) + { + Console.WriteLine("Error Code: " + response.transactionResponse.errors[0].errorCode); + Console.WriteLine("Error message: " + response.transactionResponse.errors[0].errorText); + } + else + { + Console.WriteLine("Error Code: " + response.messages.message[0].code); + Console.WriteLine("Error message: " + response.messages.message[0].text); + } + } + } + else + { + // Display the error code and message when response is null + ANetApiResponse errorResponse = controller.GetErrorResponse(); + Console.WriteLine("Failed to get response"); + if (!string.IsNullOrEmpty(errorResponse.messages.message.ToString())) + { + Console.WriteLine("Error Code: " + errorResponse.messages.message[0].code); + Console.WriteLine("Error message: " + errorResponse.messages.message[0].text); + } + } + + return response; + } + } +} diff --git a/PaymentTransactions/CreditBankAccount.cs b/PaymentTransactions/CreditBankAccount.cs index 12fa768..aeadd8a 100644 --- a/PaymentTransactions/CreditBankAccount.cs +++ b/PaymentTransactions/CreditBankAccount.cs @@ -26,13 +26,16 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var bankAccount = new bankAccountType { - accountNumber = "4111111", - routingNumber = "325070760", - echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) - nameOnAccount = "Test Name" + accountType = bankAccountTypeEnum.checking, + routingNumber = "125000105", + accountNumber = "1234567890", + nameOnAccount = "John Doe", + echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) + bankName = "Wells Fargo Bank NA", + // checkNumber = "101" // needed if echeckType is "ARC" or "BOC" }; - //standard api call to retrieve response + // standard api call to retrieve response var paymentType = new paymentType { Item = bankAccount }; var transactionRequest = new transactionRequestType @@ -45,14 +48,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/DebitBankAccount.cs b/PaymentTransactions/DebitBankAccount.cs index 14dda86..f2417c3 100644 --- a/PaymentTransactions/DebitBankAccount.cs +++ b/PaymentTransactions/DebitBankAccount.cs @@ -24,15 +24,20 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d Item = ApiTransactionKey }; + Random rand = new Random(); + int randomAccountNumber = rand.Next(10000, int.MaxValue); + var bankAccount = new bankAccountType { - accountNumber = "4111111", - routingNumber = "325070760", + accountType = bankAccountTypeEnum.checking, + routingNumber = "125008547", + accountNumber = randomAccountNumber.ToString(), + nameOnAccount = "John Doe", echeckType = echeckTypeEnum.WEB, // change based on how you take the payment (web, telephone, etc) - nameOnAccount = "Test Name" + bankName = "Wells Fargo Bank NA", + // checkNumber = "101" // needed if echeckType is "ARC" or "BOC" }; - - //standard api call to retrieve response + // standard api call to retrieve response var paymentType = new paymentType { Item = bankAccount }; var transactionRequest = new transactionRequestType @@ -44,14 +49,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/RefundTransaction.cs b/PaymentTransactions/RefundTransaction.cs index fcfa1a2..e7b6bec 100644 --- a/PaymentTransactions/RefundTransaction.cs +++ b/PaymentTransactions/RefundTransaction.cs @@ -43,14 +43,14 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, d var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/PaymentTransactions/UpdateSplitTenderGroup.cs b/PaymentTransactions/UpdateSplitTenderGroup.cs index 4cab637..2e5a6c0 100644 --- a/PaymentTransactions/UpdateSplitTenderGroup.cs +++ b/PaymentTransactions/UpdateSplitTenderGroup.cs @@ -33,12 +33,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var request = new updateSplitTenderGroupRequest { splitTenderId = splitTenderId, splitTenderStatus = splitTenderStatus }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new updateSplitTenderGroupController(request); controller.Execute(); var response = controller.GetApiResponse(); - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { Console.WriteLine("Successfully Updated ... "); diff --git a/PaymentTransactions/VoidTransaction.cs b/PaymentTransactions/VoidTransaction.cs index d04f04c..420c0e3 100644 --- a/PaymentTransactions/VoidTransaction.cs +++ b/PaymentTransactions/VoidTransaction.cs @@ -24,32 +24,22 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s Item = ApiTransactionKey }; - var creditCard = new creditCardType - { - cardNumber = "4111111111111111", - expirationDate = "0718" - }; - - //standard api call to retrieve response - var paymentType = new paymentType { Item = creditCard }; - var transactionRequest = new transactionRequestType { transactionType = transactionTypeEnum.voidTransaction.ToString(), // refund type - payment = paymentType, refTransId = TransactionID }; var request = new createTransactionRequest { transactionRequest = transactionRequest }; - // instantiate the contoller that will call the service + // instantiate the controller that will call the service var controller = new createTransactionController(request); controller.Execute(); // get the response from the service (errors contained if any) var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index ba83490..2bac29a 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("SampleCode")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("0.9.0.0")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Microsoft")] [assembly: AssemblyProduct("SampleCode")] @@ -32,5 +32,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.9.0.0")] +[assembly: AssemblyFileVersion("0.9.0.0")] + diff --git a/README.md b/README.md index 27cadaa..cc2de0d 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,34 @@ -# Sample C# Code for Authorize.Net -[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-csharp.png?branch=master)] -(https://travis-ci.org/AuthorizeNet/sample-code-csharp) +# C# Sample Code for the Authorize.Net SDK +[![Travis CI Status](https://travis-ci.org/AuthorizeNet/sample-code-csharp.svg?branch=master)](https://travis-ci.org/AuthorizeNet/sample-code-csharp) -This repository contains working code samples which demonstrate C# integration with the Authorize.Net .NET SDK -The samples are organized just like our API, which you can also try out directly here: http://developer.authorize.net/api/reference +This repository contains working code samples which demonstrate C# integration with the [Authorize.Net .NET SDK](https://www.github.com/AuthorizeNet/sdk-dotnet). +The samples are organized into categories and common usage examples, just like our [API Reference Guide](http://developer.authorize.net/api/reference). Our API Reference Guide is an interactive reference for the Authorize.Net API. It explains the request and response parameters for each API method and has embedded code windows to allow you to send actual requests right within the API Reference Guide. -##Using the Sample Code -The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line. +## Using the Sample Code -##Running the Samples - Clone this repository. - Include the Authorize.Net SDK (https://github.com/AuthorizeNet/sdk-dotnet) - `PM> Install-Package AuthorizeNet` - Build the project to produce the SampleCode console app. - Then run a sample directly by name: -```` +The samples are all completely independent and self-contained. You can analyze them to get an understanding of how a particular method works, or you can use the snippets as a starting point for your own project. + +You can also run each sample directly from the command line. + +## Running the Samples From the Command Line +* Clone this repository: +``` + $ git clone https://github.com/AuthorizeNet/sample-code-csharp.git +``` +* Include the [Authorize.Net .NET SDK](https://github.com/AuthorizeNet/sdk-dotnet): +``` + PM> Install-Package AuthorizeNet +``` + Build the project to produce the SampleCode console app. +* Run the individual samples by name. For example: +``` > SampleCode [CodeSampleName] -```` +``` e.g. -```` +``` > SampleCode ChargeCreditCard -```` +``` Running SampleCode without a parameter will give you the list of sample names. diff --git a/RecurringBilling/CancelSubscription.cs b/RecurringBilling/CancelSubscription.cs index 792ab18..8197fda 100644 --- a/RecurringBilling/CancelSubscription.cs +++ b/RecurringBilling/CancelSubscription.cs @@ -24,12 +24,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s //Please change the subscriptionId according to your request var request = new ARBCancelSubscriptionRequest { subscriptionId = subscriptionId }; - var controller = new ARBCancelSubscriptionController(request); // instantiate the contoller that will call the service + var controller = new ARBCancelSubscriptionController(request); // instantiate the controller that will call the service controller.Execute(); ARBCancelSubscriptionResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/RecurringBilling/CreateSubscription.cs b/RecurringBilling/CreateSubscription.cs index c072dae..256cda9 100644 --- a/RecurringBilling/CreateSubscription.cs +++ b/RecurringBilling/CreateSubscription.cs @@ -40,7 +40,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //standard api call to retrieve response @@ -64,12 +64,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new ARBCreateSubscriptionRequest {subscription = subscriptionType }; - var controller = new ARBCreateSubscriptionController(request); // instantiate the contoller that will call the service + var controller = new ARBCreateSubscriptionController(request); // instantiate the controller that will call the service controller.Execute(); ARBCreateSubscriptionResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/RecurringBilling/CreateSubscriptionFromCustomerProfile.cs b/RecurringBilling/CreateSubscriptionFromCustomerProfile.cs index dc54e9c..ec32399 100644 --- a/RecurringBilling/CreateSubscriptionFromCustomerProfile.cs +++ b/RecurringBilling/CreateSubscriptionFromCustomerProfile.cs @@ -41,7 +41,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //standard api call to retrieve response @@ -65,12 +65,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new ARBCreateSubscriptionRequest {subscription = subscriptionType }; - var controller = new ARBCreateSubscriptionController(request); // instantiate the contoller that will call the service + var controller = new ARBCreateSubscriptionController(request); // instantiate the controller that will call the service controller.Execute(); ARBCreateSubscriptionResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/RecurringBilling/GetListOfSubscriptions.cs b/RecurringBilling/GetListOfSubscriptions.cs index e90b1a7..9a4f942 100644 --- a/RecurringBilling/GetListOfSubscriptions.cs +++ b/RecurringBilling/GetListOfSubscriptions.cs @@ -25,12 +25,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) var request = new ARBGetSubscriptionListRequest {searchType = ARBGetSubscriptionListSearchTypeEnum.subscriptionActive }; // only gets active subscriptions - var controller = new ARBGetSubscriptionListController(request); // instantiate the contoller that will call the service + var controller = new ARBGetSubscriptionListController(request); // instantiate the controller that will call the service controller.Execute(); ARBGetSubscriptionListResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null && response.subscriptionDetails != null) diff --git a/RecurringBilling/GetSubscription.cs b/RecurringBilling/GetSubscription.cs index c4aacb4..b2511aa 100644 --- a/RecurringBilling/GetSubscription.cs +++ b/RecurringBilling/GetSubscription.cs @@ -25,12 +25,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s var request = new ARBGetSubscriptionRequest { subscriptionId = subscriptionId }; - var controller = new ARBGetSubscriptionController(request); // instantiate the contoller that will call the service + var controller = new ARBGetSubscriptionController(request); // instantiate the controller that will call the service controller.Execute(); ARBGetSubscriptionResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response.subscription != null) diff --git a/RecurringBilling/GetSubscriptionStatus.cs b/RecurringBilling/GetSubscriptionStatus.cs index ec2aac8..9a7e08f 100644 --- a/RecurringBilling/GetSubscriptionStatus.cs +++ b/RecurringBilling/GetSubscriptionStatus.cs @@ -26,12 +26,12 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, s //please update the subscriptionId according to your sandbox credentials var request = new ARBGetSubscriptionStatusRequest { subscriptionId = subscriptionId }; - var controller = new ARBGetSubscriptionStatusController(request); // instantiate the contoller that will call the service + var controller = new ARBGetSubscriptionStatusController(request); // instantiate the controller that will call the service controller.Execute(); ARBGetSubscriptionStatusResponse response = controller.GetApiResponse(); // get the response from the service (errors contained if any) - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/RecurringBilling/UpdateSubscription.cs b/RecurringBilling/UpdateSubscription.cs index 279a93a..54da0b2 100644 --- a/RecurringBilling/UpdateSubscription.cs +++ b/RecurringBilling/UpdateSubscription.cs @@ -32,7 +32,7 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s var creditCard = new creditCardType { cardNumber = "4111111111111111", - expirationDate = "0718" + expirationDate = "1035" }; //standard api call to retrieve response @@ -69,7 +69,7 @@ public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, s ARBUpdateSubscriptionResponse response = controller.GetApiResponse(); - //validate + // validate response if (response != null && response.messages.resultCode == messageTypeEnum.Ok) { if (response != null && response.messages.message != null) diff --git a/SampleCode.cs b/SampleCode.cs index c1845f4..64deac2 100644 --- a/SampleCode.cs +++ b/SampleCode.cs @@ -1,11 +1,11 @@ -using net.authorize.sample.MobileInappTransactions; using net.authorize.sample.PaymentTransactions; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using net.authorize.sample.CustomerProfiles; +using AuthorizeNet.Api.Controllers.Bases; +using AuthorizeNet.Api.Contracts.V1; +#if NETCOREAPP2_0 +using AuthorizeNet.Utilities; +#endif namespace net.authorize.sample { @@ -38,7 +38,7 @@ static void Main(string[] args) Console.WriteLine(""); Console.Write("Press to finish ..."); Console.ReadLine(); - + } private static void ShowUsage() @@ -65,7 +65,7 @@ private static void SelectMethod() private static void ShowMethods() { - + Console.WriteLine(" ChargeCreditCard"); Console.WriteLine(" AuthorizeCreditCard"); Console.WriteLine(" CapturePreviouslyAuthorizedAmount"); @@ -81,12 +81,14 @@ private static void ShowMethods() Console.WriteLine(" CreateAnApplePayTransaction"); Console.WriteLine(" CreateAnAndroidPayTransaction"); Console.WriteLine(" CreateAnAcceptTransaction"); - Console.WriteLine(" DecryptVisaCheckoutData"); - Console.WriteLine(" CreateVisaCheckoutTransaction"); + Console.WriteLine(" CreateGooglePayTransaction"); + Console.WriteLine(" DecryptVisaSrcData"); + Console.WriteLine(" CreateVisaSrcTransaction"); Console.WriteLine(" PayPalVoid"); Console.WriteLine(" PayPalAuthorizeCapture"); - Console.WriteLine(" PayPalAuthorizeCaptureContinue"); + Console.WriteLine(" PayPalAuthorizeCaptureContinued"); Console.WriteLine(" PayPalAuthorizeOnly"); + Console.WriteLine(" PayPalAuthorizeOnlyContinued"); Console.WriteLine(" PayPalCredit"); Console.WriteLine(" PayPalGetDetails"); Console.WriteLine(" PayPalPriorAuthorizationCapture"); @@ -124,9 +126,14 @@ private static void ShowMethods() Console.WriteLine(" GetTransactionDetails"); Console.WriteLine(" GetTransactionList"); Console.WriteLine(" UpdateSplitTenderGroup"); - Console.WriteLine(" UpdateHeldTransaction"); + Console.WriteLine(" GetHeldTransactionList"); + Console.WriteLine(" ApproveOrDeclineHeldTransaction"); Console.WriteLine(" GetMerchantDetails"); - Console.WriteLine(" GetHostedPaymentPage"); + Console.WriteLine(" GetAnAcceptPaymentPage"); + Console.WriteLine(" GetCustomerProfileTransactionList"); + Console.WriteLine(" CreateAnAcceptPaymentTransaction"); + Console.WriteLine(" GetAccountUpdaterJobSummary"); + Console.WriteLine(" CreateChasePayTransaction"); } private static void RunMethod(String methodName) @@ -142,14 +149,34 @@ private static void RunMethod(String methodName) //Update PayerID for which you want to run the sample code const string payerId = "M8R9JRNJ3R28Y"; - const string customerProfileId = "213213"; - const string customerPaymentProfileId = "2132345"; - const string shippingAddressId = "1223213"; + const string customerProfileId = "922449496"; //"213213"; + const string customerPaymentProfileId = "921836008"; //"2132345"; + + const string shippingAddressId = "922279358"; const decimal amount = 12.34m; const string subscriptionId = "1223213"; const short day = 45; const string emailId = "test@test.com"; +#if NETCOREAPP2_0 + // DOTNET CORE SPECIFIC + #region DOTNET CORE SPECIFIC + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + ApiOperationBase.RunEnvironment.HttpUseProxy = AuthorizeNet.Environment.getBooleanProperty(Constants.HttpsUseProxy); + + if (ApiOperationBase.RunEnvironment.HttpUseProxy) + { + ApiOperationBase.RunEnvironment.HttpUseProxy = AuthorizeNet.Environment.getBooleanProperty(Constants.HttpsUseProxy); + ApiOperationBase.RunEnvironment.HttpsProxyUsername = AuthorizeNet.Environment.GetProperty(Constants.HttpsProxyUsername); + ApiOperationBase.RunEnvironment.HttpsProxyPassword = AuthorizeNet.Environment.GetProperty(Constants.HttpsProxyPassword); + ApiOperationBase.RunEnvironment.HttpProxyHost = AuthorizeNet.Environment.GetProperty(Constants.HttpsProxyHost); + ApiOperationBase.RunEnvironment.HttpProxyPort = AuthorizeNet.Environment.getIntProperty(Constants.HttpsProxyPort); + } + + #endregion +#endif + switch (methodName) { case "ValidateCustomerPaymentProfile": @@ -212,11 +239,14 @@ private static void RunMethod(String methodName) case "CreateAnAcceptTransaction": CreateAnAcceptTransaction.Run(apiLoginId, transactionKey, 12.23m); break; - case "DecryptVisaCheckoutData": - DecryptVisaCheckoutData.Run(apiLoginId, transactionKey); + case "CreateGooglePayTransaction": + CreateGooglePayTransaction.Run(apiLoginId, transactionKey, 50.00m); break; - case "CreateVisaCheckoutTransaction": - CreateVisaCheckoutTransaction.Run(apiLoginId, transactionKey); + case "DecryptVisaSrcData": + DecryptVisaSrcData.Run(apiLoginId, transactionKey); + break; + case "CreateVisaSrcTransaction": + CreateVisaSrcTransaction.Run(apiLoginId, transactionKey); break; case "ChargeCreditCard": ChargeCreditCard.Run(apiLoginId, transactionKey, amount); @@ -260,14 +290,14 @@ private static void RunMethod(String methodName) case "PayPalAuthorizeCapture": PayPalAuthorizeCapture.Run(apiLoginId, transactionKey, amount); break; - case "PayPalAuthorizeCaptureContinue": - PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId, payerId); + case "PayPalAuthorizeCaptureContinued": + PayPalAuthorizeCaptureContinued.Run(apiLoginId, transactionKey, transactionId, payerId); break; case "PayPalAuthorizeOnly": PayPalAuthorizeOnly.Run(apiLoginId, transactionKey, amount); break; - case "PayPalAuthorizeOnlyContinue": - PayPalAuthorizeOnlyContinue.Run(apiLoginId, transactionKey, transactionId, payerId); + case "PayPalAuthorizeOnlyContinued": + PayPalAuthorizeOnlyContinued.Run(apiLoginId, transactionKey, transactionId, payerId); break; case "PayPalCredit": PayPalCredit.Run(apiLoginId, transactionKey, transactionId); @@ -285,7 +315,7 @@ private static void RunMethod(String methodName) CreateSubscription.Run(apiLoginId, transactionKey, day); break; case "CreateSubscriptionFromCustomerProfile": - CreateSubscriptionFromCustomerProfile.Run(apiLoginId, transactionKey, day, "12322","232321","123232"); + CreateSubscriptionFromCustomerProfile.Run(apiLoginId, transactionKey, day, "12322", "232321", "123232"); break; case "GetListOfSubscriptions": GetListOfSubscriptions.Run(apiLoginId, transactionKey); @@ -312,20 +342,35 @@ private static void RunMethod(String methodName) GetBatchStatistics.Run(apiLoginId, transactionKey); break; case "GetSettledBatchList": - GetSettledBatchList.Run(apiLoginId,transactionKey); - break; + GetSettledBatchList.Run(apiLoginId, transactionKey); + break; case "UpdateSplitTenderGroup": - UpdateSplitTenderGroup.Run(apiLoginId, transactionKey); - break; - case "UpdateHeldTransaction": - UpdateHeldTransaction.Run(apiLoginId, transactionKey); + UpdateSplitTenderGroup.Run(apiLoginId, transactionKey); + break; + case "GetHeldTransactionList": + GetHeldTransactionList.Run(apiLoginId, transactionKey); + break; + case "ApproveOrDeclineHeldTransaction": + ApproveOrDeclineHeldTransaction.Run(apiLoginId, transactionKey); break; case "GetMerchantDetails": - GetMerchantDetails.Run(apiLoginId, transactionKey); - break; - case "GetHostedPaymentPage": - GetHostedPaymentPage.Run(apiLoginId, transactionKey, 12.23m); + GetMerchantDetails.Run(apiLoginId, transactionKey); + break; + case "GetAnAcceptPaymentPage": + GetAnAcceptPaymentPage.Run(apiLoginId, transactionKey, 12.23m); + break; + case "CreateAnAcceptPaymentTransaction": + CreateAnAcceptPaymentTransaction.Run(apiLoginId, transactionKey, 12.23m); + break; + case "GetCustomerProfileTransactionList": + GetCustomerProfileTransactionList.Run(apiLoginId, transactionKey, customerProfileId); + break; + case "CreateChasePayTransaction": + CreateChasePayTransaction.Run(apiLoginId, transactionKey); break; + //case "GetAccountUpdaterJobSummary": + // GetAccountUpdaterJobSummary.Run(apiLoginId, transactionKey); + // break; default: ShowUsage(); break; diff --git a/SampleCode.csproj b/SampleCode.csproj index 02e62eb..0e8e5e8 100644 --- a/SampleCode.csproj +++ b/SampleCode.csproj @@ -9,8 +9,9 @@ Properties net.authorize.sample SampleCode - v4.0 + v4.6.1 512 + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,10 +32,11 @@ TRACE prompt 4 + false - - packages\AuthorizeNet.1.9.1\lib\AuthorizeNet.dll + + packages\AuthorizeNet.2.0.4\lib\AuthorizeNet.dll @@ -44,10 +47,13 @@ - - - - + + + + + + + @@ -60,11 +66,12 @@ - + + @@ -73,20 +80,20 @@ + - - - - - - - - - + + + + + + + + @@ -95,15 +102,18 @@ + + + - + - + @@ -111,11 +121,11 @@ - - + \ No newline at end of file diff --git a/SampleCode.exe b/SampleCode.exe new file mode 100644 index 0000000..9fa49a0 Binary files /dev/null and b/SampleCode.exe differ diff --git a/SampleCode.exe.config b/SampleCode.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/SampleCode.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SampleCode.sln b/SampleCode.sln index 5e4ede4..e84cfa5 100644 --- a/SampleCode.sln +++ b/SampleCode.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32228.343 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCode", "SampleCode.csproj", "{EE8CB03C-AFF3-4480-AFD5-1C8B51540570}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCodeTest", "SampleCodeTest\SampleCodeTest.csproj", "{71C96893-D93D-469D-A49D-1B3DE4985914}" diff --git a/SampleCode.vshost.exe b/SampleCode.vshost.exe new file mode 100644 index 0000000..8f90da4 Binary files /dev/null and b/SampleCode.vshost.exe differ diff --git a/SampleCode.vshost.exe.config b/SampleCode.vshost.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/SampleCode.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SampleCodeTest/Properties/AssemblyInfo.cs b/SampleCodeTest/Properties/AssemblyInfo.cs index f5998a7..4d3ee67 100644 --- a/SampleCodeTest/Properties/AssemblyInfo.cs +++ b/SampleCodeTest/Properties/AssemblyInfo.cs @@ -32,5 +32,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: AssemblyVersion("0.9.0.0")] +[assembly: AssemblyFileVersion("0.9.0.0")] + + diff --git a/SampleCodeTest/README.md b/SampleCodeTest/README.md index 20241d2..d9fbc15 100644 --- a/SampleCodeTest/README.md +++ b/SampleCodeTest/README.md @@ -1,17 +1,16 @@ # Unit Test Project for testing C# Sample Codes for Authorize.Net -[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-csharp.png?branch=master)] -(https://travis-ci.org/AuthorizeNet/sample-code-csharp) +[![Build Status](https://travis-ci.org/AuthorizeNet/sample-code-csharp.png?branch=master)](https://travis-ci.org/AuthorizeNet/sample-code-csharp) This project is a unit test project which tests whether the C# sample codes are working as expected. If any of the unit tests fail the travis build will fail. -##Using the Sample Code Test project +## Using the Sample Code Test project The samples are all completely independent and self-contained so you can look at them to get a gist of how the method works, you can use the snippets to try in your own sample project, or you can run each sample from the command line. -##Running the Samples +## Running the Samples - Clone sample code repository.
- Open the sample code project in visual studio.
- Include the AuthorizeNet.dll present in bin/debug folder.
diff --git a/SampleCodeTest/SampleCodeList.txt b/SampleCodeTest/SampleCodeList.txt index 2748ab7..b4d89fa 100644 --- a/SampleCodeTest/SampleCodeList.txt +++ b/SampleCodeTest/SampleCodeList.txt @@ -1,13 +1,12 @@ SampleCode IsDependent RunApi -CreateSubscription 1 1 CreateSubscriptionFromCustomerProfile 1 1 GetCustomerPaymentProfileList 0 1 GetTransactionList 0 1 CreateAnApplePayTransaction 1 0 CreateAnAndroidPayTransaction 1 0 CreateAnAcceptTransaction 1 0 -DecryptVisaCheckoutData 0 1 -CreateVisaCheckoutTransaction 0 0 +DecryptVisaSrcData 0 0 +CreateVisaSrcTransaction 0 0 CaptureFundsAuthorizedThroughAnotherChannel 1 1 AuthorizeCreditCard 1 1 DebitBankAccount 1 1 @@ -23,7 +22,7 @@ UpdateCustomerShippingAddress 1 1 UpdateCustomerProfile 1 1 UpdateCustomerPaymentProfile 1 1 GetCustomerShippingAddress 1 1 -GetCustomerProfileIds 1 1 +GetCustomerProfileIds 1 0 GetCustomerProfile 1 1 GetAcceptCustomerProfilePage 1 1 GetCustomerPaymentProfile 1 1 @@ -41,8 +40,8 @@ CreditBankAccount 1 0 ChargeCustomerProfile 1 1 PayPalVoid 1 0 PayPalAuthorizeCapture 1 1 -PayPalAuthorizeCaptureContinue 1 1 -PayPalAuthorizeOnlyContinue 1 0 +PayPalAuthorizeCaptureContinued 1 1 +PayPalAuthorizeOnlyContinued 1 0 PayPalCredit 1 0 PayPalGetDetails 1 1 PayPalPriorAuthorizationCapture 1 0 @@ -53,5 +52,6 @@ UpdateSubscription 1 1 CreateCustomerProfile 1 1 CreateCustomerPaymentProfile 1 1 GetMerchantDetails 0 1 -GetHostedPaymentPage 1 1 -UpdateHeldTransaction 1 0 \ No newline at end of file +GetAnAcceptPaymentPage 1 1 +UpdateHeldTransaction 1 0 +GetAccountUpdaterJobSummary 1 0 \ No newline at end of file diff --git a/SampleCodeTest/SampleCodeTest.csproj b/SampleCodeTest/SampleCodeTest.csproj index b92d43e..a3b6fd3 100644 --- a/SampleCodeTest/SampleCodeTest.csproj +++ b/SampleCodeTest/SampleCodeTest.csproj @@ -1,5 +1,6 @@  + Debug AnyCPU @@ -8,7 +9,7 @@ Properties SampleCodeTest SampleCodeTest - v4.0 + v4.6.1 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -16,6 +17,9 @@ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest + + + true @@ -25,6 +29,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -33,14 +38,14 @@ TRACE prompt 4 + false - ..\AuthorizeNet.dll + ..\packages\AuthorizeNet.2.0.3\lib\AuthorizeNet.dll - False - ..\..\NUnit-2.6.3\bin\tests\nunit.framework.dll + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll @@ -69,6 +74,9 @@ + + + @@ -89,6 +97,12 @@ + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + - + \ No newline at end of file diff --git a/SampleCodeTest/SampleCodeTest_DotNet_Core.csproj b/SampleCodeTest/SampleCodeTest_DotNet_Core.csproj new file mode 100644 index 0000000..43838c8 --- /dev/null +++ b/SampleCodeTest/SampleCodeTest_DotNet_Core.csproj @@ -0,0 +1,59 @@ + + + + netcoreapp2.0 + Microsoft + 0.9.0.0 + 0.9.0.0 + 0.9.0.0 + + + + bin\ + + + + bin\ + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ..\DotNetCoreReleaseArtifacts\AuthorizeNET.dll + + + + diff --git a/SampleCodeTest/TestRunner.cs b/SampleCodeTest/TestRunner.cs index 713e662..50e217f 100644 --- a/SampleCodeTest/TestRunner.cs +++ b/SampleCodeTest/TestRunner.cs @@ -10,7 +10,9 @@ using net.authorize.sample.PaymentTransactions; using System.Threading; using net.authorize.sample.CustomerProfiles; -using net.authorize.sample.MobileInappTransactions; +#if NETCOREAPP2_0 +using AuthorizeNet.Utilities; +#endif namespace SampleCodeTest { @@ -42,65 +44,99 @@ private static short GetMonth() [Test] public void TestAllSampleCodes() { - string fileName = Constants.CONFIG_FILE; - StreamReader reader = File.OpenText(fileName); - TestRunner tr = new TestRunner(); - var numRetries = 3; - string line; - while ((line = reader.ReadLine()) != null) +#if NETCOREAPP2_0 + // DOTNET CORE SPECIFIC + #region DOTNET CORE SPECIFIC + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + ApiOperationBase.RunEnvironment.HttpUseProxy = AuthorizeNet.Environment.getBooleanProperty(AuthorizeNet.Utilities.Constants.HttpsUseProxy); + + if(ApiOperationBase.RunEnvironment.HttpUseProxy) + { + ApiOperationBase.RunEnvironment.HttpUseProxy = AuthorizeNet.Environment.getBooleanProperty(AuthorizeNet.Utilities.Constants.HttpsUseProxy); + ApiOperationBase.RunEnvironment.HttpsProxyUsername = AuthorizeNet.Environment.GetProperty(AuthorizeNet.Utilities.Constants.HttpsProxyUsername); + ApiOperationBase.RunEnvironment.HttpsProxyPassword = AuthorizeNet.Environment.GetProperty(AuthorizeNet.Utilities.Constants.HttpsProxyPassword); + ApiOperationBase.RunEnvironment.HttpProxyHost = AuthorizeNet.Environment.GetProperty(AuthorizeNet.Utilities.Constants.HttpsProxyHost); + ApiOperationBase.RunEnvironment.HttpProxyPort = AuthorizeNet.Environment.getIntProperty(AuthorizeNet.Utilities.Constants.HttpsProxyPort); + } + + #endregion +#endif + + try { - string[] items = line.Split('\t'); - - string apiName = items[0]; - string isDependent = items[1]; - string shouldApiRun = items[2]; - - if (!shouldApiRun.Equals("1")) - continue; - - Console.WriteLine(new String('-', 20)); - Console.WriteLine("Running test case for :: " + apiName); - Console.WriteLine(new String('-', 20)); - ANetApiResponse response = null; - for (int i = 0; i < numRetries; ++i) + string fileName = Constants.CONFIG_FILE; + using (StreamReader reader = File.OpenText(fileName)) { - try + TestRunner tr = new TestRunner(); + var numRetries = 3; + + string line; + while ((line = reader.ReadLine()) != null) { - if (isDependent.Equals("0")) - { - response = InvokeRunMethod(apiName); - } - else + string[] items = line.Split('\t'); + + string apiName = items[0]; + string isDependent = items[1]; + string shouldApiRun = items[2]; + + if (!shouldApiRun.Equals("1")) + continue; + + Console.WriteLine(new String('-', 20)); + Console.WriteLine("Running test case for :: " + apiName); + Console.WriteLine(new String('-', 20)); + ANetApiResponse response = null; + for (int i = 0; i < numRetries; ++i) { - response = (ANetApiResponse)typeof(TestRunner).GetMethod("Test" + apiName).Invoke(tr, new Object[] { }); + try + { + if (isDependent.Equals("0")) + { + response = InvokeRunMethod(apiName); + } + else + { + response = (ANetApiResponse)typeof(TestRunner).GetMethod("Test" + apiName).Invoke(tr, new Object[] { }); + } + + if ((response != null) && (response.messages.resultCode == messageTypeEnum.Ok)) + break; + } + catch (Exception e) + { + Console.WriteLine(apiName); + Console.WriteLine(e.ToString()); + } } - - if ((response != null) && (response.messages.resultCode == messageTypeEnum.Ok)) - break; - } - catch (Exception e) - { - Console.WriteLine(apiName); - Console.WriteLine(e.ToString()); + Assert.IsNotNull(response); + Assert.AreEqual(response.messages.resultCode, messageTypeEnum.Ok); } } - Assert.IsNotNull(response); - Assert.AreEqual(response.messages.resultCode, messageTypeEnum.Ok); + } + catch (Exception ex) + { + + throw ex; } } public ANetApiResponse InvokeRunMethod(string className) { string namespaceString = "net.authorize.sample."; - + if (className.Equals(typeof(UpdateSplitTenderGroup).Name)) namespaceString = namespaceString + "PaymentTransactions."; if (className.Equals(typeof(CreateAnApplePayTransaction).Name)) namespaceString = namespaceString + "ApplePayTransactions."; - - Type classType = Type.GetType(namespaceString + className + ",SampleCode"); + Type classType = null; +#if NETCOREAPP2_0 + classType = Type.GetType(namespaceString + className + ",SampleCode_DotNet_Core"); +#else + classType = Type.GetType(namespaceString + className + ",SampleCode"); +#endif return (ANetApiResponse)classType.GetMethod("Run").Invoke(null, new Object[] { apiLoginId, transactionKey }); } @@ -110,25 +146,25 @@ public ANetApiResponse TestValidateCustomerPaymentProfile() var customerPaymentProfile = (createCustomerPaymentProfileResponse)CreateCustomerPaymentProfile.Run(apiLoginId, transactionKey, response.customerProfileId); var validateResponse = ValidateCustomerPaymentProfile.Run(apiLoginId, transactionKey, response.customerProfileId, customerPaymentProfile.customerPaymentProfileId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); - + return validateResponse; } public ANetApiResponse TestCaptureFundsAuthorizedThroughAnotherChannel() { - return CaptureFundsAuthorizedThroughAnotherChannel.Run(apiLoginId, transactionKey, GetAmount()); + return CaptureFundsAuthorizedThroughAnotherChannel.Run(apiLoginId, transactionKey, GetAmount()); } public ANetApiResponse TestDebitBankAccount() { return DebitBankAccount.Run(apiLoginId, transactionKey, GetAmount()); } - + public ANetApiResponse TestUpdateCustomerShippingAddress() { var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); var shippingResponse = (createCustomerShippingAddressResponse)CreateCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId); - var updateResponse = (updateCustomerShippingAddressResponse) UpdateCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId, shippingResponse.customerAddressId); + var updateResponse = (updateCustomerShippingAddressResponse)UpdateCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId, shippingResponse.customerAddressId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); return updateResponse; @@ -139,7 +175,7 @@ public ANetApiResponse TestUpdateCustomerProfile() var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); var updateResponse = UpdateCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); - + return updateResponse; } @@ -159,13 +195,13 @@ public ANetApiResponse TestGetCustomerShippingAddress() var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); var shippingResponse = (createCustomerShippingAddressResponse)CreateCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId); - var getResponse = GetCustomerShippingAddress.Run(apiLoginId, transactionKey, + var getResponse = GetCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId, shippingResponse.customerAddressId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); return getResponse; } - + public ANetApiResponse TestGetCustomerProfileIds() { return GetCustomerProfileIds.Run(apiLoginId, transactionKey); @@ -199,7 +235,7 @@ public ANetApiResponse TestGetCustomerPaymentProfile() DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); return getResponse; } - + public ANetApiResponse TestDeleteCustomerShippingAddress() { var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); @@ -233,7 +269,7 @@ public ANetApiResponse TestCreateCustomerShippingAddress() var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); var shippingResponse = (createCustomerShippingAddressResponse)CreateCustomerShippingAddress.Run(apiLoginId, transactionKey, response.customerProfileId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, response.customerProfileId); - + return shippingResponse; } @@ -248,7 +284,7 @@ public ANetApiResponse TestCreateCustomerProfileFromTransaction() var response = (createTransactionResponse)AuthorizeCreditCard.Run(apiLoginId, transactionKey, GetAmount()); var profileResponse = (createCustomerProfileResponse)CreateCustomerProfileFromTransaction.Run(apiLoginId, transactionKey, response.transactionResponse.transId); DeleteCustomerProfile.Run(apiLoginId, transactionKey, profileResponse.customerProfileId); - + return profileResponse; } @@ -301,30 +337,30 @@ public ANetApiResponse TestChargeCustomerProfile() public ANetApiResponse TestPayPalAuthorizeOnly() { return PayPalAuthorizeOnly.Run(apiLoginId, transactionKey, GetAmount()); - } - + } + public ANetApiResponse TestPayPalVoid() { var response = (createTransactionResponse)PayPalAuthorizeCapture.Run(apiLoginId, transactionKey, GetAmount()); return PayPalVoid.Run(apiLoginId, transactionKey, response.transactionResponse.transId); - } + } public ANetApiResponse TestPayPalAuthorizeCapture() { return PayPalAuthorizeCapture.Run(apiLoginId, transactionKey, GetAmount()); } - public ANetApiResponse TestPayPalAuthorizeCaptureContinue() + public ANetApiResponse TestPayPalAuthorizeCaptureContinued() { var response = (createTransactionResponse)PayPalAuthorizeCapture.Run(apiLoginId, transactionKey, GetAmount()); - return PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, response.transactionResponse.transId, payerID); - } - - public ANetApiResponse TestPayPalAuthorizeOnlyContinue() + return PayPalAuthorizeCaptureContinued.Run(apiLoginId, transactionKey, response.transactionResponse.transId, payerID); + } + + public ANetApiResponse TestPayPalAuthorizeOnlyContinued() { - return PayPalAuthorizeOnlyContinue.Run(apiLoginId, transactionKey, TransactionID, payerID); + return PayPalAuthorizeOnlyContinued.Run(apiLoginId, transactionKey, TransactionID, payerID); } - + public ANetApiResponse TestPayPalCredit() { return PayPalCredit.Run(apiLoginId, transactionKey, TransactionID); @@ -364,7 +400,7 @@ public ANetApiResponse TestCreateSubscriptionFromCustomerProfile() DeleteCustomerProfile.Run(apiLoginId, transactionKey, profileResponse.customerProfileId); return response; } - + public ANetApiResponse TestCreateSubscription() { var response = (ARBCreateSubscriptionResponse)CreateSubscription.Run(apiLoginId, transactionKey, GetMonth()); @@ -372,12 +408,12 @@ public ANetApiResponse TestCreateSubscription() return response; } - + public ANetApiResponse TestGetSubscriptionStatus() { var response = (ARBCreateSubscriptionResponse)CreateSubscription.Run(apiLoginId, transactionKey, GetMonth()); var subscriptionResponse = GetSubscriptionStatus.Run(apiLoginId, transactionKey, response.subscriptionId); - + return subscriptionResponse; } @@ -403,7 +439,7 @@ public ANetApiResponse TestCreateCustomerProfile() { return CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); } - + public ANetApiResponse TestCreateCustomerPaymentProfile() { var response = (createCustomerProfileResponse)CreateCustomerProfile.Run(apiLoginId, transactionKey, GetEmail()); @@ -426,9 +462,10 @@ public ANetApiResponse TestCreateAnAcceptTransaction() return response; } - public ANetApiResponse TestGetHostedPaymentPage() + public ANetApiResponse TestGetAnAcceptPaymentPage() { - return GetHostedPaymentPage.Run(apiLoginId, transactionKey, GetAmount()); + return GetAnAcceptPaymentPage.Run(apiLoginId, transactionKey, GetAmount()); } + } } diff --git a/SampleCodeTest/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll b/SampleCodeTest/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll deleted file mode 100644 index 95ad0cc..0000000 Binary files a/SampleCodeTest/bin/Release/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll and /dev/null differ diff --git a/SampleCodeTest/packages.config b/SampleCodeTest/packages.config new file mode 100644 index 0000000..417af1b --- /dev/null +++ b/SampleCodeTest/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/SampleCode_DotNet_Core.csproj b/SampleCode_DotNet_Core.csproj new file mode 100644 index 0000000..d915a5d --- /dev/null +++ b/SampleCode_DotNet_Core.csproj @@ -0,0 +1,44 @@ + + + + Exe + + + + netcoreapp2.0 + + exe + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + DotNetCoreReleaseArtifacts\AuthorizeNET.dll + + + \ No newline at end of file diff --git a/SampleCode_DotNet_Core.sln b/SampleCode_DotNet_Core.sln new file mode 100644 index 0000000..b26662e --- /dev/null +++ b/SampleCode_DotNet_Core.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.4 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleCode_DotNet_Core", "SampleCode_DotNet_Core.csproj", "{50A29DBF-957F-4ECE-AC1C-4659DEAADB65}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleCodeTest_DotNet_Core", "SampleCodeTest\SampleCodeTest_DotNet_Core.csproj", "{A0955044-8446-45AE-A8E9-2D97299E5C6A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {50A29DBF-957F-4ECE-AC1C-4659DEAADB65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50A29DBF-957F-4ECE-AC1C-4659DEAADB65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50A29DBF-957F-4ECE-AC1C-4659DEAADB65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50A29DBF-957F-4ECE-AC1C-4659DEAADB65}.Release|Any CPU.Build.0 = Release|Any CPU + {A0955044-8446-45AE-A8E9-2D97299E5C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0955044-8446-45AE-A8E9-2D97299E5C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0955044-8446-45AE-A8E9-2D97299E5C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0955044-8446-45AE-A8E9-2D97299E5C6A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CFEC75E8-285B-413C-A7D9-7478C46F6307} + EndGlobalSection +EndGlobal diff --git a/Sha512/ComputeTransHashSHA2.cs b/Sha512/ComputeTransHashSHA2.cs new file mode 100644 index 0000000..fbbe727 --- /dev/null +++ b/Sha512/ComputeTransHashSHA2.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Sha512 +{ + class ComputeTransHashSHA2 + { + static void TestTransHashSHA2(string[] args) + { + String key = "14B9609FFE2378449B3C0886046DD3B0F20DF12DEB758E48B5FFE1B5875615F0D2A50F7DDB1EAC417EBF76A1FAC374079793650AA493CE127601CB0960938E82"; + String transId = "60115446273"; + String apiLogin = "5T9cRn9FK"; + String amount = "9.00"; + //transHashSHA2 represents the computed TransHash2 using SignatureKey for the given transaction + //textToHash is formed by concatenating apilogin id , transId for the given transaction and transaction amount. + // For more details please visit https://developer.authorize.net/support/hash_upgrade/?utm_campaign=19Q2%20MD5%20Hash%20EOL%20Partner&utm_medium=email&utm_source=Eloqua for implementation details. + String transHashSHA2 = ComputeTransHashSHA2.HMACSHA512(key, "^"+ apiLogin+"^"+ transId +"^"+ amount+"^"); + } + + /** + * This is method to generate HMAC512 key for a given signature key and Text to Hash + * @param signatureKey + * @param textToHash + * @return + * @throws Exception + */ + public static string HMACSHA512(string key, string textToHash) + { + if (string.IsNullOrEmpty(key)) + throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be empty."); + if (string.IsNullOrEmpty(textToHash)) + throw new ArgumentNullException("HMACSHA512: textToHash", "Parameter cannot be empty."); + if (key.Length % 2 != 0 || key.Trim().Length < 2) + { + throw new ArgumentNullException("HMACSHA512: key", "Parameter cannot be odd or less than 2 characters."); + } + try + { + // This is the section to con vert byte array to hexadecimal string + byte[] k = Enumerable.Range(0, key.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(key.Substring(x, 2), 16)) + .ToArray(); + HMACSHA512 hmac = new HMACSHA512(k); + byte[] HashedValue = hmac.ComputeHash((new System.Text.ASCIIEncoding()).GetBytes(textToHash)); + return BitConverter.ToString(HashedValue).Replace("-", string.Empty); + } + catch (Exception ex) + { + throw new Exception("HMACSHA512: " + ex.Message); + } + } + + } +} diff --git a/TransactionReporting/GetAccountUpdaterJobDetails.cs b/TransactionReporting/GetAccountUpdaterJobDetails.cs new file mode 100644 index 0000000..ba201a2 --- /dev/null +++ b/TransactionReporting/GetAccountUpdaterJobDetails.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + public class GetAccountUpdaterJobDetails + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) + { + Console.WriteLine("Get Account Updater job details sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + // parameters for request + string month = "2018-05"; + + var request = new getAUJobDetailsRequest(); + request.month = month; + request.modifiedTypeFilter = AUJobTypeEnum.all; + request.paging = new Paging + { + limit = 1000, + offset = 1 + }; + + // instantiate the controller that will call the service + var controller = new getAUJobDetailsController(request); + controller.Execute(); + + // get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + + if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + { + if (response.auDetails == null) + return response; + + foreach (var update in response.auDetails) + { + Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", update.customerProfileID, update.customerPaymentProfileID); + Console.WriteLine("Update Time (UTC): {0}", update.updateTimeUTC); + Console.WriteLine("Reason Code: {0}", update.auReasonCode); + Console.WriteLine("Reason Description: {0}", update.reasonDescription); + } + + foreach (var delete in response.auDetails) + { + Console.WriteLine("Profile ID / Payment Profile ID: {0} / {1}", delete.customerProfileID, delete.customerPaymentProfileID); + Console.WriteLine("Update Time (UTC): {0}", delete.updateTimeUTC); + Console.WriteLine("Reason Code: {0}", delete.auReasonCode); + Console.WriteLine("Reason Description: {0}", delete.reasonDescription); + } + } + else if (response != null) + { + Console.WriteLine("Error: " + response.messages.message[0].code + " " + + response.messages.message[0].text); + } + + return response; + } + } +} diff --git a/TransactionReporting/GetAccountUpdaterJobSummary.cs b/TransactionReporting/GetAccountUpdaterJobSummary.cs new file mode 100644 index 0000000..35d1d16 --- /dev/null +++ b/TransactionReporting/GetAccountUpdaterJobSummary.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + public class GetAccountUpdaterJobSummary + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) + { + Console.WriteLine("Get Account Updater job summary sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + // Set a valid month for the request + string month = "2017-07"; + + // Build tbe request object + var request = new getAUJobSummaryRequest(); + request.month = month; + + // Instantiate the controller that will call the service + var controller = new getAUJobSummaryController(request); + controller.Execute(); + + // Get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + + if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + { + Console.WriteLine("SUCCESS: Get Account Updater Summary for Month : " + month); + if (response.auSummary == null) + { + Console.WriteLine("No Account Updater summary for this month."); + return response; + } + + // Displaying the summary of each response in the list + foreach (var result in response.auSummary) + { + Console.WriteLine(" Reason Code : " + result.auReasonCode); + Console.WriteLine(" Reason Description : " + result.reasonDescription); + Console.WriteLine(" # of Profiles updated for this reason : " + result.profileCount); + } + } + else if (response != null) + { + Console.WriteLine("ERROR : Invalid response"); + Console.WriteLine("Response : " + response.messages.message[0].code + " " + response.messages.message[0].text); + } + + return response; + } + } +} diff --git a/TransactionReporting/GetCustomerProfileTransactionList.cs b/TransactionReporting/GetCustomerProfileTransactionList.cs new file mode 100644 index 0000000..8be3cb9 --- /dev/null +++ b/TransactionReporting/GetCustomerProfileTransactionList.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AuthorizeNet.Api.Contracts.V1; +using AuthorizeNet.Api.Controllers; +using AuthorizeNet.Api.Controllers.Bases; + +namespace net.authorize.sample +{ + public class GetCustomerProfileTransactionList + { + public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey, string customerProfileId) + { + Console.WriteLine("Get transaction list sample"); + + ApiOperationBase.RunEnvironment = AuthorizeNet.Environment.SANDBOX; + // define the merchant information (authentication / transaction id) + ApiOperationBase.MerchantAuthentication = new merchantAuthenticationType() + { + name = ApiLoginID, + ItemElementName = ItemChoiceType.transactionKey, + Item = ApiTransactionKey, + }; + + var request = new getTransactionListForCustomerRequest(); + request.customerProfileId = "1811474252"; + + // instantiate the controller that will call the service + var controller = new getTransactionListForCustomerController(request); + controller.Execute(); + + // get the response from the service (errors contained if any) + var response = controller.GetApiResponse(); + + if (response != null && response.messages.resultCode == messageTypeEnum.Ok) + { + if (response.transactions == null) + return response; + + foreach (var transaction in response.transactions) + { + Console.WriteLine("Transaction Id: {0}", transaction.transId); + Console.WriteLine("Submitted on (Local): {0}", transaction.submitTimeLocal); + Console.WriteLine("Status: {0}", transaction.transactionStatus); + Console.WriteLine("Settle amount: {0}", transaction.settleAmount); + } + } + else if (response != null) + { + Console.WriteLine("Error: " + response.messages.message[0].code + " " + + response.messages.message[0].text); + } + + return response; + } + } +} diff --git a/TransactionReporting/GetUnsettledTransactionList.cs b/TransactionReporting/GetUnsettledTransactionList.cs index 500fa91..0bf0ffa 100644 --- a/TransactionReporting/GetUnsettledTransactionList.cs +++ b/TransactionReporting/GetUnsettledTransactionList.cs @@ -26,7 +26,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) }; var request = new getUnsettledTransactionListRequest(); - request.status = TransactionGroupStatusEnum.pendingApproval; + request.status = TransactionGroupStatusEnum.any; request.statusSpecified = true; request.paging = new Paging { diff --git a/VisaCheckout/CreateVisaCheckoutTransaction.cs b/VisaCheckout/CreateVisaSrcTransaction.cs similarity index 98% rename from VisaCheckout/CreateVisaCheckoutTransaction.cs rename to VisaCheckout/CreateVisaSrcTransaction.cs index 1f83448..afb269c 100644 --- a/VisaCheckout/CreateVisaCheckoutTransaction.cs +++ b/VisaCheckout/CreateVisaSrcTransaction.cs @@ -9,7 +9,7 @@ namespace net.authorize.sample { - public class CreateVisaCheckoutTransaction + public class CreateVisaSrcTransaction { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) { @@ -48,7 +48,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) controller.Execute(); var response = controller.GetApiResponse(); - //validate + // validate response if (response != null) { if (response.messages.resultCode == messageTypeEnum.Ok) diff --git a/VisaCheckout/DecryptVisaCheckoutData.cs b/VisaCheckout/DecryptVisaSrcData.cs similarity index 98% rename from VisaCheckout/DecryptVisaCheckoutData.cs rename to VisaCheckout/DecryptVisaSrcData.cs index cf8cade..2ce4279 100644 --- a/VisaCheckout/DecryptVisaCheckoutData.cs +++ b/VisaCheckout/DecryptVisaSrcData.cs @@ -9,7 +9,7 @@ namespace net.authorize.sample { - public class DecryptVisaCheckoutData + public class DecryptVisaSrcData { public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) { @@ -44,7 +44,7 @@ public static ANetApiResponse Run(String ApiLoginID, String ApiTransactionKey) if (decryptPaymentDataResponse != null) { - //validate response + // validate response Console.WriteLine("Result : "+decryptPaymentDataResponse.messages.message); Console.WriteLine(" : "+decryptPaymentDataResponse.messages.resultCode); Console.WriteLine("First Name : "+decryptPaymentDataResponse.billingInfo.firstName); diff --git a/packages.config b/packages.config index 0770b48..2671ed1 100644 --- a/packages.config +++ b/packages.config @@ -1,5 +1,4 @@  - - - + + \ No newline at end of file diff --git a/packagesCore.config b/packagesCore.config new file mode 100644 index 0000000..e21ee14 --- /dev/null +++ b/packagesCore.config @@ -0,0 +1,5 @@ + + + + +