33
36
class FPSConnection(AWSQueryConnection):
35
APIVersion = '2007-01-08'
36
SignatureVersion = '1'
38
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
39
is_secure=True, port=None, proxy=None, proxy_port=None,
40
host='fps.sandbox.amazonaws.com', debug=0,
41
https_connection_factory=None):
42
AWSQueryConnection.__init__(self, aws_access_key_id,
43
aws_secret_access_key,
44
is_secure, port, proxy, proxy_port,
45
host, debug, https_connection_factory)
47
def install_payment_instruction(self, instruction, token_type="Unrestricted", transaction_id=None):
49
InstallPaymentInstruction
50
instruction: The PaymentInstruction to send, for example:
52
MyRole=='Caller' orSay 'Roles do not match';
54
token_type: Defaults to "Unrestricted"
55
transaction_id: Defaults to a new ID
58
if(transaction_id == None):
59
transaction_id = uuid.uuid4()
61
params['PaymentInstruction'] = instruction
62
params['TokenType'] = token_type
63
params['CallerReference'] = transaction_id
64
response = self.make_request("InstallPaymentInstruction", params)
67
def install_caller_instruction(self, token_type="Unrestricted", transaction_id=None):
70
This will install a new caller_token into the FPS section.
71
This should really only be called to regenerate the caller token.
73
response = self.install_payment_instruction("MyRole=='Caller';", token_type=token_type, transaction_id=transaction_id)
74
body = response.read()
75
if(response.status == 200):
77
h = handler.XmlHandler(rs, self)
78
xml.sax.parseString(body, h)
79
caller_token = rs.TokenId
81
boto.config.save_system_option("FPS", "caller_token", caller_token)
83
boto.config.save_user_option("FPS", "caller_token", caller_token)
86
raise FPSResponseError(response.status, respons.reason, body)
88
def install_recipient_instruction(self, token_type="Unrestricted", transaction_id=None):
90
Set us up as a Recipient
91
This will install a new caller_token into the FPS section.
92
This should really only be called to regenerate the recipient token.
94
response = self.install_payment_instruction("MyRole=='Recipient';", token_type=token_type, transaction_id=transaction_id)
95
body = response.read()
96
if(response.status == 200):
98
h = handler.XmlHandler(rs, self)
99
xml.sax.parseString(body, h)
100
recipient_token = rs.TokenId
102
boto.config.save_system_option("FPS", "recipient_token", recipient_token)
104
boto.config.save_user_option("FPS", "recipient_token", recipient_token)
106
return recipient_token
108
raise FPSResponseError(response.status, respons.reason, body)
110
def make_url(self, returnURL, paymentReason, pipelineName, **params):
112
Generate the URL with the signature required for a transaction
114
params['callerKey'] = str(self.aws_access_key_id)
115
params['returnURL'] = str(returnURL)
116
params['paymentReason'] = str(paymentReason)
117
params['pipelineName'] = pipelineName
119
if(not params.has_key('callerReference')):
120
params['callerReference'] = str(uuid.uuid4())
126
url += "&%s=%s" % (k, urllib.quote_plus(str(params[k])))
128
url = "/cobranded-ui/actions/start?%s" % ( url[1:])
129
signature= boto.utils.encode(self.aws_secret_access_key, url, True)
130
return "https://authorize.payments-sandbox.amazon.com%s&awsSignature=%s" % (url, signature)
132
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):
134
Make a payment transaction
135
You must specify the amount and the sender token.
138
params['RecipientTokenId'] = boto.config.get("FPS", "recipient_token")
139
params['CallerTokenId'] = boto.config.get("FPS", "caller_token")
140
params['SenderTokenId'] = sender_token
141
params['TransactionAmount.Amount'] = str(amount)
142
params['TransactionAmount.CurrencyCode'] = "USD"
143
params['ChargeFeeTo'] = charge_fee_to
145
if(transactionDate != None):
146
params['TransactionDate'] = transactionDate
147
if(senderReference != None):
148
params['SenderReference'] = senderReference
149
if(recipientReference != None):
150
params['RecipientReference'] = recipientReference
151
if(senderDescription != None):
152
params['SenderDescription'] = senderDescription
153
if(recipientDescription != None):
154
params['RecipientDescription'] = recipientDescription
155
if(callerDescription != None):
156
params['CallerDescription'] = callerDescription
157
if(metadata != None):
158
params['MetaData'] = metadata
159
if(transactionDate != None):
160
params['TransactionDate'] = transactionDate
161
if(reference == None):
162
reference = uuid.uuid4()
163
params['CallerReference'] = reference
165
response = self.make_request("Pay", params)
166
body = response.read()
167
if(response.status == 200):
169
h = handler.XmlHandler(rs, self)
170
xml.sax.parseString(body, h)
173
raise FPSResponseError(response.status, response.reason, body)
38
APIVersion = '2007-01-08'
40
def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
41
is_secure=True, port=None, proxy=None, proxy_port=None,
42
proxy_user=None, proxy_pass=None,
43
host='fps.sandbox.amazonaws.com', debug=0,
44
https_connection_factory=None, path="/"):
45
AWSQueryConnection.__init__(self, aws_access_key_id, aws_secret_access_key,
46
is_secure, port, proxy, proxy_port,
47
proxy_user, proxy_pass, host, debug,
48
https_connection_factory, path)
50
def _required_auth_capability(self):
53
def install_payment_instruction(self, instruction, token_type="Unrestricted", transaction_id=None):
55
InstallPaymentInstruction
56
instruction: The PaymentInstruction to send, for example:
58
MyRole=='Caller' orSay 'Roles do not match';
60
token_type: Defaults to "Unrestricted"
61
transaction_id: Defaults to a new ID
64
if(transaction_id == None):
65
transaction_id = uuid.uuid4()
67
params['PaymentInstruction'] = instruction
68
params['TokenType'] = token_type
69
params['CallerReference'] = transaction_id
70
response = self.make_request("InstallPaymentInstruction", params)
73
def install_caller_instruction(self, token_type="Unrestricted", transaction_id=None):
76
This will install a new caller_token into the FPS section.
77
This should really only be called to regenerate the caller token.
79
response = self.install_payment_instruction("MyRole=='Caller';", token_type=token_type, transaction_id=transaction_id)
80
body = response.read()
81
if(response.status == 200):
83
h = handler.XmlHandler(rs, self)
84
xml.sax.parseString(body, h)
85
caller_token = rs.TokenId
87
boto.config.save_system_option("FPS", "caller_token", caller_token)
89
boto.config.save_user_option("FPS", "caller_token", caller_token)
92
raise FPSResponseError(response.status, response.reason, body)
94
def install_recipient_instruction(self, token_type="Unrestricted", transaction_id=None):
96
Set us up as a Recipient
97
This will install a new caller_token into the FPS section.
98
This should really only be called to regenerate the recipient token.
100
response = self.install_payment_instruction("MyRole=='Recipient';", token_type=token_type, transaction_id=transaction_id)
101
body = response.read()
102
if(response.status == 200):
104
h = handler.XmlHandler(rs, self)
105
xml.sax.parseString(body, h)
106
recipient_token = rs.TokenId
108
boto.config.save_system_option("FPS", "recipient_token", recipient_token)
110
boto.config.save_user_option("FPS", "recipient_token", recipient_token)
112
return recipient_token
114
raise FPSResponseError(response.status, response.reason, body)
116
def make_marketplace_registration_url(self, returnURL, pipelineName, maxFixedFee=0.0, maxVariableFee=0.0, recipientPaysFee=True, **params):
118
Generate the URL with the signature required for signing up a recipient
120
# use the sandbox authorization endpoint if we're using the
121
# sandbox for API calls.
122
endpoint_host = 'authorize.payments.amazon.com'
123
if 'sandbox' in self.host:
124
endpoint_host = 'authorize.payments-sandbox.amazon.com'
125
base = "/cobranded-ui/actions/start"
127
params['callerKey'] = str(self.aws_access_key_id)
128
params['returnURL'] = str(returnURL)
129
params['pipelineName'] = str(pipelineName)
130
params['maxFixedFee'] = str(maxFixedFee)
131
params['maxVariableFee'] = str(maxVariableFee)
132
params['recipientPaysFee'] = str(recipientPaysFee)
133
params["signatureMethod"] = 'HmacSHA256'
134
params["signatureVersion"] = '2'
136
if(not params.has_key('callerReference')):
137
params['callerReference'] = str(uuid.uuid4())
140
for k in sorted(params.keys()):
141
parts += "&%s=%s" % (k, urllib.quote(params[k], '~'))
143
canonical = '\n'.join(['GET',
144
str(endpoint_host).lower(),
148
signature = self._auth_handler.sign_string(canonical)
149
params["signature"] = signature
152
for k in sorted(params.keys()):
153
urlsuffix += "&%s=%s" % (k, urllib.quote(params[k], '~'))
154
urlsuffix = urlsuffix[1:] # strip the first &
156
fmt = "https://%(endpoint_host)s%(base)s?%(urlsuffix)s"
161
def make_url(self, returnURL, paymentReason, pipelineName, transactionAmount, **params):
163
Generate the URL with the signature required for a transaction
165
# use the sandbox authorization endpoint if we're using the
166
# sandbox for API calls.
167
endpoint_host = 'authorize.payments.amazon.com'
168
if 'sandbox' in self.host:
169
endpoint_host = 'authorize.payments-sandbox.amazon.com'
170
base = "/cobranded-ui/actions/start"
172
params['callerKey'] = str(self.aws_access_key_id)
173
params['returnURL'] = str(returnURL)
174
params['paymentReason'] = str(paymentReason)
175
params['pipelineName'] = pipelineName
176
params['transactionAmount'] = transactionAmount
177
params["signatureMethod"] = 'HmacSHA256'
178
params["signatureVersion"] = '2'
180
if(not params.has_key('callerReference')):
181
params['callerReference'] = str(uuid.uuid4())
184
for k in sorted(params.keys()):
185
parts += "&%s=%s" % (k, urllib.quote(params[k], '~'))
187
canonical = '\n'.join(['GET',
188
str(endpoint_host).lower(),
192
signature = self._auth_handler.sign_string(canonical)
193
params["signature"] = signature
196
for k in sorted(params.keys()):
197
urlsuffix += "&%s=%s" % (k, urllib.quote(params[k], '~'))
198
urlsuffix = urlsuffix[1:] # strip the first &
200
fmt = "https://%(endpoint_host)s%(base)s?%(urlsuffix)s"
204
def pay(self, transactionAmount, senderTokenId,
205
recipientTokenId=None, callerTokenId=None,
206
chargeFeeTo="Recipient",
207
callerReference=None, senderReference=None, recipientReference=None,
208
senderDescription=None, recipientDescription=None, callerDescription=None,
209
metadata=None, transactionDate=None, reserve=False):
211
Make a payment transaction. You must specify the amount.
212
This can also perform a Reserve request if 'reserve' is set to True.
215
params['SenderTokenId'] = senderTokenId
216
# this is for 2008-09-17 specification
217
params['TransactionAmount.Amount'] = str(transactionAmount)
218
params['TransactionAmount.CurrencyCode'] = "USD"
219
#params['TransactionAmount'] = str(transactionAmount)
220
params['ChargeFeeTo'] = chargeFeeTo
222
params['RecipientTokenId'] = (
223
recipientTokenId if recipientTokenId is not None
224
else boto.config.get("FPS", "recipient_token")
226
params['CallerTokenId'] = (
227
callerTokenId if callerTokenId is not None
228
else boto.config.get("FPS", "caller_token")
230
if(transactionDate != None):
231
params['TransactionDate'] = transactionDate
232
if(senderReference != None):
233
params['SenderReference'] = senderReference
234
if(recipientReference != None):
235
params['RecipientReference'] = recipientReference
236
if(senderDescription != None):
237
params['SenderDescription'] = senderDescription
238
if(recipientDescription != None):
239
params['RecipientDescription'] = recipientDescription
240
if(callerDescription != None):
241
params['CallerDescription'] = callerDescription
242
if(metadata != None):
243
params['MetaData'] = metadata
244
if(callerReference == None):
245
callerReference = uuid.uuid4()
246
params['CallerReference'] = callerReference
249
response = self.make_request("Reserve", params)
251
response = self.make_request("Pay", params)
252
body = response.read()
253
if(response.status == 200):
255
h = handler.XmlHandler(rs, self)
256
xml.sax.parseString(body, h)
259
raise FPSResponseError(response.status, response.reason, body)
261
def get_transaction_status(self, transactionId):
263
Returns the status of a given transaction.
266
params['TransactionId'] = transactionId
268
response = self.make_request("GetTransactionStatus", params)
269
body = response.read()
270
if(response.status == 200):
272
h = handler.XmlHandler(rs, self)
273
xml.sax.parseString(body, h)
276
raise FPSResponseError(response.status, response.reason, body)
278
def cancel(self, transactionId, description=None):
280
Cancels a reserved or pending transaction.
283
params['transactionId'] = transactionId
284
if(description != None):
285
params['description'] = description
287
response = self.make_request("Cancel", params)
288
body = response.read()
289
if(response.status == 200):
291
h = handler.XmlHandler(rs, self)
292
xml.sax.parseString(body, h)
295
raise FPSResponseError(response.status, response.reason, body)
297
def settle(self, reserveTransactionId, transactionAmount=None):
299
Charges for a reserved payment.
302
params['ReserveTransactionId'] = reserveTransactionId
303
if(transactionAmount != None):
304
params['TransactionAmount'] = transactionAmount
306
response = self.make_request("Settle", params)
307
body = response.read()
308
if(response.status == 200):
310
h = handler.XmlHandler(rs, self)
311
xml.sax.parseString(body, h)
314
raise FPSResponseError(response.status, response.reason, body)
316
def refund(self, callerReference, transactionId, refundAmount=None, callerDescription=None):
318
Refund a transaction. This refunds the full amount by default unless 'refundAmount' is specified.
321
params['CallerReference'] = callerReference
322
params['TransactionId'] = transactionId
323
if(refundAmount != None):
324
params['RefundAmount'] = refundAmount
325
if(callerDescription != None):
326
params['CallerDescription'] = callerDescription
328
response = self.make_request("Refund", params)
329
body = response.read()
330
if(response.status == 200):
332
h = handler.XmlHandler(rs, self)
333
xml.sax.parseString(body, h)
336
raise FPSResponseError(response.status, response.reason, body)
338
def get_recipient_verification_status(self, recipientTokenId):
340
Test that the intended recipient has a verified Amazon Payments account.
343
params['RecipientTokenId'] = recipientTokenId
345
response = self.make_request("GetRecipientVerificationStatus", params)
346
body = response.read()
347
if(response.status == 200):
349
h = handler.XmlHandler(rs, self)
350
xml.sax.parseString(body, h)
353
raise FPSResponseError(response.status, response.reason, body)
355
def get_token_by_caller_reference(self, callerReference):
357
Returns details about the token specified by 'callerReference'.
360
params['callerReference'] = callerReference
362
response = self.make_request("GetTokenByCaller", params)
363
body = response.read()
364
if(response.status == 200):
366
h = handler.XmlHandler(rs, self)
367
xml.sax.parseString(body, h)
370
raise FPSResponseError(response.status, response.reason, body)
371
def get_token_by_caller_token(self, tokenId):
373
Returns details about the token specified by 'callerReference'.
376
params['TokenId'] = tokenId
378
response = self.make_request("GetTokenByCaller", params)
379
body = response.read()
380
if(response.status == 200):
382
h = handler.XmlHandler(rs, self)
383
xml.sax.parseString(body, h)
386
raise FPSResponseError(response.status, response.reason, body)
388
def verify_signature(self, end_point_url, http_parameters):
390
UrlEndPoint = end_point_url,
391
HttpParameters = http_parameters,
393
response = self.make_request("VerifySignature", params)
394
body = response.read()
395
if(response.status != 200):
396
raise FPSResponseError(response.status, response.reason, body)
398
h = handler.XmlHandler(rs, self)
399
xml.sax.parseString(body, h)