Changeset 40

Show
Ignore:
Timestamp:
04/09/08 02:54:20 (4 years ago)
Author:
tim
Message:

Implemented refund. Learned that a new token is required to initiate
a refund. The doc says "The token of the original recipient who is now
the sender in the refund" which I took to mean the same token id was
required. This is not true.

Location:
trunk/fpys
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/fpys/client.py

    r39 r40  
    100100        # Hackish at best...  
    101101        root_tag = document.getroot().tag 
    102         for tag_name in ["PayResponse", "ReserveResponse", "SettleResponse"]: 
     102        for tag_name in ["PayResponse", "RefundResponse", "ReserveResponse", "SettleResponse"]: 
    103103            if self.success and root_tag.find(tag_name) >= 0: 
    104104                self.transaction = TransactionResponse() 
     
    343343        return self.execute(params) 
    344344 
    345     def refund(self): 
    346         pass 
     345    def refund(self, 
     346               caller_token, 
     347               refund_sender_token, 
     348               transaction_id, 
     349               caller_reference, 
     350               refund_amount=None, 
     351               date = None, 
     352               charge_fee_to='Recipient', 
     353               ): 
     354        params = {'Action': 'Refund', 
     355                  'CallerTokenId': caller_token, 
     356                  'RefundSenderTokenId': refund_sender_token, 
     357                  'TransactionId': transaction_id, 
     358                  'CallerReference': caller_reference, 
     359                  'ChargeFeeTo': charge_fee_to, 
     360                  } 
     361        if date is not None: 
     362            params['TransactionDate'] = date 
     363        if refund_amount is not None: 
     364            params['RefundAmount.Amount'] = refund_amount 
     365            params['RefundAmount.CurrencyCode'] = "USD" 
     366        return self.execute(params) 
    347367 
    348368    def reserve(self, 
  • trunk/fpys/tests/client_test.py

    r39 r40  
    162162    assert response.transaction.status == "Initiated" 
    163163 
     164def test_refund(): 
     165    # the following was used to create a new token to authorize the refund 
     166    #     fps_client.installPaymentInstruction("MyRole == 'Sender';\nOperationType == 'Refund';", 
     167    #                                          "unit_test_refund_01", 
     168    #                                          "SingleUse", 
     169    #                                          "Refund of Test Transaction", 
     170    #                                          "unit_test_refund_01") 
     171    response = fps_client.refund(caller_token="Z34XMGF4GCILGV7EV2D45DDO4Q6WXEJZ9175UNR5I9LFEC1H8MMX3R6NBJUJH8MQ", 
     172                                 refund_sender_token="Z74XVGZ4G2IKGVIE52D453DOEQGWXMJ491V58NR6I3LFQC2H8BM73R8NMJUJHCMN", 
     173                                 transaction_id="134OLF7MHB2L4V9T54RHADQ9FCK5NLVZHDC", 
     174                                 caller_reference="Unit Test Refund", 
     175                                 refund_amount="19.95") 
     176    assert response.success == True 
     177    assert response.transaction.status == "Initiated" 
     178    assert response.transaction.id == "134P2CRSN5JFN3KDV3RKPKVQ3OG4H67PPR8" 
     179 
    164180def test_reserve(): 
    165181    response = fps_client.reserve("Z34XMGF4GCILGV7EV2D45DDO4Q6WXEJZ9175UNR5I9LFEC1H8MMX3R6NBJUJH8MQ", 
  • trunk/fpys/tests/wsgi_responder.py

    r39 r40  
    7171        return [response] 
    7272 
     73    def Refund(self, environ): 
     74        response = """<ns0:RefundResponse xmlns:ns0="http://fps.amazonaws.com/doc/2007-01-08/"><ns0:TransactionResponse><TransactionId>134P2CRSN5JFN3KDV3RKPKVQ3OG4H67PPR8</TransactionId><Status>Initiated</Status></ns0:TransactionResponse><Status>Success</Status><RequestId>b1c83ba0-17d3-45c4-b188-b116d2a17c12:0</RequestId></ns0:RefundResponse>""" 
     75        return [response] 
     76 
    7377    def Reserve(self, environ): 
    7478        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>"""