def account_enquiry(self, account_enquiry_payload, credentials):
        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)

            else:
                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(account_enquiry_payload, credentials)
                url = rpg_environment['ACCOUNT_ENQUIRY_URL']
                if not credentials.connection_timeout:
                    credentials.connection_timeout = 30000
                config = EncryptionConfig()
                payload = {
                    'accountNo':
                    config.AES128(credentials.enc_key,
                                  account_enquiry_payload.account_number,
                                  credentials.enc_vector),
                    'bankCode':
                    config.AES128(credentials.enc_key,
                                  account_enquiry_payload.bank_code,
                                  credentials.enc_vector)
                }

                try:
                    response = requests.post(
                        url,
                        headers=headers,
                        json=payload,
                        timeout=credentials.connection_timeout)

                    account_enquiry_response = BaseResponse(response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return account_enquiry_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)
Ejemplo n.º 2
0
    def payment_status_bulk(self, payment_status_bulk_payload, credentials):

        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)
            else:
                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(payment_status_bulk_payload,
                                          credentials)
                url = rpg_environment['BULK_PAYMENT_STATUS_URL']
                if not credentials.connection_timeout:
                    credentials.connection_timeout = 30000
                config = EncryptionConfig()
                payload = {
                    'batchRef':
                    config.AES128(credentials.enc_key,
                                  payment_status_bulk_payload.batch_ref,
                                  credentials.enc_vector)
                }
                try:
                    response = requests.post(url,
                                             headers=headers,
                                             json=payload)
                    payment_status_bulk_response = BaseResponse(
                        response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return payment_status_bulk_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)
Ejemplo n.º 3
0
    def set_header(self, payment_status_payload, credentials):

        hash_string = credentials.api_key + payment_status_payload.request_id + credentials.api_token

        txn_hash = EncryptionConfig.sha512(hash_string)
        time_stamp = Timestamp()

        headers = {'Content-Type': 'application/json', 'MERCHANT_ID':credentials.merchant_id, 'API_KEY':credentials.api_key,
                   'REQUEST_ID':payment_status_payload.request_id, 'REQUEST_TS':time_stamp.dateTimeObj(dateTimeObj=datetime.now()),
                   'API_DETAILS_HASH': txn_hash}
        return headers
Ejemplo n.º 4
0
    def get_active_banks(self, get_active_banks_payload, credentials):

        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)
            else:
                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(get_active_banks_payload,
                                          credentials)
                url = rpg_environment['GET_ACTIVE_BANKS_URL']
                if not credentials.connection_timeout:
                    credentials.connection_timeout = 30000
                config = EncryptionConfig()
                payload = {}

                try:
                    response = requests.post(
                        url,
                        headers=headers,
                        json=payload,
                        timeout=credentials.connection_timeout)
                    get_active_banks_response = BaseResponse(response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return get_active_banks_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)
Ejemplo n.º 5
0
    def bulk_payment(self, bulk_payment_payload, credentials):

        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)
            else:

                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(bulk_payment_payload, credentials)
                url = rpg_environment['BULK_PAYMENT_URL']
                config = EncryptionConfig()
                encrypted_payment_detail_list = []
                encrypted_bulk_payment_info = {
                    'narration':
                    config.AES128(
                        credentials.enc_key,
                        bulk_payment_payload.bulk_payment_info.narration,
                        credentials.enc_vector),
                    'totalAmount':
                    config.AES128(
                        credentials.enc_key,
                        bulk_payment_payload.bulk_payment_info.total_amount,
                        credentials.enc_vector),
                    'batchRef':
                    config.AES128(
                        credentials.enc_key,
                        bulk_payment_payload.bulk_payment_info.batch_ref,
                        credentials.enc_vector),
                    'debitAccount':
                    config.AES128(
                        credentials.enc_key,
                        bulk_payment_payload.bulk_payment_info.debit_account,
                        credentials.enc_vector),
                    'bankCode':
                    config.AES128(
                        credentials.enc_key,
                        bulk_payment_payload.bulk_payment_info.bank_code,
                        credentials.enc_vector)
                }

                for payment_detail_values in bulk_payment_payload.payment_details:
                    encrypted_payment_details = {}
                    encrypted_payment_details.update({
                        'transRef':
                        config.AES128(credentials.enc_key,
                                      payment_detail_values.trans_ref,
                                      credentials.enc_vector),
                        'narration':
                        config.AES128(credentials.enc_key,
                                      payment_detail_values.narration,
                                      credentials.enc_vector),
                        'benficiaryEmail':
                        config.AES128(credentials.enc_key,
                                      payment_detail_values.benficiary_email,
                                      credentials.enc_vector),
                        'benficiaryBankCode':
                        config.AES128(
                            credentials.enc_key,
                            payment_detail_values.benficiary_bank_code,
                            credentials.enc_vector),
                        'benficiaryAccountNumber':
                        config.AES128(
                            credentials.enc_key,
                            payment_detail_values.benficiary_account_number,
                            credentials.enc_vector),
                        'amount':
                        config.AES128(credentials.enc_key,
                                      str(payment_detail_values.amount),
                                      credentials.enc_vector)
                    })
                    encrypted_payment_detail_list.append(
                        encrypted_payment_details)

                bulk_payment_payload.bulk_payment_info = encrypted_bulk_payment_info
                bulk_payment_payload.payment_details = encrypted_payment_detail_list

                payload = {
                    'bulkPaymentInfo': encrypted_bulk_payment_info,
                    'paymentDetails': encrypted_payment_detail_list
                }

                try:

                    response = requests.post(
                        url,
                        headers=headers,
                        json=payload,
                        timeout=credentials.connection_timeout)
                    bulk_payment_response = BaseResponse(response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return bulk_payment_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)
    def validate_account_otp(self, validate_account_otp_payload, credentials):

        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)
            else:
                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(validate_account_otp_payload,
                                          credentials)
                url = rpg_environment['VALIDATE_ACC_OTP__URL']
                if not credentials.connection_timeout:
                    credentials.connection_timeout = 30000
                config = EncryptionConfig()
                validate_account_otp_payload_list = validate_account_otp_payload.auth_params
                validate_account_otp_payload_otp_value = config.AES128(
                    credentials.enc_key,
                    validate_account_otp_payload_list["OTP"],
                    credentials.enc_vector)
                validate_account_otp_payload_card_value = config.AES128(
                    credentials.enc_key,
                    validate_account_otp_payload_list["Card"],
                    credentials.enc_vector)

                get_otp = {
                    "param1": "OTP",
                    "value": validate_account_otp_payload_otp_value
                }

                get_card = {
                    "param2": "CARD",
                    "value": validate_account_otp_payload_card_value
                }

                get_authParams = [get_otp, get_card]

                payload = {
                    'remitaTransRef':
                    config.AES128(
                        credentials.enc_key,
                        validate_account_otp_payload.remita_trans_ref,
                        credentials.enc_vector),
                    'authParams':
                    get_authParams
                }
                try:
                    response = requests.post(url,
                                             headers=headers,
                                             json=payload)
                    validate_account_otp_response = BaseResponse(
                        response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return validate_account_otp_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)
Ejemplo n.º 7
0
    def single_payment(self, single_payment_payload, credentials):

        try:
            get_response = EnvironmentConfig()
            if not get_response.credential_available(credentials):
                return get_response.throw_exception(
                    status=get_response.empty_credential_code,
                    data=get_response.empty_credential_msg)
            else:
                rpg_environment = EnvironmentConfig.set_rpg_environment(
                    credentials)
                headers = self.set_header(single_payment_payload, credentials)
                url = rpg_environment['SINGLE_PAYMENT_URL']
                if not credentials.connection_timeout:
                    credentials.connection_timeout = 30000
                config = EncryptionConfig()
                payload = {
                    'toBank':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.to_bank,
                                  credentials.enc_vector),
                    'creditAccount':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.credit_account,
                                  credentials.enc_vector),
                    'narration':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.narration,
                                  credentials.enc_vector),
                    'amount':
                    config.AES128(credentials.enc_key,
                                  str(single_payment_payload.amount),
                                  credentials.enc_vector),
                    'transRef':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.trans_ref,
                                  credentials.enc_vector),
                    'fromBank':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.from_bank,
                                  credentials.enc_vector),
                    'debitAccount':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.debit_account,
                                  credentials.enc_vector),
                    'beneficiaryEmail':
                    config.AES128(credentials.enc_key,
                                  single_payment_payload.beneficiary_email,
                                  credentials.enc_vector)
                }

                try:
                    response = requests.post(url,
                                             headers=headers,
                                             json=payload)
                    single_payment_response = BaseResponse(response.content)

                except ConnectTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ValueError:
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_IN_VALUE_CODE,
                        data=SdkResponseCode.ERROR_IN_VALUE)
                except ReadTimeout:
                    return get_response.throw_exception(
                        status=SdkResponseCode.CONNECTION_TIMEOUT_CODE,
                        data=SdkResponseCode.CONNECTION_TIMEOUT)
                except ConnectionError as e:  # This is the correct syntax
                    return get_response.throw_exception(
                        status=SdkResponseCode.ERROR_WHILE_CONNECTING_CODE,
                        data=SdkResponseCode.ERROR_WHILE_CONNECTING)

            return single_payment_response

        except Exception:
            return get_response.throw_exception(
                status=SdkResponseCode.ERROR_PROCESSING_REQUEST_CODE,
                data=SdkResponseCode.ERROR_PROCESSING_REQUEST)