예제 #1
0
    def send_otp(self, recipient=None, app_id=126) -> dict:
        if not recipient:
            raise ValueError('recipient number should not be empty')

        if not isinstance(app_id, int):
            raise TypeError(
                f'app_id should be of type <str> not {type(app_id)}')

        if not isinstance(recipient, str):
            raise TypeError(
                f'recipient number should be of type<str> not {type(recipient)}'
            )

        try:
            return requests.post(BASE_OTP_URL,
                                 headers=get_header(),
                                 json={
                                     'msisdn': recipient,
                                     'appId': app_id
                                 }).json()

        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                'Connection to Beem OTP API Refused, Please check your internet connections'
            )
예제 #2
0
 def send_sms(self, message: str, recipients, **extra_details):
     try:
         r_body = self.get_body(message, recipients, **extra_details)
         return requests.post(BASE_SMS_URL,
                              headers=get_header(),
                              json=r_body).json()
     except (requests.ConnectionError, requests.ConnectTimeout):
         raise ConnectionError(
             "Connection to Beem SMS API Refused Please check your internt connections"
         )
예제 #3
0
    def get_balance(self, app_name='USSD'):
        try:
            return requests.get(
                BPAY_BALANCE_URL.format(app_name),
                headers=get_header()
            ).json()

        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                'Connection to the USSD Get balance API Refused, Please check your internet connections')
예제 #4
0
 def get_credit_balance(self, app_name='AIRTIME'):
     try:
         return requests.get(
             AIRTIME_BALANCE_URL.format(app_name),
             headers=get_header(),
         ).json()
     except (requests.ConnectionError, requests.ConnectTimeout):
         raise ConnectionError(
             'Connection to Beem Get credit balance API refused, please check your internet connection'
         )
예제 #5
0
    def get_balance(self):
        try:
            return requests.get(
                TWOWAYSMS_BALANCE_URL,
                headers=get_header()
            ).json()

        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                'Connection to the USSD Get balance API Refused, Please check your internet connections')
예제 #6
0
    def get_balance(self, sender_id: str = None):
        if not sender_id:
            sender_id = self.sender_id

        try:
            print(sender_id)
            return requests.post(BASE_BALANCE_URL.format(sender_id),
                                 headers=get_header()).json()

        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                "Connection Refused , Please check your internt connections")
예제 #7
0
    def verify(self, pin_id: str, pin: str) -> dict:
        if not all([isinstance(pin_id, str), isinstance(pin, str)]):
            raise TypeError('Both pin_id and pin should be of type<str>')

        try:
            return requests.post(BASE_VERIFY_URL,
                                 headers=get_header(),
                                 json={
                                     'pinId': pin_id,
                                     'pin': pin
                                 }).json()
        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                'Connection to Beem Verify OTP API Refused, Please check your connections'
            )
예제 #8
0
    def transfer_airtime(self, recipient: str, amount: float) -> dict:
        if not isinstance(recipient, str):
            raise TypeError(
                f'recipient number should be of type<str> not {type(recipient)}'
            )

        if not isinstance(amount, (int, float)):
            raise TypeError(
                f'amount should either be of type<int> or type<float> but not {type(amount)}'
            )
        try:
            return requests.post(TRANSFER_AIRTIME_URL,
                                 headers=get_header(),
                                 json={
                                     'dest_addr': recipient,
                                     'amount': amount
                                 }).json()

        except (requests.ConnectionError, requests.ConnectTimeout):
            raise ConnectionError(
                'Connection to Beem Transfer Airtime API refused, please check your internet connection'
            )