/usr/lib/python2.7/dist-packages/braintree/customer.py is in python-braintree 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | import warnings
from braintree.util.http import Http
from braintree.successful_result import SuccessfulResult
from braintree.error_result import ErrorResult
from braintree.resource import Resource
from braintree.credit_card import CreditCard
from braintree.paypal_account import PayPalAccount
from braintree.address import Address
from braintree.configuration import Configuration
from braintree.ids_search import IdsSearch
from braintree.exceptions.not_found_error import NotFoundError
from braintree.resource_collection import ResourceCollection
from braintree.transparent_redirect import TransparentRedirect
class Customer(Resource):
"""
A class representing a customer.
An example of creating an customer with all available fields::
result = braintree.Customer.create({
"id": "my_customer_id",
"company": "Some company",
"email": "john.doe@example.com",
"fax": "123-555-1212",
"first_name": "John",
"last_name": "Doe",
"phone": "123-555-1221",
"website": "http://www.example.com",
"credit_card": {
"cardholder_name": "John Doe",
"cvv": "123",
"expiration_date": "12/2012",
"number": "4111111111111111",
"token": "my_token",
"billing_address": {
"first_name": "John",
"last_name": "Doe",
"company": "Braintree",
"street_address": "111 First Street",
"extended_address": "Unit 1",
"locality": "Chicago",
"postal_code": "60606",
"region": "IL",
"country_name": "United States of America"
},
"options": {
"verify_card": True
}
},
"custom_fields": {
"my_key": "some value"
}
})
print(result.customer.id)
print(result.customer.first_name)
For more information on Customers, see https://www.braintreepayments.com/docs/python/customers/create
"""
def __repr__(self):
detail_list = ["first_name", "last_name", "id"]
return super(Customer, self).__repr__(detail_list)
@staticmethod
def all():
""" Return a collection of all customers. """
return Configuration.gateway().customer.all()
@staticmethod
def confirm_transparent_redirect(query_string):
"""
Confirms a transparent redirect request. It expects the query string from the
redirect request. The query string should _not_ include the leading "?" character. ::
result = braintree.Customer.confirm_transparent_redirect_request("foo=bar&id=12345")
"""
warnings.warn("Please use TransparentRedirect.confirm instead", DeprecationWarning)
return Configuration.gateway().customer.confirm_transparent_redirect(query_string)
@staticmethod
def create(params={}):
"""
Create a Customer
No field is required::
result = braintree.Customer.create({
"company": "Some company",
"first_name": "John"
})
"""
return Configuration.gateway().customer.create(params)
@staticmethod
def delete(customer_id):
"""
Delete a customer
Given a customer_id::
result = braintree.Customer.delete("my_customer_id")
"""
return Configuration.gateway().customer.delete(customer_id)
@staticmethod
def find(customer_id):
"""
Find an customer, given a customer_id. This does not return a result
object. This will raise a :class:`NotFoundError <braintree.exceptions.not_found_error.NotFoundError>` if the provided customer_id
is not found. ::
customer = braintree.Customer.find("my_customer_id")
"""
return Configuration.gateway().customer.find(customer_id)
@staticmethod
def search(*query):
return Configuration.gateway().customer.search(*query)
@staticmethod
def tr_data_for_create(tr_data, redirect_url):
""" Builds tr_data for creating a Customer. """
return Configuration.gateway().customer.tr_data_for_create(tr_data, redirect_url)
@staticmethod
def tr_data_for_update(tr_data, redirect_url):
""" Builds tr_data for updating a Customer. """
return Configuration.gateway().customer.tr_data_for_update(tr_data, redirect_url)
@staticmethod
def transparent_redirect_create_url():
""" Returns the url to use for creating Customers through transparent redirect. """
warnings.warn("Please use TransparentRedirect.url instead", DeprecationWarning)
return Configuration.gateway().customer.transparent_redirect_create_url()
@staticmethod
def transparent_redirect_update_url():
""" Returns the url to use for updating Customers through transparent redirect. """
warnings.warn("Please use TransparentRedirect.url instead", DeprecationWarning)
return Configuration.gateway().customer.transparent_redirect_update_url()
@staticmethod
def update(customer_id, params={}):
"""
Update an existing Customer
By customer_id. The params are similar to create::
result = braintree.Customer.update("my_customer_id", {
"last_name": "Smith"
})
"""
return Configuration.gateway().customer.update(customer_id, params)
@staticmethod
def create_signature():
return [
"company", "email", "fax", "first_name", "id", "last_name", "phone", "website", "device_data", "device_session_id", "fraud_merchant_id", "payment_method_nonce",
{"credit_card": CreditCard.create_signature()},
{"custom_fields": ["__any_key__"]}
]
@staticmethod
def update_signature():
return [
"company", "email", "fax", "first_name", "id", "last_name", "phone", "website", "device_data", "device_session_id", "fraud_merchant_id", "payment_method_nonce",
{"credit_card": CreditCard.signature("update_via_customer")},
{"custom_fields": ["__any_key__"]}
]
def __init__(self, gateway, attributes):
Resource.__init__(self, gateway, attributes)
if "credit_cards" in attributes:
self.credit_cards = [CreditCard(gateway, credit_card) for credit_card in self.credit_cards]
if "addresses" in attributes:
self.addresses = [Address(gateway, address) for address in self.addresses]
if "paypal_accounts" in attributes:
self.paypal_accounts = [PayPalAccount(gateway, paypal_account) for paypal_account in self.paypal_accounts]
|