Module: StripeMock::Data

Defined in:
lib/stripe_mock/data.rb,
lib/stripe_mock/data/list.rb

Defined Under Namespace

Classes: List

Class Method Summary collapse

Class Method Details

.mock_api_errorObject



440
441
442
443
444
445
446
# File 'lib/stripe_mock/data.rb', line 440

def self.mock_api_error
  {
    :error => {
      :type => "api_error"
    }
  }
end

.mock_bank_account(params = {}) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/stripe_mock/data.rb', line 137

def self.(params={})
  {
    object: "bank_account",
    bank_name: "STRIPEMOCK TEST BANK",
    last4: "6789",
    country: "US",
    currency: "usd",
    validated: false,
    fingerprint: "aBcFinGerPrINt123"
  }.merge(params)
end

.mock_card(params = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/stripe_mock/data.rb', line 111

def self.mock_card(params={})
  StripeMock::Util.card_merge({
    id: "test_cc_default",
    object: "card",
    last4: "4242",
    type: "Visa",
    brand: "Visa",
    funding: "credit",
    exp_month: 4,
    exp_year: 2016,
    fingerprint: "wXWJT135mEK107G8",
    customer: "test_cus_default",
    country: "US",
    name: "Johnny App",
    address_line1: nil,
    address_line2: nil,
    address_city: nil,
    address_state: nil,
    address_zip: nil,
    address_country: nil,
    cvc_check: nil,
    address_line1_check: nil,
    address_zip_check: nil
  }, params)
end

.mock_charge(params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/stripe_mock/data.rb', line 33

def self.mock_charge(params={})
  charge_id = params[:id] || "ch_1fD6uiR9FAA2zc"
  {
    id: charge_id,
    object: "charge",
    created: 1366194027,
    livemode: false,
    paid: true,
    amount: 0,
    currency: "usd",
    refunded: false,
    fee: 0,
    status: 'succeeded',
    fee_details: [
    ],
    source: {
      object: "card",
      last4: "4242",
      type: "Visa",
      brand: "Visa",
      funding: "credit",
      exp_month: 12,
      exp_year: 2013,
      fingerprint: "3TQGpK9JoY1GgXPw",
      country: "US",
      name: "name",
      address_line1: nil,
      address_line2: nil,
      address_city: nil,
      address_state: nil,
      address_zip: nil,
      address_country: nil,
      cvc_check: nil,
      address_line1_check: nil,
      address_zip_check: nil
    },
    captured: params.has_key?(:capture) ? params.delete(:capture) : true,
    refunds: {
      object: "list",
      total_count: 0,
      has_more: false,
      url: "/v1/charges/#{charge_id}/refunds",
      data: []
    },
    balance_transaction: "txn_2dyYXXP90MN26R",
    failure_message: nil,
    failure_code: nil,
    amount_refunded: 0,
    customer: nil,
    invoice: nil,
    description: nil,
    dispute: nil,
    metadata: {
    }
  }.merge(params)
end

.mock_charge_arrayObject



103
104
105
106
107
108
109
# File 'lib/stripe_mock/data.rb', line 103

def self.mock_charge_array
  {
    :data => [test_charge, test_charge, test_charge],
    :object => 'list',
    :url => '/v1/charges'
  }
end

.mock_coupon(params = {}) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/stripe_mock/data.rb', line 149

def self.mock_coupon(params={})
  {
    :duration => 'repeating',
    :duration_in_months => 3,
    :percent_off => 25,
    :amount_off => nil,
    :currency => nil,
    :id => "co_test_coupon",
    :object => "coupon",
    :max_redemptions => nil,
    :redeem_by => nil,
    :times_redeemed => 0,
    :valid => true,
    :metadata => {},
  }.merge(params)
end

.mock_customer(sources, params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stripe_mock/data.rb', line 4

def self.mock_customer(sources, params)
  cus_id = params[:id] || "test_cus_default"
  sources.each {|source| source[:customer] = cus_id}
  {
    email: '[email protected]',
    description: 'an auto-generated stripe customer data mock',
    object: "customer",
    created: 1372126710,
    id: cus_id,
    livemode: false,
    delinquent: false,
    discount: nil,
    account_balance: 0,
    sources: {
      object: "list",
      total_count: sources.size,
      url: "/v1/customers/#{cus_id}/sources",
      data: sources
    },
    subscriptions: {
      object: "list",
      total_count: 0,
      url: "/v1/customers/#{cus_id}/subscriptions",
      data: []
    },
    default_source: nil
  }.merge(params)
end

.mock_delete_discount_responseObject



448
449
450
451
452
453
# File 'lib/stripe_mock/data.rb', line 448

def self.mock_delete_discount_response
  {
    :deleted => true,
    :id => "di_test_coupon"
  }
end

.mock_delete_subscription(params = {}) ⇒ Object



434
435
436
437
438
# File 'lib/stripe_mock/data.rb', line 434

def self.mock_delete_subscription(params={})
  {
    deleted: true
  }.merge(params)
end

.mock_invalid_api_key_errorObject



404
405
406
407
408
409
410
411
# File 'lib/stripe_mock/data.rb', line 404

def self.mock_invalid_api_key_error
  {
    "error" => {
      "type" => "invalid_request_error",
      "message" => "Invalid API Key provided: invalid"
    }
  }
end

.mock_invalid_exp_year_errorObject



413
414
415
416
417
418
419
420
421
422
# File 'lib/stripe_mock/data.rb', line 413

def self.mock_invalid_exp_year_error
  {
    "error" => {
      "code" => "invalid_expiry_year",
      "param" => "exp_year",
      "type" => "card_error",
      "message" => "Your card's expiration year is invalid"
    }
  }
end

.mock_invoice(lines, params = {}) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/stripe_mock/data.rb', line 193

def self.mock_invoice(lines, params={})
  in_id = params[:id] || "test_in_default"
  lines << Data.mock_line_item() if lines.empty?
  {
    id: 'in_test_invoice',
    date: 1349738950,
    period_end: 1349738950,
    period_start: 1349738950,
    lines: {
      object: "list",
      total_count: lines.count,
      url: "/v1/invoices/#{in_id}/lines",
      data: lines
    },
    subtotal: lines.map {|line| line[:amount]}.reduce(0, :+),
    total: lines.map {|line| line[:amount]}.reduce(0, :+),
    customer: "test_customer",
    object: 'invoice',
    attempted: false,
    closed: false,
    forgiven: false,
    paid: false,
    livemode: false,
    attempt_count: 0,
    amount_due: lines.map {|line| line[:amount]}.reduce(0, :+),
    currency: 'usd',
    starting_balance: 0,
    ending_balance: nil,
    next_payment_attempt: 1349825350,
    charge: nil,
    discount: nil,
    subscription: nil
  }.merge(params)
end

.mock_invoice_customer_arrayObject



277
278
279
280
281
282
283
# File 'lib/stripe_mock/data.rb', line 277

def self.mock_invoice_customer_array
  {
    :data => [test_invoice],
    :object => 'list',
    :url => '/v1/invoices?customer=test_customer'
  }
end

.mock_invoice_item(params = {}) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/stripe_mock/data.rb', line 248

def self.mock_invoice_item(params = {})
  {
    id: "test_ii",
    object: "invoiceitem",
    date: 1349738920,
    amount: 1099,
    livemode: false,
    proration: false,
    currency: "usd",
    customer: "cus_test",
    description: "invoice item desc",
    metadata: {},
    invoice: nil,
    subscription: nil
  }.merge(params)
end

.mock_line_item(params = {}) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/stripe_mock/data.rb', line 228

def self.mock_line_item(params = {})
  {
    id: "ii_test",
    object: "line_item",
    type: "invoiceitem",
    livemode: false,
    amount: 1000,
    currency: "usd",
    proration: false,
    period: {
      start: 1349738920,
      end: 1349738920
    },
    quantity: nil,
    plan: nil,
    description: "Test invoice item",
    metadata: {}
  }.merge(params)
end

.mock_list_object(data, params = {}) ⇒ Object



455
456
457
458
# File 'lib/stripe_mock/data.rb', line 455

def self.mock_list_object(data, params = {})
  list = StripeMock::Data::List.new(data, params)
  list.to_h
end

.mock_missing_id_errorObject



424
425
426
427
428
429
430
431
432
# File 'lib/stripe_mock/data.rb', line 424

def self.mock_missing_id_error
  {
    :error => {
      :param => "id",
      :type => "invalid_request_error",
      :message => "Missing id"
    }
  }
end

.mock_paid_invoiceObject



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/stripe_mock/data.rb', line 265

def self.mock_paid_invoice
  test_invoice.merge({
      :attempt_count => 1,
      :attempted => true,
      :closed => true,
      :paid => true,
      :charge => 'ch_test_charge',
      :ending_balance => 0,
      :next_payment_attempt => nil,
    })
end

.mock_plan(params = {}) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/stripe_mock/data.rb', line 285

def self.mock_plan(params={})
  {
    interval: "month",
    name: "The Basic Plan",
    amount: 2300,
    currency: "usd",
    id: "2",
    object: "plan",
    livemode: false,
    interval_count: 1,
    trial_period_days: nil
  }.merge(params)
end

.mock_recipient(cards, params = {}) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/stripe_mock/data.rb', line 299

def self.mock_recipient(cards, params={})
  rp_id = params[:id] || "test_rp_default"
  cards.each {|card| card[:recipient] = rp_id}
  {
    name: "Stripe User",
    type: "individual",
    livemode: false,
    object: "recipient",
    id: rp_id,
    active_account: {
      last4: "6789",
      bank_name: "STRIPE TEST BANK",
      country: "US",
      object: "bank_account"
    },
    created: 1304114758,
    verified: true,
    metadata: {
    },
    cards: {
      object: "list",
      url: "/v1/recipients/#{rp_id}/cards",
      data: cards,
      total_count: cards.count
    },
    default_card: nil
  }.merge(params)
end

.mock_recipient_arrayObject



328
329
330
331
332
333
334
# File 'lib/stripe_mock/data.rb', line 328

def self.mock_recipient_array
  {
    :data => [test_recipient, test_recipient, test_recipient],
    :object => 'list',
    :url => '/v1/recipients'
  }
end

.mock_refund(params = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/stripe_mock/data.rb', line 90

def self.mock_refund(params={})
  {
    id: "re_4fWhgUh5si7InF",
    amount: 1,
    currency: "usd",
    created: 1409165988,
    object: "refund",
    balance_transaction: "txn_4fWh2RKvgxcXqV",
    metadata: {},
    charge: "ch_4fWhYjzQ23UFWT"
  }.merge(params)
end

.mock_subscription(params = {}) ⇒ Object

FIXME nested overrides would be better than hardcoding plan_id



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/stripe_mock/data.rb', line 167

def self.mock_subscription(params={})
  StripeMock::Util.rmerge({
    :current_period_start => 1308595038,
    :current_period_end => 1308681468,
    :status => "trialing",
    :plan => {
      :interval => "month",
      :amount => 7500,
      :trial_period_days => 30,
      :object => "plan",
      :id => '__test_plan_id__'
    },
    :cancel_at_period_end => false,
    :canceled_at => nil,
    :ended_at => nil,
    :start => 1308595038,
    :object => "subscription",
    :trial_start => 1308595038,
    :trial_end => 1308681468,
    :customer => "c_test_customer",
    :quantity => 1,
    :tax_percent => nil,
    :metadata => {}
  }, params)
end

.mock_token(params = {}) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/stripe_mock/data.rb', line 336

def self.mock_token(params={})
  {
    :id => 'tok_default',
    :livemode => false,
    :used => false,
    :object => 'token',
    :type => 'card',
    :card => {
      :id => 'card_default',
      :object => 'card',
      :last4 => '2222',
      :type => 'Visa',
      :brand => 'Visa',
      :funding => 'credit',
      :exp_month => 9,
      :exp_year => 2017,
      :fingerprint => 'JRRLXGh38NiYygM7',
      :customer => nil,
      :country => 'US',
      :name => nil,
      :address_line1 => nil,
      :address_line2 => nil,
      :address_city => nil,
      :address_state => nil,
      :address_zip => nil,
      :address_country => nil
    }
  }.merge(params)
end

.mock_transfer(params = {}) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/stripe_mock/data.rb', line 366

def self.mock_transfer(params={})
  id = params[:id] || 'tr_test_transfer'
  {
    :status => 'pending',
    :amount => 100,
    :account => {
      :object => 'bank_account',
      :country => 'US',
      :bank_name => 'STRIPE TEST BANK',
      :last4 => '6789'
    },
    :recipient => 'test_recipient',
    :fee => 0,
    :fee_details => [],
    :id => id,
    :livemode => false,
    :currency => "usd",
    :object => "transfer",
    :date => 1304114826,
    :description => "Transfer description",
    :reversed => false,
    :reversals => {
      :object => "list",
      :total_count => 0,
      :has_more => false,
      :url => "/v1/transfers/#{id}/reversals"
    },
  }.merge(params)
end

.mock_transfer_arrayObject



396
397
398
399
400
401
402
# File 'lib/stripe_mock/data.rb', line 396

def self.mock_transfer_array
  {
    :data => [test_transfer, test_transfer, test_transfer],
    :object => 'list',
    :url => '/v1/transfers'
  }
end