Skip to content

Instantly share code, notes, and snippets.

@alexweissman
Last active January 29, 2021 19:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexweissman/b9b892df62af81a51e69f4fd894b3ec5 to your computer and use it in GitHub Desktop.
Save alexweissman/b9b892df62af81a51e69f4fd894b3ec5 to your computer and use it in GitHub Desktop.
var CryptoJS = require('crypto-js');
var timestamp = Date.now().valueOf();
var secret = pm.collectionVariables.get('secret');
var payload = pm.request.body.raw;
var signature = CryptoJS.HmacSHA256(timestamp + '.' + payload, secret);
pm.request.headers.add({
key: 'Stripe-Signature',
value: 't=' + timestamp + ',v1=' + signature
});
@alexweissman
Copy link
Author

alexweissman commented Jan 29, 2021

Copy this to "Pre-request Scripts" in your Postman collection. Then in the "Variables" tab, set secret to the value of your webhook secret retrieved from Stripe Dashboard.

This script will automatically generate the timestamp and signature and insert them into the Stripe-Signature header for your request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment