Пример #1
0
 def test_successful_add_till_receipient_request(self):
     response = requests.post(
         headers=PayTestCase.header,
         json=json_builder.pay_recipient(
             "till",
             json_builder.till_pay_recipient(till_name="Python Test Till",
                                             till_number="567567")),
         data=None,
         url=PayTestCase.pay_obj._build_url(pay.ADD_PAY_PATH))
     self.assertEqual(response.status_code, 201)
Пример #2
0
 def test_successful_add_mobile_pay_receipient_request(self):
     response = requests.post(
         headers=PayTestCase.header,
         json=json_builder.pay_recipient(
             "mobile_wallet",
             json_builder.mobile_wallet(
                 "first_name", "last_name",
                 "9764ef5f-fcd6-42c1-bbff-de280becc64b", "safaricom")),
         data=None,
         url=PayTestCase.pay_obj._build_url(pay.ADD_PAY_PATH))
     self.assertEqual(response.status_code, 201)
Пример #3
0
 def test_successful_add_paybill_receipient_request(self):
     response = requests.post(headers=PayTestCase.header,
                              json=json_builder.pay_recipient(
                                  "paybill",
                                  json_builder.paybill_pay_recipient(
                                      paybill_name="Python Paybill",
                                      paybill_number="561830",
                                      paybill_account_number="account_two",
                                  )),
                              data=None,
                              url=PayTestCase.pay_obj._build_url(
                                  pay.ADD_PAY_PATH))
     self.assertEqual(response.status_code, 201)
Пример #4
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)
Пример #5
0
 def test_pay_recipient_method_with_non_str_required_arguments_fails(self):
     with self.assertRaises(exceptions.InvalidArgumentError):
         json_builder.pay_recipient(recipient_type=1245,
                                    recipient=12345)
Пример #6
0
 def test_pay_recipient_method_with_all_required_arguments_succeeds(self):
     pay_recipient_json = json_builder.pay_recipient(recipient_type='mobile wallet',
                                                     recipient='{"name": "Stannis Baratheon "}')
     self.assertIsNotNone(pay_recipient_json)
Пример #7
0
    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)
Пример #8
0
    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,
        )