Skip to content

Commit

Permalink
Merge pull request kliment#23 from paymill/feature/expose_http_logging
Browse files Browse the repository at this point in the history
Feature/expose http logging
  • Loading branch information
yalnazov committed Nov 18, 2015
2 parents 5e318d1 + e3bb458 commit 6d05423
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions paymill/paymill_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class PaymillContext(object):
Use the getter methods in order to access the required PAYMILL service.
"""

def __init__(self, api_key):
def __init__(self, api_key, http_debug_enabled=False):
"""
:param str api_key: your PAYMILL private key
:rtype : PaymillContext
"""
self.api_url = 'https://api.paymill.com/v2.1'
self.api_key = api_key
self.http_client = http_client.HTTPClient(self.api_url, api_key, "")
self.http_client = http_client.HTTPClient(self.api_url, api_key, "", http_debug_enabled)
self.client_service = client_service.ClientService(self.http_client)
self.offer_service = offer_service.OfferService(self.http_client)
self.payment_service = payment_service.PaymentService(self.http_client)
Expand Down
11 changes: 5 additions & 6 deletions paymill/services/checksum_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ def create(self, checksum_type, amount, currency, return_url, cancel_url, descri
fee_amount=None, fee_payment=None, fee_currency=None, checkout_options=None, require_reusable_payment=None,
reusable_payment_description=None, items=None, shipping_address=None, billing_address=None, app_id=None):
"""Creates new transaction/payment Checksum
:param str checksum_type : Type of request verified by this checksum
:param str checksum_type: Type of request verified by this checksum
:param int amount: Amount (in cents) which will be charged
:param str currency: ISO 4217 formatted currency code
:param str return_url: The identifier of a client
:param int cancel_url: Fee included in the transaction amount (set by a connected app).
:param str return_url: URL to redirect customers to after checkout has completed.
:param int cancel_url: URL to redirect customers to after they have canceled the checkout.
:param str description: A short description for the transaction
:param str checksum_action: The identifier of the payment from which the fee will be charged
:param str checksum_action: enum(transaction, payment) or null_ Requested action verified by this checksum (default: transaction)
:param int fee_amount: Fee included in the transaction amount (set by a connected app). Mandatory if fee_payment is set.
:param str fee_payment: The identifier of the payment from which the fee will be charged (Payment object).
:param str fee_currency: The currency of the fee (e.g. EUR, USD). If it´s not set, the currency of the transaction is used.
We suggest to always use as it might cause problems, if your account does not support the same currencies as your merchants accounts.
:param list checkout_options: Various options that determine behavior before/during/after checkout such as editability of address fields.
:param boolean require_reusable_payment: Set this to true if you want to ask the buyer for a billing agreement during checkout.
If the buyer accepts, the resulting payment can be reused for transactions and subscriptions without additional interaction.
:param str reusable_payment_description: Description appears at the acquirers checkout page (e.g. PayPal) when you request permission for a reusable payment, max. 127 characters.
:param list of ShoppingCartItem items: Shopping cart items purchased with this transaction.
:param Address shipping_address: Billing address for this transaction.
:param Address shipping_address: Shipping address for this transaction.
:param Address billing_address: Billing address for this transaction.
:params str app_id: App (ID) that created this payment or null if created by yourself.
:return Checksum: the created Checksum object
Expand Down
20 changes: 7 additions & 13 deletions paymill/utils/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
from requests import Session
from ..utils import abstract_http_client
from .pm_error import PMError
import logging
# these two lines enable debugging at httplib level (requests->urllib3->httplib)
# you will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# the only thing missing will be the response.body which is not logged.
from six.moves import http_client
http_client.HTTPConnection.debuglevel = 1

logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests
logging.getLogger().setLevel(logging.INFO)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.ERROR)
requests_log.propagate = True

def http_debug(enabled=False):
if enabled:
# these two lines enable debugging at httplib level (requests->urllib3->httplib)
from six.moves import http_client
http_client.HTTPConnection.debuglevel = 1

class HTTPClient(abstract_http_client.AbstractHTTPClient):
def __init__(self, base_url, user_name, user_pass=''):
def __init__(self, base_url, user_name, user_pass='', http_debug_enabled=False):
"""Initialize a new paymill interface connection. Requires a private key."""
self.base_url = base_url
self.session = Session()
Expand All @@ -27,6 +20,7 @@ def __init__(self, base_url, user_name, user_pass=''):
self.operations = dict(GET=self.get, POST=self.post, PUT=self.put, DELETE=self.delete)
#for internal usage
self.response = None
http_debug(enabled=http_debug_enabled)

def __call__(self, request_type, params, url, return_type):
try:
Expand Down

0 comments on commit 6d05423

Please sign in to comment.