Class: KPM::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/kpm/account.rb

Constant Summary collapse

KILLBILL_HOST =

Killbill server

ENV['KILLBILL_HOST'] || '127.0.0.1'
KILLBILL_URL =
'http://'.concat(KILLBILL_HOST).concat(':8080')
KILLBILL_API_VERSION =
'1.0'
KILLBILL_USER =

USER/PWD

ENV['KILLBILL_USER'] || 'admin'
KILLBILL_PASSWORD =
ENV['KILLBILL_PASSWORD'] || 'password'
KILLBILL_API_KEY =

TENANT KEY

ENV['KILLBILL_API_KEY'] || 'bob'
KILLBILL_API_SECRET =
ENV['KILLBILL_API_SECRET'] || 'lazar'
TMP_DIR_PEFIX =

Temporary directory

'killbill'
TMP_DIR =
Dir.mktmpdir(TMP_DIR_PEFIX)
WHO =

Created By

'kpm_export_import'
SAFE_PAYMENT_METHOD =

safe payment method

'__EXTERNAL_PAYMENT__'
PLUGIN_NAME_COLUMN =
'plugin_name'
REMOVE_DATA_FROM =

fields to remove from the export files

{:accounts => [:name, :address1, :address2, :city, :state_or_province, :phone, :email],
:account_history => [:name, :address1, :address2, :city, :state_or_province, :phone, :email]}
DATE_COLUMNS_TO_FIX =
['created_date','updated_date','processing_available_date','effective_date',
'boot_date','start_timestamp','last_access_time','payment_date','original_created_date',
'last_sys_update_date','charged_through_date','bundle_start_date','start_date']
ROUND_TRIP_EXPORT_IMPORT_MAP =

round trip constants duplicate record

{:accounts => {:id => :accounts_id, :external_key => :accounts_id}, :all => {:account_id => :accounts_id},
                                :account_history => {:id => :account_history_id, :external_key => :accounts_id, :payment_method_id => :payment_methods_id},
                                :account_emails => {:id => :account_emails_id}, :account_email_history => {:id => :account_email_history_id},
                                :subscription_events => {:id => :subscription_events_id},:subscriptions => {:id => :subscriptions_id},
                                :bundles => {:id => :bundles_id},:blocking_states => {:id => :blocking_states_id, :blockable_id => nil},
                                :invoice_items => {:id => :invoice_items_id, :child_account_id => nil, :invoice_id => :invoices_id, :bundle_id => :bundles_id, :subscription_id => :subscriptions_id },
                                :invoices => {:id => :invoices_id},
                                :invoice_payments => {:id => :invoice_payments_id, :invoice_id => :invoices_id, :payment_id => :payments_id},
                                :invoice_parent_children => {:id => :invoice_parent_children_id, :parent_invoice_id  => nil, :child_invoice_id  => nil, :child_account_id => nil},
                                :payment_attempts => {:id => :payment_attempts_id, :payment_method_id  => :payment_methods_id, :transaction_id   => :payment_transactions_id},
                                :payment_attempt_history => {:id => :payment_attempt_history_id, :payment_method_id  => :payment_methods_id, :transaction_id   => :payment_transactions_id},
                                :payment_methods => {:id => :payment_methods_id, :external_key => :generate},:payment_method_history => {:id => :payment_method_history_id},
                                :payments => {:id => :payments_id, :payment_method_id  => :payment_methods_id},
                                :payment_history => {:id => :payment_history_id, :payment_method_id  => :payment_methods_id},
                                :payment_transactions => {:id => :payment_transactions_id, :payment_id   => :payments_id},
                                :payment_transaction_history => {:id => :payment_transaction_history_id, :payment_id   => :payments_id},
                                :_invoice_payment_control_plugin_auto_pay_off  => {:payment_method_id => :payment_methods_id, :payment_id   => :payments_id},
                                :rolled_up_usage => {:id => :rolled_up_usage_id, :subscription_id  => :subscriptions_id, :tracking_id => nil},
                                :custom_fields  => {:id => :custom_fields_id},:custom_field_history  => {:id => :custom_field_history_id},
                                :tag_definitions => {:id => :tag_definitions_id},:tag_definition_history => {:id => :tag_definition_history_id},
                                :tags => {:id => :tags_id, :object_id => nil},
                                :tag_history => {:id => :tag_history_id, :object_id => nil},
                                :audit_log => {:id => :audit_log_id}
}
DELIMITERS =

delimeters to sniff

[',','|']
DEFAULT_DELIMITER =
"|"

Instance Method Summary collapse

Constructor Details

#initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil, database_name = nil, database_credentials = nil, database_host = nil, database_port = nil, data_delimiter = nil, logger = nil) ⇒ Account

Returns a new instance of Account.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/kpm/account.rb', line 74

def initialize(config_file = nil, killbill_api_credentials = nil, killbill_credentials = nil, killbill_url = nil,
               database_name = nil, database_credentials = nil, database_host = nil, database_port = nil, data_delimiter = nil, logger = nil)
  @killbill_api_key = KILLBILL_API_KEY
  @killbill_api_secrets = KILLBILL_API_SECRET
  @killbill_url = KILLBILL_URL
  @killbill_user = KILLBILL_USER
  @killbill_password = KILLBILL_PASSWORD
  @delimiter = data_delimiter || DEFAULT_DELIMITER
  @logger = logger
  @tables_id = Hash.new


  set_killbill_options(killbill_api_credentials,killbill_credentials,killbill_url)
  set_database_options(database_host,database_port,database_name,database_credentials,logger)

  load_config_from_file(config_file)

end

Instance Method Details

#export_data(account_id = nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/kpm/account.rb', line 93

def export_data( = nil)

  if  === :export.to_s
    raise Interrupt, 'Need to specify an account id'
  end

  export_data = fetch_export_data()
  export_file = export(export_data)

  if not File.exist?(export_file)
    raise Interrupt, 'Account id not found'
  else
    @logger.info "\e[32mData exported under #{export_file}\e[0m"
  end

  export_file
end

#import_data(source_file, tenant_record_id, skip_payment_methods, round_trip_export_import = false, generate_record_id = false) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/kpm/account.rb', line 111

def import_data(source_file,tenant_record_id, skip_payment_methods, round_trip_export_import = false, generate_record_id = false)

  @generate_record_id = generate_record_id
  @tenant_record_id = tenant_record_id
  @round_trip_export_import = round_trip_export_import

  if source_file === :import.to_s
    raise Interrupt, 'Need to specify a file'
  end

  if not File.exist?(source_file)
    raise Interrupt, 'Need to specify a valid file'
  end

  @delimiter = sniff_delimiter(source_file) || @delimiter

  sanitize_and_import(source_file, skip_payment_methods)
end