Class: PayWhirl

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

Overview

PayWhirl API Client

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, api_base = 'https://api.paywhirl.com') ⇒ PayWhirl

Returns a new instance of PayWhirl.



27
28
29
30
# File 'lib/paywhirl.rb', line 27

def initialize(api_key, api_secret, api_base = 'https://api.paywhirl.com')
  @api_base = api_base
  @headers = { api_key: api_key, api_secret: api_secret }
end

Instance Method Details

#add_promo_code_to_invoice(invoice_id, promo_code) ⇒ Object



176
177
178
# File 'lib/paywhirl.rb', line 176

def add_promo_code_to_invoice(invoice_id, promo_code)
  post("/invoice/#{invoice_id}/add-promo", promo_code: promo_code)
end

#auth_customer(email, password) ⇒ Object



64
65
66
# File 'lib/paywhirl.rb', line 64

def auth_customer(email, password)
  post('/auth/customer', email: email, password: password)
end

#create_address(params) ⇒ Object



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

def create_address(params)
  post('/customer/address', params)
end

#create_card(params) ⇒ Object



228
229
230
# File 'lib/paywhirl.rb', line 228

def create_card(params)
  post('/create/card', params)
end

#create_charge(params) ⇒ Object



208
209
210
# File 'lib/paywhirl.rb', line 208

def create_charge(params)
  post('/create/charge', params)
end

#create_customer(params) ⇒ Object



68
69
70
# File 'lib/paywhirl.rb', line 68

def create_customer(params)
  post('/create/customer', params)
end

#create_invoice(params) ⇒ Object



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

def create_invoice(params)
  post('/invoices', params, true)
end

#create_plan(params) ⇒ Object



115
116
117
# File 'lib/paywhirl.rb', line 115

def create_plan(params)
  post('/create/plan', params)
end

#create_promo(params) ⇒ Object



244
245
246
# File 'lib/paywhirl.rb', line 244

def create_promo(params)
  post('/create/promo', params)
end

#delete_address(address_id) ⇒ Object



56
57
58
# File 'lib/paywhirl.rb', line 56

def delete_address(address_id)
  delete("/customer/address/#{address_id}")
end

#delete_card(card_id) ⇒ Object



232
233
234
# File 'lib/paywhirl.rb', line 232

def delete_card(card_id)
  post('/delete/card', id: card_id)
end

#delete_customer(id, forget = false) ⇒ Object



76
77
78
79
# File 'lib/paywhirl.rb', line 76

def delete_customer(id, forget = false)
  params = { id: id, forget: forget ? '1' : nil }
  post('/delete/customer', params)
end

#delete_invoice(invoice_id) ⇒ Object



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

def delete_invoice(invoice_id)
  post('/delete/invoice', id: invoice_id)
end

#delete_promo(promo_id) ⇒ Object



248
249
250
# File 'lib/paywhirl.rb', line 248

def delete_promo(promo_id)
  post('/delete/promo', id: promo_id)
end

#get_accountObject



260
261
262
# File 'lib/paywhirl.rb', line 260

def 
  get('/account')
end

#get_address(address_id) ⇒ Object



44
45
46
# File 'lib/paywhirl.rb', line 44

def get_address(address_id)
  get("/customer/address/#{address_id}")
end

#get_addresses(customer_id) ⇒ Object



40
41
42
# File 'lib/paywhirl.rb', line 40

def get_addresses(customer_id)
  get("/customer/addresses/#{customer_id}")
end

#get_answers(params_or_customer_id) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/paywhirl.rb', line 92

def get_answers(params_or_customer_id)
  params =
    if params_or_customer_id.respond_to?(:to_i)
      { customer_id: params_or_customer_id }
    else
      params_or_customer_id
    end

  get('/answers', params)
end

#get_card(card_id) ⇒ Object



224
225
226
# File 'lib/paywhirl.rb', line 224

def get_card(card_id)
  get("/card/#{card_id}")
end

#get_cards(customer_id) ⇒ Object



220
221
222
# File 'lib/paywhirl.rb', line 220

def get_cards(customer_id)
  get("/cards/#{customer_id}")
end

#get_charge(charge_id) ⇒ Object



212
213
214
# File 'lib/paywhirl.rb', line 212

def get_charge(charge_id)
  get("/charge/#{charge_id}")
end

#get_customer(customer_id) ⇒ Object



36
37
38
# File 'lib/paywhirl.rb', line 36

def get_customer(customer_id)
  get("/customer/#{customer_id}")
end

#get_customers(params = {}) ⇒ Object



32
33
34
# File 'lib/paywhirl.rb', line 32

def get_customers(params = {})
  get('/customers', params)
end

#get_email_template(template_id) ⇒ Object



252
253
254
# File 'lib/paywhirl.rb', line 252

def get_email_template(template_id)
  get("/email/#{template_id}")
end

#get_gateway(gateway_id) ⇒ Object



204
205
206
# File 'lib/paywhirl.rb', line 204

def get_gateway(gateway_id)
  get("/gateway/#{gateway_id}")
end

#get_gatewaysObject



200
201
202
# File 'lib/paywhirl.rb', line 200

def get_gateways
  get('/gateways')
end

#get_invoice(invoice_id) ⇒ Object



164
165
166
# File 'lib/paywhirl.rb', line 164

def get_invoice(invoice_id)
  get("/invoice/#{invoice_id}")
end

#get_invoices(customer_id, all_invoices = false) ⇒ Object



160
161
162
# File 'lib/paywhirl.rb', line 160

def get_invoices(customer_id, all_invoices = false)
  get("/invoices/#{customer_id}", all: all_invoices ? '1' : nil)
end

#get_multi_auth_token(params) ⇒ Object



284
285
286
# File 'lib/paywhirl.rb', line 284

def get_multi_auth_token(params)
  post('/multiauth', params)
end

#get_plan(plan_id = nil) ⇒ Object



111
112
113
# File 'lib/paywhirl.rb', line 111

def get_plan(plan_id = nil)
  get("/plan/#{plan_id}")
end

#get_plans(params = {}) ⇒ Object



107
108
109
# File 'lib/paywhirl.rb', line 107

def get_plans(params = {})
  get('/plans', params)
end

#get_profile(customer_id) ⇒ Object



60
61
62
# File 'lib/paywhirl.rb', line 60

def get_profile(customer_id)
  get("/customer/profile/#{customer_id}")
end

#get_promo(promo_id) ⇒ Object



240
241
242
# File 'lib/paywhirl.rb', line 240

def get_promo(promo_id)
  get("/promo/#{promo_id}")
end

#get_promosObject



236
237
238
# File 'lib/paywhirl.rb', line 236

def get_promos
  get('/promo')
end

#get_questions(params_or_limit = 100) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/paywhirl.rb', line 81

def get_questions(params_or_limit = 100)
  params =
    if params_or_limit.respond_to?(:to_i)
      { limit: params_or_limit }
    else
      params_or_limit
    end

  get('/questions', params)
end

#get_shipping_rule(shipping_rule_id) ⇒ Object



272
273
274
# File 'lib/paywhirl.rb', line 272

def get_shipping_rule(shipping_rule_id)
  get("/shipping/#{shipping_rule_id}")
end

#get_shipping_rulesObject



268
269
270
# File 'lib/paywhirl.rb', line 268

def get_shipping_rules
  get('/shipping')
end

#get_statsObject



264
265
266
# File 'lib/paywhirl.rb', line 264

def get_stats
  get('/stats')
end

#get_subscribers(params = {}) ⇒ Object



131
132
133
# File 'lib/paywhirl.rb', line 131

def get_subscribers(params = {})
  get('/subscribers', params)
end

#get_subscription(subscription_id) ⇒ Object



127
128
129
# File 'lib/paywhirl.rb', line 127

def get_subscription(subscription_id)
  get("/subscription/#{subscription_id}")
end

#get_subscriptions(customer_id) ⇒ Object



123
124
125
# File 'lib/paywhirl.rb', line 123

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

#get_tax_rule(tax_rule_id) ⇒ Object



280
281
282
# File 'lib/paywhirl.rb', line 280

def get_tax_rule(tax_rule_id)
  get("/tax/#{tax_rule_id}")
end

#get_tax_rulesObject



276
277
278
# File 'lib/paywhirl.rb', line 276

def get_tax_rules
  get('/tax')
end

#mark_invoice_as_paid(invoice_id) ⇒ Object



172
173
174
# File 'lib/paywhirl.rb', line 172

def mark_invoice_as_paid(invoice_id)
  post("/invoice/#{invoice_id}/mark-as-paid")
end

#process_invoice(invoice_id, params = {}) ⇒ Object



168
169
170
# File 'lib/paywhirl.rb', line 168

def process_invoice(invoice_id, params = {})
  post("/invoice/#{invoice_id}/process", params)
end

#refund_charge(charge_id, params = {}) ⇒ Object



216
217
218
# File 'lib/paywhirl.rb', line 216

def refund_charge(charge_id, params = {})
  post("/refund/charge/#{charge_id}", params)
end

#remove_promo_code_from_invoice(invoice_id) ⇒ Object



180
181
182
# File 'lib/paywhirl.rb', line 180

def remove_promo_code_from_invoice(invoice_id)
  post("/invoice/#{invoice_id}/remove-promo")
end

#send_email(params) ⇒ Object



256
257
258
# File 'lib/paywhirl.rb', line 256

def send_email(params)
  post('/send-email', params)
end

#subscribe_customer(params) ⇒ Object



135
136
137
# File 'lib/paywhirl.rb', line 135

def subscribe_customer(params)
  post('/subscribe/customer', params)
end

#unsubscribe_customer(subscription_id) ⇒ Object



156
157
158
# File 'lib/paywhirl.rb', line 156

def unsubscribe_customer(subscription_id)
  post('/unsubscribe/customer', subscription_id: subscription_id)
end

#update_address(address_id, params) ⇒ Object



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

def update_address(address_id, params)
  patch("/customer/address/#{address_id}", params)
end

#update_answer(params) ⇒ Object



103
104
105
# File 'lib/paywhirl.rb', line 103

def update_answer(params)
  post('/update/answer', params)
end

#update_customer(params) ⇒ Object



72
73
74
# File 'lib/paywhirl.rb', line 72

def update_customer(params)
  post('/update/customer', params)
end

#update_invoice_card(invoice_id, card_id) ⇒ Object



184
185
186
# File 'lib/paywhirl.rb', line 184

def update_invoice_card(invoice_id, card_id)
  post("/invoice/#{invoice_id}/card", card_id: card_id)
end

#update_invoice_items(invoice_id, line_items = {}) ⇒ Object



188
189
190
# File 'lib/paywhirl.rb', line 188

def update_invoice_items(invoice_id, line_items = {})
  post("/invoice/#{invoice_id}/items", line_items)
end

#update_plan(params) ⇒ Object



119
120
121
# File 'lib/paywhirl.rb', line 119

def update_plan(params)
  post('/update/plan', params)
end

#update_subscription(subscription_id, plan_id, quantity = nil, address_id: nil, installments_left: nil, trial_end: nil, card_id: nil) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/paywhirl.rb', line 139

def update_subscription(subscription_id, plan_id, quantity = nil,
                        address_id: nil, installments_left: nil,
                        trial_end: nil, card_id: nil)
  params = {
    subscription_id: subscription_id,
    plan_id: plan_id
  }

  params[:quantity] = quantity if quantity
  params[:address_id] = address_id if address_id
  params[:installments_left] = installments_left if installments_left
  params[:trial_end] = trial_end if trial_end
  params[:card_id] = card_id if card_id

  post('/update/subscription', params)
end