Module: StripeMock::Data

Defined in:
lib/stripe_mock/data.rb

Class Method Summary collapse

Class Method Details

.mock_api_errorObject



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

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

.mock_bank_account(params = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/stripe_mock/data.rb', line 134

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



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

def self.mock_card(params={})
  {
    id: "test_cc_default",
    object: "card",
    last4: "4242",
    type: "Visa",
    brand: "Visa",
    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
  }.merge(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
# 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,
    fee_details: [
    ],
    card: {
      object: "card",
      last4: "4242",
      type: "Visa",
      brand: "Visa",
      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



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

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

.mock_coupon(params = {}) ⇒ Object



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

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(cards, 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(cards, params)
  cus_id = params[:id] || "test_cus_default"
  cards.each {|card| card[: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,
    cards: {
      object: "list",
      count: cards.count,
      url: "/v1/customers/#{cus_id}/cards",
      data: cards
    },
    subscriptions: {
      object: "list",
      count: 0,
      url: "/v1/customers/#{cus_id}/subscriptions",
      data: []
    },
    default_card: nil
  }.merge(params)
end

.mock_delete_discount_responseObject



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

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

.mock_delete_subscription(params = {}) ⇒ Object



419
420
421
422
423
# File 'lib/stripe_mock/data.rb', line 419

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

.mock_invalid_api_key_errorObject



389
390
391
392
393
394
395
396
# File 'lib/stripe_mock/data.rb', line 389

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

.mock_invalid_exp_year_errorObject



398
399
400
401
402
403
404
405
406
407
# File 'lib/stripe_mock/data.rb', line 398

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



189
190
191
192
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
# File 'lib/stripe_mock/data.rb', line 189

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",
      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,
    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



272
273
274
275
276
277
278
# File 'lib/stripe_mock/data.rb', line 272

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

.mock_invoice_item(params = {}) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/stripe_mock/data.rb', line 243

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



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/stripe_mock/data.rb', line 223

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_missing_id_errorObject



409
410
411
412
413
414
415
416
417
# File 'lib/stripe_mock/data.rb', line 409

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

.mock_paid_invoiceObject



260
261
262
263
264
265
266
267
268
269
270
# File 'lib/stripe_mock/data.rb', line 260

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



280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/stripe_mock/data.rb', line 280

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



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/stripe_mock/data.rb', line 294

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",
      count: cards.count,
      url: "/v1/recipients/#{rp_id}/cards",
      data: cards
    },
    default_card: nil
  }.merge(params)
end

.mock_recipient_arrayObject



323
324
325
326
327
328
329
# File 'lib/stripe_mock/data.rb', line 323

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

.mock_refund(params = {}) ⇒ Object



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

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



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

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,
    :metadata => {}
  }, params)
end

.mock_token(params = {}) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/stripe_mock/data.rb', line 331

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',
      :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



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/stripe_mock/data.rb', line 360

def self.mock_transfer(params={})
  {
    :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 => "tr_test_transfer",
    :livemode => false,
    :currency => "usd",
    :object => "transfer",
    :date => 1304114826
  }.merge(params)
end

.mock_transfer_arrayObject



381
382
383
384
385
386
387
# File 'lib/stripe_mock/data.rb', line 381

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