Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Stripe::Webhook.compute_signature #915

Merged
merged 1 commit into from Apr 24, 2020

Commits on Apr 24, 2020

  1. Expose Stripe::Webhook.compute_signature

    Exposes the `.compute_signature` method, which may be useful when
    testing webhook signing in test suites.
    
    I change the API slightly so that a caller isn't forced to do as much
    string mangling, and to match the one that we already have in stripe-go:
    
    ``` go
    func ComputeSignature(t time.Time, payload []byte, secret string) []byte {
    ```
    
    Add basic documentation and test case. I also change a few things around
    so that we send `Time` objects around more often where applicable, and
    don't change then to Unix integers until the last moment that we need
    to.
    
    The one other alternative API I considered is this one, which would
    default the timestamp to the current time to allow the method to be
    called with one fewer arg:
    
    ``` ruby
    def self.compute_signature(payload, secret: timestamp: Time.now)
    ```
    
    I decided against it in the end though because it does remove some
    explicitness, and it's not a big deal to just pass in `Time.now`,
    especially given that this is not expected to be a commonly used method.
    
    Fixes #912.
    brandur committed Apr 24, 2020
    Copy the full SHA
    bb7fbaa View commit details
    Browse the repository at this point in the history