Class: Customers

Inherits:
OpenPayResource show all
Defined in:
lib/openpay/customers.rb

Instance Attribute Summary

Attributes inherited from OpenPayResource

#api_hook

Instance Method Summary collapse

Methods inherited from OpenPayResource

#delete, #delete_all, #each, #env, #errors?, #get, #get_with_custom_url, #hash2json, #initialize, #json2hash, #list, #post, #put

Constructor Details

This class inherits a constructor from OpenPayResource

Instance Method Details

#all_bank_accounts(customer) ⇒ Object



14
15
16
# File 'lib/openpay/customers.rb', line 14

def all_bank_accounts(customer)
  get("#{customer}/bankaccounts/")
end

#all_cards(customer) ⇒ Object



196
197
198
# File 'lib/openpay/customers.rb', line 196

def all_cards(customer)
  get("#{customer}/cards")
end

#all_charges(customer_id) ⇒ Object

return all charges for the given customer_id



57
58
59
# File 'lib/openpay/customers.rb', line 57

def all_charges(customer_id)
  get("#{customer_id}/charges/")
end

#all_payouts(customer_id) ⇒ Object



82
83
84
# File 'lib/openpay/customers.rb', line 82

def all_payouts(customer_id)
  get("#{customer_id}/payouts")
end

#all_subscriptions(customer_id) ⇒ Object



137
138
139
# File 'lib/openpay/customers.rb', line 137

def all_subscriptions(customer_id)
  get("#{customer_id}/subscriptions/")
end

#all_transfers(customer_id) ⇒ Object



105
106
107
# File 'lib/openpay/customers.rb', line 105

def all_transfers(customer_id)
  get("#{customer_id}/transfers/")
end

#cancel_charge(customer_id, charge_id) ⇒ Object



61
62
63
# File 'lib/openpay/customers.rb', line 61

def cancel_charge(customer_id, charge_id)
  post(charge_id, "#{customer_id}/charges/#{charge_id}/cancel")
end

#capture_charge(customer_id, charge_id) ⇒ Object



69
70
71
# File 'lib/openpay/customers.rb', line 69

def capture_charge(customer_id, charge_id)
  post('', "#{customer_id}/charges/#{charge_id}/capture")
end

#confirm_customer_capture(customer_id, charge_id, amount) ⇒ Object



73
74
75
# File 'lib/openpay/customers.rb', line 73

def confirm_customer_capture(customer_id, charge_id, amount)
  post(amount, "#{customer_id}/charges/#{charge_id}/capture")
end

#create_bank_account(customer, bank_account) ⇒ Object

Bankaccount



6
7
8
# File 'lib/openpay/customers.rb', line 6

def (customer, )
  create(, "#{customer}/bankaccounts")
end

#create_card(customer, card) ⇒ Object

Card



165
166
167
# File 'lib/openpay/customers.rb', line 165

def create_card(customer, card)
  create(card, "#{customer}/cards")
end

#create_charge(customer_id, charge) ⇒ Object

Charges customers.create_charge(customer_id,charge)



43
44
45
# File 'lib/openpay/customers.rb', line 43

def create_charge(customer_id, charge)
  create(charge, "#{customer_id}/charges")
end

#create_payout(customer_id, payout) ⇒ Object

Payouts



78
79
80
# File 'lib/openpay/customers.rb', line 78

def create_payout(customer_id, payout)
  post(payout, "#{customer_id}/payouts")
end

#create_subscription(subscription, customer_id) ⇒ Object

Subscriptions



124
125
126
127
# File 'lib/openpay/customers.rb', line 124

def create_subscription(subscription, customer_id)
  #revisar la url
  post(subscription, "#{customer_id}/subscriptions")
end

#create_transfer(customer_id, transfer) ⇒ Object

Transfers



101
102
103
# File 'lib/openpay/customers.rb', line 101

def create_transfer(customer_id, transfer)
  post(transfer, "#{customer_id}/transfers")
end

#delete_all_bank_accounts(customer) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/openpay/customers.rb', line 32

def delete_all_bank_accounts(customer)
  if env == :production
    raise OpenpayException.new('This method is not supported on PRODUCTION', false)
  end
  (customer) do ||
    delete("#{customer}/bankaccounts/#{['id']}")
  end
end

#delete_all_cards(customer_id) ⇒ Object



177
178
179
180
181
182
183
184
# File 'lib/openpay/customers.rb', line 177

def delete_all_cards(customer_id)
  if env == :production
    raise OpenpayException.new('This method is not supported on PRODUCTION', false)
  end
  each_card(customer_id) do |card|
    delete_card(customer_id, card['id'])
  end
end

#delete_all_subscriptions(customer_id) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/openpay/customers.rb', line 155

def delete_all_subscriptions(customer_id)
  if env == :production
    raise OpenpayException.new('This method is not supported on PRODUCTION', false)
  end
  all_subscriptions(customer_id).each do |sub|
    delete_subscription(customer_id, sub['id'])
  end
end

#delete_bank_account(customer, bank_id) ⇒ Object



28
29
30
# File 'lib/openpay/customers.rb', line 28

def (customer, bank_id)
  delete("#{customer}/bankaccounts/#{bank_id}")
end

#delete_card(customer, card_id) ⇒ Object



173
174
175
# File 'lib/openpay/customers.rb', line 173

def delete_card(customer, card_id)
  delete("#{customer}/cards/#{card_id}")
end

#delete_subscription(customer_id, subscription_id) ⇒ Object



129
130
131
# File 'lib/openpay/customers.rb', line 129

def delete_subscription(customer_id, subscription_id)
  delete("#{customer_id}/subscriptions/#{subscription_id}")
end

#each_bank_account(customer) ⇒ Object



22
23
24
25
26
# File 'lib/openpay/customers.rb', line 22

def (customer)
  get("#{customer}/bankaccounts/").each do ||
    yield 
  end
end

#each_card(customer) ⇒ Object



186
187
188
189
190
# File 'lib/openpay/customers.rb', line 186

def each_card(customer)
  get("#{customer}/cards").each do |card|
    yield card
  end
end

#each_payout(customer_id) ⇒ Object



90
91
92
93
94
# File 'lib/openpay/customers.rb', line 90

def each_payout(customer_id)
  all_payouts(customer_id).each do |pay|
    yield pay
  end
end

#each_subscription(customer_id) ⇒ Object



145
146
147
148
149
# File 'lib/openpay/customers.rb', line 145

def each_subscription(customer_id)
  all_subscriptions(customer_id).each do |cust|
    yield cust
  end
end

#each_transfer(customer_id) ⇒ Object



117
118
119
120
121
# File 'lib/openpay/customers.rb', line 117

def each_transfer(customer_id)
  all_transfers(customer_id).each do |trans|
    yield trans
  end
end

#get_bank_account(customer, bank_id) ⇒ Object



10
11
12
# File 'lib/openpay/customers.rb', line 10

def (customer, bank_id)
  get("#{customer}/bankaccounts/#{bank_id}")
end

#get_card(customer, card_id) ⇒ Object



169
170
171
# File 'lib/openpay/customers.rb', line 169

def get_card(customer, card_id)
  get("#{customer}/cards/#{card_id}")
end

#get_charge(customer_id, charge_id) ⇒ Object

gets a charge_id for a given customer_id



48
49
50
# File 'lib/openpay/customers.rb', line 48

def get_charge(customer_id, charge_id)
  get("#{customer_id}/charges/#{charge_id}")
end

#get_payout(customer_id, payout_id) ⇒ Object



86
87
88
# File 'lib/openpay/customers.rb', line 86

def get_payout(customer_id, payout_id)
  get("#{customer_id}/payouts/#{payout_id}")
end

#get_subscription(customer_id, subscription_id) ⇒ Object



133
134
135
# File 'lib/openpay/customers.rb', line 133

def get_subscription(customer_id, subscription_id)
  get("#{customer_id}/subscriptions/#{subscription_id}")
end

#get_transfer(customer_id, transfer_id) ⇒ Object



113
114
115
# File 'lib/openpay/customers.rb', line 113

def get_transfer(customer_id, transfer_id)
  get("#{customer_id}/transfers/#{transfer_id}")
end

#list_bankaccounts(customer, search_params) ⇒ Object



18
19
20
# File 'lib/openpay/customers.rb', line 18

def list_bankaccounts(customer, search_params)
  get("#{customer}/bankaccounts#{search_params.to_s}")
end

#list_cards(customer, search_params) ⇒ Object



192
193
194
# File 'lib/openpay/customers.rb', line 192

def list_cards(customer, search_params)
  get("#{customer}/cards#{search_params.to_s}")
end

#list_charges(customer, search_params) ⇒ Object



52
53
54
# File 'lib/openpay/customers.rb', line 52

def list_charges(customer, search_params)
  get("#{customer}/charges#{search_params.to_s}")
end

#list_payouts(customer, search_params) ⇒ Object



96
97
98
# File 'lib/openpay/customers.rb', line 96

def list_payouts(customer, search_params)
  get("#{customer}/payouts#{search_params.to_s}")
end

#list_subscriptions(customer, search_params) ⇒ Object



141
142
143
# File 'lib/openpay/customers.rb', line 141

def list_subscriptions(customer, search_params)
  get("#{customer}/subscriptions#{search_params.to_s}")
end

#list_transfers(customer, search_params) ⇒ Object



109
110
111
# File 'lib/openpay/customers.rb', line 109

def list_transfers(customer, search_params)
  get("#{customer}/transfers#{search_params.to_s}")
end

#refund_charge(customer_id, charge_id, description) ⇒ Object



65
66
67
# File 'lib/openpay/customers.rb', line 65

def refund_charge(customer_id, charge_id, description)
  post(description, "#{customer_id}/charges/#{charge_id}/refund")
end

#update_subscription(subscription, customer, params) ⇒ Object



151
152
153
# File 'lib/openpay/customers.rb', line 151

def update_subscription(subscription, customer, params)
  put(params, "#{customer}/subscriptions/#{subscription}")
end