{"action":"created","comment":{"url":"https://api.github.com/repos/andela/elven-ah/pulls/comments/214695376","pull_request_review_id":151804820,"id":214695376,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNDY5NTM3Ng==","diff_hunk":"@@ -0,0 +1,79 @@\n+import RavePay from 'ravepay';\n+import { } from 'dotenv/config';\n+import models from '../models';\n+\n+const { Payment } = models;\n+const PUBLIC_KEY = process.env.RAVE_PUBLIC_KEY;\n+const SECRET_KEY = process.env.RAVE_SECRET_KEY;\n+const SUBSCRIPTION_RATE = parseInt(process.env.MONTHLY_SUBSCRIPTION_RATE, 10);\n+/**\n+ * This class handles all payment process of the application\n+ */\n+class PaymentController {\n+  /**\n+  * @description Validates the user payment information and upgrade if successful\n+  * @param {object} req the request object\n+  * @param {object} res the response object\n+  * @returns Returns a message object specifying the state of\n+  * the user account upgrade\n+  */\n+\n+  static ValidatePayment(req, res) {\n+    const rave = new RavePay(PUBLIC_KEY, SECRET_KEY, false);\n+    const reference = req.query.ref;\n+    const transactionReference = {\n+      flw_ref: reference,\n+    };\n+    rave.Status.requery(transactionReference)\n+      .then((response) => {\n+        const { id: userId, email } = req.user;\n+        const transactionValues = response.body.data;\n+        const subscriptionType = transactionValues.amount === SUBSCRIPTION_RATE ? 'month' : 'annual';\n+        if (transactionValues.status === 'successful' && transactionValues['customer.email'] === email) {\n+          return PaymentController.ProcessUpgrade({ userId, reference, subscriptionType }, res);\n+        }\n+        return res.status(400).json({\n+          status: 'fail',\n+          message: 'Your upgrade process failed. Kindly contact the helpdesk team.',\n+        });\n+      });\n+  }\n+\n+  static ProcessUpgrade(paymentInfo, res) {","path":"server/controllers/PaymentController.js","position":42,"original_position":42,"commit_id":"94152bd9c3d70284fc3e740191f0924848b0c72b","original_commit_id":"94152bd9c3d70284fc3e740191f0924848b0c72b","user":{"login":"yomigeek","id":5827585,"node_id":"MDQ6VXNlcjU4Mjc1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/5827585?v=4","gravatar_id":"","url":"https://api.github.com/users/yomigeek","html_url":"https://github.com/yomigeek","followers_url":"https://api.github.com/users/yomigeek/followers","following_url":"https://api.github.com/users/yomigeek/following{/other_user}","gists_url":"https://api.github.com/users/yomigeek/gists{/gist_id}","starred_url":"https://api.github.com/users/yomigeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yomigeek/subscriptions","organizations_url":"https://api.github.com/users/yomigeek/orgs","repos_url":"https://api.github.com/users/yomigeek/repos","events_url":"https://api.github.com/users/yomigeek/events{/privacy}","received_events_url":"https://api.github.com/users/yomigeek/received_events","type":"User","site_admin":false},"body":"My bad as regards the camelCasing issue, I will implement the change. As regards the method name, I used that because the whole process is all about upgrading a user from a free account to a premium account.","created_at":"2018-09-03T13:49:16Z","updated_at":"2018-09-03T13:49:16Z","html_url":"https://github.com/andela/elven-ah/pull/30#discussion_r214695376","pull_request_url":"https://api.github.com/repos/andela/elven-ah/pulls/30","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/comments/214695376"},"html":{"href":"https://github.com/andela/elven-ah/pull/30#discussion_r214695376"},"pull_request":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/30"}},"in_reply_to_id":214648174},"pull_request":{"url":"https://api.github.com/repos/andela/elven-ah/pulls/30","id":212690153,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyNjkwMTUz","html_url":"https://github.com/andela/elven-ah/pull/30","diff_url":"https://github.com/andela/elven-ah/pull/30.diff","patch_url":"https://github.com/andela/elven-ah/pull/30.patch","issue_url":"https://api.github.com/repos/andela/elven-ah/issues/30","number":30,"state":"open","locked":false,"title":"#159762182 Integrate Payment","user":{"login":"yomigeek","id":5827585,"node_id":"MDQ6VXNlcjU4Mjc1ODU=","avatar_url":"https://avatars0.githubusercontent.com/u/5827585?v=4","gravatar_id":"","url":"https://api.github.com/users/yomigeek","html_url":"https://github.com/yomigeek","followers_url":"https://api.github.com/users/yomigeek/followers","following_url":"https://api.github.com/users/yomigeek/following{/other_user}","gists_url":"https://api.github.com/users/yomigeek/gists{/gist_id}","starred_url":"https://api.github.com/users/yomigeek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yomigeek/subscriptions","organizations_url":"https://api.github.com/users/yomigeek/orgs","repos_url":"https://api.github.com/users/yomigeek/repos","events_url":"https://api.github.com/users/yomigeek/events{/privacy}","received_events_url":"https://api.github.com/users/yomigeek/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\nIntegrate Payement System to allow users upgrade to a premium account on the platform\r\n\r\n#### Description of Task to be completed?\r\n- consume Flutterwave Rave API\r\n- create a dummy front-end page to initiate the payment\r\n- create a middleware that checks if the payment reference is provided \r\n- prevent user account upgrade if payment reference is invalid during a check with the Flutterwave Rave API\r\n- upgrades user account if payment reference is valid during a check with the Flutterwave Rave API\r\n\r\n#### How should this be manually tested?\r\n - clone the repo: Run `git clone https://github.com/andela/elven-ah.git` in the folder where you want the repo to be saved.\r\n - navigate into the newly created folder and install the dependencies: `cd elven-ah && npm install`\r\n - copy .env.example to .env: `cp .env.example .env`\r\n - provision a PostgreSQL database and add the credentials to the .env file.\r\n - start the server using `npm start`\r\n- initiate the payment using a front-end client to get the payment reference via the query parameter\r\n - upgrade the user account by making a `GET` request to `/api/pay` with `ref as a query parameter`\r\n\r\n#### Any background context you want to provide?\r\n- for testing purpose use the rave test API keys by sigining up with flutterwave rave sandbox\r\n- on the front-end use the test javascript reference (https://ravesandboxapi.flutterwave.com/flwv3-pug/getpaidx/api/flwpbf-inline.js)\r\n\r\n#### What are the relevant pivotal tracker stories?\r\n[#159762182](https://www.pivotaltracker.com/story/show/159762182)\r\n\r\n#### Screenshots (if appropriate)\\\r\nN/A\r\n\r\n\r\n#### Questions:\r\nN/A\r\n\r\n[Finishes #159762182]","created_at":"2018-09-03T09:28:31Z","updated_at":"2018-09-03T13:49:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"826c11ddce8f737179ee3d30ae7afa841932d168","assignee":null,"assignees":[],"requested_reviewers":[{"login":"madeofhuman","id":7345686,"node_id":"MDQ6VXNlcjczNDU2ODY=","avatar_url":"https://avatars0.githubusercontent.com/u/7345686?v=4","gravatar_id":"","url":"https://api.github.com/users/madeofhuman","html_url":"https://github.com/madeofhuman","followers_url":"https://api.github.com/users/madeofhuman/followers","following_url":"https://api.github.com/users/madeofhuman/following{/other_user}","gists_url":"https://api.github.com/users/madeofhuman/gists{/gist_id}","starred_url":"https://api.github.com/users/madeofhuman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madeofhuman/subscriptions","organizations_url":"https://api.github.com/users/madeofhuman/orgs","repos_url":"https://api.github.com/users/madeofhuman/repos","events_url":"https://api.github.com/users/madeofhuman/events{/privacy}","received_events_url":"https://api.github.com/users/madeofhuman/received_events","type":"User","site_admin":false},{"login":"chukwuemekachm","id":33798252,"node_id":"MDQ6VXNlcjMzNzk4MjUy","avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/andela/elven-ah/pulls/30/commits","review_comments_url":"https://api.github.com/repos/andela/elven-ah/pulls/30/comments","review_comment_url":"https://api.github.com/repos/andela/elven-ah/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela/elven-ah/issues/30/comments","statuses_url":"https://api.github.com/repos/andela/elven-ah/statuses/94152bd9c3d70284fc3e740191f0924848b0c72b","head":{"label":"andela:feature/159762182/integrate-payment","ref":"feature/159762182/integrate-payment","sha":"94152bd9c3d70284fc3e740191f0924848b0c72b","user":{"login":"andela","id":4100206,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQxMDAyMDY=","avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":141551482,"node_id":"MDEwOlJlcG9zaXRvcnkxNDE1NTE0ODI=","name":"elven-ah","full_name":"andela/elven-ah","owner":{"login":"andela","id":4100206,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQxMDAyMDY=","avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/elven-ah","description":null,"fork":false,"url":"https://api.github.com/repos/andela/elven-ah","forks_url":"https://api.github.com/repos/andela/elven-ah/forks","keys_url":"https://api.github.com/repos/andela/elven-ah/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/elven-ah/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/elven-ah/teams","hooks_url":"https://api.github.com/repos/andela/elven-ah/hooks","issue_events_url":"https://api.github.com/repos/andela/elven-ah/issues/events{/number}","events_url":"https://api.github.com/repos/andela/elven-ah/events","assignees_url":"https://api.github.com/repos/andela/elven-ah/assignees{/user}","branches_url":"https://api.github.com/repos/andela/elven-ah/branches{/branch}","tags_url":"https://api.github.com/repos/andela/elven-ah/tags","blobs_url":"https://api.github.com/repos/andela/elven-ah/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/elven-ah/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/elven-ah/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/elven-ah/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/elven-ah/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/elven-ah/languages","stargazers_url":"https://api.github.com/repos/andela/elven-ah/stargazers","contributors_url":"https://api.github.com/repos/andela/elven-ah/contributors","subscribers_url":"https://api.github.com/repos/andela/elven-ah/subscribers","subscription_url":"https://api.github.com/repos/andela/elven-ah/subscription","commits_url":"https://api.github.com/repos/andela/elven-ah/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/elven-ah/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/elven-ah/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/elven-ah/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/elven-ah/contents/{+path}","compare_url":"https://api.github.com/repos/andela/elven-ah/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/elven-ah/merges","archive_url":"https://api.github.com/repos/andela/elven-ah/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/elven-ah/downloads","issues_url":"https://api.github.com/repos/andela/elven-ah/issues{/number}","pulls_url":"https://api.github.com/repos/andela/elven-ah/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/elven-ah/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/elven-ah/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/elven-ah/labels{/name}","releases_url":"https://api.github.com/repos/andela/elven-ah/releases{/id}","deployments_url":"https://api.github.com/repos/andela/elven-ah/deployments","created_at":"2018-07-19T08:52:52Z","updated_at":"2018-09-03T10:43:05Z","pushed_at":"2018-09-03T10:43:04Z","git_url":"git://github.com/andela/elven-ah.git","ssh_url":"git@github.com:andela/elven-ah.git","clone_url":"https://github.com/andela/elven-ah.git","svn_url":"https://github.com/andela/elven-ah","homepage":null,"size":1005,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":0,"default_branch":"staging"}},"base":{"label":"andela:staging","ref":"staging","sha":"7dc2287747ca023f9f6e9df82fc5e91259f6adf2","user":{"login":"andela","id":4100206,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQxMDAyMDY=","avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":141551482,"node_id":"MDEwOlJlcG9zaXRvcnkxNDE1NTE0ODI=","name":"elven-ah","full_name":"andela/elven-ah","owner":{"login":"andela","id":4100206,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQxMDAyMDY=","avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/elven-ah","description":null,"fork":false,"url":"https://api.github.com/repos/andela/elven-ah","forks_url":"https://api.github.com/repos/andela/elven-ah/forks","keys_url":"https://api.github.com/repos/andela/elven-ah/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/elven-ah/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/elven-ah/teams","hooks_url":"https://api.github.com/repos/andela/elven-ah/hooks","issue_events_url":"https://api.github.com/repos/andela/elven-ah/issues/events{/number}","events_url":"https://api.github.com/repos/andela/elven-ah/events","assignees_url":"https://api.github.com/repos/andela/elven-ah/assignees{/user}","branches_url":"https://api.github.com/repos/andela/elven-ah/branches{/branch}","tags_url":"https://api.github.com/repos/andela/elven-ah/tags","blobs_url":"https://api.github.com/repos/andela/elven-ah/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/elven-ah/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/elven-ah/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/elven-ah/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/elven-ah/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/elven-ah/languages","stargazers_url":"https://api.github.com/repos/andela/elven-ah/stargazers","contributors_url":"https://api.github.com/repos/andela/elven-ah/contributors","subscribers_url":"https://api.github.com/repos/andela/elven-ah/subscribers","subscription_url":"https://api.github.com/repos/andela/elven-ah/subscription","commits_url":"https://api.github.com/repos/andela/elven-ah/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/elven-ah/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/elven-ah/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/elven-ah/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/elven-ah/contents/{+path}","compare_url":"https://api.github.com/repos/andela/elven-ah/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/elven-ah/merges","archive_url":"https://api.github.com/repos/andela/elven-ah/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/elven-ah/downloads","issues_url":"https://api.github.com/repos/andela/elven-ah/issues{/number}","pulls_url":"https://api.github.com/repos/andela/elven-ah/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/elven-ah/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/elven-ah/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/elven-ah/labels{/name}","releases_url":"https://api.github.com/repos/andela/elven-ah/releases{/id}","deployments_url":"https://api.github.com/repos/andela/elven-ah/deployments","created_at":"2018-07-19T08:52:52Z","updated_at":"2018-09-03T10:43:05Z","pushed_at":"2018-09-03T10:43:04Z","git_url":"git://github.com/andela/elven-ah.git","ssh_url":"git@github.com:andela/elven-ah.git","clone_url":"https://github.com/andela/elven-ah.git","svn_url":"https://github.com/andela/elven-ah","homepage":null,"size":1005,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":0,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/30"},"html":{"href":"https://github.com/andela/elven-ah/pull/30"},"issue":{"href":"https://api.github.com/repos/andela/elven-ah/issues/30"},"comments":{"href":"https://api.github.com/repos/andela/elven-ah/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela/elven-ah/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/andela/elven-ah/statuses/94152bd9c3d70284fc3e740191f0924848b0c72b"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"yomigeek"}}