You can test APIs from our Try it Tab in API reference on sandbox without signup
https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card
Click on the Try it tab and click send .
12-04-2017 11:01 PM
Hi,
I'm getting to close to activating an dI'm seeing an issue with the C# Charge A Credit Card" sample code.
WhenI use
ApiOperationBase(ANetApiRequest, ANetApiResponse).RunEnvironment = AuthorizeNet.Environment.SANDBOX;
I see the SANDBOX url of test.authorize.net in the VS 2013 Autos window and the controller response is null. I have successufully used my id and key on the Try It but those use XML and I can't see how to change the URL to
https://apitest.authorize.net/xml/v1/request.api
12-26-2017 03:27 PM
@BaronMatrix1 API Reference try it option is to try on fly. If you want to play around with the API requests, Please refer to Github SampleCode or SDK for APIs here.
DOTNET-SDK / DOTNET - SampleCode.
If you want to change the endpoint, you can do here in your local repo.
-Bhavana
12-26-2017 04:18 PM - edited 12-26-2017 04:19 PM
Hi,
I used the exact code in the Charge a Credit card sample.
How do I inject the new environment class referenced?
UPDATE:
realized I just out that anywhere and use it for the .RunEnvironment call.
12-26-2017 05:13 PM - edited 12-26-2017 05:15 PM
@BaronMatrix1 Was trying to understand as why you would need newEnvironment? You would need either Sandbox or Production. Both of themEnvironment.cs are available thru Environment.cs If you are looking for where the sandbox is assigned(AuthorizeNet.Environment.PRODUCTION;) Eg: Line-17-SampleCodeCSharp
Pls. clarify.
-Bhavana
12-26-2017 10:29 PM - last edited on 12-27-2017 05:13 AM by RichardH
I don't need new Environment. I'm trying to understand why I get NULL back from the controller.GetApiResponse call.
I did notice that setting to Environment.SANDBOX gives a URL of test.authorize.net.
12-27-2017 09:20 AM
@BaronMatrix1 Normally, if the endpoint is not reachable you would get that issue. I just downloaded latest from Sample-Code-Csharp and able to execute "charge a credit card" successfully. Can you debug in visual studio and see why it is null OR send me the zip file of your sample-code you are using.
-Bhavana
12-28-2017 03:27 PM - edited 12-28-2017 03:27 PM
I've stepped through the code multipel times. Returning null is difficult to debug. I'll reinstall Fiddler and see if I can get more, but as I said I used the code basically as is. I only changed it to take inputs from a form.
As it's public code:
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = id,
ItemElementName = ItemChoiceType.transactionKey,
Item = key,
};
var creditCard = new creditCardType
{
cardNumber = cardNum,
expirationDate = expire,
cardCode = ccv
};
var billingAddress = new customerAddressType
{
firstName = firstName,
lastName = lastName,
address = address,
city = city,
zip = zip,
state = state
};
//standard api call to retrieve response
var paymentType = new paymentType { Item = creditCard };
// Add line Items
var lineItems = new lineItemType[1];
lineItems[0] = new lineItemType { itemId = "1", name = "Membership", quantity = 1, unitPrice = new Decimal(20.00) };
var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // charge the card
amount = charge,
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 && response.messages.resultCode == messageTypeEnum.Ok)
{
returnModel.Code = response.transactionResponse.responseCode;
returnModel.Authorization = response.transactionResponse.authCode;
returnModel.AvsResponse = response.transactionResponse.avsResultCode;
returnModel.Reason = response.transactionResponse.messages[0].description;
returnModel.Transaction = response.transactionResponse.messages[0].code;
returnModel.TransactionId = response.transactionResponse.transId;
var user = await AddZineUserAsync(await UserManager.FindByNameAsync(User.Identity.Name));
}
else
{
returnModel = new CardModel
{
Reason = response != null ? response.transactionResponse.errors[0].errorCode : "-1",
Transaction = response != null ? response.transactionResponse.errors[0].errorText : "The error was not correctly returned. Please try again. Your card was not charged.",
};
}
12-28-2017 03:31 PM