From 1e0411a38022b3446c32ca5639ec0a6126fbbcbb Mon Sep 17 00:00:00 2001 From: Gordon McNaughton Date: Mon, 24 Aug 2015 16:13:07 +0100 Subject: [PATCH 1/3] Adds support for the 'cancellation_date' field for autorenewable subscriptions. Users can contact Apple customer support to cancel an autorenewable subscription. After doing so, validating a receipt for the subscription will return a response with a 'cancellation_date' field. From the Apple docs: "For a transaction that was canceled by Apple customer support, the time and date of the cancellation. Treat a canceled receipt the same as if no purchase had ever been made." Closes nov/itunes-receipt#18 --- lib/itunes/receipt.rb | 12 +++++++++++ .../autorenew_subscription_cancelled.json | 2 ++ spec/itunes/receipt_spec.rb | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 spec/fake_json/autorenew_subscription_cancelled.json diff --git a/lib/itunes/receipt.rb b/lib/itunes/receipt.rb index 9f82022..4dbd414 100644 --- a/lib/itunes/receipt.rb +++ b/lib/itunes/receipt.rb @@ -31,6 +31,9 @@ def initialize(attributes = {}) :bvrs, :download_id, :expires_date, + :cancellation_date, + :cancellation_date_ms, + :cancellation_date_pst, :in_app, :is_trial_period, :itunes_env, @@ -61,6 +64,15 @@ def initialize(attributes = {}) @expires_date = if receipt_attributes[:expires_date] Time.at(receipt_attributes[:expires_date].to_i / 1000) end + @cancellation_date = if receipt_attributes[:cancellation_date] + Time.parse receipt_attributes[:cancellation_date].sub('Etc/GMT', 'GMT') + end + @cancellation_date_ms = if receipt_attributes[:cancellation_date_ms] + receipt_attributes[:cancellation_date_ms].to_i + end + @cancellation_date_pst = if receipt_attributes[:cancellation_date_pst] + Time.parse receipt_attributes[:cancellation_date_pst].sub('America/Los_Angeles', 'PST') + end @in_app = if receipt_attributes[:in_app] receipt_attributes[:in_app].map { |ia| self.class.new(:receipt => ia) } end diff --git a/spec/fake_json/autorenew_subscription_cancelled.json b/spec/fake_json/autorenew_subscription_cancelled.json new file mode 100644 index 0000000..a007161 --- /dev/null +++ b/spec/fake_json/autorenew_subscription_cancelled.json @@ -0,0 +1,2 @@ +{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157508197", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_formatted_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157808000", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_formatted_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":0, "latest_receipt":"junk="} + diff --git a/spec/itunes/receipt_spec.rb b/spec/itunes/receipt_spec.rb index f849b6b..1da8ddc 100644 --- a/spec/itunes/receipt_spec.rb +++ b/spec/itunes/receipt_spec.rb @@ -90,8 +90,10 @@ receipt.original.quantity.should be_nil receipt.original.transaction_id.should == '1000000001479608' receipt.original.purchase_date.should == Time.utc(2011, 2, 17, 6, 20, 57) + receipt.original.cancellation_date.should be_nil receipt.expires_date.should be_nil receipt.receipt_data.should be_nil + receipt.cancellation_date.should be_nil receipt.itunes_env.should == :production # Those attributes are not returned from iTunes Connect Sandbox @@ -143,6 +145,7 @@ receipt.bid.should be_nil receipt.bvrs.should be_nil receipt.expires_date.should be_nil + receipt.cancellation_date.should be_nil receipt.receipt_data.should be_nil receipt.itunes_env.should == :production @@ -172,6 +175,7 @@ receipt.original.transaction_id.should == original_transaction_id receipt.original.purchase_date.should == original_purchase_date receipt.expires_date.should == Time.utc(2012, 10, 13, 19, 45, 8) + receipt.cancellation_date.should be_nil receipt.receipt_data.should be_nil # Those attributes are not returned from iTunes Connect Sandbox @@ -185,6 +189,7 @@ latest.transaction_id.should == '1000000052076747' latest.purchase_date.should == Time.utc(2012, 10, 13, 19, 40, 8) latest.expires_date.should == Time.utc(2012, 10, 13, 19, 50, 8) # five minutes after the "old" receipt + latest.cancellation_date.should be_nil latest.bid.should == 'com.notkeepingitreal.fizzbuzz' latest.bvrs.should == '1.0' latest.original.quantity.should be_nil @@ -213,6 +218,21 @@ end + context 'when cancelled autorenew subscription' do + before do + fake_json :autorenew_subscription_cancelled + end + + it 'should return valid Receipt instance for autorenew subscription, with the cancellation_date field set' do + receipt = Itunes::Receipt.verify! 'autorenew_subscription_cancelled' + receipt.should be_instance_of Itunes::Receipt + receipt.purchase_date.should == Time.utc(2012, 10, 13, 19, 40, 8) + receipt.expires_date.should == Time.utc(2012, 10, 13, 19, 45, 8) + receipt.cancellation_date.should == Time.utc(2012, 10, 13, 19, 42, 8) # user cancelled via Apple Customer Support 2 minutes after their subscription began + end + + end + context 'when offline' do before do fake_json :offline From 61b94df3614516c15c5b11a38105a7bc801a4815 Mon Sep 17 00:00:00 2001 From: Gordon McNaughton Date: Mon, 24 Aug 2015 17:57:11 +0100 Subject: [PATCH 2/3] Fix issue parsing 'expires_date' returned by Apple validator. Value used to be return as milliseconds, now it's returned as a formatted date string (with extra fields for milliseconds and PST-formatted date). Closes nov/itunes-receipt#17 --- lib/itunes/receipt.rb | 10 +++++++++- spec/fake_json/autorenew_subscription.json | 2 +- spec/fake_json/autorenew_subscription_cancelled.json | 2 +- spec/fake_json/autorenew_subscription_expired.json | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/itunes/receipt.rb b/lib/itunes/receipt.rb index 4dbd414..51ad4ec 100644 --- a/lib/itunes/receipt.rb +++ b/lib/itunes/receipt.rb @@ -31,6 +31,8 @@ def initialize(attributes = {}) :bvrs, :download_id, :expires_date, + :expires_date_ms, + :expires_date_pst, :cancellation_date, :cancellation_date_ms, :cancellation_date_pst, @@ -62,7 +64,13 @@ def initialize(attributes = {}) @bvrs = receipt_attributes[:bvrs] @download_id = receipt_attributes[:download_id] @expires_date = if receipt_attributes[:expires_date] - Time.at(receipt_attributes[:expires_date].to_i / 1000) + Time.parse receipt_attributes[:expires_date].sub('Etc/GMT', 'GMT') + end + @expires_date_ms = if receipt_attributes[:expires_date_ms] + receipt_attributes[:expires_date_ms].to_i + end + @expires_date_pst = if receipt_attributes[:expires_date_pst] + Time.parse receipt_attributes[:expires_date_pst].sub('America/Los_Angeles', 'PST') end @cancellation_date = if receipt_attributes[:cancellation_date] Time.parse receipt_attributes[:cancellation_date].sub('Etc/GMT', 'GMT') diff --git a/spec/fake_json/autorenew_subscription.json b/spec/fake_json/autorenew_subscription.json index a34f866..148f9ad 100644 --- a/spec/fake_json/autorenew_subscription.json +++ b/spec/fake_json/autorenew_subscription.json @@ -1,2 +1,2 @@ -{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157508197", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_formatted_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157808000", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_formatted_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":0, "latest_receipt":"junk="} +{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157508197", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157808000", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":0, "latest_receipt":"junk="} diff --git a/spec/fake_json/autorenew_subscription_cancelled.json b/spec/fake_json/autorenew_subscription_cancelled.json index a007161..03022c8 100644 --- a/spec/fake_json/autorenew_subscription_cancelled.json +++ b/spec/fake_json/autorenew_subscription_cancelled.json @@ -1,2 +1,2 @@ -{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157508197", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_formatted_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157808000", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_formatted_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":0, "latest_receipt":"junk="} +{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157508197", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157808000", "cancellation_date":"2012-10-13 19:42:08 Etc/GMT", "cancellation_date_ms":"1350157328197", "cancellation_date_pst":"2012-10-13 12:42:08 America/Los_Angeles", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":0, "latest_receipt":"junk="} diff --git a/spec/fake_json/autorenew_subscription_expired.json b/spec/fake_json/autorenew_subscription_expired.json index df10470..8880811 100644 --- a/spec/fake_json/autorenew_subscription_expired.json +++ b/spec/fake_json/autorenew_subscription_expired.json @@ -1,2 +1,2 @@ -{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157508197", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_formatted_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date":"1350157808000", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date_formatted":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_formatted_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":21006, "latest_receipt":"junk="} +{"receipt":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d69cc362c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157508197", "transaction_id":"1000000055076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000026553289", "bvrs":"1.0", "expires_date":"2012-10-13 19:45:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208197", "expires_date_pst":"2012-10-13 12:45:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "latest_receipt_info":{"original_purchase_date_pst":"2012-10-11 07:45:40 America/Los_Angeles", "unique_identifier":"4d79cc562c5c58ce62da68ee43721ea670907bad", "original_transaction_id":"1000000057005439", "expires_date_ms":"1350157808000", "transaction_id":"1000000052076747", "quantity":"1", "product_id":"com.notkeepingitreal.fizzbuzz.subscription.autorenew1m", "original_purchase_date_ms":"1349966740000", "bid":"com.notkeepingitreal.fizzbuzz", "web_order_line_item_id":"1000000027293289", "bvrs":"1.0", "expires_date":"2012-10-13 19:50:08 Etc/GMT", "purchase_date":"2012-10-13 19:40:08 Etc/GMT", "purchase_date_ms":"1350157208000", "expires_date_pst":"2012-10-13 12:50:08 America/Los_Angeles", "purchase_date_pst":"2012-10-13 12:40:08 America/Los_Angeles", "original_purchase_date":"2012-10-11 14:45:40 Etc/GMT", "item_id":"570504929"}, "status":21006, "latest_receipt":"junk="} From 5c686fcaef60f6608b01328b9b33ebaf82e69250 Mon Sep 17 00:00:00 2001 From: Gordon McNaughton Date: Tue, 25 Aug 2015 19:49:21 +0100 Subject: [PATCH 3/3] Adds support for the 'web_order_line_item_id' field for subscriptions. --- lib/itunes/receipt.rb | 26 ++++++++++++++------------ spec/itunes/receipt_spec.rb | 4 ++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/itunes/receipt.rb b/lib/itunes/receipt.rb index 51ad4ec..f6bb6bd 100644 --- a/lib/itunes/receipt.rb +++ b/lib/itunes/receipt.rb @@ -29,13 +29,13 @@ def initialize(attributes = {}) :bid, :bundle_id, :bvrs, + :cancellation_date, + :cancellation_date_ms, + :cancellation_date_pst, :download_id, :expires_date, :expires_date_ms, :expires_date_pst, - :cancellation_date, - :cancellation_date_ms, - :cancellation_date_pst, :in_app, :is_trial_period, :itunes_env, @@ -52,6 +52,7 @@ def initialize(attributes = {}) :request_date_pst, :transaction_id, :version_external_identifier, + :web_order_line_item_id ) def initialize(attributes = {}) @@ -62,6 +63,15 @@ def initialize(attributes = {}) @bid = receipt_attributes[:bid] @bundle_id = receipt_attributes[:bundle_id] @bvrs = receipt_attributes[:bvrs] + @cancellation_date = if receipt_attributes[:cancellation_date] + Time.parse receipt_attributes[:cancellation_date].sub('Etc/GMT', 'GMT') + end + @cancellation_date_ms = if receipt_attributes[:cancellation_date_ms] + receipt_attributes[:cancellation_date_ms].to_i + end + @cancellation_date_pst = if receipt_attributes[:cancellation_date_pst] + Time.parse receipt_attributes[:cancellation_date_pst].sub('America/Los_Angeles', 'PST') + end @download_id = receipt_attributes[:download_id] @expires_date = if receipt_attributes[:expires_date] Time.parse receipt_attributes[:expires_date].sub('Etc/GMT', 'GMT') @@ -72,15 +82,6 @@ def initialize(attributes = {}) @expires_date_pst = if receipt_attributes[:expires_date_pst] Time.parse receipt_attributes[:expires_date_pst].sub('America/Los_Angeles', 'PST') end - @cancellation_date = if receipt_attributes[:cancellation_date] - Time.parse receipt_attributes[:cancellation_date].sub('Etc/GMT', 'GMT') - end - @cancellation_date_ms = if receipt_attributes[:cancellation_date_ms] - receipt_attributes[:cancellation_date_ms].to_i - end - @cancellation_date_pst = if receipt_attributes[:cancellation_date_pst] - Time.parse receipt_attributes[:cancellation_date_pst].sub('America/Los_Angeles', 'PST') - end @in_app = if receipt_attributes[:in_app] receipt_attributes[:in_app].map { |ia| self.class.new(:receipt => ia) } end @@ -140,6 +141,7 @@ def initialize(attributes = {}) end @transaction_id = receipt_attributes[:transaction_id] @version_external_identifier = receipt_attributes[:version_external_identifier] + @web_order_line_item_id = receipt_attributes[:web_order_line_item_id] end def application_receipt? diff --git a/spec/itunes/receipt_spec.rb b/spec/itunes/receipt_spec.rb index 1da8ddc..e1def2d 100644 --- a/spec/itunes/receipt_spec.rb +++ b/spec/itunes/receipt_spec.rb @@ -95,6 +95,7 @@ receipt.receipt_data.should be_nil receipt.cancellation_date.should be_nil receipt.itunes_env.should == :production + receipt.web_order_line_item_id.should be_nil # Those attributes are not returned from iTunes Connect Sandbox receipt.app_item_id.should be_nil @@ -148,6 +149,7 @@ receipt.cancellation_date.should be_nil receipt.receipt_data.should be_nil receipt.itunes_env.should == :production + receipt.web_order_line_item_id.should be_nil # Those attributes are not returned from iTunes Connect Sandbox receipt.app_item_id.should be_nil @@ -177,6 +179,7 @@ receipt.expires_date.should == Time.utc(2012, 10, 13, 19, 45, 8) receipt.cancellation_date.should be_nil receipt.receipt_data.should be_nil + receipt.web_order_line_item_id.should == '1000000026553289' # Those attributes are not returned from iTunes Connect Sandbox receipt.app_item_id.should be_nil @@ -196,6 +199,7 @@ latest.original.transaction_id.should == original_transaction_id latest.original.purchase_date.should == original_purchase_date latest.receipt_data.should == 'junk=' + receipt.web_order_line_item_id.should == '1000000026553289' # Those attributes are not returned from iTunes Connect Sandbox latest.app_item_id.should be_nil