Пример #1
0
 def refund_open_amount_xml(self, amount_in_cents, refund_apply_order):
     elem = ElementTree.Element(self.nodename)
     elem.append(
         Resource.element_for_value('refund_apply_order',
                                    refund_apply_order))
     elem.append(
         Resource.element_for_value('amount_in_cents', amount_in_cents))
     return elem
Пример #2
0
    def _refund_open_amount_xml(self, amount_in_cents, refund_options):
        elem = ElementTreeBuilder.Element(self.nodename)
        elem.append(
            Resource.element_for_value('amount_in_cents', amount_in_cents))

        # Need to sort the keys for tests to pass in python 2 and 3
        # Can remove `sorted` when we drop python 2 support
        for k, v in sorted(iteritems(refund_options)):
            elem.append(Resource.element_for_value(k, v))
        return elem
Пример #3
0
    def refund_line_items_xml(self, line_items):
        elem = ElementTree.Element(self.nodename)
        line_items_elem = ElementTree.Element('line_items')

        for item in line_items:
            adj_elem = ElementTree.Element('adjustment')
            adj_elem.append(Resource.element_for_value('uuid',
                item['adjustment'].uuid))
            adj_elem.append(Resource.element_for_value('quantity',
            item['quantity']))
            adj_elem.append(Resource.element_for_value('prorate', item['prorate']))
            line_items_elem.append(adj_elem)

        elem.append(line_items_elem)
        return elem
Пример #4
0
    def refund_line_items_xml(self, line_items):
        elem = ElementTree.Element(self.nodename)
        line_items_elem = ElementTree.Element('line_items')

        for item in line_items:
            adj_elem = ElementTree.Element('adjustment')
            adj_elem.append(
                Resource.element_for_value('uuid', item['adjustment'].uuid))
            adj_elem.append(
                Resource.element_for_value('quantity', item['quantity']))
            adj_elem.append(
                Resource.element_for_value('prorate', item['prorate']))
            line_items_elem.append(adj_elem)

        elem.append(line_items_elem)
        return elem
Пример #5
0
    def _refund_line_items_xml(self, line_items, refund_options):
        elem = ElementTreeBuilder.Element(self.nodename)

        line_items_elem = ElementTreeBuilder.Element('line_items')

        for item in line_items:
            adj_elem = ElementTreeBuilder.Element('adjustment')
            adj_elem.append(
                Resource.element_for_value('uuid', item['adjustment'].uuid))
            adj_elem.append(
                Resource.element_for_value('quantity', item['quantity']))
            adj_elem.append(
                Resource.element_for_value('prorate', item['prorate']))
            line_items_elem.append(adj_elem)

        elem.append(line_items_elem)

        # Need to sort the keys for tests to pass in python 2 and 3
        # Can remove `sorted` when we drop python 2 support
        for k, v in sorted(iteritems(refund_options)):
            elem.append(Resource.element_for_value(k, v))

        return elem
Пример #6
0
    def generate(self, amount):
        elem = ElementTree.Element(self.nodename)
        elem.append(Resource.element_for_value('number_of_unique_codes', amount))

        url = urljoin(self._url, '%s/generate' % (self.coupon_code, ))
        body = ElementTree.tostring(elem, encoding='UTF-8')

        response = self.http_request(url, 'POST', body, { 'Content-Type':
            'application/xml; charset=utf-8' })

        if response.status not in (200, 201, 204):
            self.raise_http_error(response)

        return Page.page_for_url(response.getheader('Location'))
Пример #7
0
    def generate(self, amount):
        elem = ElementTree.Element(self.nodename)
        elem.append(Resource.element_for_value('number_of_unique_codes', amount))

        url = urljoin(self._url, '%s/generate' % (self.coupon_code, ))
        body = ElementTree.tostring(elem, encoding='UTF-8')

        response = self.http_request(url, 'POST', body, { 'Content-Type':
            'application/xml; charset=utf-8' })

        if response.status not in (200, 201, 204):
            self.raise_http_error(response)

        return Page.page_for_url(response.getheader('Location'))
Пример #8
0
def objects_for_push_notification(notification):
    """Decode a push notification with the given body XML.

    Returns a dictionary containing the constituent objects of the push
    notification. The kind of push notification is given in the ``"type"``
    member of the returned dictionary.

    """
    notification_el = ElementTree.fromstring(notification)
    objects = {'type': notification_el.tag}
    for child_el in notification_el:
        tag = child_el.tag
        res = Resource.value_for_element(child_el)
        objects[tag] = res
    return objects
Пример #9
0
def objects_for_push_notification(notification):
    """Decode a push notification with the given body XML.

    Returns a dictionary containing the constituent objects of the push
    notification. The kind of push notification is given in the ``"type"``
    member of the returned dictionary.

    """
    notification_el = ElementTree.fromstring(notification)
    objects = {'type': notification_el.tag}
    for child_el in notification_el:
        tag = child_el.tag
        res = Resource.value_for_element(child_el)
        objects[tag] = res
    return objects
Пример #10
0
    def pause(self, remaining_pause_cycles):
        """Pause a subscription"""
        url = urljoin(self._url, '/pause')
        elem = ElementTreeBuilder.Element(self.nodename)
        elem.append(
            Resource.element_for_value('remaining_pause_cycles',
                                       remaining_pause_cycles))
        body = ElementTree.tostring(elem, encoding='UTF-8')

        response = self.http_request(
            url, 'PUT', body,
            {'Content-Type': 'application/xml; charset=utf-8'})

        if response.status not in (200, 201, 204):
            self.raise_http_error(response)

        self.update_from_element(ElementTree.fromstring(response.read()))
Пример #11
0
def objects_for_push_notification(notification):
    """Decode a push notification with the given body XML.

    Returns a dictionary containing the constituent objects of the push
    notification. The kind of push notification is given in the ``"type"``
    member of the returned dictionary.

    NOTE: Push notification object attributes do not match up one-to-one with
    their Recurly Resource counterparts. Some attributes will be trimmed in this
    process.
    """
    notification_el = ElementTree.fromstring(notification)
    objects = {'type': notification_el.tag}
    for child_el in notification_el:
        tag = child_el.tag
        res = Resource.value_for_element(child_el)
        objects[tag] = res
    return objects
Пример #12
0
    attributes = (
        'message',
        'created_at',
    )

    @classmethod
    def from_element(cls, elem):
        new_note = Note()
        for child_el in elem:
            if not child_el.tag:
                continue
            setattr(new_note, child_el.tag, child_el.text)
        return new_note

Resource._learn_nodenames(locals().values())


def objects_for_push_notification(notification):
    """Decode a push notification with the given body XML.

    Returns a dictionary containing the constituent objects of the push
    notification. The kind of push notification is given in the ``"type"``
    member of the returned dictionary.

    """
    notification_el = ElementTree.fromstring(notification)
    objects = {'type': notification_el.tag}
    for child_el in notification_el:
        tag = child_el.tag
        res = Resource.value_for_element(child_el)
Пример #13
0
    Use these instead of `AddOn` instances when specifying a
    `Subscription` instance's `subscription_add_ons` attribute.

    """

    nodename = 'subscription_add_on'
    inherits_currency = True

    attributes = (
        'add_on_code',
        'quantity',
        'unit_amount_in_cents',
    )


Resource._learn_nodenames(locals().values())


def objects_for_push_notification(notification):
    """Decode a push notification with the given body XML.

    Returns a dictionary containing the constituent objects of the push
    notification. The kind of push notification is given in the ``"type"``
    member of the returned dictionary.

    """
    notification_el = ElementTree.fromstring(notification)
    objects = {'type': notification_el.tag}
    for child_el in notification_el:
        tag = child_el.tag
        res = Resource.value_for_element(child_el)
Пример #14
0
 def refund_open_amount_xml(self, amount_in_cents):
     elem = ElementTree.Element(self.nodename)
     elem.append(Resource.element_for_value('amount_in_cents',
         amount_in_cents))
     return elem
 def refund_open_amount_xml(self, amount_in_cents, refund_method):
     elem = ElementTreeBuilder.Element(self.nodename)
     elem.append(Resource.element_for_value('refund_method', refund_method))
     elem.append(
         Resource.element_for_value('amount_in_cents', amount_in_cents))
     return elem