File: recurring_application_charge.py

package info (click to toggle)
python-shopifyapi 12.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 1,752; sh: 10; makefile: 9
file content (28 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from ..base import ShopifyResource
from .usage_charge import UsageCharge


def _get_first_by_status(resources, status):
    for resource in resources:
        if resource.status == status:
            return resource
    return None


class RecurringApplicationCharge(ShopifyResource):
    def usage_charges(self):
        return UsageCharge.find(recurring_application_charge_id=self.id)

    def customize(self, **kwargs):
        self._load_attributes_from_response(self.put("customize", recurring_application_charge=kwargs))

    @classmethod
    def current(cls):
        """
        Returns first RecurringApplicationCharge object with status=active.
        If not found, None will be returned.
        """
        return _get_first_by_status(cls.find(), "active")

    def activate(self):
        self._load_attributes_from_response(self.post("activate"))