forked from dfkthf125/api-v1-client-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreceive.py
More file actions
34 lines (28 loc) · 1.27 KB
/
receive.py
File metadata and controls
34 lines (28 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""This module corresponds to functionality documented
at https://blockchain.info/api/api_receive
"""
from . import util
import json
class ReceiveResponse:
def __init__(self, fee_percent, dest, input, callback):
self.fee_percent = fee_percent
self.destination_address = dest
self.input_address = input
self.callback_url = callback
def receive(dest_addr, callback, api_code = None):
"""Call the 'api/receive' endpoint and create a forwarding address.
:param str dest_addr: destination address where the payment should be sent
:param str callback: callback URI that will be called upon payment
:param str api_code: Blockchain.info API code (optional)
:return: an instance of :class:`ReceiveResponse` class
"""
params = { 'method': 'create', 'address': dest_addr, 'callback': callback }
if api_code is not None:
params['api_code'] = api_code
resp = util.call_api('api/receive', params)
json_resp = json.loads(resp)
payment_response = ReceiveResponse(json_resp['fee_percent'],
json_resp['destination'],
json_resp['input_address'],
json_resp['callback_url'])
return payment_response