diff options
author | Mitch Garnaat <mitch@cloudright.com> | 2010-08-24 15:35:46 -0400 |
---|---|---|
committer | Mitch Garnaat <mitch@cloudright.com> | 2010-08-24 15:35:46 -0400 |
commit | db42938169f03a29640ac0004e556ba94d14b855 (patch) | |
tree | 0a29d99f0f28a320bc2144a659b26bf04548678b | |
parent | 91628f98c12cbfbafe72e2736599a5d79b03fd7d (diff) | |
download | boto-db42938169f03a29640ac0004e556ba94d14b855.tar.gz |
Incorporating a patch from James Christie to add important functionality to FPS module.
-rw-r--r-- | boto/fps/connection.py | 161 |
1 files changed, 147 insertions, 14 deletions
diff --git a/boto/fps/connection.py b/boto/fps/connection.py index 3c73199a..edcc13b0 100644 --- a/boto/fps/connection.py +++ b/boto/fps/connection.py @@ -137,19 +137,22 @@ class FPSConnection(AWSQueryConnection): return "https://authorize.payments-sandbox.amazon.com%s&awsSignature=%s" % (url, signature) - def make_payment(self, amount, sender_token, charge_fee_to="Recipient", reference=None, senderReference=None, recipientReference=None, senderDescription=None, recipientDescription=None, callerDescription=None, metadata=None, transactionDate=None): + def pay(self, transactionAmount, senderTokenId, chargeFeeTo="Recipient", + callerReference=None, senderReference=None, recipientReference=None, + senderDescription=None, recipientDescription=None, callerDescription=None, + metadata=None, transactionDate=None, reserve=False): """ - Make a payment transaction - You must specify the amount and the sender token. + Make a payment transaction. You must specify the amount. + This can also perform a Reserve request if 'reserve' is set to True. """ params = {} - params['RecipientTokenId'] = boto.config.get("FPS", "recipient_token") - params['CallerTokenId'] = boto.config.get("FPS", "caller_token") - params['SenderTokenId'] = sender_token - params['TransactionAmount.Amount'] = str(amount) + params['SenderTokenId'] = senderTokenId + params['TransactionAmount.Value'] = str(transactionAmount) params['TransactionAmount.CurrencyCode'] = "USD" - params['ChargeFeeTo'] = charge_fee_to - + params['ChargeFeeTo'] = chargeFeeTo + + #params['RecipientTokenId'] = boto.config.get("FPS", "recipient_token") + #params['CallerTokenId'] = boto.config.get("FPS", "caller_token") if(transactionDate != None): params['TransactionDate'] = transactionDate if(senderReference != None): @@ -166,11 +169,141 @@ class FPSConnection(AWSQueryConnection): params['MetaData'] = metadata if(transactionDate != None): params['TransactionDate'] = transactionDate - if(reference == None): - reference = uuid.uuid4() - params['CallerReference'] = reference - - response = self.make_request("Pay", params) + if(callerReference == None): + callerReference = uuid.uuid4() + params['CallerReference'] = callerReference + + if reserve: + response = self.make_request("Reserve", params) + else: + response = self.make_request("Pay", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def get_transaction_status(self, transactionId): + """ + Returns the status of a given transaction. + """ + params = {} + params['TransactionId'] = transactionId + + response = self.make_request("GetTransactionStatus", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def cancel(self, transactionId, description=None): + """ + Cancels a reserved or pending transaction. + """ + params = {} + params['transactionId'] = transactionId + if(description != None): + params['description'] = description + + response = self.make_request("Cancel", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def settle(self, reserveTransactionId, transactionAmount=None): + """ + Charges for a reserved payment. + """ + params = {} + params['ReserveTransactionId'] = reserveTransactionId + if(transactionAmount != None): + params['TransactionAmount'] = transactionAmount + + response = self.make_request("Settle", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def refund(self, callerReference, transactionId, refundAmount=None, callerDescription=None): + """ + Refund a transaction. This refunds the full amount by default unless 'refundAmount' is specified. + """ + params = {} + params['CallerReference'] = callerReference + params['TransactionId'] = transactionId + if(refundAmount != None): + params['RefundAmount'] = refundAmount + if(callerDescription != None): + params['CallerDescription'] = callerDescription + + response = self.make_request("Refund", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def get_recipient_verification_status(self, recipientTokenId): + """ + Test that the intended recipient has a verified Amazon Payments account. + """ + params ={} + params['RecipientTokenId'] = recipientTokenId + + response = self.make_request("GetRecipientVerificationStatus", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + + def get_token_by_caller_reference(self, callerReference): + """ + Returns details about the token specified by 'callerReference'. + """ + params ={} + params['callerReference'] = callerReference + + response = self.make_request("GetTokenByCaller", params) + body = response.read() + if(response.status == 200): + rs = ResultSet() + h = handler.XmlHandler(rs, self) + xml.sax.parseString(body, h) + return rs + else: + raise FPSResponseError(response.status, response.reason, body) + def get_token_by_caller_token(self, tokenId): + """ + Returns details about the token specified by 'callerReference'. + """ + params ={} + params['TokenId'] = tokenId + + response = self.make_request("GetTokenByCaller", params) body = response.read() if(response.status == 200): rs = ResultSet() |