Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Process receipts server side

  • Loading branch information...
commit 896268b177ef8c28a70e69c563c3619de8bff1cc 1 parent fdb3f47
Kumar McMillan authored
17 package.json
View
@@ -1,10 +1,13 @@
{
- "amd": {
- "baseUrl": "www/js/lib"
+ "name": "private-yacht",
+ "version": "0.0.1",
+ "private": true,
+ "engines": {
+ "node": ">= 0.6.17",
+ "npm": "1.1.x"
},
- "volo": {
- "dependencies": {
- "jquery": "github:jquery/jquery/1.7.2"
- }
+ "dependencies": {
+ "receiptverifier": "0.0.5",
+ "express": "3.1.0"
}
-}
+}
38 server.js
View
@@ -0,0 +1,38 @@
+var express = require('express');
+var Verifier = require('receiptverifier').receipts.Verifier;
+var app = express();
+var media = __dirname + '/www';
+
+app.configure(function() {
+ app.use(express.logger({format: 'dev'}));
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+});
+
+app.get('/', function (req, res) {
+ res.sendfile(media + '/server-index.html');
+});
+
+app.post('/verify', function (req, res) {
+ var store = new Verifier({ onlog: console.log });
+
+ // Log the request body.
+ console.log(req.body);
+ store.verifyReceipts(req.body, function (verifier) {
+ if (verifier.state.toString() === '[OK]') {
+ console.log('Verification success!');
+ res.send('OK', 200);
+ } else {
+ console.log('Verification failure!');
+ res.send('INVALID', 403);
+ }
+ });
+});
+
+app.configure(function() {
+ app.use(express.static(media));
+});
+
+var port = process.env['PORT'] || 3000;
+app.listen(port);
+console.log('Listening on port ' + port);
63 www/css/app.css
View
@@ -251,6 +251,69 @@ body {
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
+#app-disabled, #app-disabled *, #app-disabled a:hover,
+#app-disabled a:visited, #app-disabled a:active {
+ bottom: auto;
+ clear: none;
+ cursor: default;
+ font-family: Helvetica,Arial, sans-serif;
+ font-size: medium;
+ font-style: normal;
+ font-weight: normal;
+ height: auto;
+ left: auto;
+ letter-spacing: normal;
+ line-height: 1.4em;
+ max-height: none;
+ max-width:none; min-height: 0;
+ min-width: 0;
+ overflow: visible;
+ right: auto;
+ text-align: left;
+ text-decoration: none;
+ text-indent: 0;
+ text-transform: none;
+ top: auto;
+ visibility: visible;
+ white-space: normal;
+ width: auto;
+ z-index: auto;
+}
+#app-disabled a {
+ color: #00f;
+}
+#app-disabled a:visited {
+ color:#a0f;
+}
+#app-disabled a:hover {
+ text-decoration:underline;
+}
+#app-disabled {
+ position: fixed;
+ top: 0;
+ left: 0;
+ z-index: 9999;
+ background: #000;
+ opacity: 0.85;
+ width: 100%;
+ height: 100%;
+}
+
+#app-disabled p {
+ z-index: 1000;
+ position: fixed;
+ top: 100px;
+ left: 50%;
+ margin-left: -200px;
+ width: 400px;
+ padding: 0.75em 1em 0.75em 1em;
+ border: 3px solid #ccc;
+ background: #fff;
+ opacity: 1.0;
+ color: #000;
+ border-radius: 1em;
+}
+
/* ==|== media queries ======================================================
EXAMPLE Media Query for Responsive Design.
23 www/js/server-app.js
View
@@ -0,0 +1,23 @@
+(function() {
+ if (navigator.mozApps) {
+ var result = navigator.mozApps.getSelf();
+ result.onsuccess = function () {
+ if (this.result) {
+ $.post('/verify', this.result)
+ .done(function() {
+ $('#app-disabled').remove();
+ })
+ .fail(function() {
+ console.log('App disabled: Failed to verify receipt on the server');
+ });
+ } else {
+ console.log('App disabled: no receipt on device');
+ }
+ };
+ result.onerror = function () {
+ console.log('App disabled: getSelf() failed: ' + (this.error && this.error.name));
+ };
+ } else {
+ console.log('App disabled: navigator.mozApps was not defined');
+ }
+})();
35 www/server-index.html
View
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Private Yacht</title>
+ <meta name="description" content="">
+ <!-- Mobile viewport optimized: h5bp.com/viewport -->
+ <meta name="viewport" content="width=device-width">
+ <link rel="stylesheet" href="css/app.css">
+ <!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->
+ <!-- All JavaScript at the bottom, except this Modernizr build.
+ Modernizr enables HTML5 elements & feature detects for optimal performance.
+ Create your own custom Modernizr build: www.modernizr.com/download/ -->
+ <script src="js/lib/modernizr-2.5.3.min.js"></script>
+ </head>
+ <body>
+ <div id="app-disabled">
+ <p>
+ Please visit the
+ <a href="https://marketplace-dev.allizom.org/app/private-yacht/">store</a>
+ to install the application.
+ </p>
+ </div>
+ <section id="yacht-box">
+ <h1>Private Yacht</h1>
+ <img id="yacht" src="img/yacht_1024x685.jpg" alt="Your private yacht">
+ <div id="yacht-mask"></div>
+ </section>
+ <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back
+ to local if offline. -->
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script>window.jQuery || document.write('<script src="js/lib/jquery.js"><\/script>')</script>
+ <script src="js/server-app.js"></script>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.