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

问题描述:

我想用无效的美国地址覆盖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 

这些都是根据调试器发送的PARAMS:

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宝石。

PayPal默认使用USPS格式验证美国地址,这意味着当您“覆盖”买方的帐户存储地址时,无效的地址会导致错误并且不会让您通过。见地址处理过程here

+0

我有点知道,但问题是,我可以提供一个无效的地址?如果可能的话,我该怎么做? – amree

+0

对于美国地址,没有。如果您提供的美国地址无效,则使用“address_override”,流程将首先打破错误。如果没有“address_override”,则无效地址将被剥离并显示买方的账户存储地址 –