コード例 #1
0
 def test_bank_account_method_without_required_arguments_fails(self):
     with self.assertRaises(exceptions.InvalidArgumentError):
         json_builder.bank_account(first_name=None,
                                   last_name=None,
                                   account_name=None,
                                   account_number=None,
                                   bank_branch_id=None,
                                   bank_id=None,
                                   name=None)
コード例 #2
0
 def test_bank_account_method_with_non_str_required_arguments_fails(self):
     with self.assertRaises(exceptions.InvalidArgumentError):
         json_builder.bank_account(first_name='Stannis',
                                   last_name='Baratheon',
                                   account_name=1547,
                                   account_number={'Arya Strak': 'The North remembers'},
                                   bank_branch_id=('Father', 'Smith', 'Warrior'),
                                   bank_id=['Mother', 'Maiden', 'Crone'],
                                   name=89.235)
コード例 #3
0
 def test_bank_account_method_with_all_required_arguments_succeeds(self):
     bank_account_json = json_builder.bank_account(first_name='Stannis',
                                                   last_name='Baratheon',
                                                   account_name='Stannis Baratheon',
                                                   account_number='IRNBNK0056',
                                                   bank_branch_id='IRNBNKBRAVOS875',
                                                   bank_id='78456',
                                                   name='Stannis Baratheon')
     self.assertIsNotNone(bank_account_json)
コード例 #4
0
 def test_bank_account_method_with_all_required_arguments_plus_permitted_kwargs_succeeds(self):
     bank_account_json = json_builder.bank_account(first_name='Stannis',
                                                   last_name='Baratheon',
                                                   account_name='Stannis Baratheon',
                                                   account_number='IRNBNK0056',
                                                   bank_branch_id='IRNBNKBRAVOS875',
                                                   bank_id='78456',
                                                   name='Stannis Baratheon',
                                                   email='*****@*****.**',
                                                   phone='+87546214588')
     self.assertIsNotNone(bank_account_json)
コード例 #5
0
 def test_successful_add_bank_receipient_request(self):
     response = requests.post(
         headers=PayTestCase.header,
         json=json_builder.pay_recipient(
             "bank_account",
             json_builder.bank_account(
                 account_name="David Kariuki Python",
                 account_number="566566",
                 settlement_method="EFT",
                 bank_branch_ref="633aa26c-7b7c-4091-ae28-96c0687cf886",
             )),
         data=None,
         url=PayTestCase.pay_obj._build_url(pay.ADD_PAY_PATH))
     self.assertEqual(response.status_code, 201)
コード例 #6
0
ファイル: pay.py プロジェクト: DavidKar1uk1/k2-connect-python
    def add_pay_recipient(self, kwargs):
        """
        Adds external entities that will be the destination of your payments.
        Returns a request response object < class, 'requests.models.Response'>
        :param kwargs: The values constitute all user input.
        :type kwargs: dict
        :return:'requests.models.Response'
        """
        if 'access_token' not in kwargs:
            raise exceptions.InvalidArgumentError('Access Token not given.')
        if 'recipient_type' not in kwargs:
            raise exceptions.InvalidArgumentError('Recipient Type not given.')
        if 'access_token' in kwargs:
            bearer_token = kwargs['access_token']
        if 'recipient_type' in kwargs:
            recipient_type = kwargs['recipient_type']

        # define headers
        headers = dict(self._headers)

        validation.validate_string_arguments(bearer_token)

        # add bearer token
        headers['Authorization'] = 'Bearer ' + bearer_token

        # build url
        add_pay_url = self._build_url(url_path=ADD_PAY_PATH)

        if 'email' in kwargs:
            validation.validate_email(str(kwargs['email']))
        if 'phone_number' in kwargs:
            validation.validate_phone_number(str(kwargs['phone_number']))

        # expected parameters for bank account wallet recipient
        if recipient_type == BANK_ACCOUNT_RECIPIENT_TYPE:
            if 'account_name' not in kwargs or \
                    'account_number' not in kwargs or \
                    'settlement_method' not in kwargs or \
                    'bank_branch_ref' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for bank account Pay recipient')

            # build recipient json object
            recipient_object = json_builder.bank_account(
                account_name=str(kwargs['account_name']),
                account_number=str(kwargs['account_number']),
                settlement_method=str(kwargs['settlement_method']),
                bank_branch_ref=str(kwargs['bank_branch_ref']))
            # build bank payment recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)
        # expected parameters for mobile wallet recipient
        # ['first_name', 'last_name',
        # network','phone_number','email']

        elif recipient_type == MOBILE_WALLET_RECIPIENT_TYPE:
            if 'first_name' not in kwargs or \
                    'last_name' not in kwargs or \
                    'phone_number' not in kwargs or \
                    'email' not in kwargs or \
                    'network' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for mobile wallet Pay recipient')

            # create recipient json object
            recipient_object = json_builder.mobile_wallet(
                first_name=str(kwargs['first_name']),
                last_name=str(kwargs['last_name']),
                phone_number=str(kwargs['phone_number']),
                network=str(kwargs['network']),
                email=str(kwargs['email']))

            # create mobile wallet recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)

        elif recipient_type == TILL_RECIPIENT_TYPE:
            if 'till_name' not in kwargs or \
                    'till_number' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for till Pay recipient')

            # create recipient json object
            recipient_object = json_builder.till_pay_recipient(
                till_name=str(kwargs['till_name']),
                till_number=str(kwargs['till_number']))

            # create mobile wallet recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)
        # expected parameters for mobile wallet recipient
        # ['till_name', 'till_number']

        elif recipient_type == PAYBILL_RECIPIENT_TYPE:
            if 'paybill_name' not in kwargs or \
                    'paybill_number' not in kwargs or \
                    'paybill_account_number' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for paybill Pay recipient')

            # create recipient json object
            recipient_object = json_builder.paybill_pay_recipient(
                paybill_name=str(kwargs['paybill_name']),
                paybill_number=str(kwargs['paybill_number']),
                paybill_account_number=str(kwargs['paybill_account_number']))

            # create mobile wallet recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)
        # expected parameters for mobile wallet recipient
        # ['alias_name', 'till_number']

        else:
            raise exceptions.InvalidArgumentError(
                'The recipient type is not recognized by k2connect')

        return self._make_requests(headers=headers,
                                   method='POST',
                                   url=add_pay_url,
                                   payload=payment_recipient_object)
コード例 #7
0
ファイル: pay.py プロジェクト: PhilipWafula/k2-connect-python
    def add_pay_recipient(self, bearer_token, recipient_type, **kwargs):
        """
        Adds external entities that will be the destination of your payments.
        Returns a request response object < class, 'requests.models.Response'>
        :param bearer_token: Access token to be used to make calls to
        the Kopo Kopo API
        :type bearer_token: str
        :param recipient_type: The type of wallet to which pay will be sent.
                Example:
                    recipient_type = BANK_ACCOUNT_RECIPIENT_TYPE
        :type recipient_type: str
        :param kwargs: The values thAccess token to be used to make calls to
        the Kopo Kopo APIat constitute recipient types.
        :type kwargs: dict

        :return:'requests.models.Response'
        """
        # define headers
        headers = dict(self._headers)

        validation.validate_string_arguments(bearer_token)

        # add bearer token
        headers['Authorization'] = 'Bearer ' + bearer_token + ''

        # build url
        add_pay_url = self._build_url(url_path=ADD_PAY_PATH)

        if 'email' in kwargs:
            validation.validate_email(str(kwargs['email']))
        if 'phone' in kwargs:
            validation.validate_phone_number(str(kwargs['phone']))

        # expected parameters for bank account wallet recipient
        # ['account_name', 'account_number',
        # 'bank_branch_id','bank_id', name']
        if recipient_type == BANK_ACCOUNT_RECIPIENT_TYPE:
            if 'account_name' not in kwargs or \
                    'account_number' not in kwargs or \
                    'bank_branch_id' not in kwargs or \
                    'bank_id' not in kwargs or \
                    'name' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for bank account')

            # build recipient json object
            recipient_object = json_builder.bank_account(
                account_name=str(kwargs['account_name']),
                account_number=str(kwargs['account_number']),
                bank_branch_id=str(kwargs['bank_branch_id']),
                bank_id=str(kwargs['bank_id']),
                name=str(kwargs['name']),
                email=None,
                phone=None)

            # build bank payment recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)
        # expected parameters for mobile wallet recipient
        # ['first_name', 'last_name',
        # network','phone','email']

        elif recipient_type == MOBILE_WALLET_RECIPIENT_TYPE:
            if 'first_name' not in kwargs or \
                    'last_name' not in kwargs or \
                    'phone' not in kwargs or \
                    'network' not in kwargs:
                raise exceptions.InvalidArgumentError(
                    'Invalid arguments for mobile wallet')

            # create recipient json object
            recipient_object = json_builder.mobile_wallet(
                first_name=str(kwargs['first_name']),
                last_name=str(kwargs['last_name']),
                phone=str(kwargs['phone']),
                network=str(kwargs['network']),
                email=None)

            # create mobile wallet recipient json object
            payment_recipient_object = json_builder.pay_recipient(
                recipient_type=recipient_type, recipient=recipient_object)
        else:
            raise exceptions.InvalidArgumentError(
                'The recipient type is not recognized by k2connect')

        return self._make_requests(
            headers=headers,
            method='POST',
            payload=payment_recipient_object,
            url=add_pay_url,
        )