def settle_funds(self, bearer_token, transfer_value, transfer_currency='KES', transfer_destination=None): """ Creates a transfer from merchant account to a different settlement account. 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 transfer_currency: Currency of amount being transacted :type transfer_currency: str :param transfer_value: :type transfer_value:Value of money to be sent. :param transfer_destination: str :type transfer_destination: ID of the destination of funds :return: requests.models.Response """ # build settle funds url settle_funds_url = self._build_url(TRANSFER_PATH) # define headers headers = dict(self.headers) # check bearer token validation.validate_string_arguments(bearer_token, transfer_currency, transfer_value) # add authorization to headers headers['Authorization'] = 'Bearer ' + bearer_token + '' # define amount transfer_amount = json_builder.amount(currency=transfer_currency, value=transfer_value) if transfer_destination is None: settle_funds_payload = json_builder.transfers(transfers_amount=transfer_amount) else: settle_funds_payload = json_builder.transfers(transfers_amount=transfer_amount, transfer_destination=transfer_destination) return self._make_requests(headers=headers, method='POST', url=settle_funds_url, payload=settle_funds_payload)
def test_successful_blind_transfer_request(self): response = requests.post( headers=TransferTestCase.header, json=json_builder.transfers( json_builder.links( 'https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d' ), json_builder.amount('KES', "3300")), data=None, url=TransferTestCase.settlement_transfer_obj._build_url( transfers.TRANSFER_PATH)) self.assertEqual(response.status_code, 201)
def test_successful_targeted_transfer_to_merchant_wallet_request(self): response = requests.post( headers=TransferTestCase.header, json=json_builder.transfers( json_builder.links( 'https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d' ), json_builder.amount('KES', "3300"), **{ "destination_type": "merchant_wallet", "destination_reference": "eba238ae-e03f-46f6-aed5-db357fb00f9c" }), data=None, url=TransferTestCase.settlement_transfer_obj._build_url( transfers.TRANSFER_PATH)) self.assertEqual(response.status_code, 201)
def test_successful_targeted_transfer_to_merchant_bank_account_request( self): response = requests.post( headers=TransferTestCase.header, json=json_builder.transfers( json_builder.links( 'https://webhook.site/52fd1913-778e-4ee1-bdc4-74517abb758d' ), json_builder.amount('KES', "3300"), **{ "destination_type": "merchant_bank_account", "destination_reference": "87bbfdcf-fb59-4d8e-b039-b85b97015a7e" }), data=None, url=TransferTestCase.settlement_transfer_obj._build_url( transfers.TRANSFER_PATH)) self.assertEqual(response.status_code, 201)
def test_transfers_method_with_non_str_required_arguments_fails(self): with self.assertRaises(exceptions.InvalidArgumentError): transfers_amount = json_builder.amount(currency=145524, value=145524) transfer_links = json_builder.links(callback_url=145524) json_builder.transfers(transfer_links, transfers_amount)
def test_transfers_method_with_all_required_arguments_succeeds(self): transfers_json = json_builder.transfers(transfer_links='sample_transfer_links', transfers_amount='sample_transfers_amount') self.assertIsNotNone(transfers_json)
def settle_funds(self, kwargs): """ Creates a transfer from merchant account to a different settlement account. 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 'currency' not in kwargs: currency = 'KES' if 'destination_reference' not in kwargs: destination_reference = '' if 'destination_type' not in kwargs: destination_type = '' if 'callback_url' not in kwargs or \ 'value' not in kwargs: raise exceptions.InvalidArgumentError( 'Invalid arguments for creating Outgoing Pay.') # iterate through kwargs if 'access_token' in kwargs: bearer_token = kwargs['access_token'] if 'callback_url' in kwargs: callback_url = kwargs['callback_url'] if 'destination_type' in kwargs: destination_type = kwargs['destination_type'] if 'destination_reference' in kwargs: destination_reference = kwargs['destination_reference'] if 'value' in kwargs: value = kwargs['value'] # build settle funds url settle_funds_url = self._build_url(TRANSFER_PATH) # define headers headers = dict(self._headers) # check bearer token validation.validate_string_arguments(bearer_token, currency, value) # add authorization to headers headers['Authorization'] = 'Bearer ' + bearer_token + '' # define amount transfer_amount = json_builder.amount(currency=currency, value=value) # create links json object transfer_links = json_builder.links(callback_url=callback_url) if destination_reference is None and destination_type is None: settle_funds_payload = json_builder.transfers( transfer_links=transfer_links, transfers_amount=transfer_amount) else: settle_funds_payload = json_builder.transfers( transfer_links=transfer_links, transfers_amount=transfer_amount, destination_type=destination_type, destination_reference=destination_reference) return self._make_requests(headers=headers, method='POST', url=settle_funds_url, payload=settle_funds_payload)