ruby – Paymill:如何在测试时模拟付款失败?

背景

>使用Paymill’s subscription billing功能开发应用程序.
>利用Ruby wrapper,我创建了一个PaymentProvider类和规范如下.

如何使测试付款失败? (例如,卡被拒绝,或者卡在未来的订阅付款中过期)

Stripe would let me do this using special card numbers但Paymill似乎没有任何此类文件(英文).

payment_provider.rb

class PaymentProvider
  Paymill.api_key = ENV['PAYMILL_PRIVATE_KEY']

  def self.start_new_subscription(email,description,token)
    offer = Paymill::Offer.find(ENV['PAYMILL_OFFER_ID'])
    client = Paymill::Client.create(email: email,description: description)
    payment = Paymill::Payment.create(token: token,client: client.id)
    subscription = Paymill::Subscription.create(client: client.id,offer: offer.id,payment: payment.id)
    subscription.id
  end
end

payment_provider_spec.rb

require 'spec_helper'

describe PaymentProvider do

  describe "#start_new_subscription" do
    it "returns a subscription id,starting 'sub_' when successful" do
      email = "mike@mike.com"
      description = "me"
      token = get_payment_token
      subscription_id = PaymentProvider.start_new_subscription(email,token)
      expect(subscription_id[0,4]).to eq('sub_')
    end
  end

  def get_payment_token
    # Simulate the JavaScript bridge we would use in production
    params = {
      'transaction.mode'        => 'CONNECTOR_TEST','channel.id'              => ENV['PAYMILL_PUBLIC_KEY'],'jsonPFunction'           => 'any_string','account.number'          => '5500000000000004','account.expiry.month'    => 3.years.from_Now.month,'account.expiry.year'     => 3.years.from_Now.year,'account.verification'    => '111'
      #'presentation.amount3D'   => BigDecimal('10.00'),#'presentation.currency3D' => 'GBP'
    }
    http = Net::HTTP.new('test-token.paymill.de',443)
    http.use_ssl = true
    response = http.get url_query_string(params)
    response.body.scan(/tok_\w*\b/).first # Use a regex to pull the token from the (not-quite-JSON) response
  end

  def url_query_string(hash)
    "/?" << URI.escape(hash.collect{|k,v| "#{k}=#{v}"}.join('&'))
  end

end

解决方法

截至今天,没有特殊的信用卡号码来模拟这些问题.但是,由于社区的要求,目前正在积压实施.我建议发送电子邮件支持人员,以表示对此功能的兴趣.请求越多,功能实施得越快.

编辑:PAYMILL现在提供一个特殊的万事达卡号码,如果使用了到期月份和年份的特定组合,它将失败.例如,如果到期日期发送为02/2020,则卡5105105105105100将因RESPONSE_BACKEND_BLACKLISTED而失败.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...