Sha256: 5fd6b9a3c9bf0485b6b5310866cd7163720fffbcfa91aa1d94ab5469ebac6f87

Contents?: true

Size: 1.47 KB

Versions: 19

Compression:

Stored size: 1.47 KB

Contents

module Paypal
  module Payment
    class Recurring < Base
      attr_optional :start_date, :description, :identifier, :status, :name, :reference, :max_fails, :auto_bill, :aggregate_amount, :aggregate_optional_amount, :final_payment_date
      attr_accessor :activation, :billing, :regular_billing, :summary

      def initialize(attributes = {})
        super
        @activation = Activation.new attributes[:activation] if attributes[:activation]
        @billing = Billing.new attributes[:billing] if attributes[:billing]
        @regular_billing = Billing.new attributes[:regular_billing] if attributes[:regular_billing]
        @summary = Summary.new attributes[:summary] if attributes[:summary]
      end

      def to_params
        params = [
          self.billing,
          self.activation
        ].compact.inject({}) do |params, attribute|
          params.merge! attribute.to_params
        end
        if self.start_date.is_a?(Time)
          self.start_date = self.start_date.to_s(:db)
        end
        params.merge!(
          :DESC  => self.description,
          :MAXFAILEDPAYMENTS => self.max_fails,
          :AUTOBILLAMT => self.auto_bill,
          :PROFILESTARTDATE => self.start_date,
          :SUBSCRIBERNAME => self.name,
          :PROFILEREFERENCE => self.reference
        )
        params.delete_if do |k, v|
          v.blank?
        end
      end

      def numeric_attribute?(key)
        super || [:max_fails, :failed_count].include?(key)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
paypal-express-0.2.8 lib/paypal/payment/recurring.rb
paypal-express-0.2.7 lib/paypal/payment/recurring.rb
paypal-express-0.2.6 lib/paypal/payment/recurring.rb
paypal-express-0.2.5 lib/paypal/payment/recurring.rb
paypal-express-0.2.4 lib/paypal/payment/recurring.rb
paypal-express-0.2.3 lib/paypal/payment/recurring.rb
paypal-express-0.2.2 lib/paypal/payment/recurring.rb
paypal-express-0.2.1 lib/paypal/payment/recurring.rb
paypal-express-0.2.0 lib/paypal/payment/recurring.rb
paypal-express-0.1.0 lib/paypal/payment/recurring.rb
paypal-express-0.0.9 lib/paypal/payment/recurring.rb
paypal-express-0.0.8 lib/paypal/payment/recurring.rb
paypal-express-0.0.7 lib/paypal/payment/recurring.rb
paypal-express-0.0.6 lib/paypal/payment/recurring.rb
paypal-express-0.0.5 lib/paypal/payment/recurring.rb
paypal-express-0.0.4 lib/paypal/payment/recurring.rb
paypal-express-0.0.3 lib/paypal/payment/recurring.rb
paypal-express-0.0.2 lib/paypal/payment/recurring.rb
paypal-express-0.0.1 lib/paypal/payment/recurring.rb