Changeset 38 for trunk

Show
Ignore:
Timestamp:
04/08/08 23:50:22 (4 years ago)
Author:
tim
Message:

Implements and tests reserve. Some ugly bits are
starting to show: repeated code in parameter handling,
and hackery in the response parsing.

I'm going to keep working on making the API complete,
then we can start to refactor out the ugly bits. Perhaps
more patterns will emerge in the meantime.

Location:
trunk/fpys
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/fpys/client.py

    r37 r38  
    9898                                      document.find("//" + bal).find("CurrencyCode").text) 
    9999 
    100         if document.getroot().tag.find("PayResponse") >= 0: 
     100        # Hackish at best...  
     101        root_tag = document.getroot().tag 
     102        if root_tag.find("PayResponse") >= 0 or root_tag.find("ReserveResponse") >= 0: 
    101103            self.transaction = TransactionResponse() 
    102104            self.transaction.id = document.find("//TransactionId").text 
     
    343345        pass 
    344346 
    345     def reserve(self): 
    346         pass 
     347    def reserve(self, 
     348                caller_token, 
     349                sender_token, 
     350                recipient_token, 
     351                amount, 
     352                caller_reference, 
     353                date = None, 
     354                charge_fee_to='Recipient'): 
     355        params = {'Action': 'Reserve', 
     356                  'CallerTokenId': caller_token, 
     357                  'SenderTokenId': sender_token, 
     358                  'RecipientTokenId': recipient_token, 
     359                  'TransactionAmount.Amount': amount, 
     360                  'TransactionAmount.CurrencyCode': 'USD', 
     361                  'CallerReference': caller_reference, 
     362                  'ChargeFeeTo': charge_fee_to, 
     363                  } 
     364        if date is not None: 
     365            params['TransactionDate'] = date 
     366 
     367        return self.execute(params) 
    347368 
    348369    def retryTransaction(self): 
  • trunk/fpys/tests/client_test.py

    r37 r38  
    161161    assert response.transaction.id == "133I77HJS56JVM7M54OZIRITRVLUT5F227U" 
    162162    assert response.transaction.status == "Initiated" 
     163 
     164def test_reserve(): 
     165    response = fps_client.reserve("Z34XMGF4GCILGV7EV2D45DDO4Q6WXEJZ9175UNR5I9LFEC1H8MMX3R6NBJUJH8MQ", 
     166                                  "2146KQCZ13JKRP8BHCMI7JRHPTBAPZGU2VB9FTJ84UN7UF7LXAE33YJHSDB8XCG2", 
     167                                  "Z44XQGE4GAI1GV4E92DU5KDOTQPWXKJC91V5MNRII7LFICFH8HMX3RNNPJU4HCMN", 
     168                                  "19.95", 
     169                                  "unit_test_ref_1") 
     170    assert response.success == True 
     171    assert response.transaction.status == "Initiated" 
     172    assert response.transaction.id == "134OLF7MHB2L4V9T54RHADQ9FCK5NLVZHDC" 
     173 
     174     
  • trunk/fpys/tests/wsgi_responder.py

    r37 r38  
    7171        return [response] 
    7272 
     73    def Reserve(self, environ): 
     74        response = """<ns0:ReserveResponse xmlns:ns0="http://fps.amazonaws.com/doc/2007-01-08/"><ns0:TransactionResponse><TransactionId>134OLF7MHB2L4V9T54RHADQ9FCK5NLVZHDC</TransactionId><Status>Initiated</Status></ns0:TransactionResponse><Status>Success</Status><RequestId>cedef0ad-76f0-4604-82bb-ad28020a4ddc:0</RequestId></ns0:ReserveResponse>""" 
     75        return [response] 
     76 
    7377flexible_payment_service = FlexiblePaymentService() 
    7478