1

我正在尝试在 rails 应用程序中启用信用卡计费,并且在尝试创建订单时收到以下错误:undefined method 'has_key?' for #<ActiveMerchant::Billing::CreditCard:0x244b3d8>

引用的代码是purchase订单模型中的方法:

class Order < ActiveRecord::Base
  ...
  include ActiveMerchant::Billing

  ...
  def credit_card
    @credit_card ||= ActiveMerchant::Billing::CreditCard.new(   
    :type           => card_type,
    :number         => card_number,
    :month          => card_expires_on.month,
    :year               => card_expires_on.year,
    :first_name => first_name,
    :last_name  => last_name,
    :verification_value  => card_verification
    )
  end

  def purchase

    response = GATEWAY.authorize(price_in_cents, credit_card)
    if response.success?
      GATEWAY.capture(price_in_cents, response.authorization)
      cart.update_attribute(:purchased_at, Time.now)
    else
      raise StandardError, response.message
    end

  end

end

我正在使用 Paypal Express 网关,Active Merchant 库对其定义purchase如下:

  def purchase(money, options = {})
    requires!(options, :token, :payer_id)

    commit 'DoExpressCheckoutPayment', build_sale_or_authorization_request('Sale', money, options)
  end

  private
  def build_get_details_request(token)
    xml = Builder::XmlMarkup.new :indent => 2
    xml.tag! 'GetExpressCheckoutDetailsReq', 'xmlns' => PAYPAL_NAMESPACE do
      xml.tag! 'GetExpressCheckoutDetailsRequest', 'xmlns:n2' => EBAY_NAMESPACE do
        xml.tag! 'n2:Version', API_VERSION
        xml.tag! 'Token', token
      end
    end

    xml.target!
  end

  def build_sale_or_authorization_request(action, money, options)
    currency_code = options[:currency] || currency(money)

    xml = Builder::XmlMarkup.new :indent => 2
    xml.tag! 'DoExpressCheckoutPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do
      xml.tag! 'DoExpressCheckoutPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do
        xml.tag! 'n2:Version', API_VERSION
        xml.tag! 'n2:DoExpressCheckoutPaymentRequestDetails' do
          xml.tag! 'n2:PaymentAction', action
          xml.tag! 'n2:Token', options[:token]
          xml.tag! 'n2:PayerID', options[:payer_id]
          xml.tag! 'n2:PaymentDetails' do
            xml.tag! 'n2:OrderTotal', localized_amount(money, currency_code), 'currencyID' => currency_code

            # All of the values must be included together and add up to the order total
            if [:subtotal, :shipping, :handling, :tax].all?{ |o| options.has_key?(o) }
              xml.tag! 'n2:ItemTotal', localized_amount(options[:subtotal], currency_code), 'currencyID' => currency_code
              xml.tag! 'n2:ShippingTotal', localized_amount(options[:shipping], currency_code),'currencyID' => currency_code
              xml.tag! 'n2:HandlingTotal', localized_amount(options[:handling], currency_code),'currencyID' => currency_code
              xml.tag! 'n2:TaxTotal', localized_amount(options[:tax], currency_code), 'currencyID' => currency_code
            end

            xml.tag! 'n2:NotifyURL', options[:notify_url]
            xml.tag! 'n2:ButtonSource', application_id.to_s.slice(0,32) unless application_id.blank?
            xml.tag! 'n2:InvoiceID', options[:order_id]
            xml.tag! 'n2:OrderDescription', options[:description]
          end
        end
      end
    end

    xml.target!
  end

看起来credit_card我的订单模型中的参数被视为optionshas_key?Active Merchant 库中被调用的,其CreditCard代码未定义has_key?。我正在使用最新版本的 Active Merchant。

有什么帮助吗?


使用 PuTTY 在 Windows 上自动运行 Linux 上的命令

我有一个场景,我需要经常从 Windows 运行一个linux shell 命令(使用不同的文件名)。我正在使用 PuTTY 和 WinSCP 来做到这一点(需要登录名和密码)。该文件通过 WinSCP 复制到 linux 机器中的预定义文件夹,然后从 PuTTY 运行命令。有没有一种方法可以通过程序自动执行此操作。理想情况下,我想右键单击 Windows 中的文件并发出将文件复制到远程机器的命令,并以文件名作为参数运行预定义的命令(在 PuTTy 中)。

4

1 回答 1

1

看起来有些网关有不同的购买方法。

TrustCommerceGateway(代码显示在https://github.com/activemerchant/active_merchant上)

def purchase(money, creditcard_or_billing_id, options = {})

https://github.com/activemerchant/active_merchant/blob/b417c77d435b8d163b6e77588c80ac347cc1316a/lib/active_merchant/billing/gateways/trust_commerce.rb#L164

贝宝ExpressCheckoutGateway

def purchase(money, options = {})

因此,如果您想将 ActiveMerchant::Billing::CreditCard 与 Paypal 一起使用,看起来您必须使用 PaypalGateway(而不是 PaypalExpressCheckoutGateway)

于 2015-08-10T22:02:52.420 回答