在ASP.Net MVC中使用Google Checkout

7

我有一个相当简单的ASP.Net网站,使用Google结账(我有一个ImageButton,PostBackUrl设置为传递隐藏字段的Google地址),这很好用。

我一直在将这个应用程序移动到MVC,但我不确定如何处理它。我考虑使用jQuery表单,但我认为在这种情况下这不起作用,因为有时他们会被重定向到Google页面。有人在ASP.Net MVC应用程序中使用过Google结账吗?

1个回答

2

你可以像以前一样做同样的事情,只是现在需要手动完成。

听起来你正在使用基本版本,对吗?

你需要创建一个HTML表单,将Action设置为Google结帐流程,添加正确的隐藏字段(你的控制器传递下来的模型将被填充正确的值),然后添加提交按钮(或者如果你喜欢的话可以添加图片)。

因此,一个来自Google基本HTML页面的示例,修改为MVC风格,可能是这样的:

<form method="POST"
  action="https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/<%= Model.MerchantId %>"
      accept-charset="utf-8">

  <input type="hidden" name="item_name_1" value="<%= Model.Item.Name %>"/>  
  <input type="hidden" name="item_description_1" value="<%= Model.Item.Description %>>  
  <input type="hidden" name="item_quantity_1" value="<%= Model.Item.Quantity %>"/>  
  <input type="hidden" name="item_price_1" value="<%= Model.Item.Price %>"/>  
  <input type="hidden" name="item_currency_1" value="<%= Model.Item.Currency %>"/>  
  <input type="hidden" name="ship_method_name_1" value="<%= Model.Shipping.Price %>"/>  
  <input type="hidden" name="ship_method_price_1" value="<%= Model.Shipping.Price %>"/>  
  <input type="hidden" name="ship_method_currency_1" value="<%= Model.Shipping.Currency %>"/>  
  <input type="hidden" name="tax_rate" value="<%= Model.Tax.Rate %>"/>  
  <input type="hidden" name="tax_us_state" value="<%= Model.Tax.State %>"/>  
  <input type="hidden" name="_charset_"/>  
  <input type="image" name="Google Checkout" alt="Fast checkout through Google"
src="http://checkout.google.com/buttons/checkout.gif?merchant_id=<%= Model.MerchantId %>&w=180&h=46&style=white&variant=text&loc=en_US"
height="46" width="180"/>  
</form>  

很明显,你可以通过使用表单助手Html.Hidden等方法使所有内容更加符合MVC的风格,但这展示了你需要做的真正基本版本。

它们必须是隐藏字段吗?或者可以在文本框中指定数量吗?或者Google Checkout有一些规定,说它们必须是隐藏的吗? - Kassem
你能看一下这个吗:http://stackoverflow.com/questions/6285578/getting-started-with-asp-net-mvc3-google-checkout - Kassem

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接