active_merchant:字段比服务器允许的更长或更短

时间:2011-09-16 08:37:03

标签: ruby-on-rails ruby-on-rails-3 paypal activemerchant

我正在使用activemerchant实现paypal直接付款 以下是代码

def credit_card_details
    credit_card = ActiveMerchant::Billing::CreditCard.new(
                :first_name         => 'Bob',
                :last_name          => 'Bobsen',
                :number             => '4242424242424242',
                :month              => '8',
                :year               => '2012',
                :verification_value => '123')

    errors.add(:expire_year, "Credit card expired") if credit_card.expired?
    errors.add(:cc_number, "invalid credit card details") unless credit_card.valid?

    if credit_card.valid?
      # Capture $10 from the credit card
      amount = 1000
      response = PAYPAL_GATEWAY.purchase(amount, credit_card)

      if response.success?
        puts "Successfully charged $#{sprintf("%.2f", amount / 100)} to the credit card #{credit_card.display_number}"
      else

        raise StandardError, response.inspect
      end
    end
  end

我正在尝试其他信用卡详细信息,但它导致“字段比服务器允许更长或更短”此错误。所以我用active_merchants github页面中指定的cc替换cc细节仍然没有运气。 我不明白出了什么问题?

1 个答案:

答案 0 :(得分:0)

我认为你错过了card_type或分支。其中一个被弃用了。试试看哪些有效。由于您错过了信用卡类型,因此字段可能未对齐或映射错误。