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_account(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
32
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/stripe_mock/data.rb', line 4

def self.(params = {})
  id = params[:id] || 'acct_103ED82ePvKYlo2C'
  currency = params[:currency] || StripeMock.default_currency
  {
    id: id,
    email: "[email protected]",
    statement_descriptor: nil,
    display_name: "Stripe.com",
    timezone: "US/Pacific",
    details_submitted: false,
    charges_enabled: false,
    payouts_enabled: false,
    currencies_supported: [
      "usd"
    ],
    default_currency: currency,
    country: "US",
    object: "account",
    business_name: "Stripe.com",
    business_url: nil,
    support_phone: nil,
    managed: false,
    product_description: nil,
    debit_negative_balances: true,
    bank_accounts: {
      object: "list",
      total_count: 0,
      has_more: false,
      url: "/v1/accounts/#{id}/bank_accounts",
      data: [

      ]
    },
    verification: {
      fields_needed: [],
      due_by: nil,
      contacted: false
    },
    transfer_schedule: {
      delay_days: 7,
      interval: "daily"
    },
    tos_acceptance: {
      ip: nil,
      date: nil,
      user_agent: nil
    },
    external_accounts: {
        object: "list",
        data: [

        ],
        has_more: false,
        total_count: 0,
        url: "/v1/accounts/#{id}/external_accounts"
    },
    legal_entity: {
      type: nil,
      business_name: nil,
      address: {
        line1: nil,
        line2: nil,
        city: nil,
        state: nil,
        postal_code: nil,
        country: "US"
      },
      first_name: nil,
      last_name: nil,
      personal_address: {
        line1: nil,
        line2: nil,
        city: nil,
        state: nil,
        postal_code: nil,
        country: nil
      },
      dob: {
        day: nil,
        month: nil,
        year: nil
      },
      additional_owners: nil,
      verification: {
        status: "unverified",
        document: nil,
        details: nil
      }
    },
    decline_charge_on: {
      cvc_failure: false,
      avs_failure: false
    },
    keys: {
      secret: "sk_test_AmJhMTLPtY9JL4c6EG0",
      publishable: "pk_test_2rSaMTLPtY9JL449dsf"
    }
  }.merge(params)
end

.mock_api_errorObject



755
756
757
758
759
760
761
# File 'lib/stripe_mock/data.rb', line 755

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

.mock_balance(usd_balance = 10000) ⇒ Object



929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
# File 'lib/stripe_mock/data.rb', line 929

def self.mock_balance(usd_balance = 10000)
  {
    object: "balance",
    available: [
      {
        currency: "usd",
        amount: usd_balance,
        source_types: {
          card: 25907032203,
          bank_account: 108476658,
          bitcoin_receiver: 1545182
        }
      }],
    connect_reserved: [
      {
        currency: "usd",
        amount: 4700
      }],
    livemode: false,
    pending: [
      {
        currency: "usd",
        amount: 22738833554,
        source_types: {
          card: 22738826610,
          bank_account: 0,
          bitcoin_receiver: 6944
        }
      }]
  }
end

.mock_balance_transaction(params = {}) ⇒ Object



969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
# File 'lib/stripe_mock/data.rb', line 969

def self.mock_balance_transaction(params = {})
  currency = params[:currency] || StripeMock.default_currency
  bt_id = params[:id] || 'test_txn_default'
  source = params[:source] || 'ch_test_charge'
  {
    id: bt_id,
    object: "balance_transaction",
    amount: 10000,
    available_on: 1462406400,
    created: 1461880226,
    currency: currency,
    description: nil,
    fee: 320,
    fee_details: [
      {
        amount: 320,
        application: nil,
        currency: currency,
        description: "Stripe processing fees",
        type: "stripe_fee"
      }
    ],
    net: 9680,
    source: source,
    sourced_transfers: {
      object: "list",
      data: [],
      has_more: false,
      total_count: 0,
      url: "/v1/transfers?source_transaction=#{source}"
    },
    status: "pending",
    type: "charge"
  }.merge(params)
end

.mock_balance_transactions(ids = []) ⇒ Object



961
962
963
964
965
966
967
# File 'lib/stripe_mock/data.rb', line 961

def self.mock_balance_transactions(ids=[])
  bts = {}
  ids.each do |id|
    bts[id] = self.mock_balance_transaction(id: id)
  end
  bts
end

.mock_bank_account(params = {}) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/stripe_mock/data.rb', line 251

def self.(params={})
  currency = params[:currency] || StripeMock.default_currency
  {
    id: "test_ba_default",
    object: "bank_account",
    bank_name: "STRIPEMOCK TEST BANK",
    last4: "6789",
    routing_number: '110000000',
    country: "US",
    currency: currency,
    validated: false,
    status: 'new',
    account_holder_name: 'John Doe',
    account_holder_type: 'individual',
    fingerprint: "aBcFinGerPrINt123",
    metadata: {}
  }.merge(params)
end

.mock_bank_account_token(params = {}) ⇒ Object



579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/stripe_mock/data.rb', line 579

def self.(params={})
  {
    :id => 'tok_default',
    :livemode => false,
    :used => false,
    :object => 'token',
    :type => 'bank_account',
    :bank_account => {
      :id => 'bank_account_default',
      :object => 'bank_account',
      :last4 => '2222',
      :fingerprint => 'JRRLXGh38NiYygM7',
    }
  }.merge(params)
end

.mock_card(params = {}) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/stripe_mock/data.rb', line 223

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

.mock_card_token(params = {}) ⇒ Object



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/stripe_mock/data.rb', line 549

def self.mock_card_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_charge(params = {}) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
192
193
194
195
196
# File 'lib/stripe_mock/data.rb', line 135

def self.mock_charge(params={})
  charge_id = params[:id] || "ch_1fD6uiR9FAA2zc"
  currency = params[:currency] || StripeMock.default_currency
  {
    id: charge_id,
    object: "charge",
    created: 1366194027,
    livemode: false,
    paid: true,
    amount: 0,
    application_fee: nil,
    currency: currency,
    destination: nil,
    fraud_details: {},
    receipt_email: nil,
    receipt_number: nil,
    refunded: false,
    shipping: {},
    statement_descriptor: "Charge #{charge_id}",
    status: 'succeeded',
    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: []
    },
    transfer: nil,
    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



215
216
217
218
219
220
221
# File 'lib/stripe_mock/data.rb', line 215

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

.mock_country_spec(country_code) ⇒ Object



775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
# File 'lib/stripe_mock/data.rb', line 775

def self.mock_country_spec(country_code)
  id = country_code || "US"
  {
    "id"=> "US",
    "object"=> "country_spec",
    "default_currency"=> "usd",
    "supported_bank_account_currencies"=> {"usd"=>["US"]},
    "supported_payment_currencies"=> [
      "usd",
      "aed",
      "afn",
      "all",
      "amd",
      "ang",
      "aoa",
      "ars",
      "aud",
      "awg",
      "azn",
      "bam",
      "bbd",
      "bdt",
      "bgn",
      "bif",
      "bmd",
      "bnd",
      "bob",
      "brl",
      "bsd",
      "bwp",
      "bzd",
      "cad",
      "cdf",
      "chf",
      "clp",
      "cny",
      "cop",
      "crc",
      "cve",
      "czk",
      "djf",
      "dkk",
      "dop",
      "dzd",
      "egp",
      "etb",
      "eur",
      "fjd",
      "fkp",
      "gbp",
      "gel",
      "gip",
      "gmd",
      "gnf",
      "gtq",
      "gyd",
      "hkd",
      "hnl",
      "hrk",
      "htg",
      "huf",
      "idr",
      "ils",
      "inr",
      "isk",
      "jmd",
      "jpy",
      "kes",
      "kgs",
      "khr",
      "kmf",
      "krw",
      "kyd",
      "kzt",
      "lak",
      "lbp",
      "lkr",
      "lrd",
      "lsl",
      "ltl",
      "mad",
      "mdl",
      "mga",
      "mkd",
      "mnt",
      "mop",
      "mro",
      "mur",
      "mvr",
      "mwk",
      "mxn",
      "myr",
      "mzn",
      "nad",
      "ngn",
      "nio",
      "nok",
      "npr",
      "nzd",
      "pab",
      "pen",
      "pgk",
      "php",
      "pkr",
      "pln",
      "pyg",
      "qar",
      "ron",
      "rsd",
      "rub",
      "rwf",
      "sar",
      "sbd",
      "scr",
      "sek",
      "sgd",
      "shp",
      "sll",
      "sos",
      "srd",
      "std",
      "svc",
      "szl",
      "thb",
      "tjs",
      "top",
      "try",
      "ttd",
      "twd",
      "tzs",
      "uah",
      "ugx",
      "uyu",
      "uzs",
      "vnd",
      "vuv",
      "wst",
      "xaf",
      "xcd",
      "xof",
      "xpf",
      "yer",
      "zar",
      "zmw"
    ],
    "supported_payment_methods"=> [
      "alipay",
      "card",
      "stripe"
    ],
    "verification_fields"=> {"individual"=>{"minimum"=>["external_account","legal_entity.address.city","legal_entity.address.line1","legal_entity.address.postal_code","legal_entity.address.state","legal_entity.dob.day","legal_entity.dob.month","legal_entity.dob.year","legal_entity.first_name","legal_entity.last_name","legal_entity.personal_id_number","legal_entity.ssn_last_4","legal_entity.type","tos_acceptance.date","tos_acceptance.ip"],"additional"=>["legal_entity.personal_id_number","legal_entity.verification.document"]},"company"=>{"minimum"=>["external_account","legal_entity.address.city","legal_entity.address.line1","legal_entity.address.postal_code","legal_entity.address.state","legal_entity.business_name","legal_entity.business_tax_id","legal_entity.dob.day","legal_entity.dob.month","legal_entity.dob.year","legal_entity.first_name","legal_entity.last_name","legal_entity.ssn_last_4","legal_entity.type","tos_acceptance.date","tos_acceptance.ip"],"additional"=>["legal_entity.personal_id_number","legal_entity.verification.document"]}}
  }
end

.mock_coupon(params = {}) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/stripe_mock/data.rb', line 270

def self.mock_coupon(params={})
  {
    :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



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

def self.mock_customer(sources, params)
  cus_id = params[:id] || "test_cus_default"
  currency = params[:currency] || StripeMock.default_currency
  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,
    currency: currency,
    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



763
764
765
766
767
768
# File 'lib/stripe_mock/data.rb', line 763

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

.mock_delete_subscription(params = {}) ⇒ Object



749
750
751
752
753
# File 'lib/stripe_mock/data.rb', line 749

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

.mock_dispute(params = {}) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
# File 'lib/stripe_mock/data.rb', line 648

def self.mock_dispute(params={})
  @timestamp ||= Time.now.to_i
  currency = params[:currency] || StripeMock.default_currency
  id = params[:id] || "dp_test_dispute"
  {
    :id => id,
    :object => "dispute",
    :amount => 195,
    :balance_transactions => [],
    :charge => "ch_15RsQR2eZvKYlo2CA8IfzCX0",
    :created => @timestamp += 1,
    :currency => currency,
    :evidence => self.mock_dispute_evidence,
    :evidence_details => self.mock_dispute_evidence_details,
    :is_charge_refundable => false,
    :livemode => false,
    :metadata => {},
    :reason => "general",
    :status => "under_review"
  }.merge(params)
end

.mock_dispute_evidenceObject



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/stripe_mock/data.rb', line 670

def self.mock_dispute_evidence
  {
    :access_activity_log => nil,
    :billing_address => nil,
    :cancellation_policy => nil,
    :cancellation_policy_disclosure => nil,
    :cancellation_rebuttal => nil,
    :customer_communication => nil,
    :customer_email_address => nil,
    :customer_name => nil,
    :customer_purchase_ip => nil,
    :customer_signature => nil,
    :duplicate_charge_documentation => nil,
    :duplicate_charge_explanation => nil,
    :duplicate_charge_id => nil,
    :product_description => nil,
    :receipt => nil,
    :refund_policy => nil,
    :refund_policy_disclosure => nil,
    :refund_refusal_explanation => nil,
    :service_date => nil,
    :service_documentation => nil,
    :shipping_address => nil,
    :shipping_carrier => nil,
    :shipping_date => nil,
    :shipping_documentation => nil,
    :shipping_tracking_number => nil,
    :uncategorized_file => nil,
    :uncategorized_text => nil
  }
end

.mock_dispute_evidence_detailsObject



702
703
704
705
706
707
708
709
# File 'lib/stripe_mock/data.rb', line 702

def self.mock_dispute_evidence_details
  {
    :due_by => 1424303999,
    :has_evidence => false,
    :past_due => false,
    :submission_count => 0
  }
end

.mock_disputes(ids = []) ⇒ Object



640
641
642
643
644
645
646
# File 'lib/stripe_mock/data.rb', line 640

def self.mock_disputes(ids=[])
  disputes = {}
  ids.each do |id|
    disputes[id] = self.mock_dispute(id: id)
  end
  disputes
end

.mock_ephemeral_key(**params) ⇒ Object



1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'lib/stripe_mock/data.rb', line 1031

def self.mock_ephemeral_key(**params)
  created = Time.now.to_i
  expires = created + 34_000
  {
    id: "ephkey_default",
    object: "ephemeral_key",
    associated_objects: [
      {
        id: params[:customer],
        type: "customer"
      }
    ],
    created: created,
    expires: expires,
    livemode: false,
    secret: "ek_test_default"
  }
end

.mock_invalid_api_key_errorObject



719
720
721
722
723
724
725
726
# File 'lib/stripe_mock/data.rb', line 719

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

.mock_invalid_exp_year_errorObject



728
729
730
731
732
733
734
735
736
737
# File 'lib/stripe_mock/data.rb', line 728

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



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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/stripe_mock/data.rb', line 331

def self.mock_invoice(lines, params={})
  in_id = params[:id] || "test_in_default"
  currency = params[:currency] || StripeMock.default_currency
  lines << Data.mock_line_item() if lines.empty?
  invoice = {
    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, :+),
    customer: "test_customer",
    object: 'invoice',
    attempted: false,
    application_fee: nil,
    closed: false,
    description: nil,
    forgiven: false,
    metadata: {},
    paid: false,
    receipt_number: nil,
    statement_descriptor: nil,
    tax: nil,
    tax_percent: nil,
    webhooks_delivered_at: 1349825350,
    livemode: false,
    attempt_count: 0,
    amount_due: nil,
    currency: currency,
    starting_balance: 0,
    ending_balance: nil,
    next_payment_attempt: 1349825350,
    charge: nil,
    discount: nil,
    subscription: nil
  }.merge(params)
  if invoice[:discount]
    invoice[:total] = [0, invoice[:subtotal] - invoice[:discount][:coupon][:amount_off]].max if invoice[:discount][:coupon][:amount_off]
    invoice[:total] = invoice[:subtotal] * invoice[:discount][:coupon][:percent_off] / 100 if invoice[:discount][:coupon][:percent_off]
  else
    invoice[:total] = invoice[:subtotal]
  end
  due = invoice[:total] + invoice[:starting_balance]
  invoice[:amount_due] = due < 0 ? 0 : due
  invoice
end

.mock_invoice_customer_arrayObject



436
437
438
439
440
441
442
# File 'lib/stripe_mock/data.rb', line 436

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

.mock_invoice_item(params = {}) ⇒ Object



406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/stripe_mock/data.rb', line 406

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

.mock_line_item(params = {}) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/stripe_mock/data.rb', line 383

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

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



770
771
772
773
# File 'lib/stripe_mock/data.rb', line 770

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

.mock_missing_id_errorObject



739
740
741
742
743
744
745
746
747
# File 'lib/stripe_mock/data.rb', line 739

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

.mock_order(order_items, params) ⇒ Object



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/stripe_mock/data.rb', line 444

def self.mock_order(order_items, params)
  or_id = params[:id] || "test_or_default"
  currency = params[:currency] || 'eur'
  order_items << Data.mock_order_item if order_items.empty?
  {
    id: or_id,
    object: "order",
    amount: 5000,
    application: nil,
    application_fee: nil,
    charge: nil,
    created: 1448272783,
    currency: currency,
    customer: nil,
    email: nil,
    items: order_items,
    livemode: false,
    metadata: {},
    selected_shipping_method: nil,
    shipping: {
      address: {
        city: "Anytown",
        country: "US",
        line1: "1234 Main street",
        line2: nil,
        postal_code: "123456",
        state: nil
      },
      name: "Jenny Rosen",
      phone: nil
    },
    shipping_methods: nil,
    status: "created",
    updated: 1448272783
  }.merge(params)
end

.mock_order_item(params = {}) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/stripe_mock/data.rb', line 481

def self.mock_order_item(params={})
  currency = params[:currency] || 'eur'
  {
    object: "order_item",
    amount: 5000,
    currency: currency,
    description: "Anyitem",
    parent: "sku_parent",
    quantity: 1,
    type: "sku"
  }.merge(params)
end

.mock_paid_invoiceObject



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

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_payout(params = {}) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/stripe_mock/data.rb', line 625

def self.mock_payout(params={})
  currency = params[:currency] || StripeMock.default_currency
  id = params[:id] || 'po_test_payout'
  {
    :amount => 100,
    :id => id,
    :livemode => false,
    :metadata => {},
    :currency => currency,
    :object => "payout",
    :date => 1304114826,
    :description => "Payout description",
  }.merge(params)
end

.mock_plan(params = {}) ⇒ Object



494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/stripe_mock/data.rb', line 494

def self.mock_plan(params={})
  currency = params[:currency] || StripeMock.default_currency
  {
    id: "2",
    object: "plan",
    amount: 2300,
    created: 1466698898,
    currency: currency,
    interval: "month",
    interval_count: 1,
    livemode: false,
    metadata: {},
    name: "The Basic Plan",
    statement_descriptor: nil,
    trial_period_days: nil
  }.merge(params)
end

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



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/stripe_mock/data.rb', line 512

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



541
542
543
544
545
546
547
# File 'lib/stripe_mock/data.rb', line 541

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

.mock_refund(params = {}) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/stripe_mock/data.rb', line 198

def self.mock_refund(params={})
  currency = params[:currency] || StripeMock.default_currency
  {
    id: "re_4fWhgUh5si7InF",
    amount: 1,
    currency: currency,
    created: 1409165988,
    object: "refund",
    balance_transaction: "txn_4fWh2RKvgxcXqV",
    metadata: {},
    charge: "ch_4fWhYjzQ23UFWT",
    receipt_number: nil,
    status: "succeeded",
    reason: "requested_by_customer"
  }.merge(params)
end

.mock_subscription(params = {}) ⇒ Object

FIXME nested overrides would be better than hardcoding plan_id



287
288
289
290
291
292
293
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
322
323
324
325
326
327
328
329
# File 'lib/stripe_mock/data.rb', line 287

def self.mock_subscription(params={})
  StripeMock::Util.rmerge({
    created: 1478204116,
    billing: 'charge_automatically',
    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__'
    },
    items: {
      object: 'list',
      data: [{
        id: 'si_1AwFf62eZvKYlo2C9u6Dhf9',
        created: 1504035973,
        metadata: {},
        object: 'subscription_item',
        plan: {
          amount: 999,
          created: 1504035972,
          currency: StripeMock.default_currency
        },
        quantity: 1
      }]
    },
    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,
    discount: nil,
    metadata: {}
  }, params)
end

.mock_subscription_item(params = {}) ⇒ Object



1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
# File 'lib/stripe_mock/data.rb', line 1005

def self.mock_subscription_item(params = {})
  iid = params[:id] || 'test_txn_default'
  {
    id: iid,
    object: 'subscription_item',
    created: 1504716183,
    metadata: {
  },
    plan: {
      id: 'PER_USER_PLAN1',
      object: 'plan',
      amount: 1337,
      created: 1504716177,
      currency: StripeMock.default_currency,
      interval: 'month',
      interval_count: 1,
      livemode: false,
      metadata: {},
      name: 'StripeMock Default Plan ID',
      statement_descriptor: nil,
      trial_period_days: nil
    },
    quantity: 2
  }.merge(params)
end

.mock_transfer(params = {}) ⇒ Object



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/stripe_mock/data.rb', line 595

def self.mock_transfer(params={})
  currency = params[:currency] || StripeMock.default_currency
  id = params[:id] || 'tr_test_transfer'
  {
    :amount => 100,
    :amount_reversed => 0,
    :balance_transaction => "txn_2dyYXXP90MN26R",
    :id => id,
    :livemode => false,
    :metadata => {},
    :currency => currency,
    :object => "transfer",
    :created => 1304114826,
    :description => "Transfer description",
    :reversed => false,
    :reversals => {
      :object => "list",
      :data => [],
      :total_count => 0,
      :has_more => false,
      :url => "/v1/transfers/#{id}/reversals"
    },
    :destination => "acct_164wxjKbnvuxQXGu",
    :destination_payment => "py_164xRvKbnvuxQXGuVFV2pZo1",
    :source_transaction => "ch_164xRv2eZvKYlo2Clu1sIJWB",
    :source_type => "card",
    :transfer_group => "group_ch_164xRv2eZvKYlo2Clu1sIJWB",
  }.merge(params)
end

.mock_transfer_arrayObject



711
712
713
714
715
716
717
# File 'lib/stripe_mock/data.rb', line 711

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