Class: Google4R::Checkout::Item::Subscription
- Inherits:
-
Object
- Object
- Google4R::Checkout::Item::Subscription
- Defined in:
- lib/google4r/checkout/shared.rb
Defined Under Namespace
Classes: RecurrentItem, SubscriptionPayment
Constant Summary collapse
- DAILY =
Constants for period
'DAILY'- WEEKLY =
'WEEKLY'- SEMI_MONTHLY =
'SEMI_MONTHLY'- MONTHLY =
'MONTHLY'- EVERY_TWO_MONTHS =
'EVERY_TWO_MONTHS'- QUARTERLY =
'QUARTERLY'- YEARLY =
'YEARLY'- MERCHANT =
Constants for type
'merchant'- GOOGLE =
'google'
Instance Attribute Summary collapse
-
#no_charge_after ⇒ Object
Optional.
-
#payments ⇒ Object
readonly
Container for payments.
-
#period ⇒ Object
Required.
-
#recurrent_items ⇒ Object
readonly
Container for recurrent items.
-
#start_date ⇒ Object
Optional.
-
#type ⇒ Object
Required.
Class Method Summary collapse
Instance Method Summary collapse
- #add_payment {|payment| ... } ⇒ Object
- #add_recurrent_item {|item| ... } ⇒ Object
-
#initialize ⇒ Subscription
constructor
A new instance of Subscription.
Constructor Details
#initialize ⇒ Subscription
Returns a new instance of Subscription.
468 469 470 471 |
# File 'lib/google4r/checkout/shared.rb', line 468 def initialize @payments = [] @recurrent_items = [] end |
Instance Attribute Details
#no_charge_after ⇒ Object
Optional. The no-charge-after attribute specifies the latest date and time that you can charge the customer for the subscription. This element can help you to ensure that you do not overcharge your customers.
407 408 409 |
# File 'lib/google4r/checkout/shared.rb', line 407 def no_charge_after @no_charge_after end |
#payments ⇒ Object (readonly)
Container for payments
443 444 445 |
# File 'lib/google4r/checkout/shared.rb', line 443 def payments @payments end |
#period ⇒ Object
Required. The period attribute specifies how frequently you will charge the customer for the subscription. Valid values for this attribute are DAILY, WEEKLY, SEMI_MONTHLY, MONTHLY, EVERY_TWO_MONTHS, QUARTERLY, and YEARLY.
412 413 414 |
# File 'lib/google4r/checkout/shared.rb', line 412 def period @period end |
#recurrent_items ⇒ Object (readonly)
Container for recurrent items
456 457 458 |
# File 'lib/google4r/checkout/shared.rb', line 456 def recurrent_items @recurrent_items end |
#start_date ⇒ Object
Optional. The start-date attribute specifies the date that the subscription's
recurrence period will begin. Like all dates in Checkout, this is in ISO 8601
format. If you set the
426 427 428 |
# File 'lib/google4r/checkout/shared.rb', line 426 def start_date @start_date end |
#type ⇒ Object
Required. The type attribute identifies the type of subscription that you are creating. The valid values for this attribute are merchant and google, and this specifies who handles the recurrences. The merchant value specifies Merchant-Handled recurrences, and the google value specifies Google-Handled recurrences.
433 434 435 |
# File 'lib/google4r/checkout/shared.rb', line 433 def type @type end |
Class Method Details
.create_from_element(element) ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/google4r/checkout/shared.rb', line 473 def self.create_from_element(element) result = Subscription.new result.no_charge_after = Time.iso8601(element.attributes['no-charge-after']) rescue nil result.period = element.attributes['period'] rescue nil result.start_date = Time.iso8601(element.attributes['start-date']) rescue nil result.type = element.attributes['type'] rescue nil element.elements['payments/subscription-payment'].each do |payment_element| result.payments << SubscriptionPayment.create_from_element(subscription, payment_element) end element.elements['recurrent-item'].each do |item_element| result.recurrent_items << Item.create_from_element(item_element) end return result end |
Instance Method Details
#add_payment {|payment| ... } ⇒ Object
445 446 447 448 449 450 451 452 453 |
# File 'lib/google4r/checkout/shared.rb', line 445 def add_payment(&block) payment = SubscriptionPayment.new(self) @payments << payment # Pass the newly generated payment to the given block to set its attributes. yield(payment) if block_given? return payment end |
#add_recurrent_item {|item| ... } ⇒ Object
458 459 460 461 462 463 464 465 466 |
# File 'lib/google4r/checkout/shared.rb', line 458 def add_recurrent_item(&block) item = RecurrentItem.new(self) @recurrent_items << item # Pass the newly generated item to the given block to set its attributes. yield(item) if block_given? return item end |