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



824
825
826
827
828
829
830
# File 'lib/stripe_mock/data.rb', line 824

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

.mock_balance(usd_balance = 10000) ⇒ Object



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

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



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# File 'lib/stripe_mock/data.rb', line 1038

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



1030
1031
1032
1033
1034
1035
1036
# File 'lib/stripe_mock/data.rb', line 1030

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



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/stripe_mock/data.rb', line 274

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



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

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



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/stripe_mock/data.rb', line 246

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



618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/stripe_mock/data.rb', line 618

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



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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/stripe_mock/data.rb', line 158

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: params[: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



238
239
240
241
242
243
244
# File 'lib/stripe_mock/data.rb', line 238

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

.mock_checkout_session(params = {}) ⇒ Object



1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
# File 'lib/stripe_mock/data.rb', line 1221

def self.mock_checkout_session(params = {})
  cs_id = params[:id] || "test_cs_default"
  currency = params[:currency] || StripeMock.default_currency
  {
    id: cs_id,
    object: 'checkout.session',
    billing_address_collection: nil,
    cancel_url: 'https://example.com/cancel',
    client_reference_id: nil,
    customer: nil,
    customer_email: nil,
    display_items: [
      {
        amount: 1500,
        currency: currency,
        custom: {
          description: 'Comfortable cotton t-shirt',
          images: nil,
          name: 'T-shirt'
        },
        quantity: 2,
        type: 'custom'
      }
    ],
    livemode: false,
    locale: nil,
    mode: nil,
    payment_intent: mock_payment_intent[:id],
    payment_method_types: [
      'card'
    ],
    setup_intent: nil,
    submit_type: nil,
    subscription: nil,
    success_url: 'https://example.com/success'
  }.merge(params)
end

.mock_country_spec(country_code) ⇒ Object



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
928
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
960
961
962
963
964
965
966
967
968
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
# File 'lib/stripe_mock/data.rb', line 844

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



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/stripe_mock/data.rb', line 293

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/stripe_mock/data.rb', line 120

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,
    name: nil,
    preferred_locales: [],
    livemode: false,
    delinquent: false,
    discount: nil,
    account_balance: 0,
    currency: currency,
    invoice_settings: {
      default_payment_method: nil,
      custom_fields: nil,
      footer: nil
    },
    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



832
833
834
835
836
837
# File 'lib/stripe_mock/data.rb', line 832

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

.mock_delete_subscription(params = {}) ⇒ Object



818
819
820
821
822
# File 'lib/stripe_mock/data.rb', line 818

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

.mock_dispute(params = {}) ⇒ Object



717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# File 'lib/stripe_mock/data.rb', line 717

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



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/stripe_mock/data.rb', line 739

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



771
772
773
774
775
776
777
778
# File 'lib/stripe_mock/data.rb', line 771

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

.mock_disputes(ids = []) ⇒ Object



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

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



1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
# File 'lib/stripe_mock/data.rb', line 1100

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



788
789
790
791
792
793
794
795
# File 'lib/stripe_mock/data.rb', line 788

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

.mock_invalid_exp_year_errorObject



797
798
799
800
801
802
803
804
805
806
# File 'lib/stripe_mock/data.rb', line 797

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



358
359
360
361
362
363
364
365
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/stripe_mock/data.rb', line 358

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',
    status: 'open',
    invoice_pdf: 'pdf_url',
    hosted_invoice_url: 'hosted_invoice_url',
    created: 1349738950,
    period_end: 1349738950,
    period_start: 1349738950,
    due_date: nil,
    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: 10,
    tax_percent: nil,
    webhooks_delivered_at: 1349825350,
    livemode: false,
    attempt_count: 0,
    amount_due: 100,
    amount_paid: 0,
    currency: currency,
    starting_balance: 0,
    ending_balance: 0,
    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[:ending_balance] = invoice[:starting_balance] + invoice[:total] if invoice[:amount_due] == 0
  invoice
end

.mock_invoice_customer_arrayObject



474
475
476
477
478
479
480
# File 'lib/stripe_mock/data.rb', line 474

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

.mock_invoice_item(params = {}) ⇒ Object



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/stripe_mock/data.rb', line 444

def self.mock_invoice_item(params = {})
  currency = params[:currency] || StripeMock.default_currency
  {
    id: "test_ii",
    object: "invoiceitem",
    created: 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



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/stripe_mock/data.rb', line 416

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
    },
    tax_amounts: [
      {
        amount: 10
      }
    ],
    quantity: nil,
    subscription: nil,
    plan: nil,
    description: "Test invoice item",
    metadata: {}
  }.merge(params)
end

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



839
840
841
842
# File 'lib/stripe_mock/data.rb', line 839

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

.mock_missing_id_errorObject



808
809
810
811
812
813
814
815
816
# File 'lib/stripe_mock/data.rb', line 808

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

.mock_order(order_items, params) ⇒ Object



482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/stripe_mock/data.rb', line 482

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



519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/stripe_mock/data.rb', line 519

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



462
463
464
465
466
467
468
469
470
471
472
# File 'lib/stripe_mock/data.rb', line 462

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



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/stripe_mock/data.rb', line 1119

def self.mock_payment_intent(params = {})
  payment_intent_id = params[:id] || "pi_1EwXFB2eZvKYlo2CggNnFBo8"
  amount = params[:amount] || 49900
  currency = params[:currency] || StripeMock.default_currency
  {
      id: payment_intent_id,
      object: "payment_intent",
      amount: amount,
      amount_capturable: 0,
      amount_received: 0,
      application: nil,
      application_fee_amount: nil,
      canceled_at: nil,
      cancellation_reason: nil,
      capture_method: "automatic",
      charges: {
          object: "list",
          data: [],
          has_more: false,
          total_count: 1,
          url: "/v1/charges?payment_intent=pi_1EwXFB2eZvKYlo2CggNnFBo8"
      },
      client_secret: "pi_1EwXFB2eZvKYlo2CggNnFBo8_secret_vOMkpqZu8ca7hxhfiO80tpT3v",
      confirmation_method: "manual",
      created: 1563208901,
      currency: currency,
      customer: nil,
      description: nil,
      invoice: nil,
      last_payment_error: nil,
      livemode: false,
      metadata: {},
      next_action: { type: "use_stripe_sdk" },
      on_behalf_of: nil,
      payment_method: nil,
      payment_method_types: [
          "card"
      ],
      receipt_email: nil,
      review: nil,
      setup_future_usage: nil,
      shipping: nil,
      source: nil,
      statement_descriptor: nil,
      status: "requires_action",
      transfer_data: nil,
      transfer_group: nil
  }.merge(params)
end

.mock_payment_method(params = {}) ⇒ Object



1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
# File 'lib/stripe_mock/data.rb', line 1169

def self.mock_payment_method(params = {})
  payment_method_id = params[:id] || "pm_1ExEuFL2DI6wht39WNJgbybl"
  {
      id: payment_method_id,
      object: "payment_method",
      type: "card",
      billing_details: {},
      card: {
          brand: "visa",
          checks: { address_line1_check: nil, address_postal_code_check: nil, cvc_check: "pass" },
          country: "FR",
          exp_month: 2,
          exp_year: 2022,
          fingerprint: "Hr3Ly5z5IYxsokWA",
          funding: "credit",
          last4: "3155",
          three_d_secure_usage: { supported: true }
      },
      customer: params[:customer] || nil,
      metadata: {
        order_id: "123456789"
      }

  }.merge(params)
end

.mock_payout(params = {}) ⇒ Object



694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/stripe_mock/data.rb', line 694

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



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/stripe_mock/data.rb', line 532

def self.mock_plan(params={})
  currency = params[:currency] || StripeMock.default_currency
  {
    id: "mock_plan_123",
    object: "plan",
    active: true,
    aggregate_usage: nil,
    amount: 2300,
    billing_scheme: "per_unit",
    created: 1466698898,
    currency: currency,
    interval: "month",
    interval_count: 1,
    livemode: false,
    metadata: {},
    nickname: "My Mock Plan",
    product: "mock_prod_NONEXIST", # override this with your own existing product id
    tiers: nil,
    tiers_mode: nil,
    transform_usage: nil,
    trial_period_days: nil,
    usage_type: "licensed"
  }.merge(params)
end

.mock_product(params = {}) ⇒ Object



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/stripe_mock/data.rb', line 557

def self.mock_product(params={})
  {
    id: "mock_prod_abc123",
    object: "product",
    active: true,
    attributes:[],
    caption: nil,
    created: 1466698000,
    deactivate_on: [],
    description: nil,
    images: [],
    livemode: false,
    metadata: {},
    name: "The Mock Product",
    package_dimensions: nil,
    shippable: nil,
    statement_descriptor: nil,
    type: "service",
    unit_label: "my_unit",
    updated: 1537939442,
    url: nil
  }.merge(params)
end

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



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/stripe_mock/data.rb', line 581

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



610
611
612
613
614
615
616
# File 'lib/stripe_mock/data.rb', line 610

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

.mock_refund(params = {}) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/stripe_mock/data.rb', line 221

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



1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
# File 'lib/stripe_mock/data.rb', line 1195

def self.mock_setup_intent(params = {})
  setup_intent_id = params[:id] || "seti_1F96eK2aLAadsDqo0AVIyPmC"
  {
    :id => setup_intent_id,
    :object => "setup_intent",
    :application => nil,
    :cancellation_reason => nil,
    :client_secret => "seti_1F96eK2aLAadsDqo0AVIyPmC_secret_FePTYgOoPFxDOUL53fFMSoTAyiXsWAV",
    :created => 1566204936,
    :customer => nil,
    :description => nil,
    :last_setup_error => nil,
    :livemode => false,
    :metadata => {},
    :next_action => nil,
    :on_behalf_of => nil,
    :payment_method => nil,
    :payment_method_options => {
      card: {request_three_d_secure: "automatic"}
    },
    :payment_method_types => ["card"],
    :status => "requires_payment_method",
    :usage => "off_session"
  }.merge(params)
end

.mock_subscription(params = {}) ⇒ Object

FIXME nested overrides would be better than hardcoding plan_id



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
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
# File 'lib/stripe_mock/data.rb', line 310

def self.mock_subscription(params={})
  StripeMock::Util.rmerge({
    created: 1478204116,
    billing: 'charge_automatically',
    current_period_start: 1308595038,
    current_period_end: 1308681468,
    status: 'trialing',
    trial_from_plan: false,
    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: {},
    default_tax_rates: nil,
    pending_invoice_item_interval: nil,
    next_pending_invoice_item_invoice: nil
  }, params)
end

.mock_subscription_item(params = {}) ⇒ Object



1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/stripe_mock/data.rb', line 1074

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_tax_rate(params) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/stripe_mock/data.rb', line 104

def self.mock_tax_rate(params)
  {
    id: 'test_cus_default',
    object: 'tax_rate',
    active: true,
    created: 1559079603,
    description: nil,
    display_name: 'VAT',
    inclusive: false,
    jurisdiction: 'EU',
    livemode: false,
    metadata: {},
    percentage: 21.0
  }.merge(params)
end

.mock_transfer(params = {}) ⇒ Object



664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/stripe_mock/data.rb', line 664

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



780
781
782
783
784
785
786
# File 'lib/stripe_mock/data.rb', line 780

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