Stripe Mock返回相同的指纹哈希

时间:2016-09-29 14:32:32

标签: ruby stripe-payments

使用RubyMock生成条纹卡等。

我不知道为什么它总是为新卡返回相同的fingerprint哈希值。

Here it gives an example of creating cards,基本上是这样的:

card_token = StripeMock.generate_card_token(last4: rand(9999).to_s, exp_year: rand(9999)) #=> "test_tok_26"
cus = Stripe::Customer.create(source: card_token);
card = cus.sources.data.first.fingerprint #=> "wXWJT135mEK107G8"

那就是wXWJT135mEK107G8! 即使输入卡last4和exp_year改变了。

1 个答案:

答案 0 :(得分:2)

即使fingerprintlast4不同,StripeMock似乎总是生成相同的exp_year

StripeMock.start

card_token = StripeMock.generate_card_token(last4: "919#{rand 9}", exp_year: "199#{rand 9}".to_i)
cus = Stripe::Customer.create(source: card_token)
cus.sources.data.first.last4 # => "9192"
cus.sources.data.first.fingerprint # => "wXWJT135mEK107G8"

card_token = StripeMock.generate_card_token(last4: "919#{rand 9}", exp_year: "199#{rand 9}".to_i)
cus = Stripe::Customer.create(source: card_token)
cus.sources.data.first.last4 # => "9198"
cus.sources.data.first.fingerprint # => "wXWJT135mEK107G8"

正如您所看到的,即使我获得与您相同的指纹。实际上,StripeMock的指纹值是硬编码的:https://github.com/rebelidealist/stripe-ruby-mock/blob/master/lib/stripe_mock/data.rb#L228

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", # see?
    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

您可以传递自己的指纹:

card_token = StripeMock.generate_card_token(fingerprint: "anything you want")
cus = Stripe::Customer.create(source: card_token)
cus.sources.data.first.fingerprint # => "anything you want"