Beispiel #1
0
    def _get_payments(self, rows=20):
        """
        Returns income payments

        :type: rows: int: 1-50

        :param: rows: Count of payments in response
        :return: income payments (dict)
        """

        post_args = {
            'rows': rows,
            'operation': 'IN'
        }

        response = self._s.get(
            url='https://edge.qiwi.com/payment-history/v1/persons/%s/payments' % self.phone,
            params=post_args
        )

        data = response.json()

        if 'code' in data or 'errorCode' in data:
            raise QIWIAPIError(data)

        return data
Beispiel #2
0
    def _get_balance(self):
        """
        Returns full account balance info

        :return: balance (dict)
        """

        response = self._s.get('https://edge.qiwi.com/funding-sources/v1/accounts/current')

        if response is None:
            raise InvalidTokenError('Invalid token!')

        json = response.json()

        if 'code' in json or 'errorCode' in json:
            raise QIWIAPIError(json)

        balances = []

        for account in json['accounts']:
            if account['hasBalance']:
                balances.append({
                   'type': account['type'],
                   'balance': account['balance']
                })

        return balances
Beispiel #3
0
    def pay(self,
            account,
            amount,
            currency='643',
            comment=None,
            tp='Account',
            acc_id='643'):
        """
        Transfer to QIWI Wallet

        :type account: str
        :type amount: int
        :type currency: str
        :type comment: str
        :type tp: str
        :type acc_id: str

        :param account: Phone number of payee
        :param amount: Amount of money for transaction
        :param currency: Currency
        :param comment: Comment for transaction
        :param tp: Type of payee
        :param acc_id: Currency

        :return: response
        """

        post_args = {
            "id": self._transaction_id,
            "sum": {
                "amount": amount,
                "currency": currency
            },
            "paymentMethod": {
                "type": tp,
                "accountId": acc_id
            },
            "fields": {
                "account": account
            }
        }

        if comment is not None:
            post_args['comment'] = comment

        response = self._s.post(
            url='https://edge.qiwi.com/sinap/api/v2/terms/99/payments',
            json=post_args)

        data = response.json()

        if 'code' in data or 'errorCode' in data:
            raise QIWIAPIError(data)

        return response.json()
Beispiel #4
0
    def pay(self,
            provider,
            account,
            amount,
            fields=None,
            currency='643',
            comment=None,
            tp='Account',
            acc_id='643'):
        """
        Transfer to QIWI Wallet

        :type provider: str
        :type account: str
        :type amount: int
        :type currency: str
        :type comment: str
        :type tp: str
        :type acc_id: str
        :type fields: dict
        
        :param provider: Provider ID (e.g. https://qiwi.com/payment/form/26580 = 26580) 
        :param account: Phone number of payee
        :param amount: Amount of money for transaction
        :param currency: Currency
        :param comment: Comment for transaction
        :param tp: Type of payee
        :param acc_id: Currency
        :param fields: whatever you need

        :return: response
        """

        post_args = {
            "id": self._transaction_id,
            "sum": {
                "amount": amount,
                "currency": currency
            },
            "paymentMethod": {
                "type": tp,
                "accountId": acc_id
            },
            "fields": {
                "account": account
            }
        }

        if comment is not None:
            post_args['comment'] = comment

        if fields is not None:
            for key, value in fields.items():
                post_args['fields'][key] = value

        if provider is not None:
            url = 'https://edge.qiwi.com/sinap/api/v2/terms/' + provider + '/payments'
        else:
            url = 'https://edge.qiwi.com/sinap/api/v2/terms/99/payments'

        response = self._s.post(url=url, json=post_args)

        data = response.json()

        if 'code' in data or 'errorCode' in data:
            raise QIWIAPIError(data)

        return response.json()