def generate_pdf_and_upload(invoice_json):

    # Adding ".pdf" fo the name of the SDR file
    file_name = "{0}.pdf".format(invoice_json['sdr_file_name'])

    invoice_json['invoice'] = compute_invoice_details()

    order_data = invoice_json['order']

    pisa.showLogging()

    with codecs.open(TEMPLATE_PATH, 'r', 'utf-8') as f:
        template_content = f.read()

    template = Template(template_content)

    with open (file_name, "wb") as f:
        pdf = pisa.CreatePDF(template.render(invoice_json), f)

    if not pdf.err:
        with open (file_name, "r") as f:
            invoice_code = compute_uuid()

            order_code = order_data['order_code']

            order = Order.objects.get(order_code=order_code)

            invoice = Invoice(file_name=file_name, invoice_code=invoice_code, order=order)

            invoice.set_content('{0}.pdf'.format(invoice_code), f)
            invoice.save()

    invoice_json['pdf_file_name'] = file_name

    return (invoice_json, None)
    def create_order(self, params):

        email = params.get('account', None)
        pm_id = params.get('payment_method', None)
        events = params.get('events', None)

        if not email or not pm_id or not events:
            return None

        account = self.customer_manager.get_account(email)
        payment_method = self.payment_method_manager.get_valid_payment_method(
            pm_id, account)
        billing_address = self.customer_manager.get_billing_address(account)

        if not account or not payment_method:
            return None

        products = [self.get_product(event) for event in events]
        amount = sum([product.price for product in products])

        subs = filter(None, [
            product.create_subscription(account, payment_method)
            for product in products
        ])

        total = amount * 1.20
        vat = total - amount

        currency = 'GBP'
        country = 'ES'
        order_code = compute_uuid()

        order = Order(account=account,
                      payment_method=payment_method,
                      total=total,
                      currency=currency,
                      country=country,
                      order_code=order_code,
                      vat=vat,
                      amount=amount)
        order.save()

        line_items = [
            self.create_line_item(product, event, order)
            for (event, product) in zip(events, products)
        ]

        self.order_to_cash_process.start_online_order_to_cash_process(
            order, line_items, account, billing_address)

        return order
Example #3
0
    def __init__(self, model):
        self.URL = model.endpoint

        self.USERNAME = model.merchant
        self.PASSWORD = model.password

        self.SUCCESS_CALLBACK = model.success_callback
        self.ERROR_CALLBACK = model.error_callback
        self.PENDING_CALLBACK = model.pending_callback

        self.MONEY = 100
        self.CURRENCY = 'EUR'

        self.order = compute_uuid()

        self.gw = model

        self.gateways_manager = PaymentGatewayManager()
        self.payment_method_process = PaymentMethodProcess()
    def __init__(self, model):
        self.URL = model.endpoint

        self.USERNAME = model.merchant
        self.PASSWORD = model.password

        self.SUCCESS_CALLBACK = model.success_callback
        self.ERROR_CALLBACK = model.error_callback
        self.PENDING_CALLBACK = model.pending_callback

        self.MONEY    = 100
        self.CURRENCY = 'EUR'

        self.order = compute_uuid()

        self.gw = model
        
        self.gateways_manager         = PaymentGatewayManager()
        self.payment_method_process   = PaymentMethodProcess()
def create_order(json):
    # Rating an SDR file
    customer_data = json['customer']

    total  = json['total']
    amount = json['subtotal']
    vat    = json['taxes']

    currency = 'EUR'

    account_id  = customer_data['tef_account']
    country     = customer_data['country']
    order_code  = compute_uuid()

    account = Account.objects.get(account_id=account_id)

    order = Order(account=account, total=total, currency=currency, country=country, order_code=order_code, payment_method=None, amount=amount, vat=vat)
    order.save()

    json['order'] = order.to_dict()

    return (json, None)
    def create_order(self, params):

        email   = params.get('account',         None)
        pm_id   = params.get('payment_method',  None)
        events  = params.get('events',         None)

        if not email or not pm_id or not events:
            return None

        account = self.customer_manager.get_account(email)
        payment_method = self.payment_method_manager.get_valid_payment_method(pm_id, account)
        billing_address = self.customer_manager.get_billing_address(account)

        if not account or not payment_method:
            return None

        products = [self.get_product(event) for event in events]
        amount   = sum([product.price for product in products])

        subs = filter(None, [product.create_subscription(account, payment_method) for product in products])

        total = amount*1.20
        vat   = total - amount

        currency = 'GBP'
        country = 'ES'
        order_code = compute_uuid()

        order = Order(account=account, payment_method=payment_method, total=total, currency=currency, country=country, order_code=order_code, vat=vat, amount=amount)
        order.save()

        line_items = [self.create_line_item(product, event, order) for (event, product) in zip(events, products)]

        self.order_to_cash_process.start_online_order_to_cash_process(order, line_items, account, billing_address)

        return order
    def _start_standalone_contracting_process(self, subprocess, contract):

        contract.contract_id = compute_uuid()
        contract.save()