Пример #1
0
    def list_subscription_transactions(
            self, subscription_id: str, start_time: datetime,
            end_time: datetime) -> PaypalPage[SubscriptionTransaction]:
        """Calls the API to lists transactions for a subscription.
        
        Arguments:
            subscription_id {str} -- The subscription id
            start_time {datetime} -- transaction start time
            end_time {datetime} -- transaction end time
        
        Returns:
            PaypalPage[SubscriptionTransaction] -- Paged transaction info
        """
        fmt = '%Y-%m-%dT%H:%M:%S'
        url = parse_url(self._base_url, subscription_id, 'transactions')
        params = {end_time.strftime(fmt), start_time.strftime(fmt)}

        api_response = self._session.get(url, params)

        if api_response.status_code // 100 != 2:
            return PaypalPage.error(api_response)

        return PaypalPage.full_parse_success(api_response,
                                             SubscriptionTransaction,
                                             'transaction')
Пример #2
0
    def list_plans(
            self, product_id: str = None, plan_ids: List[str] = [], 
            page_size: int = 10, page: int = 1, total_required: bool = True, 
            response_type: ResponseType = ResponseType.MINIMAL
        ) -> PaypalPage[Plan]:
        """Calls the Paypal API to list different plan details in a page
        
        Keyword Arguments:
            product_id {str} -- product id to query (default: {None})
            plan_ids {List[str]} -- list of desired plan ids (10 supported) (default: {[]})
            page_size {int} -- size of the page (default: {10})
            page {int} -- desired page (default: {1})
            total_required {bool} -- flag to show the total count in the response (default: {True})
            response_type {ResponseType} -- response type (default: {ResponseType.MINIMAL})
        
        Returns:
            PaypalPage[Plan] -- Page with plan details
        """
        url = self._base_url
        params = { 'page_size': page_size, 'page': page, 'total_required': total_required }

        if product_id:
            params['product_id'] = product_id
        if plan_ids:
            params['plan_ids'] = ','.join(plan_ids)

        api_response = self._session.get(url, params, headers = { 'Prefer': response_type.as_header_value() })

        if api_response.status_code // 100 != 2:
            return PaypalPage.error(api_response)
        
        return PaypalPage.full_parse_success(api_response, Plan, 'plans', response_type)
Пример #3
0
    def list_event_notifications(
            self,
            page_size: int = 10,
            transaction_id: str = None,
            event_type: str = None,
            date: DateRange = None) -> PaypalPage[WebhookEvent]:
        params = {'page_size': 10}

        if transaction_id != None:
            params['transaction_id'] = transaction_id
        if event_type != None:
            params['event_type'] = event_type
        if date != None and date.start_time != None:
            params['start_time'] = datetime.strftime(date.start,
                                                     '%Y-%m-%dT%H:%M:%S')
        if date != None and date.end_time != None:
            params['end_time'] = datetime.strftime(date.end,
                                                   '%Y-%m-%dT%H:%M:%S')

        api_response = self._session.get(self._base_url, params=params)

        if api_response.status_code // 100 != 2:
            return PaypalPage.error(api_response)

        return PaypalPage.full_parse_success(api_response, WebhookEvent,
                                             'events')
Пример #4
0
    def list_plans_from_link(self, link: ActionLink, response_type: ResponseType = ResponseType.MINIMAL) -> PaypalPage[Plan]:
        """Calls the Paypal API to list different plan details in a page

        Arguments:
            link {ActionLink} -- Page link

        Keyword Arguments:
            response_type {ResponseType} -- response type (default: {ResponseType.MINIMAL})
        
        Returns:
            PaypalPage[Plan] -- Page with plan details
        """
        url = link.href
        api_response = self._session.get(url, headers = { 'Prefer': response_type.as_header_value() })

        if api_response.status_code // 100 != 2:
            return PaypalPage.error(api_response)
        
        return PaypalPage.full_parse_success(api_response, Plan, 'plans', response_type)