Created
November 17, 2012 23:05
-
-
Save azcoov/4101151 to your computer and use it in GitHub Desktop.
push notification with webscript.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local UA_APPKEY = '<Your Urban Airship App Key>' | |
local UA_PUSHSECRET = '<Your Urban Airship MASTER App Secret>' | |
local UA_PUSHURL = 'https://go.urbanairship.com/api/push/' | |
local STRIPE_KEY = '<Your Stripe Secret Key>' | |
local request_body = json.parse(request.body) | |
local id = request_body.id | |
local event = json.parse(http.request { | |
url = 'https://api.stripe.com/v1/events/' .. id, | |
auth = {STRIPE_KEY, ''} | |
}.content) | |
if event.type == 'charge.succeeded' then | |
local object = event.data.object | |
local payload = { | |
aps = { | |
badge = "1", | |
alert = string.format("charge charge succeded for %d", object.amount), | |
sound = "yes" | |
}, | |
aliases = {request_body.user_id} | |
} | |
local response = http.request({ | |
method = "post", | |
url = UA_PUSHURL, | |
headers = { | |
['Content-Type'] = "application/json" | |
}, | |
auth = {UA_APPKEY, UA_PUSHSECRET}, | |
data = json.stringify(payload) | |
}) | |
return response | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment