lib/mousetrap/subscription.rb in cameroncox-mousetrap-0.5.3.10 vs lib/mousetrap/subscription.rb in cameroncox-mousetrap-0.6.1
- old
+ new
@@ -6,24 +6,30 @@
:billing_first_name,
:billing_last_name,
:credit_card_number,
:credit_card_expiration_month,
:credit_card_expiration_year,
+ :credit_card_code,
+ :billing_country,
+ :billing_address,
+ :billing_city,
+ :billing_state,
: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,
- :invoices
+ :invoices,
+ :items
def self.[](code)
raise_api_unsupported_error
end
@@ -37,43 +43,38 @@
def self.exists?(code)
raise_api_unsupported_error
end
+ def current_invoice
+ invoice_attributes = if invoices['invoice'].kind_of?(Array)
+ invoices['invoice'][0]
+ else
+ invoices['invoice']
+ end
+
+ Invoice.new(invoice_attributes)
+ end
+
def attributes
{
:id => id,
:plan_code => plan_code,
:billing_first_name => billing_first_name,
:billing_last_name => billing_last_name,
:credit_card_number => credit_card_number,
:credit_card_expiration_month => credit_card_expiration_month,
:credit_card_expiration_year => credit_card_expiration_year,
+ :credit_card_code => credit_card_code,
+ :billing_country => billing_country,
+ :billing_address => billing_address,
+ :billing_city => billing_city,
+ :billing_state => billing_state,
:billing_zip_code => billing_zip_code,
}
end
- def current_invoice
- invoice_record = if invoices['invoice'].kind_of?(Array)
- Invoice.new({
- :id => invoices['invoice'][0]['id'],
- :number => invoices['invoice'][0]['number'],
- :created_at => invoices['invoice'][0]['createdDatetime'],
- :billing_date => invoices['invoice'][0]['billingDatetime']
- })
- else
- Invoice.new({
- :id => invoices['invoice']['id'],
- :number => invoices['invoice']['number'],
- :created_at => invoices['invoice']['createdDatetime'],
- :billing_date => invoices['invoice']['billingDatetime']
- })
- end
-
- invoice_record
- end
-
def attributes_for_api
self.class.attributes_for_api(attributes)
end
def destroy
@@ -113,10 +114,11 @@
:canceled_at,
:created_at,
:credit_card_expiration_date,
:credit_card_last_four_digits,
:credit_card_type,
+ :credit_card_verification_code,
:items,
:invoices
def self.plural_resource_name
'subscriptions'
@@ -132,10 +134,15 @@
: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],
+ :ccCardCode => attributes[:credit_card_code],
+ :ccCountry => attributes[:billing_country],
+ :ccAddress => attributes[:billing_address],
+ :ccCity => attributes[:billing_city],
+ :ccState => attributes[:billing_state],
:ccZip => attributes[:billing_zip_code]
}
end
def self.attributes_from_api(attributes)
@@ -144,11 +151,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'],
- :invoices => attributes['invoices']
+ :invoices => attributes['invoices'],
+ :items => attributes['items']
}
end
end
end