Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit dfbb150

Browse files
committed
FastSpring payment notification listener
1 parent 41abd3a commit dfbb150

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/scripts/fastspring.coffee

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Description
2+
# An HTTP listener for FastSpring payment notifications
3+
#
4+
# Dependencies:
5+
# None
6+
#
7+
# Configuration:
8+
# HUBOT_FASTSPRING_PRIVATE_KEY
9+
#
10+
# Commands:
11+
# None
12+
#
13+
# URLS:
14+
# POST /hubot/fastspring
15+
# room=<room>
16+
# fullName=<customer's full name>
17+
# email=<customer's email>
18+
# productName=<product name, can also be an array of products>
19+
# totalPriceValue=<total price value>
20+
# totalPriceCurrency=<total price currency>
21+
# url=<invoice's url>
22+
#
23+
# Notes:
24+
# See FastSpring notifications overview for further details
25+
# https://support.fastspring.com/entries/236490-Notifications-Overview
26+
#
27+
# Author:
28+
# matteoagosti
29+
30+
http = require "http"
31+
querystring = require "querystring"
32+
crypto = require "crypto"
33+
34+
module.exports = (robot) ->
35+
privateKey = process.env.HUBOT_FASTSPRING_PRIVATE_KEY
36+
37+
unless privateKey
38+
robot.logger.error "Please set the HUBOT_FASTSPRING_PRIVATE_KEY environment variable."
39+
return
40+
41+
robot.router.post "/hubot/fastspring", (req, res) ->
42+
query = req.body
43+
res.end
44+
45+
unless query.room
46+
return
47+
48+
unless crypto.createHash("md5").update(query.security_data + privateKey, 'utf8').digest('hex') is query.security_hash
49+
return
50+
51+
robot.messageRoom query.room, "#{query.fullName} (#{query.email}) just bought #{query.productName} for #{query.totalPriceValue}#{query.totalPriceCurrency}. #{query.url}"

0 commit comments

Comments
 (0)