Google Checkout Level 1 and 2 on Google App Engine (demo)



You are buying an apple for $0.99




Readme



  • To test it, you can use this fake credit card. Type: American Express, Number: 3782 8224 6310 005, CVC: any four digit, Expiration Date: any future date.
  • After completing the payment click on "back to..." or visit /plugin_checkout/default/checkorder to see how this application receives the notification from Google.
  • This application is a web2py plugin, i.e. once installed in web2py it can be used by other web2py applications. It is based on a modified version of gchecky created by Evgeniy Tarassov.
  • The source code of this app can be downloaded here


  • Here is the sample controller used here



    1.
    2.
    3.
    4.
    5.
    6.
    7.
    8.
    9.
    10.
    11.
    12.
    13.
    14.
    15.
    16.
    17.
    18.
    19.
    20.
    21.
    22.
    23.
    24.
    25.
    26.
    27.
    28.
    29.
    30.
    31.
    32.
    33.
    34.
    35.
    36.
    37.
    38.
    39.
    40.
    41.
    42.
    43.
    44.
    45.
    46.
    47.
    48.
    import applications.plugin_checkout.modules.gchecky.model as gmodel
    import applications.plugin_checkout.modules.gchecky.controller as gcontroller
    import uuid

    class Level2Controller(gcontroller.Controller):
    def __init__(self,merchant_id,merchant_key,is_sandbox=True,currency='USD'):
    gcontroller.Controller.__init__(self,merchant_id,merchant_key,
    is_sandbox,currency)
    def handle_new_order(self, message, order_id, order, context):
    id=int(message.shopping_cart.items[0].merchant_item_id)
    db(db.order.id==id).update(order_id=order_id,status='SUBMITTED')
    return gmodel.ok_t()
    def handle_order_state_change(self, message, order_id, order, context):
    db(db.order.order_id==order_id).update(status=message.financial_order_state)
    return gmodel.ok_t()
    def handle_charge_amount(self, message, order_id, order, context):
    db(db.order.order_id==order_id).update(status='CHARGED')
    return gmodel.ok_t()

    mycontroller=Level2Controller(GOOGLE_MERCHANT_ID,GOOGLE_MERCHANT_KEY,is_sandbox=True)

    def notify():
    response.headers['Content-Type']='text/xml'
    return mycontroller.receive_xml(request.body.read())

    def index(): redirect(URL(r=request,f='checkout'))

    def checkout():
    session.id=db.order.insert(status='PRE-PROCESSING')
    order=gmodel.checkout_shopping_cart_t()
    order.shopping_cart=gmodel.shopping_cart_t(items=[])
    order.shopping_cart.items.append(
    gmodel.item_t(merchant_item_id = session.id,
    name = 'apple',
    description = 'a tasty fruit!',
    unit_price = gmodel.price_t(value=0.99,currency='USD'),
    quantity = 1))
    next='http://web2py.appspot.com/plugin_checkout/default/checkorder'
    order.checkout_flow_support=gmodel.checkout_flow_support_t(
    continue_shopping_url=next,request_buyer_phone_number=False)
    prepared = mycontroller.prepare_order(order)
    return dict(button=XML(prepared.html()))

    def checkorder():
    if not session.id: redirect('checkout')
    rows=db(db.order.id==session.id).select()
    if not rows: redirect('checkout')
    return dict(status=rows[0].status)