{"action":"created","comment":{"url":"https://api.github.com/repos/bonobos/spree/pulls/comments/30230902","id":30230902,"diff_hunk":"@@ -0,0 +1,32 @@\n+class Spree::OrderCapturing\n+  class_attribute :eligible_payments\n+  self.eligible_payments = []\n+\n+  def initialize(order)\n+    @order = order\n+  end\n+\n+  def capture_payments\n+    return if @order.paid?\n+\n+    Spree::OrderMutex.with_lock!(@order) do\n+      uncaptured_amount = @order.total\n+\n+      while uncaptured_amount > 0 do\n+        payment = sorted_eligible_payments(@order).shift\n+        break unless payment\n+\n+        amount = [uncaptured_amount, payment.amount].min\n+        payment.capture!((amount * 100).to_i)\n+        uncaptured_amount -= amount\n+      end\n+    end\n+  end\n+\n+  private\n+\n+  def sorted_eligible_payments(order)\n+    payments = order.reload.pending_payments\n+    payments = payments.sort_by { |p| [eligible_payments.index(p.payment_method.class), p.id] }","path":"core/app/models/spree/order_capturing.rb","position":30,"original_position":30,"commit_id":"125b16b71c943e52641d2bf709b5018a37708092","original_commit_id":"125b16b71c943e52641d2bf709b5018a37708092","user":{"login":"athal7","id":467872,"avatar_url":"https://avatars.githubusercontent.com/u/467872?v=3","gravatar_id":"","url":"https://api.github.com/users/athal7","html_url":"https://github.com/athal7","followers_url":"https://api.github.com/users/athal7/followers","following_url":"https://api.github.com/users/athal7/following{/other_user}","gists_url":"https://api.github.com/users/athal7/gists{/gist_id}","starred_url":"https://api.github.com/users/athal7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/athal7/subscriptions","organizations_url":"https://api.github.com/users/athal7/orgs","repos_url":"https://api.github.com/users/athal7/repos","events_url":"https://api.github.com/users/athal7/events{/privacy}","received_events_url":"https://api.github.com/users/athal7/received_events","type":"User","site_admin":false},"body":"nice hook!","created_at":"2015-05-13T13:40:51Z","updated_at":"2015-05-13T13:40:51Z","html_url":"https://github.com/bonobos/spree/pull/358#discussion_r30230902","pull_request_url":"https://api.github.com/repos/bonobos/spree/pulls/358","_links":{"self":{"href":"https://api.github.com/repos/bonobos/spree/pulls/comments/30230902"},"html":{"href":"https://github.com/bonobos/spree/pull/358#discussion_r30230902"},"pull_request":{"href":"https://api.github.com/repos/bonobos/spree/pulls/358"}}},"pull_request":{"url":"https://api.github.com/repos/bonobos/spree/pulls/358","id":35255374,"html_url":"https://github.com/bonobos/spree/pull/358","diff_url":"https://github.com/bonobos/spree/pull/358.diff","patch_url":"https://github.com/bonobos/spree/pull/358.patch","issue_url":"https://api.github.com/repos/bonobos/spree/issues/358","number":358,"state":"open","locked":false,"title":"OrderCapturing","user":{"login":"philbirt","id":208828,"avatar_url":"https://avatars.githubusercontent.com/u/208828?v=3","gravatar_id":"","url":"https://api.github.com/users/philbirt","html_url":"https://github.com/philbirt","followers_url":"https://api.github.com/users/philbirt/followers","following_url":"https://api.github.com/users/philbirt/following{/other_user}","gists_url":"https://api.github.com/users/philbirt/gists{/gist_id}","starred_url":"https://api.github.com/users/philbirt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbirt/subscriptions","organizations_url":"https://api.github.com/users/philbirt/orgs","repos_url":"https://api.github.com/users/philbirt/repos","events_url":"https://api.github.com/users/philbirt/events{/privacy}","received_events_url":"https://api.github.com/users/philbirt/received_events","type":"User","site_admin":false},"body":"Added a service object that allows you to capture payments for an `Spree::Order` in a certain order.\r\n\r\nWe don't have plans to hook this up to much of anything in spree itself -- we are going to have a cron job that will use it -- but thought it would be good to submit it here first in case there is interest in something like this more broadly. One example: It might be something we could put in place of OrderContents#process_payments in the future. Opinions definitely welcome.\r\n\r\ncc @cbrunsdon @jordan-brough ","created_at":"2015-05-12T18:21:21Z","updated_at":"2015-05-13T13:40:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"99e137cf664538d9120f37b1a360f2419581af68","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bonobos/spree/pulls/358/commits","review_comments_url":"https://api.github.com/repos/bonobos/spree/pulls/358/comments","review_comment_url":"https://api.github.com/repos/bonobos/spree/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bonobos/spree/issues/358/comments","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/125b16b71c943e52641d2bf709b5018a37708092","head":{"label":"bonobos:order_capturing","ref":"order_capturing","sha":"125b16b71c943e52641d2bf709b5018a37708092","user":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"repo":{"id":12625383,"name":"spree","full_name":"bonobos/spree","owner":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bonobos/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/bonobos/spree","forks_url":"https://api.github.com/repos/bonobos/spree/forks","keys_url":"https://api.github.com/repos/bonobos/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bonobos/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bonobos/spree/teams","hooks_url":"https://api.github.com/repos/bonobos/spree/hooks","issue_events_url":"https://api.github.com/repos/bonobos/spree/issues/events{/number}","events_url":"https://api.github.com/repos/bonobos/spree/events","assignees_url":"https://api.github.com/repos/bonobos/spree/assignees{/user}","branches_url":"https://api.github.com/repos/bonobos/spree/branches{/branch}","tags_url":"https://api.github.com/repos/bonobos/spree/tags","blobs_url":"https://api.github.com/repos/bonobos/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bonobos/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bonobos/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/bonobos/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/bonobos/spree/languages","stargazers_url":"https://api.github.com/repos/bonobos/spree/stargazers","contributors_url":"https://api.github.com/repos/bonobos/spree/contributors","subscribers_url":"https://api.github.com/repos/bonobos/spree/subscribers","subscription_url":"https://api.github.com/repos/bonobos/spree/subscription","commits_url":"https://api.github.com/repos/bonobos/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/bonobos/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/bonobos/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/bonobos/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/bonobos/spree/contents/{+path}","compare_url":"https://api.github.com/repos/bonobos/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bonobos/spree/merges","archive_url":"https://api.github.com/repos/bonobos/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bonobos/spree/downloads","issues_url":"https://api.github.com/repos/bonobos/spree/issues{/number}","pulls_url":"https://api.github.com/repos/bonobos/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/bonobos/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/bonobos/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bonobos/spree/labels{/name}","releases_url":"https://api.github.com/repos/bonobos/spree/releases{/id}","created_at":"2013-09-05T18:28:25Z","updated_at":"2015-05-07T18:58:45Z","pushed_at":"2015-05-12T22:17:30Z","git_url":"git://github.com/bonobos/spree.git","ssh_url":"git@github.com:bonobos/spree.git","clone_url":"https://github.com/bonobos/spree.git","svn_url":"https://github.com/bonobos/spree","homepage":"http://spreecommerce.com","size":81242,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":10,"forks":1,"open_issues":10,"watchers":1,"default_branch":"2-2-dev"}},"base":{"label":"bonobos:2-2-dev","ref":"2-2-dev","sha":"3632cb8f50ea7d141349ebf7655a7e2e1d2c6200","user":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"repo":{"id":12625383,"name":"spree","full_name":"bonobos/spree","owner":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bonobos/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/bonobos/spree","forks_url":"https://api.github.com/repos/bonobos/spree/forks","keys_url":"https://api.github.com/repos/bonobos/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bonobos/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bonobos/spree/teams","hooks_url":"https://api.github.com/repos/bonobos/spree/hooks","issue_events_url":"https://api.github.com/repos/bonobos/spree/issues/events{/number}","events_url":"https://api.github.com/repos/bonobos/spree/events","assignees_url":"https://api.github.com/repos/bonobos/spree/assignees{/user}","branches_url":"https://api.github.com/repos/bonobos/spree/branches{/branch}","tags_url":"https://api.github.com/repos/bonobos/spree/tags","blobs_url":"https://api.github.com/repos/bonobos/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bonobos/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bonobos/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/bonobos/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/bonobos/spree/languages","stargazers_url":"https://api.github.com/repos/bonobos/spree/stargazers","contributors_url":"https://api.github.com/repos/bonobos/spree/contributors","subscribers_url":"https://api.github.com/repos/bonobos/spree/subscribers","subscription_url":"https://api.github.com/repos/bonobos/spree/subscription","commits_url":"https://api.github.com/repos/bonobos/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/bonobos/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/bonobos/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/bonobos/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/bonobos/spree/contents/{+path}","compare_url":"https://api.github.com/repos/bonobos/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bonobos/spree/merges","archive_url":"https://api.github.com/repos/bonobos/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bonobos/spree/downloads","issues_url":"https://api.github.com/repos/bonobos/spree/issues{/number}","pulls_url":"https://api.github.com/repos/bonobos/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/bonobos/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/bonobos/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bonobos/spree/labels{/name}","releases_url":"https://api.github.com/repos/bonobos/spree/releases{/id}","created_at":"2013-09-05T18:28:25Z","updated_at":"2015-05-07T18:58:45Z","pushed_at":"2015-05-12T22:17:30Z","git_url":"git://github.com/bonobos/spree.git","ssh_url":"git@github.com:bonobos/spree.git","clone_url":"https://github.com/bonobos/spree.git","svn_url":"https://github.com/bonobos/spree","homepage":"http://spreecommerce.com","size":81242,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":10,"forks":1,"open_issues":10,"watchers":1,"default_branch":"2-2-dev"}},"_links":{"self":{"href":"https://api.github.com/repos/bonobos/spree/pulls/358"},"html":{"href":"https://github.com/bonobos/spree/pull/358"},"issue":{"href":"https://api.github.com/repos/bonobos/spree/issues/358"},"comments":{"href":"https://api.github.com/repos/bonobos/spree/issues/358/comments"},"review_comments":{"href":"https://api.github.com/repos/bonobos/spree/pulls/358/comments"},"review_comment":{"href":"https://api.github.com/repos/bonobos/spree/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bonobos/spree/pulls/358/commits"},"statuses":{"href":"https://api.github.com/repos/bonobos/spree/statuses/125b16b71c943e52641d2bf709b5018a37708092"}}}}