Sha256: 61f58aead758388b2400f8b3dfad8b0f43f70164e8dac4c67a0fb48d9730567d

Contents?: true

Size: 1.47 KB

Versions: 41

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,
          :AUTOBILLOUTAMT => 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

41 entries across 41 versions & 4 rubygems

Version Path
ianfleeton-paypal-express-0.8.7 lib/paypal/payment/recurring.rb
ianfleeton-paypal-express-0.8.6 lib/paypal/payment/recurring.rb
ianfleeton-paypal-express-0.8.5 lib/paypal/payment/recurring.rb
ianfleeton-paypal-express-0.8.4 lib/paypal/payment/recurring.rb
ianfleeton-paypal-express-0.8.3 lib/paypal/payment/recurring.rb
ianfleeton-paypal-express-0.8.2 lib/paypal/payment/recurring.rb
dfg-paypal-0.8.2 lib/paypal/payment/recurring.rb
creative-paypal-express-1.0.1.dev2 lib/paypal/payment/recurring.rb
creative-paypal-express-1.0.1.dev1 lib/paypal/payment/recurring.rb
creative-paypal-express-1.0.0 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.2.4 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.2.3 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.2.2 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.2.1 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.2 lib/paypal/payment/recurring.rb
creative-paypal-express-0.8.1 lib/paypal/payment/recurring.rb
paypal-express-0.8.1 lib/paypal/payment/recurring.rb
paypal-express-0.8.0 lib/paypal/payment/recurring.rb
paypal-express-0.7.1 lib/paypal/payment/recurring.rb
paypal-express-0.7.0 lib/paypal/payment/recurring.rb