def pre_processor(self, data):
     #  API might return empty string instead of dictionary object
     if ParamValidator.is_empty(data['settings']):
         del data['settings']
     #  API might return empty string instead of dictionary object
     if ParamValidator.is_empty(data['paymentOptions']):
             del data['paymentOptions']
     elif 'paymentOptions' in data and ParamValidator.not_empty(data['paymentOptions']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for i, item in data['paymentOptions'].items():
             list.append(item)
         data['paymentOptions'] = list
     #  API might return empty string instead of dictionary object
     if ParamValidator.is_empty(data['countryOptionList']):
         del data['countryOptionList']
     elif 'countryOptionList' in data and ParamValidator.not_empty(data['countryOptionList']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for i, item in data['countryOptionList'].items():
             list.append(item)
         data['countryOptionList'] = list
     #  API might return empty string instead of dictionary object
     if 'paymentProfiles' in data and ParamValidator.is_empty(data['paymentProfiles']):
         del data['paymentProfiles']
     elif 'paymentProfiles' in data and ParamValidator.not_empty(data['paymentProfiles']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for i, item in data['paymentProfiles'].items():
             list.append(item)
         data['paymentProfiles'] = list
     return data
Exemple #2
0
 def get_parameters(self):
     # Validation
     ParamValidator.assert_not_empty(self.amount, 'amount')
     ParamValidator.assert_not_empty(self.ip_address, 'ip_address')
     ParamValidator.assert_not_empty(self.finish_url, 'finish_url')
     if ParamValidator.not_empty(
             self.transfer_value) and (self.transfer_type == 'transaction'
                                       or self.transfer_type == 'merchant'):
         raise ValueError(
             'TransferValue cannot be set without valid TransferType, please fix this.'
         )
     # Default api parameters
     rs = self.get_std_parameters()
     #  Append our own parameters
     rs['amount'] = self.amount
     rs['ipAddress'] = self.ip_address
     rs['finishUrl'] = self.finish_url
     if ParamValidator.not_empty(self.payment_option_id):
         rs['paymentOptionId'] = self.payment_option_id
     if ParamValidator.not_empty(self.payment_option_sub_id):
         rs['paymentOptionSubId'] = self.payment_option_sub_id
     if self.test_mode:
         rs['testMode'] = 1
     else:
         rs['testMode'] = 0
     if ParamValidator.not_empty(self.transfer_type):
         rs['transferType'] = self.transfer_type
     if ParamValidator.not_empty(self.transfer_value):
         rs['transferValue'] = self.transfer_value
     # Now handle complex types
     self._merge_transaction_dict(rs)
     self._merge_stats_data_dict(rs)
     self._merge_sales_data_dict(rs)
     self._merge_end_user_dict(rs)
     return rs
Exemple #3
0
    def _merge_stats_data_dict(self, innerdict):
        if ParamValidator.is_null(self.stats_data):
            innerdict[
                'statsData[object]'] = 'pythonsdk v' + PAYNL_CLIENT_VERSION
            return
        if ParamValidator.is_empty(self.stats_data.object):
            innerdict[
                'statsData[object]'] = 'pythonsdk v' + PAYNL_CLIENT_VERSION

        if ParamValidator.not_empty(self.stats_data.promotor_id):
            innerdict['statsData[promotorId]'] = self.stats_data.promotor_id
        if ParamValidator.not_empty(self.stats_data.info):
            innerdict['statsData[info]'] = self.stats_data.info
        if ParamValidator.not_empty(self.stats_data.tool):
            innerdict['statsData[tool]'] = self.stats_data.tool
        if ParamValidator.not_empty(self.stats_data.extra1):
            innerdict['statsData[extra1]'] = self.stats_data.extra1
        if ParamValidator.not_empty(self.stats_data.extra2):
            innerdict['statsData[extra2]'] = self.stats_data.extra2
        if ParamValidator.not_empty(self.stats_data.extra3):
            innerdict['statsData[extra3]'] = self.stats_data.extra3
        if ParamValidator.not_empty(self.stats_data.domain_id):
            innerdict['statsData[domainId]'] = self.stats_data.domain_id
        if ParamValidator.not_empty(self.stats_data.object):
            innerdict['statsData[object]'] = self.stats_data.object
Exemple #4
0
 def get_parameters(self):
     # Validation
     ParamValidator.assert_not_empty(self.transaction_id, 'transaction_id')
     # Get default api parameters
     rs = self.get_std_parameters()
     # Add own parameters
     rs['transactionId'] = self.transaction_id
     if ParamValidator.not_empty(self.amount):
         rs['amount'] = self.amount
     if ParamValidator.not_empty(self.description):
         rs['description'] = self.description
     if ParamValidator.not_empty(self.process_date):
         rs['processDate'] = self.process_date
     return rs
 def get_parameters(self):
     # Get default api parameters
     rs = self.get_std_parameters()
     # Add own parameters
     if ParamValidator.not_empty(self.payment_method_id):
         rs['paymentMethodId'] = self.payment_method_id
     return rs
Exemple #6
0
 def get_parameters(self):
     # Validation
     ParamValidator.assert_not_empty(self.transaction_id, 'transaction_id')
     # Get default api parameters
     rs = self.get_std_parameters()
     # Add own parameters
     rs['transactionId'] = self.transaction_id
     if ParamValidator.not_empty(self.entrance_code):
         rs['entranceCode'] = self.entrance_code
     return rs
Exemple #7
0
 def get_parameters(self):
     # Validation
     ParamValidator.assert_not_empty(self.transaction_id, 'transaction_id')
     # Get default api parameters
     rs = self.get_std_parameters()
     # Add own parameters
     rs['transactionId'] = self.transaction_id
     if self.products.__len__() > 0:
         rs['products'] = self.products
     if ParamValidator.not_empty(self.tracktrace):
         rs['tracktrace'] = self.tracktrace
     return rs
Exemple #8
0
 def _merge_sales_data_dict(self, innerdict):
     if ParamValidator.is_null(self.sale_data):
         return
     if not ParamValidator.is_null(self.sale_data.delivery_date):
         innerdict[
             'saleData[deliveryDate]'] = self.sale_data.delivery_date.strftime(
                 '%d-%m-%Y')
     if not ParamValidator.is_null(self.sale_data.invoice_date):
         innerdict[
             'saleData[invoiceDate]'] = self.sale_data.invoice_date.strftime(
                 '%d-%m-%Y')
     if ParamValidator.not_empty(self.sale_data.order_data) and len(
             self.sale_data.order_data) > 0:
         i = 0
         for item in self.sale_data.order_data:
             ParamValidator.assert_not_empty(
                 item.product_id, 'sales_data.order_data.product_id')
             ParamValidator.assert_not_empty(item.price,
                                             'sales_data.order_data.price')
             ParamValidator.assert_not_empty(
                 item.quantity, 'sales_data.order_data.quantity')
             innerdict['saleData[orderData][{}][productId]'.format(
                 i)] = item.product_id
             innerdict['saleData[orderData][{}][price]'.format(
                 i)] = item.price
             innerdict['saleData[orderData][{}][quantity]'.format(
                 i)] = item.quantity
             if ParamValidator.not_empty(item.description):
                 innerdict['saleData[orderData][{}][description]'.format(
                     i)] = item.description
             if ParamValidator.not_empty(item.vat_code):
                 innerdict['saleData[orderData][{}][vatCode]'.format(
                     i)] = item.vat_code
             if ParamValidator.not_empty(item.vat_percentage):
                 innerdict['saleData[orderData][{}][vatPercentage]'.format(
                     i)] = item.vat_percentage
             if ParamValidator.not_empty(item.product_type):
                 innerdict['saleData[orderData][{}][productType]'.format(
                     i)] = item.product_type
Exemple #9
0
 def preprocess(self, data):
     # Fix EMPTY settings
     if ParamValidator.is_empty(data['settings']):
         del data['settings']
     if ParamValidator.is_empty(data['countryOptionList']):
         del data['countryOptionList']
     elif 'countryOptionList' in data and ParamValidator.not_empty(data['countryOptionList']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for i, item in data['countryOptionList'].items():
             list.append(item)
         data['countryOptionList'] = list
     return data
Exemple #10
0
 def pre_processor(self, data):
     # Again, the API returns an empty string where it SHOULD return null or an empty list.
     if 'refundedTransactions' in data and ParamValidator.is_empty(
             data['refundedTransactions']):
         data['refundedTransactions'] = []
     elif 'refundedTransactions' in data and ParamValidator.not_empty(
             data['refundedTransactions']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for item in data['refundedTransactions']:
             list.append(item)
         data['refundedTransactions'] = list
     if 'failedTransactions' in data and ParamValidator.is_empty(
             data['failedTransactions']):
         data['failedTransactions'] = []
     elif 'failedTransactions' in data and ParamValidator.not_empty(
             data['failedTransactions']):
         #  v2.x has NO fields.Dict implementation like fields.List, so we'll have to handle this ourselves
         list = []
         for item in data['failedTransactions']:
             list.append(item)
         data['failedTransactions'] = list
     return data
Exemple #11
0
 def _merge_stats_data_dict(self, innerdict):
     if ParamValidator.is_null(self.stats_data):
         return
     if ParamValidator.not_empty(self.stats_data.promotor_id):
         innerdict['statsData[promotorId]'] = self.stats_data.promotor_id
     if ParamValidator.not_empty(self.stats_data.info):
         innerdict['statsData[info]'] = self.stats_data.info
     if ParamValidator.not_empty(self.stats_data.tool):
         innerdict['statsData[tool]'] = self.stats_data.tool
     if ParamValidator.not_empty(self.stats_data.extra1):
         innerdict['statsData[extra1]'] = self.stats_data.extra1
     if ParamValidator.not_empty(self.stats_data.extra2):
         innerdict['statsData[extra2]'] = self.stats_data.extra2
     if ParamValidator.not_empty(self.stats_data.extra3):
         innerdict['statsData[extra3]'] = self.stats_data.extra3
     if ParamValidator.not_empty(self.stats_data.domain_id):
         innerdict['statsData[domainId]'] = self.stats_data.domain_id
Exemple #12
0
 def get_parameters(self):
     # Validation
     ParamValidator.assert_not_empty(self.transaction_id, 'transaction_id')
     # Get default api parameters
     rs = self.get_std_parameters()
     # Add own parameters
     rs['transactionId'] = self.transaction_id
     if ParamValidator.not_empty(self.amount):
         rs['amount'] = self.amount
     if ParamValidator.not_empty(self.description):
         rs['description'] = self.description
     if ParamValidator.not_empty(self.process_date):
         rs['processDate'] = self.process_date
     if ParamValidator.not_empty(self.products):
         rs['products'] = self.products
     if ParamValidator.not_empty(self.vat_percentage):
         rs['fVatPercentage'] = self.vat_percentage
     if ParamValidator.not_empty(self.exchange_url):
         rs['exchangeUrl'] = self.exchange_url
     return rs
Exemple #13
0
 def _merge_transaction_dict(self, innerdict):
     if ParamValidator.is_null(self.transaction):
         return
     if ParamValidator.not_empty(self.transaction.currency):
         innerdict['transaction[currency]'] = self.transaction.currency
     if ParamValidator.not_empty(self.transaction.costs_vat):
         innerdict['transaction[costsVat]'] = self.transaction.costs_vat
     if ParamValidator.not_empty(self.transaction.order_exchange_url):
         innerdict[
             'transaction[orderExchangeUrl]'] = self.transaction.order_exchange_url
     if ParamValidator.not_empty(self.transaction.description):
         innerdict[
             'transaction[description]'] = self.transaction.description
     if ParamValidator.not_empty(self.transaction.expire_date):
         innerdict[
             'transaction[expireDate]'] = self.transaction.expire_date.strftime(
                 '%d-%m-%Y %H:%M:%s')
     if ParamValidator.not_empty(self.transaction.order_number):
         innerdict[
             'transaction[orderNumber]'] = self.transaction.order_number
Exemple #14
0
    def perform_request(self, request: RequestBase, method: str = 'POST'):
        """
        Performs the actual call to the API and fill the responses.

        This method will basically verify the given :class:`paynlsdk.api.requestbase.RequestBase` class,
        perform the call to the API, interpret the result and fill the request's
        :ivar:`paynlsdk.api.requestbase.RequestBase.response`.
        Interpreting the result is done by evaluating the returned JSON using marshmallow.
        When validation is complete, the request class will internally set the response, which is always an instance
        of a :class:`paynlsdk.api.responsebase.ResponseBase` instance

        .. seealso::
            :class:`paynlsdk.api.requestbase.RequestBase` and all it's derived classes

            :class:`paynlsdk.api.responsebase.ResponseBase` and all it's derived classes

        :param request: the generic request to perform
        :type request: paynlsdk.api.requestbase.RequestBase
        :param method: HTTP method (stick to POST!)
        :type method: str
        :return: void
        :rtype: void
        :raise paynlsdk.exceptions.ErrorException: generic error occurred
        :raise paynlsdk.exceptions.SchemaException: error occurred during result parsing (schema load/validation failure)
        """
        headers = {
            'Accept': 'application/json',
            'User-Agent': self.user_agent()
        }
        if APIAuthentication.use_http_auth:
            headers['Authorization'] = 'Basic {auth}'.format(
                auth=self.get_auth())

        # Lazy loader for api credentials.
        if request.requires_api_token() and ParamValidator.is_empty(request.api_token)\
                and ParamValidator.not_empty(APIAuthentication.api_token):
            request.api_token = APIAuthentication.api_token
        if request.requires_service_id() and ParamValidator.is_empty(request.service_id)\
                and ParamValidator.not_empty(APIAuthentication.service_id):
            request.service_id = APIAuthentication.service_id

        # Build url
        url = "{0}/{1}".format(PAYNL_END_POINT, request.get_url())
        parameters = request.get_parameters()
        if APIAuthentication.use_http_auth and 'token' in parameters:
            del parameters['token']

        if self.print_debug:
            print("Calling {} using {}".format(url, method))
            print("HTTP Headers: {}".format(json.dumps(headers)))
            print("Params: {}".format(json.dumps(parameters)))

        if method.upper() == 'GET':
            response = requests.get(url,
                                    verify=True,
                                    headers=headers,
                                    params=parameters)
        else:
            response = requests.post(url,
                                     verify=True,
                                     headers=headers,
                                     data=parameters)

        if response.status_code not in self.__supported_status_codes:
            response.raise_for_status()

        if self.print_debug:
            print("Response object: {}".format(response))
            print("Raw response: {}".format(response.text))

        # Now the we have a response, let the request class handle the response.
        request.raw_response = response.text

        if self.print_debug:
            print(type(request.response))

        if request.response.is_error():
            raise ErrorException(request.response.request)
Exemple #15
0
 def _merge_end_user_dict(self, innerdict):
     if ParamValidator.is_null(self.end_user):
         return
     if ParamValidator.not_empty(self.end_user.access_code):
         innerdict['enduser[accessCode]'] = self.end_user.access_code
     if ParamValidator.not_empty(self.end_user.language):
         innerdict['enduser[language]'] = self.end_user.language
     if ParamValidator.not_empty(self.end_user.initials):
         innerdict['enduser[initials]'] = self.end_user.initials
     if ParamValidator.not_empty(self.end_user.last_name):
         innerdict['enduser[lastName]'] = self.end_user.last_name
     if ParamValidator.not_empty(self.end_user.gender):
         innerdict['enduser[gender]'] = self.end_user.gender
     if ParamValidator.not_empty(self.end_user.dob):
         innerdict['enduser[dob]'] = self.end_user.dob.strftime('%d-%m-%Y')
     if ParamValidator.not_empty(self.end_user.phone_number):
         innerdict['enduser[phoneNumber]'] = self.end_user.phone_number
     if ParamValidator.not_empty(self.end_user.email_address):
         innerdict['enduser[emailAddress]'] = self.end_user.email_address
     if ParamValidator.not_empty(self.end_user.bank_account):
         innerdict['enduser[bankAccount]'] = self.end_user.bank_account
     if ParamValidator.not_empty(self.end_user.iban):
         innerdict['enduser[iban]'] = self.end_user.iban
     if ParamValidator.not_empty(self.end_user.bic):
         innerdict['enduser[bic]'] = self.end_user.bic
     if self.end_user.send_confirm_email:
         innerdict['enduser[sendConfirmMail]'] = 1
     else:
         innerdict['enduser[sendConfirmMail]'] = 0
     if ParamValidator.not_empty(self.end_user.customer_reference):
         innerdict[
             'enduser[customerReference]'] = self.end_user.customer_reference
     if ParamValidator.not_empty(self.end_user.customer_trust):
         innerdict['enduser[customerTrust]'] = self.end_user.customer_trust
     if not ParamValidator.is_null(self.end_user.address):
         if not ParamValidator.is_empty(self.end_user.address.street_name):
             innerdict[
                 'enduser[address][streetName]'] = self.end_user.address.street_name
         if not ParamValidator.is_empty(
                 self.end_user.address.street_number):
             innerdict[
                 'enduser[address][streetNumber]'] = self.end_user.address.street_number
         if not ParamValidator.is_empty(
                 self.end_user.address.street_number_extension):
             innerdict[
                 'enduser[address][streetNumberExtension]'] = self.end_user.address.street_number_extension
         if not ParamValidator.is_empty(self.end_user.address.zip_code):
             innerdict[
                 'enduser[address][zipCode]'] = self.end_user.address.zip_code
         if not ParamValidator.is_empty(self.end_user.address.city):
             innerdict[
                 'enduser[address][city]'] = self.end_user.address.city
         if not ParamValidator.is_empty(self.end_user.address.region_code):
             innerdict[
                 'enduser[address][regionCode]'] = self.end_user.address.region_code
         if not ParamValidator.is_empty(self.end_user.address.country_code):
             innerdict[
                 'enduser[address][countryCode]'] = self.end_user.address.country_code
     if not ParamValidator.is_null(self.end_user.invoice_address):
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.initials):
             innerdict[
                 'enduser[invoiceAddress][initials]'] = self.end_user.invoice_address.initials
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.last_name):
             innerdict[
                 'enduser[invoiceAddress][lastName]'] = self.end_user.invoice_address.last_name
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.gender):
             innerdict[
                 'enduser[invoiceAddress][gender]'] = self.end_user.invoice_address.gender
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.street_name):
             innerdict[
                 'enduser[invoiceAddress][streetName]'] = self.end_user.invoice_address.street_name
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.street_number):
             innerdict[
                 'enduser[invoiceAddress][streetNumber]'] = self.end_user.invoice_address.street_number
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.street_number_extension):
             innerdict[
                 'enduser[invoiceAddress][streetNumberExtension]'] = self.end_user.invoice_address.street_number_extension
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.zip_code):
             innerdict[
                 'enduser[invoiceAddress][zipCode]'] = self.end_user.invoice_address.zip_code
         if not ParamValidator.is_empty(self.end_user.invoice_address.city):
             innerdict[
                 'enduser[invoiceAddress][city]'] = self.end_user.invoice_address.city
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.region_code):
             innerdict[
                 'enduser[invoiceAddress][regionCode]'] = self.end_user.invoice_address.region_code
         if not ParamValidator.is_empty(
                 self.end_user.invoice_address.country_code):
             innerdict[
                 'enduser[invoiceAddress][countryCode]'] = self.end_user.invoice_address.country_code
     if not ParamValidator.is_null(self.end_user.company):
         if not ParamValidator.is_empty(self.end_user.company.name):
             innerdict[
                 'enduser[company][name]'] = self.end_user.company.name
         if not ParamValidator.is_empty(self.end_user.company.coc_number):
             innerdict[
                 'enduser[company][cocNumber]'] = self.end_user.company.coc_number
         if not ParamValidator.is_empty(self.end_user.company.vat_number):
             innerdict[
                 'enduser[company][vatNumber]'] = self.end_user.company.vat_number
         if not ParamValidator.is_empty(self.end_user.company.country_code):
             innerdict[
                 'enduser[company][countryCode]'] = self.end_user.company.country_code