【问题标题】:Ruby date format for PayPal Button Manager APIPayPal Button Manager API 的 Ruby 日期格式
【发布时间】:2017-04-29 06:14:05
【问题描述】:

我无法获得 PayPal 将通过其 PayPal 按钮管理器 API 接受的日期格式。 “指定的开始日期无效。”是错误。

尝试1:直接从文档中复制字符串:

"start_date": "2017-12-22T09:13:49Z"

我看到了这个https://github.com/paypal/PayPal-Ruby-SDK/issues/107所以尝试了

strftime('%Y-%m-%dT%H:%M:%SZ') and utc.iso8601

start_date = "1980-02-19T00:37:04Z"
start_date = (DateTime.now - 10.years).utc.iso8601
start_date = (DateTime.now - 10.years).utc

@bm_build_button_search = @api.build_bm_button_search({ "start_date" => start_date })
# Make API call & get response
@bm_button_search_response = @api.BMButtonSearch(@bm_build_button_search)

@Errors=[#<PayPal::SDK::ButtonManager::DataTypes::ErrorType:0x007fa58b12e110 @ShortMessage="Invalid Argument", @LongMessage="The start date specified is invalid.", @ErrorCode="11998

(byebug) @bm_build_button_search.start_date.class
PayPal::SDK::Core::API::DataTypes::SimpleTypes::DateTime
So it looks like PayPal is fine with this DateTime format but when I call
@api.BMButtonSearch(@bm_build_button_search) 

我收到错误@LongMessage="指定的开始日期无效。"

【问题讨论】:

    标签: date utc iso8601 paypal


    【解决方案1】:

    我刚刚使用 Ruby 版本 2.3.3 验证了以下脚本,并且它工作正常。以下是我在 ruby​​ 控制台中使用的脚本。

    Step1: install Paypal SDK 
    $ gem install paypal-sdk-buttonmanager 
    
    
    Step2:
    
    require 'paypal-sdk-buttonmanager'
    @api = PayPal::SDK::ButtonManager::API.new(
    :mode      => "sandbox",  # Set "live" for production
    :app_id    => "APP-80W284485P519543T",
    :username  => "jb-us-seller_api1.paypal.com",
    :password  => "WX4WTU3S8MY44S7F",
    :signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-
    RWy" )
    
    Step3:
    
     start_date = "1980-02-19T00:37:04Z"
     @bm_build_button_search = @api.build_bm_button_search({ "start_date" => start_date })
     @bm_button_search_response = @api.BMButtonSearch(@bm_build_button_search)
    

    响应:我,[2017-05-06T05:43:14.803444 #6541] INFO -- : Action: BMButtonSearch 我,[2017-05-06T05:43:14.803551 #6541] INFO -- : Request[post]: https://api-3t.sandbox.paypal.com/2.0/

    我,[2017-05-06T05:43:27.057413 #6541] INFO -- : 响应 [200]:好的,持续时间:12.254 秒

    **Please verify using Ruby 2.3.3. Screenshot has been attached. thanks!**
    

    参考:https://github.com/paypal/buttonmanager-sdk-ruby

    【讨论】:

    • 我仍然从 rails 控制台收到错误消息。使用相同的 @api 配置,你和我怎么可能得到不同的结果?请求[发布]:api-3t.sandbox.paypal.com/2.0 响应[200]:好的,持续时间:0.354s => #<:sdk::buttonmanager::datatypes::bmbuttonsearchresponsetype:0x007fc55250aec8 buttonmanager::datatypes::errortype:0x007fc5525096e0 argument>
    • 这在 IRB 中有效,但在 Rails 中无效——这就是问题所在。问题在于 Rails 中的日期格式。
    猜你喜欢
    • 2018-07-30
    • 2014-09-25
    • 2013-02-23
    • 1970-01-01
    • 2011-07-05
    • 2012-08-09
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    相关资源
    最近更新 更多