{"action":"created","comment":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/comments/36907518","id":36907518,"diff_hunk":"@@ -694,6 +694,10 @@ def covered_by_store_credit?\n     end\n     alias_method :covered_by_store_credit, :covered_by_store_credit?\n \n+    def covered_by_valid_payments?\n+      return payments.where(state: %w(checkout pending)).sum(:amount) >= total","path":"core/app/models/spree/order.rb","position":5,"original_position":5,"commit_id":"dcc09205e79445dc41c96838b071453df233236a","original_commit_id":"dcc09205e79445dc41c96838b071453df233236a","user":{"login":"jhawthorn","id":131752,"avatar_url":"https://avatars.githubusercontent.com/u/131752?v=3","gravatar_id":"","url":"https://api.github.com/users/jhawthorn","html_url":"https://github.com/jhawthorn","followers_url":"https://api.github.com/users/jhawthorn/followers","following_url":"https://api.github.com/users/jhawthorn/following{/other_user}","gists_url":"https://api.github.com/users/jhawthorn/gists{/gist_id}","starred_url":"https://api.github.com/users/jhawthorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhawthorn/subscriptions","organizations_url":"https://api.github.com/users/jhawthorn/orgs","repos_url":"https://api.github.com/users/jhawthorn/repos","events_url":"https://api.github.com/users/jhawthorn/events{/privacy}","received_events_url":"https://api.github.com/users/jhawthorn/received_events","type":"User","site_admin":false},"body":"`return` not needed here.\r\n\r\nIs there a pre-defined scope on payments we can use instead?","created_at":"2015-08-12T20:10:52Z","updated_at":"2015-08-12T20:10:52Z","html_url":"https://github.com/solidusio/solidus/pull/281#discussion_r36907518","pull_request_url":"https://api.github.com/repos/solidusio/solidus/pulls/281","_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments/36907518"},"html":{"href":"https://github.com/solidusio/solidus/pull/281#discussion_r36907518"},"pull_request":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/281"}}},"pull_request":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/281","id":42282810,"html_url":"https://github.com/solidusio/solidus/pull/281","diff_url":"https://github.com/solidusio/solidus/pull/281.diff","patch_url":"https://github.com/solidusio/solidus/pull/281.patch","issue_url":"https://api.github.com/repos/solidusio/solidus/issues/281","number":281,"state":"open","locked":false,"title":"Prevent an order from completing if its pending payments do not cover the total price of the order","user":{"login":"plongyear","id":2524312,"avatar_url":"https://avatars.githubusercontent.com/u/2524312?v=3","gravatar_id":"","url":"https://api.github.com/users/plongyear","html_url":"https://github.com/plongyear","followers_url":"https://api.github.com/users/plongyear/followers","following_url":"https://api.github.com/users/plongyear/following{/other_user}","gists_url":"https://api.github.com/users/plongyear/gists{/gist_id}","starred_url":"https://api.github.com/users/plongyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plongyear/subscriptions","organizations_url":"https://api.github.com/users/plongyear/orgs","repos_url":"https://api.github.com/users/plongyear/repos","events_url":"https://api.github.com/users/plongyear/events{/privacy}","received_events_url":"https://api.github.com/users/plongyear/received_events","type":"User","site_admin":false},"body":"A check is made [here] (https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order.rb#L685-L687) to ensure that an order's payments cover the total cost of the order before transitioning from the payment state to confirm. If the state machine transitions ever change so that an order is able to reach confirm or complete without making the payment -> confirm transition then this check will be bypassed and it will be possible for a user to checkout without having enough payments to cover the total cost of the order.\r\n\r\nI think it makes sense to check that the payments will cover the cost of the order before transitioning to complete. This should guarantee that an order will never complete unless its payments can cover the total cost.\r\n\r\nI'm also curious if there are any reasons not to perform the check when transitioning to complete. I wasn't able to think of any, but I'm not sure if there's some case I may be missing where this check would be unwanted.","created_at":"2015-08-12T20:09:54Z","updated_at":"2015-08-12T20:10:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2105fda883e2ebb0092be339f4e554d5203c644d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/solidusio/solidus/pulls/281/commits","review_comments_url":"https://api.github.com/repos/solidusio/solidus/pulls/281/comments","review_comment_url":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solidusio/solidus/issues/281/comments","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/dcc09205e79445dc41c96838b071453df233236a","head":{"label":"plongyear:payment-errors","ref":"payment-errors","sha":"dcc09205e79445dc41c96838b071453df233236a","user":{"login":"plongyear","id":2524312,"avatar_url":"https://avatars.githubusercontent.com/u/2524312?v=3","gravatar_id":"","url":"https://api.github.com/users/plongyear","html_url":"https://github.com/plongyear","followers_url":"https://api.github.com/users/plongyear/followers","following_url":"https://api.github.com/users/plongyear/following{/other_user}","gists_url":"https://api.github.com/users/plongyear/gists{/gist_id}","starred_url":"https://api.github.com/users/plongyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plongyear/subscriptions","organizations_url":"https://api.github.com/users/plongyear/orgs","repos_url":"https://api.github.com/users/plongyear/repos","events_url":"https://api.github.com/users/plongyear/events{/privacy}","received_events_url":"https://api.github.com/users/plongyear/received_events","type":"User","site_admin":false},"repo":{"id":38247853,"name":"solidus","full_name":"plongyear/solidus","owner":{"login":"plongyear","id":2524312,"avatar_url":"https://avatars.githubusercontent.com/u/2524312?v=3","gravatar_id":"","url":"https://api.github.com/users/plongyear","html_url":"https://github.com/plongyear","followers_url":"https://api.github.com/users/plongyear/followers","following_url":"https://api.github.com/users/plongyear/following{/other_user}","gists_url":"https://api.github.com/users/plongyear/gists{/gist_id}","starred_url":"https://api.github.com/users/plongyear/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plongyear/subscriptions","organizations_url":"https://api.github.com/users/plongyear/orgs","repos_url":"https://api.github.com/users/plongyear/repos","events_url":"https://api.github.com/users/plongyear/events{/privacy}","received_events_url":"https://api.github.com/users/plongyear/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/plongyear/solidus","description":"Solidus e-commerce system","fork":true,"url":"https://api.github.com/repos/plongyear/solidus","forks_url":"https://api.github.com/repos/plongyear/solidus/forks","keys_url":"https://api.github.com/repos/plongyear/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plongyear/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plongyear/solidus/teams","hooks_url":"https://api.github.com/repos/plongyear/solidus/hooks","issue_events_url":"https://api.github.com/repos/plongyear/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/plongyear/solidus/events","assignees_url":"https://api.github.com/repos/plongyear/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/plongyear/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/plongyear/solidus/tags","blobs_url":"https://api.github.com/repos/plongyear/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plongyear/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plongyear/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/plongyear/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plongyear/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/plongyear/solidus/languages","stargazers_url":"https://api.github.com/repos/plongyear/solidus/stargazers","contributors_url":"https://api.github.com/repos/plongyear/solidus/contributors","subscribers_url":"https://api.github.com/repos/plongyear/solidus/subscribers","subscription_url":"https://api.github.com/repos/plongyear/solidus/subscription","commits_url":"https://api.github.com/repos/plongyear/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/plongyear/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/plongyear/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/plongyear/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/plongyear/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/plongyear/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plongyear/solidus/merges","archive_url":"https://api.github.com/repos/plongyear/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plongyear/solidus/downloads","issues_url":"https://api.github.com/repos/plongyear/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/plongyear/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/plongyear/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/plongyear/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plongyear/solidus/labels{/name}","releases_url":"https://api.github.com/repos/plongyear/solidus/releases{/id}","created_at":"2015-06-29T13:00:12Z","updated_at":"2015-06-29T13:00:15Z","pushed_at":"2015-08-12T20:07:09Z","git_url":"git://github.com/plongyear/solidus.git","ssh_url":"git@github.com:plongyear/solidus.git","clone_url":"https://github.com/plongyear/solidus.git","svn_url":"https://github.com/plongyear/solidus","homepage":"","size":62730,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"solidusio:master","ref":"master","sha":"955c75b725bdf75989974064c684b2c69cf5d6c0","user":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"repo":{"id":30985840,"name":"solidus","full_name":"solidusio/solidus","owner":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solidusio/solidus","description":"Solidus, Rails eCommerce System","fork":false,"url":"https://api.github.com/repos/solidusio/solidus","forks_url":"https://api.github.com/repos/solidusio/solidus/forks","keys_url":"https://api.github.com/repos/solidusio/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solidusio/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solidusio/solidus/teams","hooks_url":"https://api.github.com/repos/solidusio/solidus/hooks","issue_events_url":"https://api.github.com/repos/solidusio/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/solidusio/solidus/events","assignees_url":"https://api.github.com/repos/solidusio/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/solidusio/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/solidusio/solidus/tags","blobs_url":"https://api.github.com/repos/solidusio/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solidusio/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solidusio/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/solidusio/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/solidusio/solidus/languages","stargazers_url":"https://api.github.com/repos/solidusio/solidus/stargazers","contributors_url":"https://api.github.com/repos/solidusio/solidus/contributors","subscribers_url":"https://api.github.com/repos/solidusio/solidus/subscribers","subscription_url":"https://api.github.com/repos/solidusio/solidus/subscription","commits_url":"https://api.github.com/repos/solidusio/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/solidusio/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/solidusio/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/solidusio/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/solidusio/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/solidusio/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solidusio/solidus/merges","archive_url":"https://api.github.com/repos/solidusio/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solidusio/solidus/downloads","issues_url":"https://api.github.com/repos/solidusio/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/solidusio/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/solidusio/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/solidusio/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solidusio/solidus/labels{/name}","releases_url":"https://api.github.com/repos/solidusio/solidus/releases{/id}","created_at":"2015-02-18T20:41:58Z","updated_at":"2015-08-12T20:06:20Z","pushed_at":"2015-08-12T20:09:54Z","git_url":"git://github.com/solidusio/solidus.git","ssh_url":"git@github.com:solidusio/solidus.git","clone_url":"https://github.com/solidusio/solidus.git","svn_url":"https://github.com/solidusio/solidus","homepage":"http://solidus.io/","size":65978,"stargazers_count":28,"watchers_count":28,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"open_issues_count":37,"forks":17,"open_issues":37,"watchers":28,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/281"},"html":{"href":"https://github.com/solidusio/solidus/pull/281"},"issue":{"href":"https://api.github.com/repos/solidusio/solidus/issues/281"},"comments":{"href":"https://api.github.com/repos/solidusio/solidus/issues/281/comments"},"review_comments":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/281/comments"},"review_comment":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/281/commits"},"statuses":{"href":"https://api.github.com/repos/solidusio/solidus/statuses/dcc09205e79445dc41c96838b071453df233236a"}}}}