-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick_start.rb
More file actions
51 lines (45 loc) · 1.2 KB
/
quick_start.rb
File metadata and controls
51 lines (45 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require "bundler/setup"
# Load the gem
require "facturapi"
# Setup your api key
# Facturapi.configuration.api_key = "sk_test_API_KEY"
Facturapi.configuration.api_key = "sk_test_r2QW0xXyOwNgnwqEPB3nKk8EJV6Yq43B"
# Create a new customer
customer = Facturapi::Customer.create({
legal_name: "Juan Perez Perez",
tax_id: "XAXX010101000",
email: "juanperez@example.com",
address: {
zip: "05000",
street: "Av. Gansitos"
}
})
# Create a new product
product = Facturapi::Product.create({
description: "Guitarra",
product_key: "60131303", # Check for this catalogue
sku: "TVP090909",
price: 1500.00
})
# Create the invoice
invoice = Facturapi::Invoice.create({
customer: customer.id, # use the customer id
items: [
{
quantity: 2,
product: product.id # use the product id
}
],
use: "G03",
payment_form: Facturapi::Invoice::PaymentForm::TARJETA_DE_CREDITO, # add a payment form
payment_method: Facturapi::Invoice::PaymentMethod::UNA_EXHIBICION,
folio_number: "300",
series: "F"
})
# Send the invoice by email
invoice.send_by_email!
# Or download it
Dir.mkdir "tmp" unless File.exist? "tmp"
File.open("tmp/#{invoice.id}.zip", "w") do |f|
f.write invoice.download_zip!
end