我要建一个使用PayPal快速一个市场应用。我已经得到了卖方输入他们的PayPal API证书的形式,但我需要一种方法通过使某种呼叫到PayPal,以验证它们。

我使用ActiveMerchant的PaypalExpressGateway,我没有看到比标准采购控制其它任何东西。有任何种类的空操作,可用于?

任何帮助将不胜感激!

有帮助吗?

解决方案

由于安全原因没有检查,如果邮件是一个有效的PayPal帐户的方式。你总是可以做一个小的事务,然后作废了,如果真的是需要考虑的有效性。

其他提示

我使用的 TransactionSearch 用于此目的的操作。通过指定STARTDATE=2100-01-01 00:00:00它基本上导致无操作。

有将验证凭证你,没有从卖方要求任何额外的输入。

我没有答案个人。但我知道Railscasts.com的瑞恩·贝茨近日专门六(!)的情节,以ActiveMerchant和Paypal特别。检查出通过#146发作#141 railscasts.com

确定,在4小时后...

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    class PaypalExpressGateway < Gateway

      def get_balance(options = {})
        commit 'GetBalance', build_get_balance_request(options)
      end

    private
      def build_get_balance_request(options)
        xml = Builder::XmlMarkup.new :indent => 2
        xml.tag! 'GetBalanceReq', 'xmlns' => PAYPAL_NAMESPACE do
          xml.tag! 'GetBalanceRequest', 'xmlns:n2' => EBAY_NAMESPACE do
            xml.tag! 'n2:Version', API_VERSION
            xml.tag! 'n2:ReturnAllCurrencies', '1'
          end
        end

        xml.target!
      end
    end
  end
end

class SellerMerchantValidator < ActiveModel::Validator
  def validate(record)
    paypal_attrs = ['paypal_api_username', 'paypal_api_password', 'paypal_api_signature']
    if record.paypal_merchant? && (record.changed - paypal_attrs).size < record.changed.size # one of paypal_attrs changed
      response = record.gateway.get_balance
      unless response.params['balance'].present?
        record.errors[:base] << "Please check the PayPal details and make sure all three are entered correctly."
      end
    end
  end
end

由于尼尔斯的想法来检查TransactionSearch。

请让我知道,如果有更好的方法来检查是否有任何的API领域的变化。

还有在API中对于为getBalance的呼叫。 一些示例代码

看起来最简单的(和最快?)的方法。

贝确实有一个AddressVerify API。它证实了邮寄地址和邮政编码是否匹配指定的支付宝账户持有人。我在实施它在我们的网站现在,其实过程。

您可以阅读更多关于它在这里:点击 https://www.x.com/docs/DOC-1162#id0862M0QH02L

和这里:结果 https://cms.paypal.com/us / cgi-bin目录/?&CMD = _render含量&CONTENT_ID =显影剂/ e_howto_api_nvp_r_AddressVerify

右,所以如果你想使用ActiveMerchant测试用户的凭据,使用transaction_search方法在网关

的https:// github上。 COM / Shopify / active_merchant /斑点/ cb72e0f9c58f57b1293e6e976229b26cfbfee6a8 / LIB / active_merchant /计费/网关/贝宝/ paypal_common_api.rb

这个例子将返回成功(请务必填写您的测试证书)

@username = ''
@password = ''
@signature = ''
gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
  login:      @username,
  password:   @password,
  signature:  @signature,
  test:       true
)

gateway.transaction_search({start_date: DateTime.now})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top