Skip to content

Instantly share code, notes, and snippets.

@jaredk2g
jaredk2g / list-customers.php
Created June 21, 2019 15:46
Retrieves customer list through Invoiced using pagination
<?php
require("../vendor/autoload.php");
$invoiced = new Invoiced\Client("MY-API-KEY");
$page = 1;
$hasNextPage = true;
while ($hasNextPage) {
@jaredk2g
jaredk2g / example.md
Created May 25, 2018 14:12
Editing subscription with coupons
curl https://api.sandbox.invoiced.com/subscriptions \
	-u 1234: \
	-d customer=137208 \
	-d plan=starter \
	-d discounts="test"
{
@jaredk2g
jaredk2g / invoice.mustache
Created April 19, 2018 19:56
Standard invoice template
<div class="two-col clearfix">
<div class="title">
{{theme.header}}
<small>{{invoice.number}}</small>
</div>
<div class="col">
<div class="from-holder">
<div class="logo">
{{#company.logo}}<img src="{{company.logo}}" />{{/company.logo}}
@jaredk2g
jaredk2g / flag_invoices.py
Created April 2, 2018 17:44
Flag invoices on Invoiced that are > 60 days old
import datetime
import time
import invoiced
apiKey = "enter api key here"
# Flags open invoices that are > N days old
threshold = 60 # days
client = invoiced.Client(apiKey, True)
@jaredk2g
jaredk2g / gist:3a505bcc1d24d8ee73af9b1125cc9105
Created December 11, 2017 22:53
Creating an invoice with a ship to address
curl "https://api.sandbox.invoiced.com/invoices" \
-u 4d7a57bdfecc2a2cb4319f3a7c158c14: \
-d customer=93886 \
-d payment_terms="NET 14" \
-d items[0][name]="Copy paper, Case" \
-d items[0][quantity]=1 \
-d items[0][unit_cost]=45 \
-d items[1][catalog_item]="delivery" \
-d items[1][quantity]=1 \
-d ship_to[name]="Parag Patel" \
@jaredk2g
jaredk2g / create_credit_note.rb
Created December 11, 2017 15:46
Creating a credit note on Invoiced in Ruby
require 'invoiced'
invoiced = Invoiced::Client.new('XXXXX', true)
customerId = 134523
invoiceId = 1213602
creditNote = invoiced.CreditNote.create(
:customer => customerId,
:invoice => invoiceId,
@jaredk2g
jaredk2g / idempotence.rb
Last active July 27, 2017 14:11
Invoiced API Impotence
require 'invoiced'
require 'securerandom'
invoiced = Invoiced::Client.new('api_key_here')
# This will create a customer
customer = invoiced.Customer.create({
:name => 'My Customer'
}, {
:idempotency_key => SecureRandom.uuid
@jaredk2g
jaredk2g / create_invoice.rb
Created March 31, 2017 15:39
Invoice billing period
invoiced.Invoice.create(
# ...
:metadata => {
:billing_period => "Mar 1, 2017 - Mar 31, 2017"
}
)
@jaredk2g
jaredk2g / get_subscription_approvals.py
Created January 30, 2017 22:18
Gets list of subscription approvals from Invoiced
import invoiced
client = invoiced.Client('_YOUR_API_KEY_')
subscriptions, metadata = client.Subscription.list(per_page=1000, expand="customer")
for subscription in subscriptions:
if (subscription.approval):
print(subscription.customer['name']+" approved "+subscription.plan+" from IP: "+subscription.approval['ip'])
@jaredk2g
jaredk2g / events.php
Last active September 12, 2016 21:29
List the events for an invoice on Invoiced (PHP)
<?php
// prerequisite: run "composer require invoiced/invoiced"
require 'vendor/autoload.php';
$invoiced = new Invoiced\Client('TODO_INSERT_API_KEY');
$objectType = 'invoice';
$invoiceId = 'TODO_INSERT_INVOICE_ID';