{"action":"created","comment":{"url":"https://api.github.com/repos/praekelt/vumi-go/pulls/comments/25779245","id":25779245,"diff_hunk":"@@ -247,6 +250,32 @@ def create_transaction_interaction(self, cursor, account_number,\n         session_len_credits = MessageCost.calculate_session_length_credit_cost(\n             session_len_cost, markup_percent)\n \n+        query = \"\"\"SELECT credit_balance, last_topup_balance\n+                   FROM billing_account\n+                   WHERE account_number = %(account_number)s\"\"\"\n+\n+        params = {'account_number': account_number}\n+        cursor = yield cursor.execute(query, params)\n+        result = yield cursor.fetchone()\n+\n+        if result is None:\n+            raise BillingError(\n+                \"Unable to find billing account %s while checking\"\n+                \" credit balance. Message was %s to/from tag pool %s.\" % (\n+                    account_number, message_direction, tag_pool_name))\n+\n+        last_topup_balance = result.get('last_topup_balance')\n+        credit_balance = result.get('credit_balance')\n+\n+        def credit_percent():\n+            return self._ceil_percent(credit_balance, last_topup_balance)\n+\n+        # If the message is outbound and limit is reached, don't charge\n+        if (app_settings.ENABLE_LOW_CREDIT_CUTOFF and last_topup_balance and\n+                message_direction == MESSAGE_DIRECTION_OUTBOUND):\n+            if credit_percent() < self._notification_mapping[0]:\n+                defer.returnValue({'credit_cutoff_reached': True})","path":"go/billing/api.py","position":38,"original_position":38,"commit_id":"0b1c0f2f52cb1cf55ea2f4df5afb3e0b97e9a2f1","original_commit_id":"0b1c0f2f52cb1cf55ea2f4df5afb3e0b97e9a2f1","user":{"login":"hodgestar","id":165551,"avatar_url":"https://avatars.githubusercontent.com/u/165551?v=3","gravatar_id":"","url":"https://api.github.com/users/hodgestar","html_url":"https://github.com/hodgestar","followers_url":"https://api.github.com/users/hodgestar/followers","following_url":"https://api.github.com/users/hodgestar/following{/other_user}","gists_url":"https://api.github.com/users/hodgestar/gists{/gist_id}","starred_url":"https://api.github.com/users/hodgestar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hodgestar/subscriptions","organizations_url":"https://api.github.com/users/hodgestar/orgs","repos_url":"https://api.github.com/users/hodgestar/repos","events_url":"https://api.github.com/users/hodgestar/events{/privacy}","received_events_url":"https://api.github.com/users/hodgestar/received_events","type":"User","site_admin":false},"body":"Woot. Maybe let's make the change now then?\n","created_at":"2015-03-04T14:48:21Z","updated_at":"2015-03-04T14:48:21Z","html_url":"https://github.com/praekelt/vumi-go/pull/1210#discussion_r25779245","pull_request_url":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210","_links":{"self":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/comments/25779245"},"html":{"href":"https://github.com/praekelt/vumi-go/pull/1210#discussion_r25779245"},"pull_request":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210"}}},"pull_request":{"url":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210","id":30085585,"html_url":"https://github.com/praekelt/vumi-go/pull/1210","diff_url":"https://github.com/praekelt/vumi-go/pull/1210.diff","patch_url":"https://github.com/praekelt/vumi-go/pull/1210.patch","issue_url":"https://api.github.com/repos/praekelt/vumi-go/issues/1210","number":1210,"state":"open","locked":false,"title":"billing api to block accounts with insufficient credits","user":{"login":"rudigiesler","id":8234653,"avatar_url":"https://avatars.githubusercontent.com/u/8234653?v=3","gravatar_id":"","url":"https://api.github.com/users/rudigiesler","html_url":"https://github.com/rudigiesler","followers_url":"https://api.github.com/users/rudigiesler/followers","following_url":"https://api.github.com/users/rudigiesler/following{/other_user}","gists_url":"https://api.github.com/users/rudigiesler/gists{/gist_id}","starred_url":"https://api.github.com/users/rudigiesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudigiesler/subscriptions","organizations_url":"https://api.github.com/users/rudigiesler/orgs","repos_url":"https://api.github.com/users/rudigiesler/repos","events_url":"https://api.github.com/users/rudigiesler/events{/privacy}","received_events_url":"https://api.github.com/users/rudigiesler/received_events","type":"User","site_admin":false},"body":"The billing API should return something in it's reply to notify the billing dispatcher that the account has run out of credits, which the billing dispatcher could then handle.","created_at":"2015-02-26T15:15:11Z","updated_at":"2015-03-04T14:48:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c85de1457388421d16ef37fa8bb6a5b435a6d7d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210/commits","review_comments_url":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210/comments","review_comment_url":"https://api.github.com/repos/praekelt/vumi-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekelt/vumi-go/issues/1210/comments","statuses_url":"https://api.github.com/repos/praekelt/vumi-go/statuses/0b1c0f2f52cb1cf55ea2f4df5afb3e0b97e9a2f1","head":{"label":"praekelt:feature/issue-1210-billing-api-to-block-accounts-with-insufficient-credits","ref":"feature/issue-1210-billing-api-to-block-accounts-with-insufficient-credits","sha":"0b1c0f2f52cb1cf55ea2f4df5afb3e0b97e9a2f1","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":1946622,"name":"vumi-go","full_name":"praekelt/vumi-go","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/vumi-go","description":"","fork":false,"url":"https://api.github.com/repos/praekelt/vumi-go","forks_url":"https://api.github.com/repos/praekelt/vumi-go/forks","keys_url":"https://api.github.com/repos/praekelt/vumi-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/vumi-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/vumi-go/teams","hooks_url":"https://api.github.com/repos/praekelt/vumi-go/hooks","issue_events_url":"https://api.github.com/repos/praekelt/vumi-go/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/vumi-go/events","assignees_url":"https://api.github.com/repos/praekelt/vumi-go/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/vumi-go/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/vumi-go/tags","blobs_url":"https://api.github.com/repos/praekelt/vumi-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/vumi-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/vumi-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/vumi-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/vumi-go/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/vumi-go/languages","stargazers_url":"https://api.github.com/repos/praekelt/vumi-go/stargazers","contributors_url":"https://api.github.com/repos/praekelt/vumi-go/contributors","subscribers_url":"https://api.github.com/repos/praekelt/vumi-go/subscribers","subscription_url":"https://api.github.com/repos/praekelt/vumi-go/subscription","commits_url":"https://api.github.com/repos/praekelt/vumi-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/vumi-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/vumi-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/vumi-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/vumi-go/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/vumi-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/vumi-go/merges","archive_url":"https://api.github.com/repos/praekelt/vumi-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/vumi-go/downloads","issues_url":"https://api.github.com/repos/praekelt/vumi-go/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/vumi-go/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/vumi-go/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/vumi-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/vumi-go/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/vumi-go/releases{/id}","created_at":"2011-06-24T08:46:21Z","updated_at":"2015-03-04T08:05:26Z","pushed_at":"2015-03-04T10:48:22Z","git_url":"git://github.com/praekelt/vumi-go.git","ssh_url":"git@github.com:praekelt/vumi-go.git","clone_url":"https://github.com/praekelt/vumi-go.git","svn_url":"https://github.com/praekelt/vumi-go","homepage":"","size":42002,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":110,"forks":14,"open_issues":110,"watchers":16,"default_branch":"develop"}},"base":{"label":"praekelt:develop","ref":"develop","sha":"d5cf1f03a3ef6d9f5730c6e56c936c28aa8697df","user":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"repo":{"id":1946622,"name":"vumi-go","full_name":"praekelt/vumi-go","owner":{"login":"praekelt","id":81810,"avatar_url":"https://avatars.githubusercontent.com/u/81810?v=3","gravatar_id":"","url":"https://api.github.com/users/praekelt","html_url":"https://github.com/praekelt","followers_url":"https://api.github.com/users/praekelt/followers","following_url":"https://api.github.com/users/praekelt/following{/other_user}","gists_url":"https://api.github.com/users/praekelt/gists{/gist_id}","starred_url":"https://api.github.com/users/praekelt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekelt/subscriptions","organizations_url":"https://api.github.com/users/praekelt/orgs","repos_url":"https://api.github.com/users/praekelt/repos","events_url":"https://api.github.com/users/praekelt/events{/privacy}","received_events_url":"https://api.github.com/users/praekelt/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/praekelt/vumi-go","description":"","fork":false,"url":"https://api.github.com/repos/praekelt/vumi-go","forks_url":"https://api.github.com/repos/praekelt/vumi-go/forks","keys_url":"https://api.github.com/repos/praekelt/vumi-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekelt/vumi-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekelt/vumi-go/teams","hooks_url":"https://api.github.com/repos/praekelt/vumi-go/hooks","issue_events_url":"https://api.github.com/repos/praekelt/vumi-go/issues/events{/number}","events_url":"https://api.github.com/repos/praekelt/vumi-go/events","assignees_url":"https://api.github.com/repos/praekelt/vumi-go/assignees{/user}","branches_url":"https://api.github.com/repos/praekelt/vumi-go/branches{/branch}","tags_url":"https://api.github.com/repos/praekelt/vumi-go/tags","blobs_url":"https://api.github.com/repos/praekelt/vumi-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekelt/vumi-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekelt/vumi-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekelt/vumi-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekelt/vumi-go/statuses/{sha}","languages_url":"https://api.github.com/repos/praekelt/vumi-go/languages","stargazers_url":"https://api.github.com/repos/praekelt/vumi-go/stargazers","contributors_url":"https://api.github.com/repos/praekelt/vumi-go/contributors","subscribers_url":"https://api.github.com/repos/praekelt/vumi-go/subscribers","subscription_url":"https://api.github.com/repos/praekelt/vumi-go/subscription","commits_url":"https://api.github.com/repos/praekelt/vumi-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekelt/vumi-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekelt/vumi-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekelt/vumi-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekelt/vumi-go/contents/{+path}","compare_url":"https://api.github.com/repos/praekelt/vumi-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekelt/vumi-go/merges","archive_url":"https://api.github.com/repos/praekelt/vumi-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekelt/vumi-go/downloads","issues_url":"https://api.github.com/repos/praekelt/vumi-go/issues{/number}","pulls_url":"https://api.github.com/repos/praekelt/vumi-go/pulls{/number}","milestones_url":"https://api.github.com/repos/praekelt/vumi-go/milestones{/number}","notifications_url":"https://api.github.com/repos/praekelt/vumi-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekelt/vumi-go/labels{/name}","releases_url":"https://api.github.com/repos/praekelt/vumi-go/releases{/id}","created_at":"2011-06-24T08:46:21Z","updated_at":"2015-03-04T08:05:26Z","pushed_at":"2015-03-04T10:48:22Z","git_url":"git://github.com/praekelt/vumi-go.git","ssh_url":"git@github.com:praekelt/vumi-go.git","clone_url":"https://github.com/praekelt/vumi-go.git","svn_url":"https://github.com/praekelt/vumi-go","homepage":"","size":42002,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":110,"forks":14,"open_issues":110,"watchers":16,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210"},"html":{"href":"https://github.com/praekelt/vumi-go/pull/1210"},"issue":{"href":"https://api.github.com/repos/praekelt/vumi-go/issues/1210"},"comments":{"href":"https://api.github.com/repos/praekelt/vumi-go/issues/1210/comments"},"review_comments":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210/comments"},"review_comment":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekelt/vumi-go/pulls/1210/commits"},"statuses":{"href":"https://api.github.com/repos/praekelt/vumi-go/statuses/0b1c0f2f52cb1cf55ea2f4df5afb3e0b97e9a2f1"}}}}