开发者

active_merchant: A field was longer or shorter than the server allows

I'm implementing paypal direct payment using activemerchant Following is the code

def credit_card_details
    credit_card = ActiveMerchant::Billing::CreditC开发者_C百科ard.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

I was trying with other credit card details but it was causing "A field was longer or shorter than the server allows" this error. So I replaced cc details with one specified in active_merchants github page still no luck. I dont understand what is wrong?


I think you missed the card_type or branch. One of those two is deprecated. Try and see which works. Since you missed the credit card type, maybe fields are misaligned or mapped wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜