{"action":"created","comment":{"url":"https://api.github.com/repos/komoju/spree_komoju/pulls/comments/47469125","id":47469125,"diff_hunk":"@@ -0,0 +1,54 @@\n+module Spree\n+  class Gateway::KomojuWebMoney < KomojuGateway\n+    def auto_capture?\n+      true\n+    end\n+\n+    def purchase(money, source, options)\n+      raise SpreeKomoju::Errors::UnsupportedCurrency if options[:currency] != \"JPY\"\n+\n+      details = {\n+        type: \"web_money\",\n+        email: source.email,\n+        prepaid_number: source.prepaid_number\n+      }\n+      options = change_options_to_dollar(options)\n+\n+      if uuid = continue_uuid(options[:order_id])\n+        response = provider.continue(uuid, details)\n+      else\n+        response = provider.purchase(money - options[:tax], details, options)\n+      end\n+\n+      source.update!(\n+        prepaid_cards: response.params[\"payment_details\"][\"prepaid_cards\"],\n+        short_amount: response.params[\"payment_details\"][\"short_amount\"]\n+      ) if response.success?\n+\n+      if response.params[\"status\"] == \"pending\"\n+        source.update!(payment_uuid: response.params[\"id\"])\n+        response = multi_card_response(response)\n+      end\n+\n+      response\n+    end\n+\n+    private\n+\n+    def multi_card_response(response)\n+      response.instance_variable_set(:@success, false)\n+      response.instance_variable_set(:@message, I18n.t('spree.komoju.web_money.insufficient_funds'))\n+      response\n+    end\n+\n+    def continue_uuid(current_order_id)\n+      order = Spree::Order.find_by_number(current_order_id.split('-').first)\n+      \n+      # NOTE: Since the current payment is this payment, find the payment before\n+      # and see if it was for a webmoney transaction. If it was check if it has a payment UUID\n+      # to continue the transaction.\n+      source = WebMoneyDecorator.new(order.payments.last(2).first.try(:source))","path":"app/models/spree/gateway/komoju_web_money.rb","position":50,"original_position":50,"commit_id":"af72a81fe36fafcbde2bba760e83b64a43202844","original_commit_id":"af72a81fe36fafcbde2bba760e83b64a43202844","user":{"login":"camelmasa","id":189824,"avatar_url":"https://avatars.githubusercontent.com/u/189824?v=3","gravatar_id":"","url":"https://api.github.com/users/camelmasa","html_url":"https://github.com/camelmasa","followers_url":"https://api.github.com/users/camelmasa/followers","following_url":"https://api.github.com/users/camelmasa/following{/other_user}","gists_url":"https://api.github.com/users/camelmasa/gists{/gist_id}","starred_url":"https://api.github.com/users/camelmasa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camelmasa/subscriptions","organizations_url":"https://api.github.com/users/camelmasa/orgs","repos_url":"https://api.github.com/users/camelmasa/repos","events_url":"https://api.github.com/users/camelmasa/events{/privacy}","received_events_url":"https://api.github.com/users/camelmasa/received_events","type":"User","site_admin":false},"body":"\r\nNote: You said we can remove this line.\r\n\r\nWe can do following.\r\n```rb\r\norder.payments.last(2).first.try(:source).try(:payment_uuid)\r\n```","created_at":"2015-12-14T07:57:52Z","updated_at":"2015-12-14T07:57:52Z","html_url":"https://github.com/komoju/spree_komoju/pull/29#discussion_r47469125","pull_request_url":"https://api.github.com/repos/komoju/spree_komoju/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/comments/47469125"},"html":{"href":"https://github.com/komoju/spree_komoju/pull/29#discussion_r47469125"},"pull_request":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/komoju/spree_komoju/pulls/29","id":53528909,"html_url":"https://github.com/komoju/spree_komoju/pull/29","diff_url":"https://github.com/komoju/spree_komoju/pull/29.diff","patch_url":"https://github.com/komoju/spree_komoju/pull/29.patch","issue_url":"https://api.github.com/repos/komoju/spree_komoju/issues/29","number":29,"state":"open","locked":false,"title":"Add webmoney payment option","user":{"login":"rramsden","id":82835,"avatar_url":"https://avatars.githubusercontent.com/u/82835?v=3","gravatar_id":"","url":"https://api.github.com/users/rramsden","html_url":"https://github.com/rramsden","followers_url":"https://api.github.com/users/rramsden/followers","following_url":"https://api.github.com/users/rramsden/following{/other_user}","gists_url":"https://api.github.com/users/rramsden/gists{/gist_id}","starred_url":"https://api.github.com/users/rramsden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rramsden/subscriptions","organizations_url":"https://api.github.com/users/rramsden/orgs","repos_url":"https://api.github.com/users/rramsden/repos","events_url":"https://api.github.com/users/rramsden/events{/privacy}","received_events_url":"https://api.github.com/users/rramsden/received_events","type":"User","site_admin":false},"body":"This pull request adds the Webmoney payment option to Spree.\r\n\r\nA few notes:\r\n\r\n* Multi-card transactions in Komoju require PATCH instead of POST'ing to a resource. ActiveMerchant supports PATCH in the latest release, however, Spree 3.0.4 version locks ActiveMerchant @ 1.47.0. Because of this I've created a extension to `connection.rb` which is only required with ActiveMerchant == '1.47.0' which adds `:patch`\r\n* I ended up using Javascript instead of Coffescript. For some reason `.js.coffee` files were not being recognised. I think this is because assets are compiled in the `vendor` directory rather that into `app/assets`.\r\n\r\n![image](https://cloud.githubusercontent.com/assets/82835/11774350/7f1efdc2-a277-11e5-8724-78ab16721a71.png)","created_at":"2015-12-14T06:29:56Z","updated_at":"2015-12-14T07:57:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd15ccde57e10345fb611bd3cd96562a5d5be929","assignee":{"login":"camelmasa","id":189824,"avatar_url":"https://avatars.githubusercontent.com/u/189824?v=3","gravatar_id":"","url":"https://api.github.com/users/camelmasa","html_url":"https://github.com/camelmasa","followers_url":"https://api.github.com/users/camelmasa/followers","following_url":"https://api.github.com/users/camelmasa/following{/other_user}","gists_url":"https://api.github.com/users/camelmasa/gists{/gist_id}","starred_url":"https://api.github.com/users/camelmasa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camelmasa/subscriptions","organizations_url":"https://api.github.com/users/camelmasa/orgs","repos_url":"https://api.github.com/users/camelmasa/repos","events_url":"https://api.github.com/users/camelmasa/events{/privacy}","received_events_url":"https://api.github.com/users/camelmasa/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/komoju/spree_komoju/pulls/29/commits","review_comments_url":"https://api.github.com/repos/komoju/spree_komoju/pulls/29/comments","review_comment_url":"https://api.github.com/repos/komoju/spree_komoju/pulls/comments{/number}","comments_url":"https://api.github.com/repos/komoju/spree_komoju/issues/29/comments","statuses_url":"https://api.github.com/repos/komoju/spree_komoju/statuses/af72a81fe36fafcbde2bba760e83b64a43202844","head":{"label":"rramsden:add-webmoney","ref":"add-webmoney","sha":"af72a81fe36fafcbde2bba760e83b64a43202844","user":{"login":"rramsden","id":82835,"avatar_url":"https://avatars.githubusercontent.com/u/82835?v=3","gravatar_id":"","url":"https://api.github.com/users/rramsden","html_url":"https://github.com/rramsden","followers_url":"https://api.github.com/users/rramsden/followers","following_url":"https://api.github.com/users/rramsden/following{/other_user}","gists_url":"https://api.github.com/users/rramsden/gists{/gist_id}","starred_url":"https://api.github.com/users/rramsden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rramsden/subscriptions","organizations_url":"https://api.github.com/users/rramsden/orgs","repos_url":"https://api.github.com/users/rramsden/repos","events_url":"https://api.github.com/users/rramsden/events{/privacy}","received_events_url":"https://api.github.com/users/rramsden/received_events","type":"User","site_admin":false},"repo":{"id":47533685,"name":"spree_komoju","full_name":"rramsden/spree_komoju","owner":{"login":"rramsden","id":82835,"avatar_url":"https://avatars.githubusercontent.com/u/82835?v=3","gravatar_id":"","url":"https://api.github.com/users/rramsden","html_url":"https://github.com/rramsden","followers_url":"https://api.github.com/users/rramsden/followers","following_url":"https://api.github.com/users/rramsden/following{/other_user}","gists_url":"https://api.github.com/users/rramsden/gists{/gist_id}","starred_url":"https://api.github.com/users/rramsden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rramsden/subscriptions","organizations_url":"https://api.github.com/users/rramsden/orgs","repos_url":"https://api.github.com/users/rramsden/repos","events_url":"https://api.github.com/users/rramsden/events{/privacy}","received_events_url":"https://api.github.com/users/rramsden/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rramsden/spree_komoju","description":"Spree extension for using the Komoju Payments API.","fork":true,"url":"https://api.github.com/repos/rramsden/spree_komoju","forks_url":"https://api.github.com/repos/rramsden/spree_komoju/forks","keys_url":"https://api.github.com/repos/rramsden/spree_komoju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rramsden/spree_komoju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rramsden/spree_komoju/teams","hooks_url":"https://api.github.com/repos/rramsden/spree_komoju/hooks","issue_events_url":"https://api.github.com/repos/rramsden/spree_komoju/issues/events{/number}","events_url":"https://api.github.com/repos/rramsden/spree_komoju/events","assignees_url":"https://api.github.com/repos/rramsden/spree_komoju/assignees{/user}","branches_url":"https://api.github.com/repos/rramsden/spree_komoju/branches{/branch}","tags_url":"https://api.github.com/repos/rramsden/spree_komoju/tags","blobs_url":"https://api.github.com/repos/rramsden/spree_komoju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rramsden/spree_komoju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rramsden/spree_komoju/git/refs{/sha}","trees_url":"https://api.github.com/repos/rramsden/spree_komoju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rramsden/spree_komoju/statuses/{sha}","languages_url":"https://api.github.com/repos/rramsden/spree_komoju/languages","stargazers_url":"https://api.github.com/repos/rramsden/spree_komoju/stargazers","contributors_url":"https://api.github.com/repos/rramsden/spree_komoju/contributors","subscribers_url":"https://api.github.com/repos/rramsden/spree_komoju/subscribers","subscription_url":"https://api.github.com/repos/rramsden/spree_komoju/subscription","commits_url":"https://api.github.com/repos/rramsden/spree_komoju/commits{/sha}","git_commits_url":"https://api.github.com/repos/rramsden/spree_komoju/git/commits{/sha}","comments_url":"https://api.github.com/repos/rramsden/spree_komoju/comments{/number}","issue_comment_url":"https://api.github.com/repos/rramsden/spree_komoju/issues/comments{/number}","contents_url":"https://api.github.com/repos/rramsden/spree_komoju/contents/{+path}","compare_url":"https://api.github.com/repos/rramsden/spree_komoju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rramsden/spree_komoju/merges","archive_url":"https://api.github.com/repos/rramsden/spree_komoju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rramsden/spree_komoju/downloads","issues_url":"https://api.github.com/repos/rramsden/spree_komoju/issues{/number}","pulls_url":"https://api.github.com/repos/rramsden/spree_komoju/pulls{/number}","milestones_url":"https://api.github.com/repos/rramsden/spree_komoju/milestones{/number}","notifications_url":"https://api.github.com/repos/rramsden/spree_komoju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rramsden/spree_komoju/labels{/name}","releases_url":"https://api.github.com/repos/rramsden/spree_komoju/releases{/id}","created_at":"2015-12-07T06:27:52Z","updated_at":"2015-12-07T06:27:54Z","pushed_at":"2015-12-14T07:24:40Z","git_url":"git://github.com/rramsden/spree_komoju.git","ssh_url":"git@github.com:rramsden/spree_komoju.git","clone_url":"https://github.com/rramsden/spree_komoju.git","svn_url":"https://github.com/rramsden/spree_komoju","homepage":null,"size":127,"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":"komoju:master","ref":"master","sha":"c811148d9af6c4a58b2f6ea97ffd81c62ccc7d3e","user":{"login":"komoju","id":8425317,"avatar_url":"https://avatars.githubusercontent.com/u/8425317?v=3","gravatar_id":"","url":"https://api.github.com/users/komoju","html_url":"https://github.com/komoju","followers_url":"https://api.github.com/users/komoju/followers","following_url":"https://api.github.com/users/komoju/following{/other_user}","gists_url":"https://api.github.com/users/komoju/gists{/gist_id}","starred_url":"https://api.github.com/users/komoju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/komoju/subscriptions","organizations_url":"https://api.github.com/users/komoju/orgs","repos_url":"https://api.github.com/users/komoju/repos","events_url":"https://api.github.com/users/komoju/events{/privacy}","received_events_url":"https://api.github.com/users/komoju/received_events","type":"Organization","site_admin":false},"repo":{"id":33156767,"name":"spree_komoju","full_name":"komoju/spree_komoju","owner":{"login":"komoju","id":8425317,"avatar_url":"https://avatars.githubusercontent.com/u/8425317?v=3","gravatar_id":"","url":"https://api.github.com/users/komoju","html_url":"https://github.com/komoju","followers_url":"https://api.github.com/users/komoju/followers","following_url":"https://api.github.com/users/komoju/following{/other_user}","gists_url":"https://api.github.com/users/komoju/gists{/gist_id}","starred_url":"https://api.github.com/users/komoju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/komoju/subscriptions","organizations_url":"https://api.github.com/users/komoju/orgs","repos_url":"https://api.github.com/users/komoju/repos","events_url":"https://api.github.com/users/komoju/events{/privacy}","received_events_url":"https://api.github.com/users/komoju/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/komoju/spree_komoju","description":"Spree extension for using the Komoju Payments API.","fork":false,"url":"https://api.github.com/repos/komoju/spree_komoju","forks_url":"https://api.github.com/repos/komoju/spree_komoju/forks","keys_url":"https://api.github.com/repos/komoju/spree_komoju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/komoju/spree_komoju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/komoju/spree_komoju/teams","hooks_url":"https://api.github.com/repos/komoju/spree_komoju/hooks","issue_events_url":"https://api.github.com/repos/komoju/spree_komoju/issues/events{/number}","events_url":"https://api.github.com/repos/komoju/spree_komoju/events","assignees_url":"https://api.github.com/repos/komoju/spree_komoju/assignees{/user}","branches_url":"https://api.github.com/repos/komoju/spree_komoju/branches{/branch}","tags_url":"https://api.github.com/repos/komoju/spree_komoju/tags","blobs_url":"https://api.github.com/repos/komoju/spree_komoju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/komoju/spree_komoju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/komoju/spree_komoju/git/refs{/sha}","trees_url":"https://api.github.com/repos/komoju/spree_komoju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/komoju/spree_komoju/statuses/{sha}","languages_url":"https://api.github.com/repos/komoju/spree_komoju/languages","stargazers_url":"https://api.github.com/repos/komoju/spree_komoju/stargazers","contributors_url":"https://api.github.com/repos/komoju/spree_komoju/contributors","subscribers_url":"https://api.github.com/repos/komoju/spree_komoju/subscribers","subscription_url":"https://api.github.com/repos/komoju/spree_komoju/subscription","commits_url":"https://api.github.com/repos/komoju/spree_komoju/commits{/sha}","git_commits_url":"https://api.github.com/repos/komoju/spree_komoju/git/commits{/sha}","comments_url":"https://api.github.com/repos/komoju/spree_komoju/comments{/number}","issue_comment_url":"https://api.github.com/repos/komoju/spree_komoju/issues/comments{/number}","contents_url":"https://api.github.com/repos/komoju/spree_komoju/contents/{+path}","compare_url":"https://api.github.com/repos/komoju/spree_komoju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/komoju/spree_komoju/merges","archive_url":"https://api.github.com/repos/komoju/spree_komoju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/komoju/spree_komoju/downloads","issues_url":"https://api.github.com/repos/komoju/spree_komoju/issues{/number}","pulls_url":"https://api.github.com/repos/komoju/spree_komoju/pulls{/number}","milestones_url":"https://api.github.com/repos/komoju/spree_komoju/milestones{/number}","notifications_url":"https://api.github.com/repos/komoju/spree_komoju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/komoju/spree_komoju/labels{/name}","releases_url":"https://api.github.com/repos/komoju/spree_komoju/releases{/id}","created_at":"2015-03-31T00:59:23Z","updated_at":"2015-04-23T08:11:26Z","pushed_at":"2015-12-14T07:24:50Z","git_url":"git://github.com/komoju/spree_komoju.git","ssh_url":"git@github.com:komoju/spree_komoju.git","clone_url":"https://github.com/komoju/spree_komoju.git","svn_url":"https://github.com/komoju/spree_komoju","homepage":null,"size":161,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/29"},"html":{"href":"https://github.com/komoju/spree_komoju/pull/29"},"issue":{"href":"https://api.github.com/repos/komoju/spree_komoju/issues/29"},"comments":{"href":"https://api.github.com/repos/komoju/spree_komoju/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/komoju/spree_komoju/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/komoju/spree_komoju/statuses/af72a81fe36fafcbde2bba760e83b64a43202844"}}}}