コード例 #1
0
ファイル: forms.py プロジェクト: Dpetters/Umeqo
    def __init__(self, subscription_type, current_billing_cycle, *args,
                 **kwargs):
        super(ChangeBillingForm, self).__init__(*args, **kwargs)
        stripe.api_key = s.STRIPE_SECRET
        billing_cycle_choices = []
        if subscription_type in s.SUBSCRIPTION_UIDS.keys():
            billing_cycles = s.SUBSCRIPTION_UIDS[subscription_type]
            monthly_price = None
            for billing_cycle, value in billing_cycles.items():
                times, plan_stripe_id = value
                plan = stripe.Plan.retrieve(plan_stripe_id)
                amount = plan.amount
                string = "Bill me %s per %s" % (format_money(
                    plan.amount), billing_cycle)

                if billing_cycle == "month":
                    monthly_price = amount
                elif monthly_price:
                    percentage = int(
                        (1.0 - amount / float(monthly_price * times)) * 100)
                    string += " (save %d%%)" % (percentage)

                if current_billing_cycle != billing_cycle and not (
                        current_billing_cycle == "year"
                        and billing_cycle == "month"):
                    billing_cycle_choices.append((billing_cycle, string))

            self.fields['billing_cycle'].choices = billing_cycle_choices
        else:
            raise Http500("Unhandled subscription type: %s" %
                          subscription_type)
コード例 #2
0
ファイル: forms.py プロジェクト: Dpetters/Umeqo
    def __init__(self, subscription_type, current_billing_cycle, *args, **kwargs):
        super(ChangeBillingForm, self).__init__(*args, **kwargs)
        stripe.api_key = s.STRIPE_SECRET
        billing_cycle_choices = []
        if subscription_type in s.SUBSCRIPTION_UIDS.keys():
            billing_cycles = s.SUBSCRIPTION_UIDS[subscription_type]
            monthly_price = None
            for billing_cycle, value in billing_cycles.items():
                times, plan_stripe_id = value 
                plan = stripe.Plan.retrieve(plan_stripe_id)
                amount = plan.amount
                string = "Bill me %s per %s" % (format_money(plan.amount), billing_cycle)

                if billing_cycle == "month":
                    monthly_price = amount
                elif monthly_price:
                    percentage = int((1.0-amount/float(monthly_price*times))*100)
                    string += " (save %d%%)" % (percentage) 

                if current_billing_cycle != billing_cycle and not(current_billing_cycle == "year" and billing_cycle == "month"):
                    billing_cycle_choices.append((billing_cycle, string))
                    
            self.fields['billing_cycle'].choices = billing_cycle_choices
        else:
            raise Http500("Unhandled subscription type: %s" % subscription_type)
コード例 #3
0
ファイル: view_helpers.py プロジェクト: Dpetters/Umeqo
def get_or_create_receipt_pdf(charge, invoice, employer_name):
    pdf_name = "Umeqo-Receipt-%s-%s.pdf" % (format_unix_time(
        charge.created).replace("/", "-"), charge.id)
    path = "%semployer/receipts/" % (s.MEDIA_ROOT)
    if not os.path.exists(path):
        os.makedirs(path)
    pdf_path = "%s%s" % (path, pdf_name)
    if not os.path.exists(pdf_path):
        story = []
        story.append(Spacer(3 * cm, 2 * cm))

        story.append(Paragraph('Umeqo Receipt', styles['Heading1']))
        story.append(Paragraph(employer_name, styles['Heading2']))
        story.append(Paragraph("Charge ID: %s" % charge.id,
                               styles['Heading3']))
        story.append(Spacer(1 * cm, 1 * cm))

        hitem = Paragraph('''<b>Item</b>''', styles["Normal"])
        hdate = Paragraph('''<b>Date</b>''', styles["Normal"])
        hamount = Paragraph('''<b>Amount</b>''', styles["Normal"])

        data = [[hitem, hdate, hamount]]

        for subscription in invoice.lines.subscriptions:
            item = Paragraph(subscription.plan.name, styles["Normal"])
            date = Paragraph(
                "%s-%s" % (format_unix_time(subscription.period.start),
                           format_unix_time(subscription.period.end)),
                styles["Normal"])
            amount = Paragraph(format_money(subscription.amount),
                               right_align_style)
            data.append([item, date, amount])

        for invoice_item in invoice.lines.invoiceitems:
            item = Paragraph(invoice_item.description, styles["Normal"])
            date = Paragraph(format_unix_time(invoice_item.date),
                             styles["Normal"])
            amount = Paragraph(format_money(invoice_item.amount),
                               right_align_style)
            data.append([item, date, amount])

        for proration in invoice.lines.prorations:
            item = Paragraph(proration.description, styles["Normal"])
            date = Paragraph(format_unix_time(proration.date),
                             styles["Normal"])
            amount = Paragraph(format_money(proration.amount),
                               right_align_style)
            data.append([item, date, amount])

        table = Table(data, colWidths=[8.5 * cm, 4.5 * cm, 2.5 * cm])

        table.setStyle(
            TableStyle([
                ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
                ('BOX', (0, 0), (-1, -1), 0.25, colors.black),
            ]))

        story.append(table)

        total_amount_style = ParagraphStyle(name='BodyText',
                                            parent=styles['Normal'],
                                            alignment=TA_RIGHT,
                                            spaceBefore=1)
        total_amount = Paragraph(
            "<strong>Total:</strong> %s" % format_money(charge.amount),
            total_amount_style)
        story.append(total_amount)

        story.append(Spacer(1 * cm, 3 * cm))

        story.append(Paragraph('''Umeqo''', styles["Normal"]))
        story.append(Paragraph('''645 Harrison Suite 200''', styles["Normal"]))
        story.append(Paragraph('''San Francisco, CA 94107''',
                               styles["Normal"]))
        story.append(Paragraph('''https://www.umeqo.com''', styles["Normal"]))
        story.append(Paragraph('''(650) 543-1400''', styles["Normal"]))

        doc = SimpleDocTemplate(pdf_path, pagesize=A4, topMargin=0)
        doc.build(story)
    return pdf_path
コード例 #4
0
ファイル: view_helpers.py プロジェクト: Dpetters/Umeqo
def get_or_create_receipt_pdf(charge, invoice, employer_name):
    pdf_name = "Umeqo-Receipt-%s-%s.pdf" % (format_unix_time(charge.created).replace("/", "-"), charge.id)
    path = "%semployer/receipts/" % (s.MEDIA_ROOT)
    if not os.path.exists(path):
        os.makedirs(path)
    pdf_path = "%s%s" % (path, pdf_name)
    if not os.path.exists(pdf_path):
        story = []
        story.append(Spacer(3*cm, 2*cm))
        
        story.append(Paragraph('Umeqo Receipt', styles['Heading1']))
        story.append(Paragraph(employer_name, styles['Heading2']))
        story.append(Paragraph("Charge ID: %s" % charge.id, styles['Heading3']))
        story.append(Spacer(1*cm, 1*cm))

        hitem = Paragraph('''<b>Item</b>''', styles["Normal"])
        hdate = Paragraph('''<b>Date</b>''', styles["Normal"])
        hamount = Paragraph('''<b>Amount</b>''', styles["Normal"])

        data= [[hitem, hdate,  hamount]]
                
        for subscription in invoice.lines.subscriptions:
            item = Paragraph(subscription.plan.name, styles["Normal"])
            date = Paragraph("%s-%s" % (format_unix_time(subscription.period.start), format_unix_time(subscription.period.end)), styles["Normal"])
            amount = Paragraph(format_money(subscription.amount), right_align_style)
            data.append([item, date, amount])

        for invoice_item in invoice.lines.invoiceitems:
            item = Paragraph(invoice_item.description, styles["Normal"])
            date = Paragraph(format_unix_time(invoice_item.date), styles["Normal"])
            amount = Paragraph(format_money(invoice_item.amount), right_align_style)
            data.append([item, date, amount])

        for proration in invoice.lines.prorations:
            item = Paragraph(proration.description, styles["Normal"])
            date = Paragraph(format_unix_time(proration.date), styles["Normal"])
            amount = Paragraph(format_money(proration.amount), right_align_style)
            data.append([item, date, amount])
        
        
        table = Table(data, colWidths=[8.5 * cm, 4.5 * cm, 2.5 * cm])
        
        table.setStyle(TableStyle([
                               ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                               ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                               ]))
        
        story.append(table)
        
        total_amount_style = ParagraphStyle(name='BodyText', parent=styles['Normal'], alignment=TA_RIGHT, spaceBefore=1)
        total_amount = Paragraph("<strong>Total:</strong> %s" % format_money(charge.amount), total_amount_style)
        story.append(total_amount)
        
        
        story.append(Spacer(1*cm, 3*cm))

        story.append(Paragraph('''Umeqo''', styles["Normal"]))
        story.append(Paragraph('''645 Harrison Suite 200''', styles["Normal"]))
        story.append(Paragraph('''San Francisco, CA 94107''', styles["Normal"]))
        story.append(Paragraph('''https://www.umeqo.com''', styles["Normal"]))
        story.append(Paragraph('''(650) 543-1400''', styles["Normal"]))        
        
        doc = SimpleDocTemplate(pdf_path, pagesize = A4, topMargin=0)
        doc.build(story)
    return pdf_path