2011-05-24 14 views
5

के साथ परेशानी है मैं एक गैर-लाभकारी दान मंच पर काम कर रहा हूं और मैं पहली बार एमवीसी का उपयोग कर रहा हूं। मुझे इसे अधिकांश भाग के लिए लटका दिया गया है लेकिन अभी मुझे एक समस्या है जिसमें मुझे पता नहीं है कि कैसे पता लगाना है। मैं AthorizeNet.Helpers क्लास का उपयोग कर रहा हूं और जब मैं एक्सपैम्पल्स से कोड जोड़ता हूं, तो यह अधिकांश भाग के लिए काम करता है, इसके अलावा यह फ़ॉर्म लेता है और इसे टैग के ऊपर रखता है हालांकि यह फॉर्म फ़ील्ड को सही जगह पर रखता है। मैं सही जगह पर टैग को प्रस्तुत करने का तरीका जानने का प्रयास कर रहा हूं।एमवीसी एचटीएमएल हेल्पर रेजर

@using AuthorizeNet.Helpers; 

@using (Html.BeginSIMForm("http://127.0.0.1:4768", 1.99M, "xxx_key", "yyy_key", true)) 
{ 
    @Html.Raw(Html.CheckoutFormInputs(true)) 
    @Html.Hidden("order_id", "1234") 
    <input type = "submit" value = "Pay" /> 
} 

यह है कि यह कैसे HTML आउटपुट में दिखाई देता है:

<form action = 'https://test.authorize.net/gateway/transact.dll' method = 'post'> 
    <input type = 'hidden' name = 'x_fp_hash' value = '6bef386eaa89944efd62b47b86042910' \> 
    <input type = 'hidden' name = 'x_fp_sequence' value = '117'\> 
    <input type = 'hidden' name = 'x_fp_timestamp' value = 'xxx_key' \> 
    <input type = 'hidden' name = 'x_login' value = 'yyy_key' \> 
    <input type = 'hidden' name = 'x_amount' value = '1.99' \> 
    <input type = 'hidden' name = 'x_relay_url' value = 'http://127.0.0.1:4768' \> 
    <input type = 'hidden' name = 'x_relay_response' value = 'TRUE' \> 
</form><!DOCTYPE html> 
<html> 
<body> 
<h2>Payment Information</h2> 
       <div style = 'border: 1px solid #990000; padding:12px; margin-bottom:24px; background-color:#ffffcc;width:300px'>Test Mode</div> 
       <div style = 'float:left;width:250px;'> 
        <label>Credit Card Number</label> 
        <div id = 'CreditCardNumber'> 
         <input type = 'text' size = '28' name = 'x_card_num' value = '4111111111111111' id = 'x_card_num'/> 
        </div> 
       </div> 
       <div style = 'float:left;width:70px;'> 
        <label>Exp.</label> 
        <div id = 'CreditCardExpiration'> 
         <input type = 'text' size = '5' maxlength = '5' name = 'x_exp_date' value = '0116' id = 'x_exp_date'/> 
        </div> 
       </div> 
       <div style = 'float:left;width:70px;'> 
        <label>CCV</label> 
        <div id = 'CCV'> 
         <input type = 'text' size = '5' maxlength = '5' name = 'x_card_code' id = 'x_card_code' value = '123' /> 
        </div> 
       </div><input id="order_id" name="order_id" type="hidden" value="1234" />  <input type = "submit" value = "Pay" /> 

उत्तर

5

इस तरह की समस्या आमतौर पर तब होती है जब एक सहायक जो सीधे आउटपुट स्ट्रीम पर लिख रहा है एएसपी.नेट एमवीसी 1 के लिए लिखा गया था (और उपयोग में संलग्न हेल्पर्स ज्यादातर समय स्ट्रीमिंग स्ट्रीम पर सीधे लिख रहे हैं)। ASP.NET MVC 1 में आप इस का उपयोग कर उत्पादन धारा को लिख सकते हैं:

htmlHelper.ViewContext.HttpContext.Response.Output 

बाद ASP.NET MVC संस्करण में आप इस का उपयोग करना चाहिए:

htmlHelper.ViewContext.Writer 

कि उस्तरा संगतता सुनिश्चित करता है। अगर आपके पास AuthorizeNet तक पहुंच है। हेल्पर स्रोत कोड आप इसे स्वयं ठीक कर सकते हैं, अगर आपको इसे ठीक करने के लिए लेखकों से संपर्क करने की आवश्यकता नहीं है।

1

यह संभव है कि AuthorizeNet से सहायक सही ढंग से उस्तरा के साथ काम करने में नहीं लिखा है। वास्तव में उनकी असेंबली के स्रोत को देखे बिना यह कहना मुश्किल है कि यह मामला है। आप अपने ग्राहक समर्थन के संपर्क में रहने की कोशिश कर सकते हैं।

12

इस तरह मैंने इसे ठीक किया।

के रूप में आप कहा, (सही)

अन्य परिवर्तन करने के लिए Html.CheckoutFormInputs आसपास @ Html.Raw() जोड़ने

namespace AuthorizeNet.Helpers -> CheckoutFormBuilders.cs 

में

using System.IO; 
की एक का उपयोग कर जोड़ने है

HttpResponseBase to TextWriter 

मैंने इसे तीन स्थानों में किया था।

HttpResponseBase _response; to TextWriter _response; 

public SIMForm(TextWriter response, string returnUrl, decimal amount, 
       string apiLogin, string transactionKey) 
       :this(response,returnUrl,amount,apiLogin,transactionKey,true){} 

public SIMForm(TextWriter response, string returnUrl, decimal amount, 
       string apiLogin, string transactionKey, bool isTest) { 
     _response = response; 
     _amount = amount; 
     _apiLogin = apiLogin; 
     _transactionkey = transactionKey; 
     _returnUrl = returnUrl; 
     _isTest = isTest; 
     OpenForm(); 
} 

दो और परिवर्तन

छोड़ दिया के रूप में tpeczek जवाब में निर्देशित, आप इस

public static SIMForm BeginSIMForm(this HtmlHelper helper, string returnUrl, 
           decimal amount, string apiLogin, 
           string transactionKey) { 

return new SIMForm(helper.ViewContext.Writer, 
        returnUrl,amount,apiLogin, 
        transactionKey,true);} 

public static SIMForm BeginSIMForm(this HtmlHelper helper, string returnUrl, 
           decimal amount, string apiLogin, 
           string transactionKey, bool isTest) { 

return new SIMForm(helper.ViewContext.Writer, 
        returnUrl, amount, apiLogin, 
        transactionKey,isTest);} 
तरह दिखेगा

helper.ViewContext.HttpContext.Response 

को
helper.ViewContext.Writer 

बदलने की जरूरत है

1

उपरोक्त EpicThreeDev से उदाहरण का उपयोग करके मैं फ़ॉर्म एचटीएमएल सही ढंग से दिखाई देने में सक्षम था। भुगतान बटन हालांकि, सीसीवी क्षेत्र से ऊपर जुड़ा हुआ था, ताकि सूचकांक पर इसे ठीक किया जा सके।cshtml कोड बेस मैं तथापि कर कि मैं त्रुटि है कि पोस्ट में संबोधित किया जाता है मिल गया के बाद

     <br />       
    <input type = "submit" value = "Pay" style="position:relative; top:35px;" />  

एक बार मैंने किया है कि मैं फार्म पोस्ट करने के लिए कर रहा था करने के लिए HTML बदल गया है,।

http://community.developer.authorize.net/t5/Integration-and-Testing/Having-Trouble-setting-up-MVC3-application-with-DPM/m-p/13226

0

यहाँ मेरी समाधान है। यह सिर्फ Authorize.net छिपा फ़ील्ड प्रिंट करता है, ताकि आप अपना खुद का फॉर्म टैग लिख सकें। प्रासंगिक AppSettings मानों के साथ अपने web.config भरें। इस तरह आप विकास और उत्पादन के बीच आसानी से बदल सकते हैं।

public static class MyAuthNetHelper 
{ 
    public const string TEST_URL = "https://test.authorize.net/gateway/transact.dll"; 
    public const string LIVE_URL = "https://secure.authorize.net/gateway/transact.dll"; 

    public static string ApiLogin 
    { 
     get { return ConfigurationManager.AppSettings["AuthNetAPILogin"]; } 
    } 

    public static string TransactionKey 
    { 
     get { return ConfigurationManager.AppSettings["AuthNetAPITransactionKey"]; } 
    } 

    public static string ReturnUrl 
    { 
     get { return ConfigurationManager.AppSettings["AuthNetReturnUrl"]; } 
    } 

    public static string ThanksUrl 
    { 
     get { return ConfigurationManager.AppSettings["AuthNetThanksUrl"]; } 
    } 

    public static bool TestMode 
    { 
     get { return bool.Parse(ConfigurationManager.AppSettings["AuthNetTestMode"]); } 
    } 

    public static string GatewayUrl 
    { 
     get { return TestMode ? TEST_URL : LIVE_URL; } 
    } 

    public static MvcHtmlString AuthNetDirectPostFields(this HtmlHelper helper, decimal amount) 
    { 

     var seq = Crypto.GenerateSequence(); 
     var stamp = Crypto.GenerateTimestamp(); 

     var fingerPrint = Crypto.GenerateFingerprint(TransactionKey, 
      ApiLogin, amount, seq.ToString(), stamp.ToString()); 

     var str = new StringBuilder(); 

     str.Append(helper.Hidden("x_fp_hash", fingerPrint)); 
     str.Append(helper.Hidden("x_fp_sequence", seq)); 
     str.Append(helper.Hidden("x_fp_timestamp", stamp)); 
     str.Append(helper.Hidden("x_login", ApiLogin)); 
     str.Append(helper.Hidden("x_amount", amount)); 
     str.Append(helper.Hidden("x_relay_url", ReturnUrl)); 
     str.Append(helper.Hidden("x_relay_response", "TRUE")); 

     return MvcHtmlString.Create(str.ToString()); 
    } 
} 

cshtml:

<form id="paymentForm" method="POST" action="@MyAuthNetHelper.GatewayUrl" class="form-horizontal offset1"> 
@Html.AuthNetDirectPostFields(PutYourAmountHere) 
... 
</form> 

ThanksUrl Authorize.net से प्रतिक्रिया को संभालने के लिए अपनी कार्रवाई में प्रयोग किया जाता है। इसे और अधिक के लिए जांचें: http://developer.authorize.net/integration/fifteenminutes/csharp/

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^