Sha256: 10d5857e5ec35a0c897edb7bde2c6f1f4cd9b448e48004be7416b9dadadb85a6

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

module PayPal
  module Recurring
    module Response
      class Profile < Base
        mapping(
          :profile_id          => :PROFILEID,
          :status              => :STATUS,
          :description         => :DESC,
          :outstanding         => :AUTOBILLOUTAMT,
          :failed              => :MAXFAILEDPAYMENTS,
          :payer_name          => :SUBSCRIBERNAME,
          :start_at            => :PROFILESTARTDATE,
          :reference           => :PROFILEREFERENCE,
          :completed           => :NUMCYCLESCOMPLETED,
          :remaining           => :NUMCYCLESREMAINING,
          :outstanding_balance => :OUTSTANDINGBALANCE,
          :failed_count        => :FAILEDPAYMENTCOUNT,
          :last_payment_date   => :LASTPAYMENTDATE,
          :last_payment_amount => :LASTPAYMENTAMT,
          :period              => :BILLINGPERIOD,
          :frequency           => :BILLINGFREQUENCY,
          :currency            => :CURRENCYCODE,
          :amount              => :AMT
        )

        OUTSTANDING = {
          "AddToNextBilling" => :next_billing,
          "NoAutoBill" => :no_auto
        }

        STATUS = {
          "Cancelled" => :canceled,
          "Active"    => :active,
          "Suspended" => :suspended
        }

        PERIOD = {
          "Month" => :monthly,
          "Year"  => :yearly,
          "Day"   => :daily
        }

        def active?
          status == :active
        end

        private
        def build_outstanding(value)
          OUTSTANDING.fetch(value, value)
        end

        def build_status(value)
          STATUS.fetch(value, value)
        end

        def build_date(string)
          Time.parse(string)
        end

        def build_period(value)
          PERIOD.fetch(value, value)
        end

        alias_method :build_start_at, :build_date
        alias_method :build_last_payment_date, :build_date
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
paypal-recurring-0.1.1 lib/paypal/recurring/response/profile.rb
paypal-recurring-0.1.0 lib/paypal/recurring/response/profile.rb