Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Checkout in ASP.Net MVC

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?

like image 483
Mikejh99 Avatar asked Nov 19 '09 22:11

Mikejh99


1 Answers

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.

like image 128
Paul Avatar answered Nov 12 '22 22:11

Paul