コード例 #1
0
def charge_amount_notification(req, dom):
    """Called iff the incoming XML request is a 'charge-amount-notification'"""
    order_num = myutil.extract_node(dom, 'google-order-number')
    latest_amt = myutil.extract_node(dom, 'latest-charge-amount')
    total_amt = myutil.extract_node(dom, 'total-charge-amount')
    timestamp = myutil.extract_node(dom, 'timestamp')

    response = do_db_work(req, {'event': 'charge-amount-notification', \
                                'google-order-number' : order_num, \
                                'latest-charge-amount' : latest_amt, \
                                'total-charge-amount' : total_amt, \
                                'timestamp' : timestamp })
    if response == True:
        log(
            req, "Charge amount successful, order " + str(order_num) +
            " amount " + str(total_amt))

        log(req, "Sending ship notification for order " + str(order_num))
        postdata =  \
"""<?xml version="1.0" encoding="UTF-8"?>

<deliver-order xmlns="http://checkout.google.com/schema/2"
    google-order-number="%(order_num)s">
</deliver-order>
""" % {'order_num' : order_num}
        log(req, "Postdata is: " + str(postdata))
        # Make the web service call and return a minidom object from the received XML
        dom = myutil.gchk_call(req, postdata)
        log(req, "deliver-order response was " + dom.toxml())
        return apache.OK
    else:
        log(
            req, "Charge amount call failed, order " + str(order_num) +
            " amount " + str(total_amt))
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #2
0
ファイル: gcheckout.py プロジェクト: AlexandrBasan/RiseFTP
def charge_amount_notification(req, dom):
    """Called iff the incoming XML request is a 'charge-amount-notification'"""
    order_num = myutil.extract_node(dom, 'google-order-number')
    latest_amt = myutil.extract_node(dom, 'latest-charge-amount')
    total_amt = myutil.extract_node(dom, 'total-charge-amount')
    timestamp = myutil.extract_node(dom, 'timestamp')
    
    response = do_db_work(req, {'event': 'charge-amount-notification', \
                                'google-order-number' : order_num, \
                                'latest-charge-amount' : latest_amt, \
                                'total-charge-amount' : total_amt, \
                                'timestamp' : timestamp })
    if response == True:
        log(req, "Charge amount successful, order " + str(order_num) + " amount " + str(total_amt))
        
        log(req, "Sending ship notification for order " + str(order_num))
        postdata =  \
"""<?xml version="1.0" encoding="UTF-8"?>

<deliver-order xmlns="http://checkout.google.com/schema/2"
    google-order-number="%(order_num)s">
</deliver-order>
""" % {'order_num' : order_num}
        log(req, "Postdata is: " + str(postdata))
        # Make the web service call and return a minidom object from the received XML
        dom = myutil.gchk_call(req, postdata)
        log(req, "deliver-order response was " + dom.toxml())
        return apache.OK
    else:
        log(req, "Charge amount call failed, order " + str(order_num) + " amount " + str(total_amt))
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #3
0
ファイル: gcheckout.py プロジェクト: AlexandrBasan/RiseFTP
def new_order_notification(req, dom):    
    """Called iff the incoming XML request is a 'new-order-notification'"""    
    order_number = myutil.extract_node(dom, "google-order-number")
    buyer_id = myutil.extract_node(dom, "buyer-id")
    order_total = myutil.extract_node(dom, "order-total")
    timestamp = myutil.extract_node(dom, "timestamp")
    
    # Translate the dollar value of the user's order into GB's of transfer credit,
    # or -1 for infinite
    transfer_credit = myutil.get_price_value_map()[int(float(order_total))]
    
    # The item description in the shopping cart will contain a substring 
    # like "android_id=123456789" that we must extract.
    # Something could throw an exception in this section with bad input, which is fine.
    description_text = myutil.extract_node(dom, ["shopping-cart", "items", "item", \
                                          "item-description"])
    log(req, "Description is: " + description_text)
    re_pattern = re.compile('android_id=([a-zA-Z0-9]+),')
    re_match = re_pattern.search(description_text)
    android_id = re_match.group(1)

    log(req, "Order number is: " + order_number)
    log(req, "Buyer ID is: " + buyer_id)
    log(req, "Android ID is: " + android_id)
    log(req, "Order total is: " + order_total)
    log(req, "Timestamp is: " + timestamp)
    log(req, "Transfer credit: " + str(transfer_credit))
    
    req.content_type = "application/xml"

    if order_number is None or buyer_id is None or android_id is None \
       or order_total is None or timestamp is None or transfer_credit is None:
        req.write("Internal error")
        return apache.HTTP_INTERNAL_SERVER_ERROR

    response = do_db_work(req, \
                          {'event' : 'new-order-notification', \
                           'google-order-number' : order_number, \
                           'android_id' : android_id, \
                           'order-total' : order_total, \
                           'timestamp' : timestamp, \
                           'buyer-id' : buyer_id, \
                           'transfer-credit' : transfer_credit})
    if response == True:
        # On success, we will have received an empty JSON object
        log(req, "New order notification success")
        return apache.OK
    else:
        log(req, "New order notification failed")
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #4
0
def new_order_notification(req, dom):
    """Called iff the incoming XML request is a 'new-order-notification'"""
    order_number = myutil.extract_node(dom, "google-order-number")
    buyer_id = myutil.extract_node(dom, "buyer-id")
    order_total = myutil.extract_node(dom, "order-total")
    timestamp = myutil.extract_node(dom, "timestamp")

    # Translate the dollar value of the user's order into GB's of transfer credit,
    # or -1 for infinite
    transfer_credit = myutil.get_price_value_map()[int(float(order_total))]

    # The item description in the shopping cart will contain a substring
    # like "android_id=123456789" that we must extract.
    # Something could throw an exception in this section with bad input, which is fine.
    description_text = myutil.extract_node(dom, ["shopping-cart", "items", "item", \
                                          "item-description"])
    log(req, "Description is: " + description_text)
    re_pattern = re.compile('android_id=([a-zA-Z0-9]+),')
    re_match = re_pattern.search(description_text)
    android_id = re_match.group(1)

    log(req, "Order number is: " + order_number)
    log(req, "Buyer ID is: " + buyer_id)
    log(req, "Android ID is: " + android_id)
    log(req, "Order total is: " + order_total)
    log(req, "Timestamp is: " + timestamp)
    log(req, "Transfer credit: " + str(transfer_credit))

    req.content_type = "application/xml"

    if order_number is None or buyer_id is None or android_id is None \
       or order_total is None or timestamp is None or transfer_credit is None:
        req.write("Internal error")
        return apache.HTTP_INTERNAL_SERVER_ERROR

    response = do_db_work(req, \
                          {'event' : 'new-order-notification', \
                           'google-order-number' : order_number, \
                           'android_id' : android_id, \
                           'order-total' : order_total, \
                           'timestamp' : timestamp, \
                           'buyer-id' : buyer_id, \
                           'transfer-credit' : transfer_credit})
    if response == True:
        # On success, we will have received an empty JSON object
        log(req, "New order notification success")
        return apache.OK
    else:
        log(req, "New order notification failed")
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #5
0
ファイル: gcheckout.py プロジェクト: AlexandrBasan/RiseFTP
def order_state_change_notification(req, dom):
    """Called iff the incoming XML request is an 'order-state-change-notification'"""
    order_num = myutil.extract_node(dom, 'google-order-number')
    order_state = myutil.extract_node(dom, 'new-financial-order-state')
    timestamp = myutil.extract_node(dom, 'timestamp')
    
    response = do_db_work(req, {'event' : 'order-state-change-notification', \
                                'google-order-number' : order_num, \
                                'new-financial-order-state' : order_state, \
                                'timestamp' : timestamp})
                                
    # The server will return an empty JSON object on success
    if response == True:
        log(req, "Order state change successful, order " + str(order_num) + " to state " + str(order_state))
        return apache.OK
    else:
        log(req, "Order state change failed, order " + str(order_num) + " state " + str(order_state))
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #6
0
def order_state_change_notification(req, dom):
    """Called iff the incoming XML request is an 'order-state-change-notification'"""
    order_num = myutil.extract_node(dom, 'google-order-number')
    order_state = myutil.extract_node(dom, 'new-financial-order-state')
    timestamp = myutil.extract_node(dom, 'timestamp')

    response = do_db_work(req, {'event' : 'order-state-change-notification', \
                                'google-order-number' : order_num, \
                                'new-financial-order-state' : order_state, \
                                'timestamp' : timestamp})

    # The server will return an empty JSON object on success
    if response == True:
        log(
            req, "Order state change successful, order " + str(order_num) +
            " to state " + str(order_state))
        return apache.OK
    else:
        log(
            req, "Order state change failed, order " + str(order_num) +
            " state " + str(order_state))
        return apache.HTTP_INTERNAL_SERVER_ERROR
コード例 #7
0
ファイル: place_order.py プロジェクト: xavornik/swiftp
def handler(req):
    req.content_type = "text/html"
    gchk_response = None
    
    formdata = util.FieldStorage(req)
    
    android_id = formdata['android_id']
    price = formdata['price']
    transferamt = myutil.form_price_to_transfer_amt(price)
    if transferamt == None:
        # The incoming form price was not one of the valid choices
        log(req, "Invalid price selection")
        req.write(error_page.get())
        return apache.OK
    log(req, "0")
    description = myutil.transfer_amount_to_description(transferamt)
    log(req, "1")
    req.write("android_id " + android_id + " wants to buy " + price \
              + " described as \"" + description + "\"\n")
    log(req, "2")
    postdata = \
"""<?xml version="1.0" encoding="UTF-8"?>

<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
  <shopping-cart>
    <items>
      <item>
        <item-name>SwiFTP transfer credit - %(description)s</item-name>
        <item-description>For android_id=%(android_id)s, increase SwiFTP proxy transfer quota by %(description)s</item-description>
        <unit-price currency="USD">%(price)s.00</unit-price>
        <quantity>1</quantity>
      </item>
    </items>
  </shopping-cart>
</checkout-shopping-cart>
""" % {'android_id': android_id, 'transferamt' : transferamt, 'description' : description, 'price' : price}

#    This code is now factored out into the myutil module
#    gchk_url = myutil.get_gchk_url()
#    gchk_req = urllib2.Request(gchk_url)
#    (merch_id, merch_key) = myutil.get_gchk_creds()
#    auth_header = "Basic " + base64.b64encode(merch_id + ':' + merch_key)
#    gchk_req.add_header('Authorization', auth_header)
#    gchk_req.add_header('Content-Type', 'application/xml')
#    gchk_req.add_header('Accept', 'application/xml')
#    log(req, "Sending checkout API req")
#    gchk_response = urllib2.urlopen(gchk_req, postdata).read()
#    req.write("Got response: <br>\n")
#    req.write(gchk_response)
#    req.write("<br>\n")
#    dom = xml.dom.minidom.parseString(gchk_response)

    # Make the web service call and return a minidom object from the received XML
    #url = myutil.get_place_order_url()
    dom = myutil.gchk_call(req, postdata)

    #redir_url = dom.getElementsByTagName("redirect-url")[0].childNodes[0].data
    redir_url = myutil.extract_node(dom, 'redirect-url')
    if not (redir_url[0:5] == 'https'):
        # We didn't get a success response from Google Checkout
        log(req, "Bad response from Google Checkout: " + gchk_response)
        return apache.HTTP_INTERNAL_SERVER_ERROR  # code 500
    log(req, "Formatting")
    req.write("Got URL: <a href=\"%(url)s\">%(url)s</a>" % {'url' : redir_url}) 
        
    return apache.OK