{"action":"created","comment":{"url":"https://api.github.com/repos/npm/newww/pulls/comments/26231423","id":26231423,"diff_hunk":"@@ -0,0 +1,233 @@\n+var nodemailer = require('nodemailer')\n+var config = require('../../config')\n+var Joi = require('joi')\n+var moment = require('moment')\n+\n+module.exports = function (options) {\n+  var stripe = require('stripe')(options.secretkey)\n+  var SUB_TYPE_MONTHLY = 1, SUB_TYPE_ANNUAL = 2, SUB_TYPE_MULTI_SEAT = 3\n+  var VALID_SUBSCRIPTION_TYPES = [SUB_TYPE_MONTHLY, SUB_TYPE_ANNUAL, SUB_TYPE_MULTI_SEAT]\n+\n+  return function (request, reply) {\n+\n+    var createLicense = request.server.methods.npme.createLicense\n+    var getCustomer = request.server.methods.npme.getCustomer\n+    var updateCustomer = request.server.methods.npme.updateCustomer\n+\n+    if (request.method != 'post') {\n+      return reply('expecting POST request').code(405)\n+    }\n+\n+    var schema = Joi.object().keys({\n+      id: Joi.string().token(),\n+      livemode: Joi.string(),\n+      client_ip: Joi.string(),\n+      created: Joi.string(),\n+      used: Joi.string(),\n+      object: Joi.string(),\n+      type: Joi.string(),\n+      card: Joi.object(),\n+      email: Joi.string().regex(/^.+@.+\\..+$/), // email default accepts \"boom@boom\", which is kinda no bueno atm\n+      verification_allowed: Joi.string(),\n+      amount: Joi.number(),\n+      subType: Joi.number(),\n+      quantity: Joi.number(),\n+      customerId: Joi.number()\n+    })\n+\n+    Joi.validate(request.payload, schema, function (err, token) {\n+\n+      if (err) {\n+        request.logger.error('validation error')\n+        request.logger.error(err)\n+        reply('validation error').code(403)\n+        return\n+      }\n+\n+      if (VALID_SUBSCRIPTION_TYPES.indexOf(token.subType) === -1) {\n+        request.logger.error('invalid subscription type: ' + token.subType + '; email=' + token.email)\n+        reply('invalid subscription type').code(403)\n+        return\n+      }\n+\n+      // load the customer by email and make sure the ID matches the one passed in\n+      getCustomer(token.email,function(err, customer) {\n+\n+        if (err) {\n+          request.logger.error('error finding customer; email=' + token.email)\n+          request.logger.error(err)\n+          reply('error loading customer').code(500)\n+          return\n+        }\n+\n+        if (!customer) {\n+          request.logger.error('no customer found; email=' + token.email)\n+          request.logger.error(err)\n+          reply('customer not found').code(500)","path":"facets/enterprise/buy-license.js","position":66,"original_position":66,"commit_id":"2263940523a0b342dba5cb4445916f7d42ec8493","original_commit_id":"2263940523a0b342dba5cb4445916f7d42ec8493","user":{"login":"rockbot","id":954269,"avatar_url":"https://avatars.githubusercontent.com/u/954269?v=3","gravatar_id":"","url":"https://api.github.com/users/rockbot","html_url":"https://github.com/rockbot","followers_url":"https://api.github.com/users/rockbot/followers","following_url":"https://api.github.com/users/rockbot/following{/other_user}","gists_url":"https://api.github.com/users/rockbot/gists{/gist_id}","starred_url":"https://api.github.com/users/rockbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rockbot/subscriptions","organizations_url":"https://api.github.com/users/rockbot/orgs","repos_url":"https://api.github.com/users/rockbot/repos","events_url":"https://api.github.com/users/rockbot/events{/privacy}","received_events_url":"https://api.github.com/users/rockbot/received_events","type":"User","site_admin":false},"body":"customer not found should be a 404, no?","created_at":"2015-03-11T16:58:00Z","updated_at":"2015-03-11T16:58:00Z","html_url":"https://github.com/npm/newww/pull/724#discussion_r26231423","pull_request_url":"https://api.github.com/repos/npm/newww/pulls/724","_links":{"self":{"href":"https://api.github.com/repos/npm/newww/pulls/comments/26231423"},"html":{"href":"https://github.com/npm/newww/pull/724#discussion_r26231423"},"pull_request":{"href":"https://api.github.com/repos/npm/newww/pulls/724"}}},"pull_request":{"url":"https://api.github.com/repos/npm/newww/pulls/724","id":30907651,"html_url":"https://github.com/npm/newww/pull/724","diff_url":"https://github.com/npm/newww/pull/724.diff","patch_url":"https://github.com/npm/newww/pull/724.patch","issue_url":"https://api.github.com/repos/npm/newww/issues/724","number":724,"state":"open","locked":false,"title":"Enterprise payment flow","user":{"login":"seldo","id":185893,"avatar_url":"https://avatars.githubusercontent.com/u/185893?v=3","gravatar_id":"","url":"https://api.github.com/users/seldo","html_url":"https://github.com/seldo","followers_url":"https://api.github.com/users/seldo/followers","following_url":"https://api.github.com/users/seldo/following{/other_user}","gists_url":"https://api.github.com/users/seldo/gists{/gist_id}","starred_url":"https://api.github.com/users/seldo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seldo/subscriptions","organizations_url":"https://api.github.com/users/seldo/orgs","repos_url":"https://api.github.com/users/seldo/repos","events_url":"https://api.github.com/users/seldo/events{/privacy}","received_events_url":"https://api.github.com/users/seldo/received_events","type":"User","site_admin":false},"body":"A new flow that allows a new or existing npm Enterprise customer to sign up for one of three plans\r\n- starter pack, billed monthly\r\n- starter pack, billed annually\r\n- fixed-seat license (up to 100 seats), billed monthly","created_at":"2015-03-11T01:00:41Z","updated_at":"2015-03-11T16:58:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8234b1a2c04b4fd0e0978f586bcdd4d34ee73239","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/npm/newww/pulls/724/commits","review_comments_url":"https://api.github.com/repos/npm/newww/pulls/724/comments","review_comment_url":"https://api.github.com/repos/npm/newww/pulls/comments{/number}","comments_url":"https://api.github.com/repos/npm/newww/issues/724/comments","statuses_url":"https://api.github.com/repos/npm/newww/statuses/2263940523a0b342dba5cb4445916f7d42ec8493","head":{"label":"npm:ljv-enterprise-payment","ref":"ljv-enterprise-payment","sha":"2263940523a0b342dba5cb4445916f7d42ec8493","user":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"repo":{"id":19872239,"name":"newww","full_name":"npm/newww","owner":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/npm/newww","description":"The npm website","fork":false,"url":"https://api.github.com/repos/npm/newww","forks_url":"https://api.github.com/repos/npm/newww/forks","keys_url":"https://api.github.com/repos/npm/newww/keys{/key_id}","collaborators_url":"https://api.github.com/repos/npm/newww/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/npm/newww/teams","hooks_url":"https://api.github.com/repos/npm/newww/hooks","issue_events_url":"https://api.github.com/repos/npm/newww/issues/events{/number}","events_url":"https://api.github.com/repos/npm/newww/events","assignees_url":"https://api.github.com/repos/npm/newww/assignees{/user}","branches_url":"https://api.github.com/repos/npm/newww/branches{/branch}","tags_url":"https://api.github.com/repos/npm/newww/tags","blobs_url":"https://api.github.com/repos/npm/newww/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/npm/newww/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/npm/newww/git/refs{/sha}","trees_url":"https://api.github.com/repos/npm/newww/git/trees{/sha}","statuses_url":"https://api.github.com/repos/npm/newww/statuses/{sha}","languages_url":"https://api.github.com/repos/npm/newww/languages","stargazers_url":"https://api.github.com/repos/npm/newww/stargazers","contributors_url":"https://api.github.com/repos/npm/newww/contributors","subscribers_url":"https://api.github.com/repos/npm/newww/subscribers","subscription_url":"https://api.github.com/repos/npm/newww/subscription","commits_url":"https://api.github.com/repos/npm/newww/commits{/sha}","git_commits_url":"https://api.github.com/repos/npm/newww/git/commits{/sha}","comments_url":"https://api.github.com/repos/npm/newww/comments{/number}","issue_comment_url":"https://api.github.com/repos/npm/newww/issues/comments{/number}","contents_url":"https://api.github.com/repos/npm/newww/contents/{+path}","compare_url":"https://api.github.com/repos/npm/newww/compare/{base}...{head}","merges_url":"https://api.github.com/repos/npm/newww/merges","archive_url":"https://api.github.com/repos/npm/newww/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/npm/newww/downloads","issues_url":"https://api.github.com/repos/npm/newww/issues{/number}","pulls_url":"https://api.github.com/repos/npm/newww/pulls{/number}","milestones_url":"https://api.github.com/repos/npm/newww/milestones{/number}","notifications_url":"https://api.github.com/repos/npm/newww/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/npm/newww/labels{/name}","releases_url":"https://api.github.com/repos/npm/newww/releases{/id}","created_at":"2014-05-16T22:12:47Z","updated_at":"2015-03-11T04:04:45Z","pushed_at":"2015-03-11T00:58:56Z","git_url":"git://github.com/npm/newww.git","ssh_url":"git@github.com:npm/newww.git","clone_url":"https://github.com/npm/newww.git","svn_url":"https://github.com/npm/newww","homepage":"http://npmjs.com","size":12060,"stargazers_count":258,"watchers_count":258,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":78,"mirror_url":null,"open_issues_count":118,"forks":78,"open_issues":118,"watchers":258,"default_branch":"master"}},"base":{"label":"npm:master","ref":"master","sha":"805015068c24fa1c7b42be58b3c70df1489427cb","user":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"repo":{"id":19872239,"name":"newww","full_name":"npm/newww","owner":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/npm/newww","description":"The npm website","fork":false,"url":"https://api.github.com/repos/npm/newww","forks_url":"https://api.github.com/repos/npm/newww/forks","keys_url":"https://api.github.com/repos/npm/newww/keys{/key_id}","collaborators_url":"https://api.github.com/repos/npm/newww/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/npm/newww/teams","hooks_url":"https://api.github.com/repos/npm/newww/hooks","issue_events_url":"https://api.github.com/repos/npm/newww/issues/events{/number}","events_url":"https://api.github.com/repos/npm/newww/events","assignees_url":"https://api.github.com/repos/npm/newww/assignees{/user}","branches_url":"https://api.github.com/repos/npm/newww/branches{/branch}","tags_url":"https://api.github.com/repos/npm/newww/tags","blobs_url":"https://api.github.com/repos/npm/newww/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/npm/newww/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/npm/newww/git/refs{/sha}","trees_url":"https://api.github.com/repos/npm/newww/git/trees{/sha}","statuses_url":"https://api.github.com/repos/npm/newww/statuses/{sha}","languages_url":"https://api.github.com/repos/npm/newww/languages","stargazers_url":"https://api.github.com/repos/npm/newww/stargazers","contributors_url":"https://api.github.com/repos/npm/newww/contributors","subscribers_url":"https://api.github.com/repos/npm/newww/subscribers","subscription_url":"https://api.github.com/repos/npm/newww/subscription","commits_url":"https://api.github.com/repos/npm/newww/commits{/sha}","git_commits_url":"https://api.github.com/repos/npm/newww/git/commits{/sha}","comments_url":"https://api.github.com/repos/npm/newww/comments{/number}","issue_comment_url":"https://api.github.com/repos/npm/newww/issues/comments{/number}","contents_url":"https://api.github.com/repos/npm/newww/contents/{+path}","compare_url":"https://api.github.com/repos/npm/newww/compare/{base}...{head}","merges_url":"https://api.github.com/repos/npm/newww/merges","archive_url":"https://api.github.com/repos/npm/newww/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/npm/newww/downloads","issues_url":"https://api.github.com/repos/npm/newww/issues{/number}","pulls_url":"https://api.github.com/repos/npm/newww/pulls{/number}","milestones_url":"https://api.github.com/repos/npm/newww/milestones{/number}","notifications_url":"https://api.github.com/repos/npm/newww/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/npm/newww/labels{/name}","releases_url":"https://api.github.com/repos/npm/newww/releases{/id}","created_at":"2014-05-16T22:12:47Z","updated_at":"2015-03-11T04:04:45Z","pushed_at":"2015-03-11T00:58:56Z","git_url":"git://github.com/npm/newww.git","ssh_url":"git@github.com:npm/newww.git","clone_url":"https://github.com/npm/newww.git","svn_url":"https://github.com/npm/newww","homepage":"http://npmjs.com","size":12060,"stargazers_count":258,"watchers_count":258,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":78,"mirror_url":null,"open_issues_count":118,"forks":78,"open_issues":118,"watchers":258,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/npm/newww/pulls/724"},"html":{"href":"https://github.com/npm/newww/pull/724"},"issue":{"href":"https://api.github.com/repos/npm/newww/issues/724"},"comments":{"href":"https://api.github.com/repos/npm/newww/issues/724/comments"},"review_comments":{"href":"https://api.github.com/repos/npm/newww/pulls/724/comments"},"review_comment":{"href":"https://api.github.com/repos/npm/newww/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/npm/newww/pulls/724/commits"},"statuses":{"href":"https://api.github.com/repos/npm/newww/statuses/2263940523a0b342dba5cb4445916f7d42ec8493"}}}}