Created
August 17, 2011 17:56
-
-
Save robrocker7/1152153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc = minidom.Document() | |
# cart object world | |
cart = doc.createElement('checkout-shopping-cart') | |
cart.setAttribute("xmlns","http://checkout.google.com/schema/2") | |
item_cart = doc.createElement('shopping-cart') | |
cart.appendChild(item_cart) | |
# merchant item data | |
merch_data = doc.createElement('merchant-private-data') | |
item_cart.appendChild(merch_data) | |
merch_data_info = doc.createElement('user-id') | |
merch_data_info_text = doc.createTextNode('%s' % request.user.id) | |
merch_data_info.appendChild(merch_data_info_text) | |
merch_data.appendChild(merch_data_info) | |
items = doc.createElement('items') | |
item_cart.appendChild(items) | |
item = doc.createElement('item') | |
items.appendChild(item) | |
# merchant item id | |
merch_id = doc.createElement('merchant-item-id') | |
merch_id_text = doc.createTextNode('MONTHLY') | |
merch_id.appendChild(merch_id_text) | |
item.appendChild(merch_id) | |
# name info | |
name = doc.createElement('item-name') | |
name_text = doc.createTextNode('WEREWOLF GAME PRO Account') | |
name.appendChild(name_text) | |
item.appendChild(name) | |
# description | |
desc = doc.createElement('item-description') | |
desc_text = doc.createTextNode('Subscription to werewolf-game.com.') | |
desc.appendChild(desc_text) | |
item.appendChild(desc) | |
# price | |
price = doc.createElement('unit-price') | |
price.setAttribute('currency', 'USD') | |
price_text = doc.createTextNode('2.00') | |
price.appendChild(price_text) | |
item.appendChild(price) | |
# quantity | |
quantity = doc.createElement('quantity') | |
quantity_text = doc.createTextNode('1') | |
quantity.appendChild(quantity_text) | |
item.appendChild(quantity) | |
# subscription info | |
sub = doc.createElement('subscription') | |
sub.setAttribute('period', 'MONTHLY') | |
sub.setAttribute('type', 'google') | |
item.appendChild(sub) | |
# payments | |
payments = doc.createElement('payments') | |
sub.appendChild(payments) | |
#subscription payment | |
sub_payment = doc.createElement('subscription-payment') | |
payments.appendChild(sub_payment) | |
# max-charge | |
max_charge = doc.createElement('maximum-charge') | |
max_charge.setAttribute('currency', 'USD') | |
max_charge_text = doc.createTextNode('2.00') | |
max_charge.appendChild(max_charge_text) | |
sub_payment.appendChild(max_charge) | |
# recurring item | |
re_item = doc.createElement('recurrent-item') | |
sub.appendChild(re_item) | |
# item name | |
re_item_name = doc.createElement('item-name') | |
re_item_name_text = doc.createTextNode('Werewolf Game subscription for ONE month') | |
re_item_name.appendChild(re_item_name_text) | |
re_item.appendChild(re_item_name) | |
# item description | |
re_item_desc = doc.createElement('item-description') | |
re_item_desc_text = doc.createTextNode('Your flat fee for having a pro account on www.werewolf-game.com') | |
re_item_desc.appendChild(re_item_desc_text) | |
re_item.appendChild(re_item_desc) | |
# item quantity | |
re_item_quantity = doc.createElement('quantity') | |
re_item_quantity_text = doc.createTextNode('1') | |
re_item_quantity.appendChild(re_item_quantity_text) | |
re_item.appendChild(re_item_quantity) | |
# re price | |
re_price = doc.createElement('unit-price') | |
re_price.setAttribute('currency', 'USD') | |
re_price_text = doc.createTextNode('2.00') | |
re_price.appendChild(re_price_text) | |
re_item.appendChild(re_price) | |
# digital content | |
re_digital_content = doc.createElement('digital-content') | |
re_item.appendChild(re_digital_content) | |
# display disposition | |
re_display_disp = doc.createElement('display-disposition') | |
re_display_disp_text = doc.createTextNode('OPTIMISTIC') | |
re_display_disp.appendChild(re_display_disp_text) | |
re_digital_content.appendChild(re_display_disp) | |
# url | |
re_display_url = doc.createElement('url') | |
re_display_url_text = doc.createTextNode('http://www.werewolf-game.com') | |
re_display_url.appendChild(re_display_url_text) | |
re_digital_content.appendChild(re_display_url) | |
# description | |
re_display_desc = doc.createElement('description') | |
re_display_desc_text = doc.createTextNode('You can now login to your pro account!') | |
re_display_desc.appendChild(re_display_desc_text) | |
re_digital_content.appendChild(re_display_desc) | |
# append the cart | |
doc.appendChild(cart) | |
data = doc.toxml(encoding="utf-8") | |
#return HttpResponse(data) | |
res = GoogleResponse() | |
# send to google | |
ch = pycurl.Curl() | |
ch.setopt(pycurl.URL, MERCHANT_URL) | |
ch.setopt(pycurl.POST, 1) | |
ch.setopt(pycurl.POSTFIELDS, data) | |
ch.setopt(pycurl.WRITEFUNCTION, res.body_callback) | |
ch.perform() | |
ch.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment