def pre_processor(self, data): # type: (dict) -> dict # Again, the API could return an empty string where it SHOULD return null or an empty object. if ParamValidator.is_empty(data['endUser']): del data['endUser'] if ParamValidator.is_empty(data['transaction']): del data['transaction'] return data
def pre_processor(self, data): # type: (dict) -> dict # 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
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 i, item in data['refundedTransactions'].items(): 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 i, item in data['failedTransactions'].items(): list.append(item) data['failedTransactions'] = list return data
def pre_processor(self, data): # type: (dict) -> dict # 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
def perform_request(self, request, method='POST'): # type: (RequestBase, str) -> NoneResponse """ Performs the actual call to the API and fill the responses. This method will basically verify the given :class:`paynlsdk2.api.requestbase.RequestBase` class, perform the call to the API, interpret the result and fill the request's :ivar:`paynlsdk2.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:`paynlsdk2.api.responsebase.ResponseBase` instance .. seealso:: :class:`paynlsdk2.api.requestbase.RequestBase` and all it's derived classes :class:`paynlsdk2.api.responsebase.ResponseBase` and all it's derived classes :param request: the generic request to perform :type request: paynlsdk2.api.requestbase.RequestBase :param method: HTTP method (stick to POST!) :type method: str :return: void :rtype: void :raise paynlsdk2.exceptions.ErrorException: generic error occurred :raise paynlsdk2.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)
def _merge_end_user_dict(self, innerdict): # type: (dict) -> None 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