lib/mousetrap/subscription.rb in cameroncox-mousetrap-0.5.3.3 vs lib/mousetrap/subscription.rb in cameroncox-mousetrap-0.5.3.4
- old
+ new
@@ -8,22 +8,22 @@
:credit_card_number,
:credit_card_expiration_month,
:credit_card_expiration_year,
:billing_zip_code,
:plan,
-
:customer_code # belongs to customer
# Attributes that come _from_ the API.
attr_reader \
:id,
:canceled_at,
:created_at,
:credit_card_expiration_date,
:credit_card_last_four_digits,
:credit_card_type,
- :items
+ :items,
+ :invoices
def self.[](code)
raise_api_unsupported_error
end
@@ -50,10 +50,27 @@
:credit_card_expiration_year => credit_card_expiration_year,
:billing_zip_code => billing_zip_code,
}
end
+ def current_invoice
+ invoice_record = if invoices.kind_of?(Array)
+ invoices['invoice'].first
+ else
+ invoices['invoice']
+ end
+
+ attributes = {
+ :id => invoice_record['id'],
+ :number => invoice_record['number'],
+ :created_at => invoice_record['createdDatetime'],
+ :billing_date => invoice_record['billingDatetime']
+ }
+
+ Invoice.new(attributes)
+ end
+
def attributes_for_api
self.class.attributes_for_api(attributes)
end
def destroy
@@ -93,11 +110,12 @@
:canceled_at,
:created_at,
:credit_card_expiration_date,
:credit_card_last_four_digits,
:credit_card_type,
- :items
+ :items,
+ :invoices
def self.plural_resource_name
'subscriptions'
end
@@ -111,11 +129,11 @@
:ccFirstName => attributes[:billing_first_name],
:ccLastName => attributes[:billing_last_name],
:ccNumber => attributes[:credit_card_number],
:ccExpMonth => ("%02d" % attributes[:credit_card_expiration_month] if attributes[:credit_card_expiration_month]),
:ccExpYear => attributes[:credit_card_expiration_year],
- :ccZip => attributes[:billing_zip_code],
+ :ccZip => attributes[:billing_zip_code]
}
end
def self.attributes_from_api(attributes)
{
@@ -123,10 +141,11 @@
:canceled_at => attributes['canceledDatetime'],
:created_at => attributes['createdDatetime'],
:credit_card_expiration_date => attributes['ccExpirationDate'],
:credit_card_last_four_digits => attributes['ccLastFour'],
:credit_card_type => attributes['ccType'],
- :items => attributes['items']
+ :items => attributes['items'],
+ :invoices => attributes['invoices']
}
end
end
end