'south', 'django_common', "django_braintree", ) BRAINTREE_MERCHANT = 'zyr39d95p83gcf6z' BRAINTREE_PUBLIC_KEY = '5tzg943xmcc24jgd' BRAINTREE_PRIVATE_KEY = 'fb2ca740b92bcc832abeecaf9de63922' from braintree import Configuration, Environment Configuration.configure( Environment.Sandbox, BRAINTREE_MERCHANT, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY ) # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. # See http://docs.djangoproject.com/en/dev/topics/logging for # more details on how to customize your logging configuration. LOGGING = { 'version': 1, 'disable_existing_loggers': False,
from customers.models import Profile from django.contrib.auth.models import User from utilities.format import json_response # Sandbox API Keys API_KEYS = { 'merchant_id': 'qymc7fr9ct6xbd9x', 'public_key': '8d9g5rg8jsm4r2qm', 'private_key': '7d88960a48e944ee76f511ae4f25e1ff', 'cse_key': 'MIIBCgKCAQEAttvzhxtNmLlSJ0nPLwrwOrdtvU8sYVnVG3LYQrgMOI1WOY3J7Crsr1/LHrAVMrIr/IakrU9ChHPVHx33Wyg5czkx3QGEvMO2mme7Kcn2isQbTtowoc05c9qabuRTQR05BMnmUDb1bjZjdUaWXhqgSJgrycBGh1fdc5K1e048J8kaAZPPstntwGdg0CwJy45gNHGotjK02hTnEDDS4qdc5IWcSvPziusP8WG69PIYxqBgFyL9A3DOI25etr6S9l6wIRC63F12dmkqG89PsLIOKelzAHBiEp4B8nlcOsMA+BRG0QZ1ZKNLqkxf883QpE929wwZIeDY8QaiAAcCrbUosQIDAQAB', } Configuration.configure( Environment.Sandbox, API_KEYS['merchant_id'], API_KEYS['public_key'], API_KEYS['private_key'] ) def create_customer(user=None): """ 创建一个braintree.Customer对象 @user: Braintree支持使用自己的 ID 作为客户 ID, 所以这里使用User的 id 作为customer_id来创建用户,不使用email的原因是braintree不支持使用@符号 @return: 返回customer_id """ pass def get_client_token(user=None): """
def capture_payment(self, testing=False, order=None, amount=None): """Process payments without an authorization step.""" braintree_settings = config_get_group('PAYMENT_SATCHMO_BRAINTREE') # Configure Braintree Configuration.configure( Environment.Production if django_settings.IS_PROD else Environment.Sandbox, braintree_settings.MERCHANT_ID.value, braintree_settings.PUBLIC_KEY.value, braintree_settings.PRIVATE_KEY.value ) if order: self.prepare_data(order) else: order = self.order if order.paid_in_full: self.log_extra('%s is paid in full, no capture attempted.', order) results = ProcessorResult(self.key, True, _("No charge needed, paid in full.")) self.record_payment() else: self.log_extra('Capturing payment for %s', order) amount = order.balance result = Transaction.sale({ "amount": amount, # "order_id": "123", "credit_card": { "number": order.credit_card.decryptedCC, "expiration_date": order.credit_card.expirationDate, # 05/2012 ? "cvv": order.credit_card.ccv }, "customer": { "first_name": order.contact.first_name, "last_name": order.contact.last_name, "email": order.contact.email, }, "billing": { "first_name": order.contact.first_name, "last_name": order.contact.last_name, "street_address": order.full_bill_street, "locality": order.bill_city, "region": order.bill_state, "postal_code": order.bill_postal_code, }, "options": { "submit_for_settlement": True } }) if result.is_success: payment = self.record_authorization(order=order, amount=amount, transaction_id=result.transaction.id) response_text = 'Success' else: response_text = '' for error in result.errors.deep_errors: if response_text != '': response_text += ', %s' % error.message else: response_text = error.message payment = self.record_failure(amount=amount) return ProcessorResult(self.key, result.is_success, response_text, payment=payment) # standard = self.get_standard_charge_data(amount=amount) # results = self.send_post(standard, testing) return results
# Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/dev/howto/static-files/ STATIC_URL = '/static/' MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') CART_SESSION_ID = 'cart' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Braintree settings BRAINTREE_MERCHANT_ID = '' BRAINTREE_PUBLIC_KEY = '' BRAINTREE_PRIVATE_KEY = '' from braintree import Configuration, Environment Configuration.configure( Environment.Sandbox, # Environment.Production, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY ) STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static/') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') CART_SESSION_ID = 'cart' # CELERY_ALWAYS_EAGER позволит вам выполнять асинхронные задачи локально в # синхронном режиме вместо отправки их в очередь. Это бывает полезно для # запуска юнит-тестов или запуска приложения локально без установки Celery. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' BRAINTREE_MERCHANT_ID = 'vfs246n6j2c42z69' BRAINTREE_PUBLIC_KEY = '9d24xf2p42qgtw22' BRAINTREE_PRIVATE_KEY = 'd6db579303b1a8dd236fc62311da3538' from braintree import Configuration, Environment Configuration.configure( Environment.Sandbox, # for production, use Environment.Production BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY) REDIS_HOST = 'localhost' REDIS_PORT = 6379 REDIS_DB = 1
STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') MEDIA_URL = '/media/' # this is our local path where our media located MEDIA_ROOT = os.path.join(BASE_DIR, 'media') CART_SESSION_ID = 'cart' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' BRAINTREE_MERCHANT_ID = os.environ.get('Merchant ID') BRAINTREE_PUBLIC_KEY = os.environ.get('Public Key') BRAINTREE_PRIVATE_KEY = os.environ.get('Private Key') Configuration.configure(Environment.Sandbox, merchant_id=BRAINTREE_MERCHANT_ID, private_key=BRAINTREE_PRIVATE_KEY, public_key=BRAINTREE_PUBLIC_KEY) # mimetypes.add_type("text/css", ".css", True) LOCALE_PATHS = [ os.path.join(BASE_DIR, 'locale'), ] INTERNAL_IPS = [ # ... '127.0.0.1', # ... ]
ADMIN_REORDER = ( { 'app': 'market', 'models': ('market.Mask', 'market.Filter') }, { 'app': 'orders', 'models': ('orders.Order', 'orders.SalesStatistic') }, { 'app': 'auth', 'models': ('auth.User', 'auth.Group') }, ) # Количество записей на одной страницев в админ. панеле ADMIN_LIST_PER_PAGE = 20 # ID корзины товаров, используемый для извлечение ее из сессий CART_SESSION_ID = 'cart' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Настройки платежной системы Braintree. BRAINTREE_MERCHANT_ID = 'qsc7ntkzzdxcpx6q' BRAINTREE_PUBLIC_KEY = 'mfx6ktp3zy4bpvbc' BRAINTREE_PRIVATE_KEY = '10601c57d88c730abec38efb7eb87b41' Configuration.configure(Environment.Sandbox, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY)
def capture_payment(self, testing=False, order=None, amount=None): """Process payments without an authorization step.""" if braintree_wrapper_server: transaction_sale = braintree_wrapper_server._sale_transaction else: braintree_settings = config_get_group('PAYMENT_SATCHMO_BRAINTREE') # Configure Braintree Configuration.configure( Environment.Production if getattr(django_settings, 'IS_PROD', False) else Environment.Sandbox, braintree_settings.MERCHANT_ID.value, braintree_settings.PUBLIC_KEY.value, braintree_settings.PRIVATE_KEY.value) transaction_sale = Transaction.sale if order: self.prepare_data(order) else: order = self.order if order.paid_in_full: self.log_extra('%s is paid in full, no capture attempted.', order) results = ProcessorResult(self.key, True, _("No charge needed, paid in full.")) self.record_payment() else: self.log_extra('Capturing payment for %s', order) amount = order.balance if braintree_wrapper_server: data = {} else: data = { "amount": amount, # "order_id": "123", "credit_card": { "number": order.credit_card.decryptedCC, "expiration_date": order.credit_card.expirationDate, # 05/2012 ? "cvv": order.credit_card.ccv }, "customer": { "first_name": order.contact.first_name, "last_name": order.contact.last_name, }, "billing": { "first_name": order.contact.first_name, "last_name": order.contact.last_name, "street_address": order.full_bill_street, "locality": order.bill_city, "region": order.bill_state, "postal_code": order.bill_postal_code, }, "options": { "submit_for_settlement": True } } signals.satcho_braintree_order_validate.send(sender=self, data=data, order=order) result = transaction_sale(data) if result.is_success: payment = self.record_authorization( order=order, amount=amount, transaction_id=result.transaction.id) response_text = 'Success' else: response_text = '' for error in result.errors.deep_errors: response_text += '%s ' % error.message payment = self.record_failure(amount=amount) return ProcessorResult(self.key, result.is_success, response_text, payment=payment) # standard = self.get_standard_charge_data(amount=amount) # results = self.send_post(standard, testing) return results
USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static/') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') CART_SESSION_ID = 'cart' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Настройки Braintree BRAINTREE_MERCHANT_ID = '********' # ID продавца BRAINTREE_PUBLIC_KEY = '********' # Публичный ключ BRAINTREE_PRIVATE_KEY = '********' # Секретный ключ Configuration.configure( Environment.Sandbox, # при публикации приложения, необходимо заменить на Environment.Production BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY )
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' # There're more options here (not only these five) EMAIL_HOST = EMAIL_HOST EMAIL_HOST_USER = EMAIL_HOST_USER EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD EMAIL_PORT = 587 EMAIL_USE_TLS = True # Recommendation engine related REDIS_HOST = 'localhost' REDIS_PORT = 6379 REDIS_DB = 1 # Braintree settings # here: https://www.braintreegateway.com BRAINTREE_MERCHANT_ID = BRT_MERCHANT_ID BRAINTREE_PUBLIC_KEY = BRT_PUBLIC_KEY BRAINTREE_PRIVATE_KEY = BRT_PRIVATE_KEY Configuration.configure( # There's another option 'Production' # Also, it's OKAY that we don't get a auto-completion here :P Environment.Sandbox, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY, )
def capture_payment(self, testing=False, order=None, amount=None): """Process payments without an authorization step.""" if braintree_wrapper_server: transaction_sale = braintree_wrapper_server._sale_transaction else: braintree_settings = config_get_group("PAYMENT_SATCHMO_BRAINTREE") # Configure Braintree Configuration.configure( Environment.Production if getattr(django_settings, "IS_PROD", False) else Environment.Sandbox, braintree_settings.MERCHANT_ID.value, braintree_settings.PUBLIC_KEY.value, braintree_settings.PRIVATE_KEY.value, ) transaction_sale = Transaction.sale if order: self.prepare_data(order) else: order = self.order if order.paid_in_full: self.log_extra("%s is paid in full, no capture attempted.", order) results = ProcessorResult(self.key, True, _("No charge needed, paid in full.")) self.record_payment() else: self.log_extra("Capturing payment for %s", order) amount = order.balance if braintree_wrapper_server: data = {} else: data = { "amount": amount, # "order_id": "123", "credit_card": { "number": order.credit_card.decryptedCC, "expiration_date": order.credit_card.expirationDate, # 05/2012 ? "cvv": order.credit_card.ccv, }, "customer": {"first_name": order.contact.first_name, "last_name": order.contact.last_name}, "billing": { "first_name": order.contact.first_name, "last_name": order.contact.last_name, "street_address": order.full_bill_street, "locality": order.bill_city, "region": order.bill_state, "postal_code": order.bill_postal_code, }, "options": {"submit_for_settlement": True}, } signals.satcho_braintree_order_validate.send(sender=self, data=data, order=order) result = transaction_sale(data) if result.is_success: payment = self.record_authorization(order=order, amount=amount, transaction_id=result.transaction.id) response_text = "Success" else: response_text = "" for error in result.errors.deep_errors: response_text += "%s " % error.message payment = self.record_failure(amount=amount) return ProcessorResult(self.key, result.is_success, response_text, payment=payment) # standard = self.get_standard_charge_data(amount=amount) # results = self.send_post(standard, testing) return results
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(PROJECT_DIR) AUTH_USER_MODEL = "accounts.User" CART_SESSION_ID = "cart" # Braintree settings BRAINTREE_MERCHANT_ID = os.getenv("BRAINTREE_MERCHANT_ID") BRAINTREE_PUBLIC_KEY = os.getenv("BRAINTREE_PUBLIC_KEY") BRAINTREE_PRIVATE_KEY = os.getenv("BRAINTREE_PRIVATE_KEY") BraintreeConfiguration.configure( BraintreeEnvironment.Sandbox, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY, ) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # Application definition INSTALLED_APPS = [ "accounts", "addresses", "cart", "community", "contact", "content_migration",
USE_I18N = True USE_L10N = True USE_TZ = True CART_SESSION_ID = 'cart' # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') # email configs EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER') EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD') EMAIL_USE_TLS = True # Braintree settings Configuration.configure(Environment.Sandbox, os.getenv('BRAINTREE_MERCHANT_ID'), os.getenv('BRAINTREE_PUBLIC_KEY'), os.getenv('BRAINTREE_PRIVATE_KEY'))
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/var/tmp/django_cache', 'TIMEOUT': 60 * 60, 'OPTIONS': { 'MAX_ENTRIES': 10000 } } } BRAINTREE_MERCHANT_ID = 'YOUR_BT_MERCH_ID' BRAINTREE_PUBLIC_KEY = 'YOUR_BT_PUBLIC_KEY' BRAINTREE_PRIVATE_KEY = 'YOUR_BT_PRIVATE_KEY' from braintree import Configuration, Environment Configuration.configure( Environment.Production if IS_PROD else Environment.Sandbox, BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY) # If your django's version is 1.2, you must config the cache like below, # and make sure the directory exists and is readable and writable by the user apache. CACHE_BACKEND = 'file:///var/tmp/django_cache' AWS_ACCESS_KEY_ID = None AWS_SECRET_ACCESS_KEY = None S3_BUCKET_NAME = None # Forced language setting, if you configure this value, the system will display messages/page by using this language. # Default: en-us # If you configure this value, you must provide files: # 1.JS language package file "l10n_[FORCED_LANGUAGE_CODE].js" in the directory MHLogin/media/js/localization FORCED_LANGUAGE_CODE = 'en-us'
USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static/') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') CART_SESSION_ID = 'cart' # EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = config('EMAIL_USER') EMAIL_HOST_PASSWORD = config('EMAIL_PASSWORD') EMAIL_PORT = 587 EMAIL_USE_TLS = True BROKER_URL = 'amqp://localhost' Configuration.configure( Environment.Sandbox, # При продакшене заменить на Environment.Production config('BRAINTREE_MERCHANT_ID'), config('BRAINTREE_PUBLIC_KEY'), config('BRAINTREE_PRIVATE_KEY'))