Class: Google4R::Checkout::Item::Subscription

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSubscription

Returns a new instance of Subscription.



475
476
477
478
# File 'lib/google4r/checkout/shared.rb', line 475

def initialize
  @payments = []
  @recurrent_items = []
end

Instance Attribute Details

#no_charge_afterObject

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.



414
415
416
# File 'lib/google4r/checkout/shared.rb', line 414

def no_charge_after
  @no_charge_after
end

#paymentsObject (readonly)

Container for payments



450
451
452
# File 'lib/google4r/checkout/shared.rb', line 450

def payments
  @payments
end

#periodObject

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.



419
420
421
# File 'lib/google4r/checkout/shared.rb', line 419

def period
  @period
end

#recurrent_itemsObject (readonly)

Container for recurrent items



463
464
465
# File 'lib/google4r/checkout/shared.rb', line 463

def recurrent_items
  @recurrent_items
end

#start_dateObject

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 <unit-price> tag’s value to a nonzero value, then the start-date for the subscription will automatically be set to the time that is exactly one recurrence period after the order is placed.



433
434
435
# File 'lib/google4r/checkout/shared.rb', line 433

def start_date
  @start_date
end

#typeObject

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.



440
441
442
# File 'lib/google4r/checkout/shared.rb', line 440

def type
  @type
end

Class Method Details

.create_from_element(element, shopping_cart) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/google4r/checkout/shared.rb', line 480

def self.create_from_element(element, shopping_cart)
  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.each('payments/subscription-payment') do |payment_element|
    result.payments << SubscriptionPayment.create_from_element(result, payment_element)
  end
  
  element.elements.each('recurrent-item') do |item_element|
    result.recurrent_items << Item.create_from_element(item_element, shopping_cart)
  end
  
  return result
end

Instance Method Details

#add_payment {|payment| ... } ⇒ Object

Yields:

  • (payment)


452
453
454
455
456
457
458
459
460
# File 'lib/google4r/checkout/shared.rb', line 452

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

Yields:

  • (item)


465
466
467
468
469
470
471
472
473
# File 'lib/google4r/checkout/shared.rb', line 465

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