예제 #1
0
    def _process_membership_item(self, sale, item, item_num, membership_type,
                                 dur_amt, dur_unit):
        month = self.month_in_str(item['name'])

        family = None
        for modifier in item["modifiers"]:
            lmod = modifier["name"].lower()
            if lmod == "just myself": family = 0
            elif lmod == "1 add'l family member": family = 1
            elif lmod == "2 add'l family members": family = 2
            elif lmod == "3 add'l family members": family = 3
            elif lmod == "4 add'l family members": family = 4
            elif lmod == "5 add'l family members": family = 5
            if membership_type == Membership.MT_WORKTRADE and month is None:
                month = self.month_in_str(lmod)

        if family is None:
            ctrlid = sale['ctrlid']

            # A special case because the 12 month membership item was set up incorrectly.
            if ctrlid == "SQ:kZxawM1NBAxvqr2vKU2ZnzMF" and item_num == 1:
                family = 0

            else:
                print("Couldn't determine family count for {}:{}".format(
                    sale['ctrlid'], item_num))
                family = 0

        quantity = int(float(item['quantity']))
        for n in range(1, quantity + 1):
            mship = Membership()
            mship.sale = Sale(id=sale['id'])
            mship.membership_type = membership_type
            mship.ctrlid = "{}:{}:{}".format(sale['ctrlid'], item_num, n)
            mship.start_date = parse(sale['sale_date']).date()
            if mship.membership_type == Membership.MT_WORKTRADE:
                mship.start_date = mship.start_date.replace(
                    day=1)  # WT always starts on the 1st.
                if month is not None:  # Hopefully, the buyer specified the month.
                    mship.start_date = mship.start_date.replace(month=month)
            mship.end_date = mship.start_date + relativedelta(**{
                dur_unit: dur_amt,
                "days": -1
            })
            mship.sale_price = Decimal(
                item['gross_sales_money']['amount']) / Decimal(
                    quantity * 100.0)
            mship.sale_price -= Decimal(10.00) * Decimal(family)
            self.upsert(mship)

            for f in range(family):
                fam = Membership()
                fam.sale = mship.sale
                fam.sale_price = 10
                fam.membership_type = Membership.MT_FAMILY
                fam.start_date = mship.start_date
                fam.end_date = mship.end_date
                fam.ctrlid = "{}:{}".format(mship.ctrlid, f)
                self.upsert(fam)
예제 #2
0
    def _process_membership_item(self, sale, item, item_num, membership_type, dur_amt, dur_unit):
        month = self.month_in_str(item['name'])

        family = None
        for modifier in item["modifiers"]:
            lmod = modifier["name"].lower()
            if lmod == "just myself": family = 0
            elif lmod == "1 add'l family member":  family = 1
            elif lmod == "2 add'l family members": family = 2
            elif lmod == "3 add'l family members": family = 3
            elif lmod == "4 add'l family members": family = 4
            elif lmod == "5 add'l family members": family = 5
            if membership_type == Membership.MT_WORKTRADE and month is None:
                month = self.month_in_str(lmod)

        if family is None:
            ctrlid = sale['ctrlid']

            # A special case because the 12 month membership item was set up incorrectly.
            if ctrlid == "SQ:kZxawM1NBAxvqr2vKU2ZnzMF" and item_num == 1:
                family = 0

            else:
                print("Couldn't determine family count for {}:{}".format(sale['ctrlid'], item_num))
                family = 0

        quantity = int(float(item['quantity']))
        for n in range(1, quantity+1):
            mship = Membership()
            mship.sale = Sale(id=sale['id'])
            mship.membership_type = membership_type
            mship.ctrlid = "{}:{}:{}".format(sale['ctrlid'], item_num, n)
            mship.start_date = parse(sale['sale_date']).date()
            if mship.membership_type == Membership.MT_WORKTRADE:
                mship.start_date = mship.start_date.replace(day=1)  # WT always starts on the 1st.
                if month is not None:  # Hopefully, the buyer specified the month.
                    mship.start_date = mship.start_date.replace(month=month)
            mship.end_date = mship.start_date + relativedelta(**{dur_unit:dur_amt, "days":-1})
            mship.sale_price = Decimal(item['gross_sales_money']['amount']) / Decimal(quantity * 100.0)
            mship.sale_price -= Decimal(10.00) * Decimal(family)
            self.upsert(mship)

            for f in range(family):
                fam = Membership()
                fam.sale            = mship.sale
                fam.sale_price      = 10
                fam.membership_type = Membership.MT_FAMILY
                fam.start_date      = mship.start_date
                fam.end_date        = mship.end_date
                fam.ctrlid          = "{}:{}".format(mship.ctrlid, f)
                self.upsert(fam)
예제 #3
0
    def _process_lineitems(self, djgo_sale, lineitems):

        if len(lineitems) > 1:
            print("WARNING: More than two line items in invoice.")

        for lineitem in lineitems:
            amt = Decimal(lineitem.customer_amount)
            assert amt >= 50, "Didn't expect line item amount < 50."
            assert amt % 10 == 0, "Didn't expect line item amount that's not a multiple of 10."
            assert len(lineitem.options) <= 1
            assert lineitem.status in ["bill", "refund"]

            mship = Membership()

            mship.sale = Sale(id=djgo_sale['id'])
            mship.start_date    = parse(djgo_sale['sale_date']).date()  # Inclusive
            mship.end_date      = mship.start_date + relativedelta(months=+1, days=-1)  # Inclusive
            mship.sale_price    = 50
            mship.ctrlid        = "2CO:{}:{}".format(lineitem.invoice_id, lineitem.lineitem_id)
            self.upsert(mship)

            family = int((amt-50)/10)
            for n in range(family):
                fam = Membership()
                fam.sale            = mship.sale
                fam.sale_price      = 10
                fam.membership_type = Membership.MT_FAMILY
                fam.start_date      = mship.start_date
                fam.end_date        = mship.end_date
                fam.ctrlid          = "{}:{}".format(mship.ctrlid, n)
                self.upsert(fam)
예제 #4
0
 def _special_case_7cQ69ctaeYok1Ry3KOTFbyMF(self, sale):
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.membership_type = Membership.MT_REGULAR
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2016, 4, 5)
     mship.end_date = date(2015, 4, 18)
     mship.sale_price = 25.00
     self.upsert(mship)
예제 #5
0
 def _special_case_ixStxgstn56QI8jnJtcCtzMF(self, sale):
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.membership_type = Membership.MT_REGULAR
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2014, 12, 12)
     mship.end_date = date(2015, 6, 11)
     mship.sale_price = 225.00
     self.upsert(mship)
예제 #6
0
 def _special_case_ixStxgstn56QI8jnJtcCtzMF(self, sale):
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.membership_type = Membership.MT_REGULAR
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2014, 12, 12)
     mship.end_date = date(2015, 6, 11)
     mship.sale_price = 225.00
     self.upsert(mship)
예제 #7
0
 def _special_case_7cQ69ctaeYok1Ry3KOTFbyMF(self, sale):
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.membership_type = Membership.MT_REGULAR
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2016, 4, 5)
     mship.end_date = date(2015, 4, 18)
     mship.sale_price = 25.00
     self.upsert(mship)
예제 #8
0
 def _special_case_0JFN0loJ0kcy8DXCvuDVwwMF(self, sale):
     # Verify: This was erroneously entered as a donation but was really a work-trade payment.
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.member = Member(id=19)  # Lookup by name would be better but I don't want to have names in the code.
     mship.membership_type = Membership.MT_WORKTRADE
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2015, 12, 1)
     mship.end_date = date(2015, 12, 31)
     mship.sale_price = 10.00
     self.upsert(mship)
예제 #9
0
    def _process_subscription_charges(self, charges, subscription, family):
        for charge in charges:

            state = charge["state"]
            if state == "refunded":
                refund = True
            elif state == "captured":
                refund = False
            elif state == "failed":
                continue
            else:
                print("State not handled: " + state)
                continue

            sale = Sale()
            sale.payer_name = subscription['payer_name']
            sale.payer_email = subscription['payer_email']
            if subscription['fee_payer'] == "payer":
                print(
                    "Fee is paid by payer. Situation has not yet been analyzed."
                )
            sale.payment_method = Sale.PAID_BY_WEPAY
            sale.sale_date = date.fromtimestamp(int(
                charge['create_time']))  # TODO: This is UTC timezone.
            sale.total_paid_by_customer = charge["amount"]
            sale.processing_fee = charge["fee"]
            sale.ctrlid = "{}:{}".format(self.CTRLID_PREFIX,
                                         charge['subscription_charge_id'])
            django_sale = self.upsert(sale)

            mship = Membership()
            mship.sale = Sale(id=django_sale['id'])
            mship.sale_price = sale.total_paid_by_customer
            if subscription['fee_payer'] == 'payer':
                mship.sale_price -= sale.processing_fee
            if family > 0: mship.sale_price -= Decimal(10.00) * Decimal(family)
            mship.ctrlid = "{}:{}".format(self.CTRLID_PREFIX,
                                          charge['subscription_charge_id'])
            mship.start_date = sale.sale_date
            mship.end_date = mship.start_date + relativedelta(months=1,
                                                              days=-1)
            self.upsert(mship)

            for n in range(family):
                fam = Membership()
                fam.sale = mship.sale
                fam.sale_price = 10.00
                fam.membership_type = Membership.MT_FAMILY
                fam.start_date = mship.start_date
                fam.end_date = mship.end_date
                fam.ctrlid = "{}:{}:{}".format(self.CTRLID_PREFIX,
                                               mship.ctrlid, n)
                self.upsert(fam)
예제 #10
0
 def _special_case_0JFN0loJ0kcy8DXCvuDVwwMF(self, sale):
     # Verify: This was erroneously entered as a donation but was really a work-trade payment.
     mship = Membership()
     mship.sale = Sale(id=sale['id'])
     mship.member = Member(
         id=19
     )  # Lookup by name would be better but I don't want to have names in the code.
     mship.membership_type = Membership.MT_WORKTRADE
     mship.ctrlid = "{}:1:1".format(sale['ctrlid'])
     mship.start_date = date(2015, 12, 1)
     mship.end_date = date(2015, 12, 31)
     mship.sale_price = 10.00
     self.upsert(mship)
예제 #11
0
    def _member_and_family(self, sale: Sale, months: int):

        primary_membership_price = Fetcher.prices[months]
        assert primary_membership_price <= sale.total_paid_by_customer
        remaining = sale.total_paid_by_customer - primary_membership_price
        assert remaining % Decimal(
            10.00) == 0  # Additional family members should be $10/mo
        fam_count = int(remaining) // 10 // months

        mship = Membership()
        mship.sale = sale
        mship.membership_type = Membership.MT_REGULAR
        mship.ctrlid = "{}:P".format(sale.ctrlid)
        mship.start_date = sale.sale_date
        mship.end_date = mship.start_date + relativedelta(months=months,
                                                          days=-1)
        mship.sale_price = Decimal(primary_membership_price)
        self.upsert(mship)

        for f in range(1, fam_count + 1):
            mship.membership_type = Membership.MT_FAMILY
            mship.ctrlid = "{}:{}".format(sale.ctrlid, f)
            mship.sale_price = Decimal(months * 10.00)
            self.upsert(mship)
예제 #12
0
    def _process_membership_sale(self, sale, checkout, months, family):

        mship = Membership()
        mship.sale = Sale(id=sale.id)
        mship.sale_price = sale.total_paid_by_customer
        if checkout['fee_payer'] == 'payer': mship.sale_price -= sale.processing_fee
        if family > 0: mship.sale_price -= Decimal(10.00) * Decimal(family)
        mship.ctrlid = "{}:{}".format(self.CTRLID_PREFIX, checkout['checkout_id'])
        mship.start_date = sale.sale_date
        mship.end_date = mship.start_date + relativedelta(months=months, days=-1)
        self.upsert(mship)

        for n in range(family):
            fam = Membership()
            fam.sale            = mship.sale
            fam.sale_price      = 10.00
            fam.membership_type = Membership.MT_FAMILY
            fam.start_date      = mship.start_date
            fam.end_date        = mship.end_date
            fam.ctrlid          = "{}:{}:{}".format(self.CTRLID_PREFIX, mship.ctrlid, n)
            self.upsert(fam)
예제 #13
0
    def _process_membership_sale(self, sale, checkout, months, family):

        mship = Membership()
        mship.sale = Sale(id=sale.id)
        mship.sale_price = sale.total_paid_by_customer
        if checkout['fee_payer'] == 'payer': mship.sale_price -= sale.processing_fee
        if family > 0: mship.sale_price -= Decimal(10.00) * Decimal(family)
        mship.ctrlid = "{}:{}".format(self.CTRLID_PREFIX, checkout['checkout_id'])
        mship.start_date = sale.sale_date
        mship.end_date = mship.start_date + relativedelta(months=months, days=-1)
        self.upsert(mship)

        for n in range(family):
            fam = Membership()
            fam.sale            = mship.sale
            fam.sale_price      = 10.00
            fam.membership_type = Membership.MT_FAMILY
            fam.start_date      = mship.start_date
            fam.end_date        = mship.end_date
            fam.ctrlid          = "{}:{}:{}".format(self.CTRLID_PREFIX, mship.ctrlid, n)
            self.upsert(fam)
예제 #14
0
    def _process_subscription_charges(self, charges, subscription, family):
        for charge in charges:

            if not charge["state"].startswith("captured"):
                if not charge["state"] == "failed": print(charge["state"])
                continue

            sale = Sale()
            sale.payer_name = subscription['payer_name']
            sale.payer_email = subscription['payer_email']
            if subscription['fee_payer'] == "payer":
                print("Fee is paid by payer. Situation has not yet been analyzed.")
            sale.payment_method = Sale.PAID_BY_WEPAY
            sale.sale_date = date.fromtimestamp(int(charge['create_time']))  # TODO: This is UTC timezone.
            sale.total_paid_by_customer = charge["amount"]
            sale.processing_fee = charge["fee"]
            sale.ctrlid = "{}:{}".format(self.CTRLID_PREFIX, charge['subscription_charge_id'])
            django_sale = self.upsert(sale)

            mship = Membership()
            mship.sale = Sale(id=django_sale['id'])
            mship.sale_price = sale.total_paid_by_customer
            if subscription['fee_payer'] == 'payer': mship.sale_price -= sale.processing_fee
            if family > 0: mship.sale_price -= Decimal(10.00) * Decimal(family)
            mship.ctrlid = "{}:{}".format(self.CTRLID_PREFIX, charge['subscription_charge_id'])
            mship.start_date = sale.sale_date
            mship.end_date = mship.start_date + relativedelta(months=1, days=-1)
            self.upsert(mship)

            for n in range(family):
                fam = Membership()
                fam.sale            = mship.sale
                fam.sale_price      = 10.00
                fam.membership_type = Membership.MT_FAMILY
                fam.start_date      = mship.start_date
                fam.end_date        = mship.end_date
                fam.ctrlid          = "{}:{}:{}".format(self.CTRLID_PREFIX, mship.ctrlid, n)
                self.upsert(fam)