How can I autogenerate the PurchaseId?
I am following a tutorial from here: http://www.tandasoft.com/2011/05/05/using-authorize-net-dpm-direct-post-method-from-asp-net-web-form...
This part is trying to grab a PurchaseId from somewhere (unknown to me as to where), but I just want to have my application create the id automatically for me.
if (Session["PurchaseID"] != null) { nPurchaseID = (Int32)Session["PurchaseID"]; } else { // You might throw here, but this is just an example, so assign a bogus PurchaseID nPurchaseID = 1; }
Here is my full code here:
protected void Page_Load(object sender, System.EventArgs e) { // In my application, I've already written the pending purchase to the database // and assigned an ID before redirecting to this page. if (Session["PurchaseID"] != null) { nPurchaseID = (Int32)Session["PurchaseID"]; } else { // You might throw here, but this is just an example, so assign a bogus PurchaseID nPurchaseID = 1; } // This is the way we get a Web Forms app to post to a different URL... btnSubmit.PostBackUrl = "https://test.authorize.net/gateway/transact.dll"; strAuthorizeNet_x_amount = "175.00"; strAuthorizeNet_x_login = ConfigurationManager.AppSettings["AUTHORIZE_NET_API_LOGIN"]; strAuthorizeNet_x_first_name = "John"; strAuthorizeNet_x_last_name = "Doe"; strAuthorizeNet_x_address = "123 Main St"; strAuthorizeNet_x_city = "Anywhere"; strAuthorizeNet_x_state = "CO"; strAuthorizeNet_x_zip = "12345"; strAuthorizeNet_x_fp_timestamp = AuthorizeNet.Crypto.GenerateTimestamp().ToString(); strAuthorizeNet_x_fp_sequence = AuthorizeNet.Crypto.GenerateSequence(); strAuthorizeNet_x_relay_response = "TRUE"; strAuthorizeNet_x_test_request = "TRUE"; strAuthorizeNet_x_fp_hash = AuthorizeNet.Crypto.GenerateFingerprint(ConfigurationManager.AppSettings["AUTHORIZE_NET_TRANSACTION_KEY"], strAuthorizeNet_x_login, decimal.Parse(strAuthorizeNet_x_amount), strAuthorizeNet_x_fp_sequence, strAuthorizeNet_x_fp_timestamp); // CRITICALLY IMPORTANT: This link must direct to your SIM.aspx page, and MUST be accessible... // it will NOT work if your test/development web server is behind a firewall!! // Also, if you use https, make sure your SSL certificate is signed and valid // or Authorize.NET will reject the URL. strAuthorizeNet_x_relay_url = ConfigurationManager.AppSettings["MainWebURL"] + "SIM.aspx"; // I'm not certain authorize.net will ever utilize this link... Authorize.NET simply hits your // x_relay_url and relays the response contents to the client's browser. See SIM.aspx // for more details. strAuthorizeNet_x_receipt_link_url = ConfigurationManager.AppSettings["MainWebURL"] + "Thanks.aspx"; } private int nPurchaseID; public int PurchaseID { get { return nPurchaseID; } } private string strAuthorizeNet_x_fp_hash; public string AuthorizeNet_x_fp_hash { get { return strAuthorizeNet_x_fp_hash; } } private string strAuthorizeNet_x_fp_timestamp; public string AuthorizeNet_x_fp_timestamp { get { return strAuthorizeNet_x_fp_timestamp; } } private string strAuthorizeNet_x_fp_sequence; public string AuthorizeNet_x_fp_sequence { get { return strAuthorizeNet_x_fp_sequence; } } private string strAuthorizeNet_x_login; public string AuthorizeNet_x_login { get { return strAuthorizeNet_x_login; } } private string strAuthorizeNet_x_relay_url; public string AuthorizeNet_x_relay_url { get { return strAuthorizeNet_x_relay_url; } } private string strAuthorizeNet_x_receipt_link_url; public string AuthorizeNet_x_receipt_link_url { get { return strAuthorizeNet_x_receipt_link_url; } } private string strAuthorizeNet_x_relay_response; public string AuthorizeNet_x_relay_response { get { return strAuthorizeNet_x_relay_response; } } private string strAuthorizeNet_x_test_request; public string AuthorizeNet_x_test_request { get { return strAuthorizeNet_x_test_request; } } private string strAuthorizeNet_x_amount; public string AuthorizeNet_x_amount { get { return strAuthorizeNet_x_amount; } } private string strAuthorizeNet_x_first_name; public string AuthorizeNet_x_first_name { get { return strAuthorizeNet_x_first_name; } } private string strAuthorizeNet_x_last_name; public string AuthorizeNet_x_last_name { get { return strAuthorizeNet_x_last_name; } } private string strAuthorizeNet_x_address; public string AuthorizeNet_x_address { get { return strAuthorizeNet_x_address; } } private string strAuthorizeNet_x_city; public string AuthorizeNet_x_city { get { return strAuthorizeNet_x_city; } } private string strAuthorizeNet_x_state; public string AuthorizeNet_x_state { get { return strAuthorizeNet_x_state; } } private string strAuthorizeNet_x_zip; public string AuthorizeNet_x_zip { get { return strAuthorizeNet_x_zip; } } public string CardNumber { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return "4111111111111111"; } return ""; } } public string ExpirationDate { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return DateTime.Now.AddMonths(1).ToString("MM-yy"); } return ""; } } public string CCV { get { if (strAuthorizeNet_x_test_request.Equals("TRUE")) { return "123"; } return ""; } } public void Confirm() { Load += Page_Load; }
01-07-2016 05:45 AM
Hello @rockon77
It's been a while since this was first posted. I would recommend subscribing to this topic so that you'll be alerted via email if anyone from the community is able to respond with any comments. To subscribe, click Topic Options at the top of this thread and then select Subscribe. You'll then receive an email once anyone replies.
Thanks,
Richard
01-15-2016 05:50 AM