ruby-on-rails - 如何使用 Rails Invoice SDK 插入 X-PAYPAL header ?

标签 ruby-on-rails ruby sdk paypal

我正在使用位于此处的 paypal SDK 开发票: https://github.com/paypal/invoice-sdk-ruby

效果很好。

我为 rails 集成了 paypal 权限 SDK: https://github.com/paypal/permissions-sdk-ruby

授权工作流程运行良好。

所以现在我需要把它们放在一起。获得 token 后,权限 sdk 的文档就会消失。它没有解释如何将它与其他 Paypal SDK 一起使用(至少不是这样我可以理解 :D )发票 sdk 告诉您查看 Auth sdk。

Paypal 告诉我:

# Third-party Auth headers
-H "X-PAYPAL-SECURITY-SUBJECT:<receiverEdress>"  # Merchant's PayPal e-mail
-H "X-PAYPAL-AUTHENTICATION:<OAuthSig>"          # Generated OAuth Signature

不知道怎么插入。请求是在我的模型中生成的:

    @create_and_send_invoice = api.build_create_and_send_invoice(paypalized || default_api_value)

数据本身像这样组装在发票模型中:

paypalized = {
:access_token => self.user.paypal_token, 
:invoice => {
  :merchantEmail => self.user.paypal_email || self.user.email,
  :payerEmail => self.client.email,
  :itemList => @itemlist,
  :currencyCode => "USD",
  :paymentTerms => "DueOnReceipt",
  :invoiceDate => self.updated_at,
  :number => self.name,
  :note => self.description,
  :merchantInfo => @businessinfo
  # project / Invoice title?
 } # end invoice
} # end paypalized
return paypalized

此实现无效,access_token 字段被拒绝。我查看了与 sdks 关联的 gem,但看不到 header 本身的构建位置或如何与之交互。

更新:发现这个给了我一个线索......

       INVOICE_HTTP_HEADER = { "X-PAYPAL-REQUEST-SOURCE" => "invoice-ruby-sdk-#{VERSION}" }

这似乎是在 paypal-sdk-invoice gem 中的调用期间使用的:

    # Service Call: CreateAndSendInvoice
  # @param CreateAndSendInvoiceRequest
  # @return CreateAndSendInvoiceResponse
  def CreateAndSendInvoice(options = {} , http_header = {})
    request_object  = BuildCreateAndSendInvoice(options)
    request_hash    = request_object.to_hash
    ...

我注意到有两个参数:options 和 http_header。我可以修改 http_header 参数并在我的 Controller 中以这种方式传递它:

@create_and_send_invoice_response = api.create_and_send_invoice(@create_and_send_invoice, @cutsom_header)

或者也许

@create_and_send_invoice = api.build_create_and_send_invoice(data, custom_header)

我会保持更新,因为我在谷歌上搜索了很多,但找不到关于如何做到这一点的任何明确答案......

最佳答案

创建第三方认证的API对象时必须传递tokentoken_secret

@api = PayPal::SDK::Invoice::API.new({
   :token => "replace with token",
   :token_secret => "replace with token-secret" })

关于ruby-on-rails - 如何使用 Rails Invoice SDK 插入 X-PAYPAL header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17985072/

相关文章:

ruby-on-rails - Rails 4 包括 Rails.application.routes.url_helper 未定义的方法路由为 nil :NilClass

ruby - 在 ruby​​ 中使用 google 的 api 客户端获取 Gmail 消息的正确方法是什么?

android - 如何在 Android/iOS 移动 SDK 产品中捕获日志和崩溃报告?

iphone - 如何卸载旧的 Xcode 自定义安装?

android-studio - SDK 构建工具版本 (23.0.1) 对于项目 ':app' 来说太低。最低要求为 25.0.0

android - 物联网通信 - REST API 与 Websockets

ruby-on-rails - 不理解在 Rails 中使用 Grape API gem 的嵌套资源

mysql - 未知的慢 SQL 查询

ruby - 使用 Chef 捕获 HTTP 调用响应

java - LSP 对像 Ruby 这样的动态类型语言也有意义吗?