我正在使用位于此处的 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对象时必须传递token
和token_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/