【问题标题】:No signatures found matching the expected signature for payload未找到与有效负载的预期签名匹配的签名
【发布时间】:2019-09-04 08:52:10
【问题描述】:

我正在开发市场应用程序。当从平台支付到连接帐户时,我想更新帐户的余额信息并在我的应用程序中添加收据模型。但是出现No signatures found matching the expected signature for payload 错误,我无法获得payout.paid 事件。

stripe.rb

StripeEvent.configure do |events|
  # The case transfer created
  events.subscribe(
    'payout.paid',
    Events::PayoutPaid.new
  )
end

apps/services/events/payout_paid.rb

class Events::PayoutPaid
  def call(event)
    source = event.data.object

    # Fetch balence information
    account = source.destination
    balance = Stripe::Balance.retrieve(
        {stripe_account: account}
      )

    @user = User.find_by({
      stripe_account_id: account
    })
    @user.balance = balance["available"][0]["amount"]
    @user.save

    # create receipt
    @receipt = Receipt.new
    @receipt.user = @user
    @receipt.amount = source.amount
    @receipt.save
  end
end

虽然其他条带 webhook 也可以。

【问题讨论】:

    标签: ruby-on-rails stripe-payments ngrok


    【解决方案1】:

    那是因为你还没有将签名秘密加载到 StripeEvent

    免得说您在 Stripe 仪表板上创建了 2 个 webhook,一个订阅了发票事件,另一个订阅了客户事件。您首先需要复制每个签名密钥(单击显示),然后将它们存储在 config/credentials.yml.enc 文件中

    首先,运行命令EDITOR="atom --wait" rails credentials:edit(使用您选择的编辑器)。然后,添加以下值:

        stripe:
          development:
            secret_key: MY_SECRET_KEY
            publishable_key: MY_PUBLISHABLE_KEY
            signing_secret_customer_endpoint: MY_SIGNING_SECRET_CUSTOMERS
            signing_secrets_invoice_endpoint: MY_SIGNING_SECRET_INVOICES
    

    保存文件。现在编辑 stripeEvent 的初始化程序。就我而言,它是config/initializers/stripe.rb 并添加:

    StripeEvent.signing_secrets = [
      Rails.application.credentials[:stripe][Rails.env.to_sym][:signing_secret_customer_endpoint],
      Rails.application.credentials[:stripe][Rails.env.to_sym][:signing_secrets_invoice_endpoint]]
    

    现在签名密钥已加载,webhook 应该可以工作了

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,解决方法是:

      1. 登录 Stripe
      2. 转到失败的 webhook 的页面
      3. 从该页面中间获取签名密钥
      4. 并设置一个名为 STRIPE_SIGNING_SECRET 的 env VAR,并将签名密钥作为其值。

      Stripe 文档here 中提到了这一点。

      【讨论】:

        猜你喜欢
        • 2021-02-19
        • 2019-05-22
        • 2019-11-10
        • 2020-07-07
        • 2021-07-26
        • 2022-12-12
        • 2020-04-25
        • 2021-03-14
        • 2011-06-18
        相关资源
        最近更新 更多