使用无效的美国地址覆盖送货地址

时间:2015-09-07 05:07:56

标签: ruby-on-rails-4 paypal-sandbox paypal

我想用无效的美国地址覆盖PayPal的送货地址。我确实在https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECCustomizing/中读到了我只需要使用ADDROVERRIDE=1然后使用PAYMENTREQUEST_0_SHIPTOSTREET覆盖地址(以及其他一些相关的参数)。

但是,有文档的指南对我不起作用。如果送货地址位于美国境外,则可以使用此功能。我已经设置了一个测试应用程序,这些是代码:

class HomeController < ApplicationController
  def index
  end

  def pay
    paypal_options = {
      no_shipping: true, # if you want to disable shipping information
      allow_note: false, # if you want to disable notes
      pay_on_paypal: true # if you don't plan on showing your own confirmation step
    }

    response = paypal_request.setup(
      payment_request,
      'http://localhost:3000/done',
      'http://localhost:3000/done',
      paypal_options  # Optional
    )

    redirect_to response.redirect_uri

  rescue Paypal::Exception::HttpError, Paypal::Exception::APIError => e
    puts "------- ERROR"
    puts e.response.details.map(&:long_message).join("")
  end

  def done
    @response = paypal_request.checkout!(
      params[:token],
      params[:PayerID],
      payment_request
    )
  end

  private

  def payment_request
    Paypal::Payment::Request.new(
      :description   => "Some description",    # item description
      :quantity      => 1,      # item quantity
      :amount        => 1.00,   # item value
      :custom_fields => {
        METHOD: 'SetExpressCheckout',
        ADDROVERRIDE: 1,
        REQCONFIRMSHIPPING: 0,
        :"PAYMENTREQUEST_{n}_SHIPTONAME" => 'Donna W. Brogan',
        :"PAYMENTREQUEST_{n}_SHIPTOCITY" => 'Oak Lawns',
        :"PAYMENTREQUEST_{n}_SHIPTOSTREET" => '4223 Flinderation Road',
        :"PAYMENTREQUEST_{n}_SHIPTOSTREET2" => '',
        :"PAYMENTREQUEST_{n}_SHIPTOSTATE" => 'IL',
        :"PAYMENTREQUEST_{n}_SHIPTOCOUNTRYCODE" => 'US',
        :"PAYMENTREQUEST_{n}_SHIPTOZIP" => '60453'
      }
    )
  end

  def paypal_request
    Paypal::Express::Request.new(
      :username   => PAYPAL_CONFIG[:username],
      :password   => PAYPAL_CONFIG[:password],
      :signature  => PAYPAL_CONFIG[:signature]
    )
  end
end

地址无效,因为没有Oak Lawns,请注意额外的s

我得到的错误是:

Shipping Address Invalid City State Postal Code

这些是基于调试器发送的参数:

ADDROVERRIDE=1
&ALLOWNOTE=0
&CANCELURL=http%3A%2F%2Flocalhost%3A3000%2Fdone
&METHOD=SetExpressCheckout
&NOSHIPPING=1
&PAYMENTREQUEST_0_AMT=1.00
&PAYMENTREQUEST_0_DESC=Some+description
&PAYMENTREQUEST_0_SHIPPINGAMT=0.00
&PAYMENTREQUEST_0_SHIPTOCITY=Oak+Lawns
&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US
&PAYMENTREQUEST_0_SHIPTONAME=Donna+W.+Brogan
&PAYMENTREQUEST_0_SHIPTOSTATE=IL
&PAYMENTREQUEST_0_SHIPTOSTREET2=
&PAYMENTREQUEST_0_SHIPTOSTREET=4223+Flinderation+Road
&PAYMENTREQUEST_0_SHIPTOZIP=60453
&PAYMENTREQUEST_0_TAXAMT=0.00
&REQCONFIRMSHIPPING=0
&RETURNURL=http%3A%2F%2Flocalhost%3A3000%2Fdone

如果我将城市更改为Oak Lawn这是一个有效的送货地址,这将很有效。我正在使用https://github.com/nov/paypal-express gem来实现此目的。

1 个答案:

答案 0 :(得分:0)

默认情况下,PayPal使用USPS格式验证美国地址,这意味着当您“覆盖”买方的帐户存储地址时使用无效的地址时,它会出错并且不会让您通过。请参阅地址处理流程here