Class: Besepa::Customer
- Defined in:
- lib/besepa/customer.rb
Constant Summary collapse
- FIELDS =
[:id, :name, :taxid, :reference, :contact_name, :contact_email, :contact_phone, :contact_language, :address_street, :address_city, :address_postalcode, :address_state, :address_country, :group_ids, :status, :created_at]
Constants inherited from Resource
Constants included from Utils::Request
Utils::Request::END_POINT_URL_PREFIX
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
-
#add_bank_account(iban, bic = nil, bank_name = nil, mandate_options = {}) ⇒ Object
Adds a bank account to this customer.
-
#add_debit(debtor_bank_account_id, reference, description, amount, collect_at, creditor_account_id = nil, metadata = nil) ⇒ Object
Generates a direct debit that will be charged to this customer.
-
#add_subscription(starts_at, product_code, bank_account_code, setup_fee = 0, metadata = nil) ⇒ Object
Creates a new subscription for this customer.
-
#add_to_group(group_id) ⇒ Object
Adds this customer to the given group.
-
#bank_accounts ⇒ Object
Customer’s bank accounts.
-
#debits ⇒ Object
Debits sent to this customer.
-
#groups ⇒ Object
List of groups this customers blongs to.
-
#remove_from_group(group_id) ⇒ Object
Removed this customer from the given group.
-
#subscriptions ⇒ Object
Subscriptions from this customer.
Methods included from ApiCalls::Destroy
Methods included from ApiCalls::Update
Methods included from ApiCalls::Create
Methods included from ApiCalls::Search
Methods included from ApiCalls::List
Methods inherited from Resource
#allowed_nils, api_path, #as_json, handle_errors, #initialize, klass_name, #klass_name, query_params, #serializable_hash, #to_hash
Methods included from Utils::Request
Methods included from Utils::Connection
Constructor Details
This class inherits a constructor from Besepa::Resource
Instance Method Details
#add_bank_account(iban, bic = nil, bank_name = nil, mandate_options = {}) ⇒ Object
Adds a bank account to this customer. IBAN and BIC are the only mandatory fields. If you already have the mandate signed, you can pass mandate detail’s and account will be activated by default. Otherwise BankAccount will be marked as inactive (not usable for creating debits or subscriptions) until mandate is signed. BankAccount includes mandate’s info, including signature URL.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/besepa/customer.rb', line 103 def add_bank_account(iban, bic=nil, bank_name=nil, ={}) params = {:iban => iban } params[:bank_name] = bank_name if bank_name params[:bic] = bic if bic params[:mandate] = { scheme: ([:scheme] || "CORE"), used: ([:used] || false), mandate_type: ([:type] || "RECURRENT") } if [:signature_date] params[:mandate][:signed_at] = [:signature_date] params[:mandate][:reference] = [:reference] if [:reference] else params[:mandate][:signature_type] = [:signature_type] || 'checkbox' params[:mandate][:phone_number] = [:phone_number] if [:phone_number] end params[:mandate][:redirect_after_signature] = [:redirect_after_signature] if [:redirect_after_signature] BankAccount.create( params, {:customer_id => id} ) end |
#add_debit(debtor_bank_account_id, reference, description, amount, collect_at, creditor_account_id = nil, metadata = nil) ⇒ Object
Generates a direct debit that will be charged to this customer.
135 136 137 138 139 140 141 |
# File 'lib/besepa/customer.rb', line 135 def add_debit(debtor_bank_account_id, reference, description, amount, collect_at, creditor_account_id=nil, =nil) params = {:reference => reference, :description => description, :debtor_bank_account_id => debtor_bank_account_id, :amount => amount, :collect_at => collect_at} params[:creditor_bank_account_id] = creditor_account_id if creditor_account_id params[:metadata] = if Debit.create( params, {:customer_id => id} ) end |
#add_subscription(starts_at, product_code, bank_account_code, setup_fee = 0, metadata = nil) ⇒ Object
Creates a new subscription for this customer
76 77 78 79 80 81 |
# File 'lib/besepa/customer.rb', line 76 def add_subscription(starts_at, product_code, bank_account_code, setup_fee=0, =nil) params = {:starts_at => starts_at, :product_id => product_code, :debtor_bank_account_id => bank_account_code} params[:setup_fee] = setup_fee if setup_fee params[:metadata] = if Subscription.create( params, {:customer_id => id} ) end |
#add_to_group(group_id) ⇒ Object
Adds this customer to the given group
52 53 54 55 |
# File 'lib/besepa/customer.rb', line 52 def add_to_group(group_id) response = post "#{self.class.api_path}/#{id}/memberships/#{group_id}" response['response'].select{|c| c['id'] == group_id}.any? end |
#bank_accounts ⇒ Object
Customer’s bank accounts
22 23 24 |
# File 'lib/besepa/customer.rb', line 22 def bank_accounts BankAccount.all( {:customer_id => id} ) end |
#debits ⇒ Object
Debits sent to this customer
29 30 31 |
# File 'lib/besepa/customer.rb', line 29 def debits Debit.all( {:customer_id => id} ) end |
#groups ⇒ Object
List of groups this customers blongs to
43 44 45 |
# File 'lib/besepa/customer.rb', line 43 def groups Group.all( {:customer_id => id} ) end |
#remove_from_group(group_id) ⇒ Object
Removed this customer from the given group
62 63 64 65 |
# File 'lib/besepa/customer.rb', line 62 def remove_from_group(group_id) response = delete "#{self.class.api_path}/#{id}/memberships/#{group_id}" response['response'].select{|c| c['id'] == group_id}.empty? end |
#subscriptions ⇒ Object
Subscriptions from this customer
36 37 38 |
# File 'lib/besepa/customer.rb', line 36 def subscriptions Subscription.all( {:customer_id => id} ) end |