{"action":"created","comment":{"url":"https://api.github.com/repos/pichak/purchase/pulls/comments/44856889","id":44856889,"diff_hunk":"@@ -0,0 +1,94 @@\n+require 'venice'\n+\n+module Purchase\n+\tmodule InApp\n+\t\tclass InAppAppleSub\n+\t\t\tdef self.subscription_id receipt, transaction_id\n+\t\t\t\treceipt_data = receipt.fetch(:receipt)\n+\t\t\t\tr = Venice::Receipt.verify!(receipt_data , { shared_secret: Configuration.apple_psk })\n+\t\t\t\traise MalformedReceiptException.new(\"invalid receipt\") unless r\n+\t\t\t\tr.in_app.each do |in_app_r|\n+\t\t\t\t\treturn in_app_r.original.transaction_id if in_app_r.transaction_id.eql? transaction_id\n+\t\t\t\tend\n+\t\t\tend\n+\n+\t\t\tdef self.verify client_receipt: , custom_data:, transaction_id:\n+\t\t\t\tclient_receipt_data = client_receipt.fetch(:receipt)\n+\t\t\t\tproduct_name = client_receipt.fetch(:product_name)\n+\t\t\t\treceipt = extract_receipt!(client_receipt_data)\n+\n+\t\t\t\tunless check_receipt(receipt.in_app, product_name, transaction_id)\n+\t\t\t\t\traise PurchaseGeneralException.new(\"Bad transaction_id or product_name\")\n+\t\t\t\tend\n+\n+\t\t\t\ttransaction = create_schedule_transaction receipt, client_receipt_data, custom_data, transaction_id\n+\t\t\t\treturn [] unless transaction\n+\t\t\t\t[transaction.get_order]\n+\t\t\trescue Venice::Receipt::VerificationError => e\n+\t\t\t\tcase e.code\n+\t\t\t\twhen 21006\n+\t\t\t\t\thandle_cancel_transaction\n+\t\t\t\telse\n+\t\t\t\t\traise PurchaseGeneralException.new(\"[#{e.code}] #{e.message}\")\n+\t\t\t\tend\n+\t\t\trescue => e\n+\t\t\t\traise PurchaseGeneralException.new(\"[#{e.class}]: #{e.message}\")\n+\t\t\tend\n+\n+private\n+\t\t\tdef self.schedule_transaction transaction\n+\t\t\t\treturn transaction if transaction.expires_at < Time.now\n+\t\t\t\t\n+\t\t\t\tdeadline = transaction.expires_at - margin_time.days\n+\t\t\t\t# if the transaction is not new, below line will not create new entry\n+\t\t\t\tScheduled.create(transaction_id: transaction.id, deadline: deadline, vendor: \"apple\")\n+\t\t\t\ttransaction\n+\t\t\tend\n+\n+\t\t\tdef self.margin_time\n+\t\t\t\tConfiguration.margin_time\n+\t\t\tend\n+\n+\t\t\t# only one transaction is supposed to find here <--> tran_id\n+\t\t\tdef self.create_schedule_transaction r, client_receipt, custom_data, tran_id\n+\t\t\t\ttransaction = Sub::Apple::Transaction.find_by_tran_id(tran_id)\n+\t\t\t\treturn schedule_transaction(transaction) if transaction.present?\n+\n+\t\t\t\tr.in_app.each do |receipt|\n+\t\t\t\t\tnext unless receipt.transaction_id.eql? tran_id\n+\t\t\t\t\tnext if Sub::Apple::Transaction.exists?(tran_id: receipt.transaction_id)","path":"lib/purchase/in_app/in_app_apple_sub.rb","position":59,"original_position":59,"commit_id":"a27b57fe5edfe1dd6411df7653c48e6702f69622","original_commit_id":"a27b57fe5edfe1dd6411df7653c48e6702f69622","user":{"login":"fattaholmanan","id":8071372,"avatar_url":"https://avatars.githubusercontent.com/u/8071372?v=3","gravatar_id":"","url":"https://api.github.com/users/fattaholmanan","html_url":"https://github.com/fattaholmanan","followers_url":"https://api.github.com/users/fattaholmanan/followers","following_url":"https://api.github.com/users/fattaholmanan/following{/other_user}","gists_url":"https://api.github.com/users/fattaholmanan/gists{/gist_id}","starred_url":"https://api.github.com/users/fattaholmanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fattaholmanan/subscriptions","organizations_url":"https://api.github.com/users/fattaholmanan/orgs","repos_url":"https://api.github.com/users/fattaholmanan/repos","events_url":"https://api.github.com/users/fattaholmanan/events{/privacy}","received_events_url":"https://api.github.com/users/fattaholmanan/received_events","type":"User","site_admin":false},"body":"Fixed.","created_at":"2015-11-14T09:28:18Z","updated_at":"2015-11-14T09:28:18Z","html_url":"https://github.com/pichak/purchase/pull/22#discussion_r44856889","pull_request_url":"https://api.github.com/repos/pichak/purchase/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/pichak/purchase/pulls/comments/44856889"},"html":{"href":"https://github.com/pichak/purchase/pull/22#discussion_r44856889"},"pull_request":{"href":"https://api.github.com/repos/pichak/purchase/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/pichak/purchase/pulls/22","id":48076950,"html_url":"https://github.com/pichak/purchase/pull/22","diff_url":"https://github.com/pichak/purchase/pull/22.diff","patch_url":"https://github.com/pichak/purchase/pull/22.patch","issue_url":"https://api.github.com/repos/pichak/purchase/issues/22","number":22,"state":"open","locked":false,"title":"Subscription revise","user":{"login":"fattaholmanan","id":8071372,"avatar_url":"https://avatars.githubusercontent.com/u/8071372?v=3","gravatar_id":"","url":"https://api.github.com/users/fattaholmanan","html_url":"https://github.com/fattaholmanan","followers_url":"https://api.github.com/users/fattaholmanan/followers","following_url":"https://api.github.com/users/fattaholmanan/following{/other_user}","gists_url":"https://api.github.com/users/fattaholmanan/gists{/gist_id}","starred_url":"https://api.github.com/users/fattaholmanan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fattaholmanan/subscriptions","organizations_url":"https://api.github.com/users/fattaholmanan/orgs","repos_url":"https://api.github.com/users/fattaholmanan/repos","events_url":"https://api.github.com/users/fattaholmanan/events{/privacy}","received_events_url":"https://api.github.com/users/fattaholmanan/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-19T14:15:16Z","updated_at":"2015-11-14T09:28:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6482fb7e2618e143dfd0a6d9b6426e7086fe0ad1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pichak/purchase/pulls/22/commits","review_comments_url":"https://api.github.com/repos/pichak/purchase/pulls/22/comments","review_comment_url":"https://api.github.com/repos/pichak/purchase/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pichak/purchase/issues/22/comments","statuses_url":"https://api.github.com/repos/pichak/purchase/statuses/a27b57fe5edfe1dd6411df7653c48e6702f69622","head":{"label":"pichak:subscription-revise","ref":"subscription-revise","sha":"a27b57fe5edfe1dd6411df7653c48e6702f69622","user":{"login":"pichak","id":4709713,"avatar_url":"https://avatars.githubusercontent.com/u/4709713?v=3","gravatar_id":"","url":"https://api.github.com/users/pichak","html_url":"https://github.com/pichak","followers_url":"https://api.github.com/users/pichak/followers","following_url":"https://api.github.com/users/pichak/following{/other_user}","gists_url":"https://api.github.com/users/pichak/gists{/gist_id}","starred_url":"https://api.github.com/users/pichak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pichak/subscriptions","organizations_url":"https://api.github.com/users/pichak/orgs","repos_url":"https://api.github.com/users/pichak/repos","events_url":"https://api.github.com/users/pichak/events{/privacy}","received_events_url":"https://api.github.com/users/pichak/received_events","type":"Organization","site_admin":false},"repo":{"id":34600886,"name":"purchase","full_name":"pichak/purchase","owner":{"login":"pichak","id":4709713,"avatar_url":"https://avatars.githubusercontent.com/u/4709713?v=3","gravatar_id":"","url":"https://api.github.com/users/pichak","html_url":"https://github.com/pichak","followers_url":"https://api.github.com/users/pichak/followers","following_url":"https://api.github.com/users/pichak/following{/other_user}","gists_url":"https://api.github.com/users/pichak/gists{/gist_id}","starred_url":"https://api.github.com/users/pichak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pichak/subscriptions","organizations_url":"https://api.github.com/users/pichak/orgs","repos_url":"https://api.github.com/users/pichak/repos","events_url":"https://api.github.com/users/pichak/events{/privacy}","received_events_url":"https://api.github.com/users/pichak/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pichak/purchase","description":"","fork":false,"url":"https://api.github.com/repos/pichak/purchase","forks_url":"https://api.github.com/repos/pichak/purchase/forks","keys_url":"https://api.github.com/repos/pichak/purchase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pichak/purchase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pichak/purchase/teams","hooks_url":"https://api.github.com/repos/pichak/purchase/hooks","issue_events_url":"https://api.github.com/repos/pichak/purchase/issues/events{/number}","events_url":"https://api.github.com/repos/pichak/purchase/events","assignees_url":"https://api.github.com/repos/pichak/purchase/assignees{/user}","branches_url":"https://api.github.com/repos/pichak/purchase/branches{/branch}","tags_url":"https://api.github.com/repos/pichak/purchase/tags","blobs_url":"https://api.github.com/repos/pichak/purchase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pichak/purchase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pichak/purchase/git/refs{/sha}","trees_url":"https://api.github.com/repos/pichak/purchase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pichak/purchase/statuses/{sha}","languages_url":"https://api.github.com/repos/pichak/purchase/languages","stargazers_url":"https://api.github.com/repos/pichak/purchase/stargazers","contributors_url":"https://api.github.com/repos/pichak/purchase/contributors","subscribers_url":"https://api.github.com/repos/pichak/purchase/subscribers","subscription_url":"https://api.github.com/repos/pichak/purchase/subscription","commits_url":"https://api.github.com/repos/pichak/purchase/commits{/sha}","git_commits_url":"https://api.github.com/repos/pichak/purchase/git/commits{/sha}","comments_url":"https://api.github.com/repos/pichak/purchase/comments{/number}","issue_comment_url":"https://api.github.com/repos/pichak/purchase/issues/comments{/number}","contents_url":"https://api.github.com/repos/pichak/purchase/contents/{+path}","compare_url":"https://api.github.com/repos/pichak/purchase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pichak/purchase/merges","archive_url":"https://api.github.com/repos/pichak/purchase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pichak/purchase/downloads","issues_url":"https://api.github.com/repos/pichak/purchase/issues{/number}","pulls_url":"https://api.github.com/repos/pichak/purchase/pulls{/number}","milestones_url":"https://api.github.com/repos/pichak/purchase/milestones{/number}","notifications_url":"https://api.github.com/repos/pichak/purchase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pichak/purchase/labels{/name}","releases_url":"https://api.github.com/repos/pichak/purchase/releases{/id}","created_at":"2015-04-26T06:36:07Z","updated_at":"2015-08-19T05:07:43Z","pushed_at":"2015-11-07T12:50:23Z","git_url":"git://github.com/pichak/purchase.git","ssh_url":"git@github.com:pichak/purchase.git","clone_url":"https://github.com/pichak/purchase.git","svn_url":"https://github.com/pichak/purchase","homepage":null,"size":730,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"pichak:master","ref":"master","sha":"bb25b72daf5aef3847791c9c3b90d021f001e0c2","user":{"login":"pichak","id":4709713,"avatar_url":"https://avatars.githubusercontent.com/u/4709713?v=3","gravatar_id":"","url":"https://api.github.com/users/pichak","html_url":"https://github.com/pichak","followers_url":"https://api.github.com/users/pichak/followers","following_url":"https://api.github.com/users/pichak/following{/other_user}","gists_url":"https://api.github.com/users/pichak/gists{/gist_id}","starred_url":"https://api.github.com/users/pichak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pichak/subscriptions","organizations_url":"https://api.github.com/users/pichak/orgs","repos_url":"https://api.github.com/users/pichak/repos","events_url":"https://api.github.com/users/pichak/events{/privacy}","received_events_url":"https://api.github.com/users/pichak/received_events","type":"Organization","site_admin":false},"repo":{"id":34600886,"name":"purchase","full_name":"pichak/purchase","owner":{"login":"pichak","id":4709713,"avatar_url":"https://avatars.githubusercontent.com/u/4709713?v=3","gravatar_id":"","url":"https://api.github.com/users/pichak","html_url":"https://github.com/pichak","followers_url":"https://api.github.com/users/pichak/followers","following_url":"https://api.github.com/users/pichak/following{/other_user}","gists_url":"https://api.github.com/users/pichak/gists{/gist_id}","starred_url":"https://api.github.com/users/pichak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pichak/subscriptions","organizations_url":"https://api.github.com/users/pichak/orgs","repos_url":"https://api.github.com/users/pichak/repos","events_url":"https://api.github.com/users/pichak/events{/privacy}","received_events_url":"https://api.github.com/users/pichak/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pichak/purchase","description":"","fork":false,"url":"https://api.github.com/repos/pichak/purchase","forks_url":"https://api.github.com/repos/pichak/purchase/forks","keys_url":"https://api.github.com/repos/pichak/purchase/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pichak/purchase/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pichak/purchase/teams","hooks_url":"https://api.github.com/repos/pichak/purchase/hooks","issue_events_url":"https://api.github.com/repos/pichak/purchase/issues/events{/number}","events_url":"https://api.github.com/repos/pichak/purchase/events","assignees_url":"https://api.github.com/repos/pichak/purchase/assignees{/user}","branches_url":"https://api.github.com/repos/pichak/purchase/branches{/branch}","tags_url":"https://api.github.com/repos/pichak/purchase/tags","blobs_url":"https://api.github.com/repos/pichak/purchase/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pichak/purchase/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pichak/purchase/git/refs{/sha}","trees_url":"https://api.github.com/repos/pichak/purchase/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pichak/purchase/statuses/{sha}","languages_url":"https://api.github.com/repos/pichak/purchase/languages","stargazers_url":"https://api.github.com/repos/pichak/purchase/stargazers","contributors_url":"https://api.github.com/repos/pichak/purchase/contributors","subscribers_url":"https://api.github.com/repos/pichak/purchase/subscribers","subscription_url":"https://api.github.com/repos/pichak/purchase/subscription","commits_url":"https://api.github.com/repos/pichak/purchase/commits{/sha}","git_commits_url":"https://api.github.com/repos/pichak/purchase/git/commits{/sha}","comments_url":"https://api.github.com/repos/pichak/purchase/comments{/number}","issue_comment_url":"https://api.github.com/repos/pichak/purchase/issues/comments{/number}","contents_url":"https://api.github.com/repos/pichak/purchase/contents/{+path}","compare_url":"https://api.github.com/repos/pichak/purchase/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pichak/purchase/merges","archive_url":"https://api.github.com/repos/pichak/purchase/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pichak/purchase/downloads","issues_url":"https://api.github.com/repos/pichak/purchase/issues{/number}","pulls_url":"https://api.github.com/repos/pichak/purchase/pulls{/number}","milestones_url":"https://api.github.com/repos/pichak/purchase/milestones{/number}","notifications_url":"https://api.github.com/repos/pichak/purchase/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pichak/purchase/labels{/name}","releases_url":"https://api.github.com/repos/pichak/purchase/releases{/id}","created_at":"2015-04-26T06:36:07Z","updated_at":"2015-08-19T05:07:43Z","pushed_at":"2015-11-07T12:50:23Z","git_url":"git://github.com/pichak/purchase.git","ssh_url":"git@github.com:pichak/purchase.git","clone_url":"https://github.com/pichak/purchase.git","svn_url":"https://github.com/pichak/purchase","homepage":null,"size":730,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pichak/purchase/pulls/22"},"html":{"href":"https://github.com/pichak/purchase/pull/22"},"issue":{"href":"https://api.github.com/repos/pichak/purchase/issues/22"},"comments":{"href":"https://api.github.com/repos/pichak/purchase/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/pichak/purchase/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/pichak/purchase/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pichak/purchase/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/pichak/purchase/statuses/a27b57fe5edfe1dd6411df7653c48e6702f69622"}}}}