cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Accept Hosted - Prepopulate email and phone

Hi all, I am integrating accepted hosted to my page, and am using the below code, things work great, the email and phone do not carry through to the auth.net popup though. Has anyone else had this issue? 

 

 

ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;




ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = moduleSettings["ApiLoginID"].ToString(),
ItemElementName = ItemChoiceType.transactionKey,
Item = moduleSettings["ApiTransactionKey"].ToString(),
};

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;




settingType[] settings = new settingType[10];

settings[0] = new settingType();
settings[0].settingName = settingNameEnum.hostedPaymentButtonOptions.ToString();
settings[0].settingValue = "{\"text\": \"Submit Gift\"}";

settings[1] = new settingType();
settings[1].settingName = settingNameEnum.hostedPaymentOrderOptions.ToString();
settings[1].settingValue = "{\"show\": false}";

settings[2] = new settingType();
settings[2].settingName = settingNameEnum.hostedPaymentBillingAddressOptions.ToString();
settings[2].settingValue = "{\"show\": true}";

settings[3] = new settingType(); 
settings[3].settingName = settingNameEnum.hostedPaymentReturnOptions.ToString();
settings[3].settingValue = "{\"showReceipt\": false}";settings[4] = new settingType();

settings[4].settingName = settingNameEnum.hostedPaymentPaymentOptions.ToString();
settings[4].settingValue = "{\"cardCodeRequired\": true, \"showCreditCard\": true, \"showBankAccount\": false}";

settings[5] = new settingType();
settings[5].settingName = settingNameEnum.hostedPaymentSecurityOptions.ToString();
settings[5].settingValue = "{\"captcha\": true}";

settings[6] = new settingType();
settings[6].settingName = settingNameEnum.hostedPaymentStyleOptions.ToString(); 
settings[6].settingValue = "{\"bgColor\": \"#0f175e\"}";

settings[7] = new settingType();
settings[7].settingName = settingNameEnum.hostedPaymentIFrameCommunicatorUrl.ToString();
settings[7].settingValue = "{\"url\": \"" + System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Scheme) + System.Web.HttpContext.Current.Request.Url.Host + "/xxx/hosted.html\"}";settings[8] = new settingType();

settings[8].settingName = settingNameEnum.hostedPaymentCustomerOptions.ToString();
settings[8].settingValue = "{\"showEmail\": true}";



var billTo = new customerAddressType();
billTo.firstName = firstName;
billTo.lastName = lastName;
billTo.country = country;
billTo.zip = zip;
billTo.address = address;
billTo.city = city;
billTo.state = state;
billTo.email = email;

if (phoneNumber != "null") billTo.phoneNumber = phoneNumber;


var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), 
amount = amount,
billTo = billTo
};



var request = new getHostedPaymentPageRequest();
request.transactionRequest = transactionRequest;
request.hostedPaymentSettings = settings;

// 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();

I can create the customer separately through the createCustomerProfileRequest, I just don't know how to tie it into this when a payment is made. I was told to do it in the transactionRequestType object by setting the customer object in there but it doesn't work for me, the request comes back as a success, but then the call to the payment url for Authorize.NET popup comes back with a 404 so nothing is displayed (https://test.authorize.net/payment/payment?token=...). Leaving it as shown above shoes the email and phone fields just not populated like the other fields. Any help would be so greatly appreciated.  

 

8 REPLIES 8
@marco_envision

You pass those under a CustomerDataType object.
Renaissance
All Star

Hi, thank you for the response!

 

I did and nothing works, it throws a 404 when loading the popup if I try doing either of the below:

 

            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // authorize capture only
                amount = amount,
                billTo = billTo,
                //customer = new customerDataType()
                //customer = new customerDataType() { id = _merchantCustomerId, email = billTo.email, type = customerTypeEnum.individual }
            };

Any ideas?

 

Many thanks,

 

Marco

 

I also just tried sending the customer object in only with the email as I've seen instructed, if I pass the customer object at all through, the auth.net popup iframe throws a 404 every time. But the initial handshake returns a success. 

@marco_envision 

 

 

  var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authCaptureTransaction.ToString(),    // authorize capture only
                amount = amount,
                billTo = billTo,
                //customer = new customerDataType()
                //customer = new customerDataType() { id = _merchantCustomerId, email = billTo.email, type = customerTypeEnum.individual }
            };

Try defining the customer outside of the transactionRequestType object. In the above code you have the customer commented out, so I can imagine it throwing an error. What I type below won't be correct syntax, but will give you an idea.

 

 

var billTo = new customerAddressType();
billTo.firstName = firstName;
billTo.lastName = lastName;
billTo.country = country;
billTo.zip = zip;
billTo.address = address;
billTo.city = city;
billTo.state = state;
billTo.email = email;

var customer = new customerDataType();
customer.email = email;
//corrected customer object

if (phoneNumber != "null") customer.phoneNumber = phoneNumber;


var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), 
amount = amount,
billTo = billTo,
customer = customer
};

 

 

 

HI, yes I had commented it out, I was merely showing you the things I've tried. I've also tried creating a customer object and passing it in, as you mentioned, with no success. I'm at a loss why the object is there to be sent but does not work in any case when passed in. Has anyone been able to pass a customerDataType object to a transactionRequestType object? I would be so grateful for any assistance.

 

- Marco

@marco_envision 

 

I have passed it no problem on 3 separate web applications, at least 100 times. Did you try the code I posted? I think that should work, although you might have to make syntax changes. 

http://dnn922research.envisionbeta.net/donation

 

This is a sample, if you run through the process (tied to the sandbox account, not live), and hit "Continue to secure payment", it will open the popup, but will return a 404 error when hitting the auth.net page, I've logged the json response from the handshake to the console log, looks fine, just throws a 404. If I remove the customer being added to the transactionRequest it works fine. 

 

See code that is there now:

 


public static ANetApiResponse Run(decimal amount, string firstName, string lastName, string country, string zip, string address,
string city, string state, string phoneNumber, string email, System.Collections.Hashtable moduleSettings)
{

if (moduleSettings["Environment"].ToString() == "PRODUCTION")
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.PRODUCTION;
}
else
{
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
}

ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = moduleSettings["ApiLoginID"].ToString(),
ItemElementName = ItemChoiceType.transactionKey,
Item = moduleSettings["ApiTransactionKey"].ToString(),
};

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

 

settingType[] settings = new settingType[10];

settings[0] = new settingType();
settings[0].settingName = settingNameEnum.hostedPaymentButtonOptions.ToString();
settings[0].settingValue = "{\"text\": \"Submit Gift\"}";

settings[1] = new settingType();
settings[1].settingName = settingNameEnum.hostedPaymentOrderOptions.ToString();
settings[1].settingValue = "{\"show\": false}";

settings[2] = new settingType();
settings[2].settingName = settingNameEnum.hostedPaymentBillingAddressOptions.ToString();
settings[2].settingValue = "{\"show\": true}";

settings[3] = new settingType();
settings[3].settingName = settingNameEnum.hostedPaymentReturnOptions.ToString();
settings[3].settingValue = "{\"showReceipt\": false}";

settings[4] = new settingType();
settings[4].settingName = settingNameEnum.hostedPaymentPaymentOptions.ToString();
settings[4].settingValue = "{\"cardCodeRequired\": true, \"showCreditCard\": true, \"showBankAccount\": false}";

settings[5] = new settingType();
settings[5].settingName = settingNameEnum.hostedPaymentSecurityOptions.ToString();
settings[5].settingValue = "{\"captcha\": true}";


settings[6] = new settingType();
settings[6].settingName = settingNameEnum.hostedPaymentStyleOptions.ToString();
settings[6].settingValue = "{\"bgColor\": \"#0f175e\"}";

settings[7] = new settingType();
settings[7].settingName = settingNameEnum.hostedPaymentIFrameCommunicatorUrl.ToString();
settings[7].settingValue = "{\"url\": \"" + System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Scheme) + System.Web.HttpContext.Current.Request.Url.Host + "/DesktopModules/Donation_Module/hosted.html\"}";

settings[8] = new settingType();
settings[8].settingName = settingNameEnum.hostedPaymentCustomerOptions.ToString();
settings[8].settingValue = "{\"showEmail\": true}";

 

var billTo = new customerAddressType();
billTo.firstName = firstName;
billTo.lastName = lastName;
billTo.country = country;
billTo.zip = zip;
billTo.address = address;
billTo.city = city;
billTo.state = state;
billTo.email = email;

if (phoneNumber != "null") billTo.phoneNumber = phoneNumber;

var cust = new customerDataType();
cust.email = email;

var transactionRequest = new transactionRequestType
{
transactionType = transactionTypeEnum.authCaptureTransaction.ToString(), // authorize capture only
amount = amount,
billTo = billTo,
customer = cust
};


var request = new getHostedPaymentPageRequest();
request.transactionRequest = transactionRequest;
request.hostedPaymentSettings = settings;

// 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 response
if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
{
Console.WriteLine("Message code : " + response.messages.message[0].code);
Console.WriteLine("Message text : " + response.messages.message[0].text);
Console.WriteLine("Token : " + response.token);
}
else if (response != null)
{
Console.WriteLine("Error: " + response.messages.message[0].code + " " + response.messages.message[0].text);
Console.WriteLine("Failed to get hosted payment page");
}

return response;
}

 

I turned into just uncertain if this became good enough for cases where a person takes a mail order payment on the telephone, so the cardboard holder is not present? The website regarded to indicate that you needed to use the virtual terminal for this.

shsie3l3
Member