<commit_before>import logging
from zExceptions import Redirect
from zope.i18nmessageid import MessageFactory
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from bda.plone.orders.common import OrderData
from tvl.payment.dps import dps
from tvl.payment.dps.dps_parameters import DPSConfig
from bda.plone.orders import interfaces as ifaces
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from plone import api
from ..interfaces import IPaymentData
from ..interfaces import ISurcharge
from .. import Payment
from .. import Payments
import os
import sys
import traceback


logger = logging.getLogger('bda.plone.payment')
_ = MessageFactory('bda.plone.payment')

DEPLOYMENT = os.environ.get('deployment', '')


class PxPayPayment(Payment):
    pid = 'pxpay_payment'

    @property
    def label(self):
        settings = ISurcharge(self.context)
        if settings.percent_surcharge and settings.fixed_surcharge:
            return _('pxpay_payment',
                     default=u'Credit card - DPS PaymentExpress - '
                             u'surcharge of ${percent}% '
                             u'and ${fixed} ${currency} '
                             u'added to the order total',
                     mapping={
                         'percent': settings.percent_surcharge,
                         'fixed': settings.fixed_surcharge,
                         'currency': settings.currency
                         })
        elif settings.percent_surcharge:
            return _('pxpay_payment',
                     default=u'Credit card - DPS PaymentExpress - '
                             u'${percent}% surcharge '
                             u'added to the order total',
                     mapping={
                         'percent': settings.percent_surcharge,
                         })
        elif settings.fixed_surcharge:
            return _('pxpay_payment',
                     default=u'Credit card - DPS PaymentExpress - '
                             u'surcharge of ${fixed} ${currency} '
                             u'added to the order total',
                     mapping={
                         'fixed': settings.fixed_surcharge,
                         'currency': settings.currency,
                         })
        else:
            return _('pxpay_payment', 'Credit card - DPS PaymentExpress')

    def init_url(self, uid):
        return '%s/@@pxpay_payment?uid=%s' % (api.portal.get().absolute_url(),
                                              uid)


class PxPayError(Exception):
    """Raised if PxPay payment return an error.
    """


class PxPay(BrowserView):

    def __call__(self):
        base_url = api.portal.get().absolute_url()
        order_uid = self.request['uid']
        logger.info('Start')
        try:
            data = IPaymentData(self.context).data(order_uid)
            dps_parms = DPSConfig()
            req = dps.GenerateRequest()
            req.PxPayUserId = dps_parms.PxPayUserId
            req.PxPayKey = dps_parms.PxPayKey
            req.AmountInput = "%0.2f" % (float(data['amount']) / 100.0)
            req.CurrencyInput = data['currency']
            req.MerchantReference = data['ordernumber']
            req.TxnData1 = 'IPurchaseProcess'
            req.TxnData2 = order_uid
            req.add_txn_parameters(ordernumber=data['ordernumber'])<commit_msg>handle ISurcharge not being there yet for install<commit_after>import logging
from zExceptions import Redirect
from zope.i18nmessageid import MessageFactory
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from bda.plone.orders.common import OrderData
from tvl.payment.dps import dps
from tvl.payment.dps.dps_parameters import DPSConfig
from bda.plone.orders import interfaces as ifaces
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityManagement import setSecurityManager
from plone import api
from ..interfaces import IPaymentData
from ..interfaces import ISurcharge
from .. import Payment
from .. import Payments
import os
import sys
import traceback


logger = logging.getLogger('bda.plone.payment')
_ = MessageFactory('bda.plone.payment')

DEPLOYMENT = os.environ.get('deployment', '')


class PxPayPayment(Payment):
    pid = 'pxpay_payment'

    @property
    def label(self):
        try:
            settings = ISurcharge(self.context)
        except TypeError:
            settings = None

        if settings:
            if settings.percent_surcharge and settings.fixed_surcharge:
                return _('pxpay_payment',
                         default=u'Credit card - DPS PaymentExpress - '
                                 u'surcharge of ${percent}% '
                                 u'and ${fixed} ${currency} '
                                 u'added to the order total',
                         mapping={
                             'percent': settings.percent_surcharge,
                             'fixed': settings.fixed_surcharge,
                             'currency': settings.currency
                             })
            elif settings.percent_surcharge:
                return _('pxpay_payment',
                         default=u'Credit card - DPS PaymentExpress - '
                                 u'${percent}% surcharge '
                                 u'added to the order total',
                         mapping={
                             'percent': settings.percent_surcharge,
                             })
            elif settings.fixed_surcharge:
                return _('pxpay_payment',
                         default=u'Credit card - DPS PaymentExpress - '
                                 u'surcharge of ${fixed} ${currency} '
                                 u'added to the order total',
                         mapping={
                             'fixed': settings.fixed_surcharge,
                             'currency': settings.currency,
                             })

        return _('pxpay_payment', 'Credit card - DPS PaymentExpress')

    def init_url(self, uid):
        return '%s/@@pxpay_payment?uid=%s' % (api.portal.get().absolute_url(),
                                              uid)


class PxPayError(Exception):
    """Raised if PxPay payment return an error.
    """


class PxPay(BrowserView):

    def __call__(self):
        base_url = api.portal.get().absolute_url()
        order_uid = self.request['uid']
        logger.info('Start')
        try:
            data = IPaymentData(self.context).data(order_uid)
            dps_parms = DPSConfig()
            req = dps.GenerateRequest()
            req.PxPayUserId = dps_parms.PxPayUserId
            req.PxPayKey = dps_parms.PxPayKey
            req.AmountInput = "%0.2f" % (float(data['amount']) / 100.0)
            req.CurrencyInput = data['currency']
            req.MerchantReference = data['ordernumber']
            req.TxnData1 = 'IPurchaseProcess'
            req.TxnData2 = order_uid
            req.add_txn_parameters(ordernumber=data['ordernumber'])
{'fraction_non_alphanumeric': 0.08571036752605596, 'fraction_numerical': 0.0027427317608337905, 'mean_word_length': 1.793182688625048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4433474', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1853, 'n_words': 432}