Google Checkout in ASP.Net MVC
Asked Answered
S

1

7

I have a fairly simple ASP.Net site that uses google checkout (I have an imagebutton with the PostBackUrl set to the Google address passing values of hidden fields) which works fine.

I've been moving this app to MVC and I'm not sure how to handle this. I thought about using jQuery form but I don't believe this would work in this situation because there are times when they're redirected to the google pages. Has anyone used google checkout in an asp.net MVC app?

Sensitize answered 19/11, 2009 at 22:39 Comment(0)
F
2

You can do the same thing as you were doing before, just you end up doing it manually.

Sounds like you're using just the basic version, yes?

You create an HTML form that has the Action set to the Google checkout process, add in the proper Hidden fields (the model your controller passes down would be populated w/ the correct values for those) and then you have a submit button (or image if you prefer).

So, an example off Google's Basic HTML page, modified for some MVC-ish-ness would be something like this:

<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>  

Obviously, you could make all that even more MVC-ish by using the form helper Html.Hidden and so on, but that shows the really basic version of what you need to do.

Facilitation answered 5/6, 2010 at 19:53 Comment(2)
Do they have to be hidden fields? Or is it possible to specify the quantity in a textbox for example? Or does google checkout have some policy that says they have to be hidden?Porcia
Could you take a look at this please: #6286078Porcia

© 2022 - 2024 — McMap. All rights reserved.