2013-08-01 21 views
1

我正在使用paypal SDK進行開票: https://github.com/paypal/invoice-sdk-ruby如何在Rails Invoice SDK中插入X-PAYPAL標頭?

這很好用。

我整合了貝寶的權限SDK的軌道: https://github.com/paypal/permissions-sdk-ruby

授權流程是偉大的工作。

所以現在我需要把它們放在一起。獲得令牌後,權限sdk的文檔將會停止。它沒有解釋如何與其他PayPal SDK一起使用它(至少不是我能理解的:D)發票sdk告訴你看到Auth sdk。

貝寶告訴我:

# 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相關的寶石,但無法看到標題本身的構建方式或與之交互的方式。

UPDATE:發現這這給了我一個線索...

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

這似乎期間,在貝寶SDK發票寶石呼叫用在這裏:

# 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參數,並通過它在我的控制器是這樣的:

@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) 

我會繼續,因爲我用Google搜索周圍有很多這種更新,找不到任何明確的答案如何做到這一點......

+0

'my_header = { 「X-PAYPAL-SECURITY-SUBJECT」=> @ invoice.user.email, 「X-PAYPAL-AUTHENTICATION」=> @ invoice.user.token } @create_and_send_invoice_response = api.create_and_send_invoice(@create_and_send_invoice,my_header)' 這樣做了。 – user2001960

回答

0

您必須通過tokentoken_secret,同時創建API對象進行第三方認證。

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