Ejemplo n.º 1
0
def build_invoice(event, context):
    log.info('Getting customer config')
    customers = get_customer_config()

    for customer in customers:
        next_due = datetime.strptime(customer['next_payment_date'], '%m/%d/%Y')
        if not is_payment_due(datetime.now().date(), next_due.date()):
            log.info('No payment due for {} until {}'.format(
                customer['customer_email'], next_due.strftime('%m/%d/%Y')))
            continue

        invoice = Invoice({
            'merchant_info': {
                'email': '*****@*****.**',
                'first_name': 'FIRSTNAME',
                'last_name': 'LASTNAME'
            },
            'billing_info': [{
                'email': customer['customer_email']
            }],
            'items': [{
                'name': 'Hosting Plan',
                'quantity': 1,
                'unit_price': {
                    'currency': 'USD',
                    'value': float(customer['plan_rate'])
                }
            }]
        })

        if invoice.create():
            log.info("Invoice[%s] created successfully" % (invoice.id))
        else:
            log.info(invoice.error)

        if invoice.send():
            log.info("Invoice[%s] sent successfully" % (invoice.id))
        else:
            log.info(invoice.error)

        next_payment = set_next_payment_date(next_due, customer['bill_freq'])
        customer['next_payment_date'] = next_payment.strftime('%m/%d/%Y')

    log.info('Writing new customers file to S3')
    write_new_file(customers)
Ejemplo n.º 2
0
        "address": {
            "line1": "1234 Broad St.",
            "city": "Portland",
            "state": "OR",
            "postal_code": "97216",
            "country_code": "US"
        }
    }
})

if invoice.create():
    print(("Invoice[%s] created successfully" % (invoice.id)))
else:
    print((invoice.error))

if invoice.send():  # return True or False
    print(("Invoice[%s] send successfully" % (invoice.id)))
else:
    print((invoice.error))

payment_attr = {
    "method": "CASH",
    "date": "2014-07-10 03:30:00 PST",
    "note": "Cash received."
}

if invoice.record_payment(payment_attr):  # return True or False
    print(("Payment record on Invoice[%s] successfully" % (invoice.id)))
else:
    print((invoice.error))
Ejemplo n.º 3
0
    "address": {
      "line1": "1234 Broad St.",
      "city": "Portland",
      "state": "OR",
      "postal_code": "97216",
      "country_code": "US"
    }
  }
})

if invoice.create():
  print("Invoice[%s] created successfully"%(invoice.id))
else:
  print(invoice.error)
    
if invoice.send():  # return True or False
  print("Invoice[%s] send successfully"%(invoice.id))
else:
  print(invoice.error)

payment_attr = {
    "method" : "CASH",
    "date" : "2014-07-10 03:30:00 PST",
    "note" : "Cash received."
}

if invoice.record_payment(payment_attr):  # return True or False
  print("Payment record on Invoice[%s] successfully"%(invoice.id))
else:
  print(invoice.error)