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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
from braintree.error_result import ErrorResult
from braintree.merchant_account import MerchantAccount
from braintree.resource import Resource
from braintree.successful_result import SuccessfulResult
from braintree.exceptions.not_found_error import NotFoundError
class MerchantAccountGateway(object):
def __init__(self, gateway):
self.gateway = gateway
self.config = gateway.config
def create(self, params={}):
Resource.verify_keys(params, MerchantAccountGateway._detect_signature(params))
return self._post("/merchant_accounts/create_via_api", {"merchant_account": params})
def update(self, merchant_account_id, params={}):
Resource.verify_keys(params, MerchantAccountGateway._update_signature())
return self._put("/merchant_accounts/%s/update_via_api" % merchant_account_id, {"merchant_account": params})
def find(self, merchant_account_id):
try:
if merchant_account_id == None or merchant_account_id.strip() == "":
raise NotFoundError()
response = self.config.http().get("/merchant_accounts/" + merchant_account_id)
return MerchantAccount(self.gateway, response["merchant_account"])
except NotFoundError:
raise NotFoundError("merchant account with id " + merchant_account_id + " not found")
def _post(self, url, params={}):
response = self.config.http().post(url, params)
if "merchant_account" in response:
return SuccessfulResult({"merchant_account": MerchantAccount(self.gateway, response["merchant_account"])})
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])
def _put(self, url, params={}):
response = self.config.http().put(url, params)
if "merchant_account" in response:
return SuccessfulResult({"merchant_account": MerchantAccount(self.gateway, response["merchant_account"])})
elif "api_error_response" in response:
return ErrorResult(self.gateway, response["api_error_response"])
@staticmethod
def _detect_signature(attributes):
if 'applicant_details' in attributes:
# Warn deprecated
return MerchantAccountGateway._create_deprecated_signature()
else:
return MerchantAccountGateway._create_signature()
@staticmethod
def _create_deprecated_signature():
return [
{'applicant_details': [
'company_name',
'first_name',
'last_name',
'email',
'phone',
'date_of_birth',
'ssn',
'tax_id',
'routing_number',
'account_number',
{'address': [
'street_address',
'postal_code',
'locality',
'region']}
]
},
'tos_accepted',
'master_merchant_account_id',
'id'
]
@staticmethod
def _create_signature():
return [
{'individual': [
'first_name',
'last_name',
'email',
'phone',
'date_of_birth',
'ssn',
{'address': [
'street_address',
'postal_code',
'locality',
'region']}
]
},
{'business': [
'dba_name',
'legal_name',
'tax_id',
{'address': [
'street_address',
'postal_code',
'locality',
'region']}
]
},
{'funding': [
'routing_number',
'account_number',
'destination',
'email',
'mobile_phone',
]
},
'tos_accepted',
'master_merchant_account_id',
'id'
]
@staticmethod
def _update_signature():
return [
{'individual': [
'first_name',
'last_name',
'email',
'phone',
'date_of_birth',
'ssn',
{'address': [
'street_address',
'postal_code',
'locality',
'region']}
]
},
{'business': [
'dba_name',
'legal_name',
'tax_id',
{'address': [
'street_address',
'postal_code',
'locality',
'region']}
]
},
{'funding': [
'routing_number',
'account_number',
'destination',
'email',
'mobile_phone',
]
},
'master_merchant_account_id',
'id'
]
|