PayPal卡更新错误...参数数量错误?

时间:2015-12-23 18:15:12

标签: ruby-on-rails ruby paypal

所以我尝试使用PayPal-Ruby-SDK更新卡片。我直接从示例here中获取了大部分代码。

要查找要更新的卡片:

@credit_card = CreditCard.find(user.card_id)
=>
#<PayPal::SDK::REST::DataTypes::CreditCard:0x007f954d8b9a68
 @create_time="2015-12-22T00:58:40Z",
 @error=nil,
 @expire_month=10,
 @expire_year=2017,
 @id="CARD-8JN90741LM8220207KZ4KAQA",
 @links=
  [#<PayPal::SDK::REST::DataTypes::Links:0x007f954d89c990
    @error=nil,
    @href=
     "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA",
    @method="GET",
    @rel="self">,
   #<PayPal::SDK::REST::DataTypes::Links:0x007f954d89c378
    @error=nil,
    @href=
     "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA",
    @method="DELETE",
    @rel="delete">,
   #<PayPal::SDK::REST::DataTypes::Links:0x007f954d88bc08
    @error=nil,
    @href=
     "https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA",
    @method="PATCH",
    @rel="patch">],
 @number="xxxxxxxxxxxx3124",
 @state="ok",
 @type="discover",
 @update_time="2015-12-22T00:58:40Z",
 @valid_until="2018-12-21T00:00:00Z">

更新卡片......

@updated_card = {
  :op=> "replace",
  :path=> "/billing_address",
  :value=> {
    :line1=> "111 First Street",
    :city=> "Saratoga",
    :country_code=> "US",
    :state=> "CA",
    :postal_code=> "95070"
  }
}

patch_request = Patch.new(@updated_card)
@credit_card.update(patch_request)

当我尝试使用这种方法时,它告诉我我使用了错误数量的参数...

ArgumentError: wrong number of arguments (1 for 0)
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/paypal-sdk-rest-1.3.4/lib/paypal-sdk/rest/data_types.rb:196:in `update'
from (irb):56
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/commands/console.rb:9:in `start'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
from /Users/doug/workspace/pokersprout/coaching/bin/rails:8:in `<top (required)>'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:183:in `block in serve'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:156:in `fork'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:156:in `serve'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:131:in `block in run'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:125:in `loop'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application.rb:125:in `run'
from /Users/doug/.rvm/gems/ruby-2.1.3/gems/spring-1.4.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/doug/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/doug/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'2.1.3

我不太确定该错误是什么,因为文档告诉我必须传递更新的卡参数。它似乎是最新的,这是PayPal的文档推荐的软件包。

如果我尝试只使用没有参数的update(这没有多大意义),我会得到这样的答复:

PayPal-Request-Id: 29fc28cf-9aeb-4ca0-bbaa-2ecab741fa43
Request[patch]: https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA
Request.body={"id":"CARD-8JN90741LM8220207KZ4KAQA","number":"xxxxxxxxxxxx3124","type":"discover","expire_month":10,"expire_year":2017,"state":"ok","valid_until":"2018-12-21T00:00:00Z","create_time":"2015-12-22T00:58:40Z","update_time":"2015-12-22T00:58:40Z","links":[{"href":"https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA","rel":"delete","method":"DELETE"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-cards/CARD-8JN90741LM8220207KZ4KAQA","rel":"patch","method":"PATCH"}]}  request.header={"X-PAYPAL-SANDBOX-EMAIL-ADDRESS"=>"reid-facilitator@pokersprout.com", "Authorization"=>"Bearer A101.VF7UC2sTfYAAjpAIEgURryx08ur2UhHZGhqjZnMA4l9_NbsxYQcsH83v37HIVEC9.5Y9P29NrkohOap3ONlr4w3Wp84O", "Content-Type"=>"application/json", "User-Agent"=>"PayPalSDK/PayPal-Ruby-SDK 1.3.4 (paypal-sdk-core 1.3.4; ruby 2.1.3p242-x86_64-darwin13.0;OpenSSL 1.0.1j 15 Oct 2014)", "PayPal-Request-Id"=>"29fc28cf-9aeb-4ca0-bbaa-2ecab741fa43"}
Response[400]: Bad Request, Duration: 0.657s
Response.body={"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/docs/api/#MALFORMED_REQUEST","debug_id":"700d334028fdd"}   Response.header={"date"=>["Wed, 23 Dec 2015 18:07:48 GMT"], "server"=>["Apache"], "proxy_server_info"=>["host=slcsbplatformapiserv3002.slc.paypal.com;threadId=333"], "paypal-debug-id"=>["700d334028fdd", "700d334028fdd"], "content-language"=>["*"], "correlation-id"=>["700d334028fdd"], "content-length"=>["195"], "vary"=>["Authorization"], "content-type"=>["application/json"], "set-cookie"=>["X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D880%26app%3Dplatformapiserv%26TIME%3D4108483158; domain=.paypal.com; path=/; Secure; HttpOnly", "X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT"], "connection"=>["close"]}

我无法想到它会让我用0参数使用这个方法。我错过了一些明显的东西吗?

0 个答案:

没有答案