itunes_receipt_encoder 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/itunes_receipt_encoder +94 -0
- data/lib/itunes_receipt_encoder/asn1.rb +0 -4
- data/lib/itunes_receipt_encoder/in_app.rb +12 -10
- data/lib/itunes_receipt_encoder/payload.rb +8 -7
- data/lib/itunes_receipt_encoder/utils.rb +46 -5
- data/lib/itunes_receipt_encoder/version.rb +1 -1
- data/lib/itunes_receipt_encoder.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764169e8628039b7be28cf64669011048fb7e396
|
4
|
+
data.tar.gz: 244e326b8df96c21910d892c97224d6c026cb540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 760e7ee222a82a8bd4654ff541f8e26e0707e350ef20ab6ef9ffab22b3507175084c880767d80768a3fa4136f259aecb1316afca1224bd68d24c38182d6c4b73
|
7
|
+
data.tar.gz: 601c632f5d57810e057b36b6e61b5cecd4011f1b643e5ea4f82f31d3aadbf5492ec11aea986ff4908556ee318c2ce55db322ec87d24748e2f19e90a2de8e029b
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'optparse'
|
7
|
+
require 'itunes_receipt_encoder'
|
8
|
+
|
9
|
+
options = {
|
10
|
+
style: :unified
|
11
|
+
}
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
opts.program_name = 'itunes_receipt_encoder'
|
14
|
+
opts.banner = 'Usage: itunes_receipt_encoder [options] file'
|
15
|
+
|
16
|
+
opts.separator ''
|
17
|
+
opts.separator 'file: receipt data as JSON'
|
18
|
+
|
19
|
+
opts.separator ''
|
20
|
+
opts.separator 'Options:'
|
21
|
+
|
22
|
+
opts.on('-s', '--style STYLE',
|
23
|
+
%i(unified transaction),
|
24
|
+
'iTunes receipt output style',
|
25
|
+
'unified or transaction',
|
26
|
+
'defaults to unified') do |style|
|
27
|
+
options[:style] = style
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-r', '--raw', 'Return raw ouptput instead of Base64') do |raw|
|
31
|
+
options[:raw] = raw
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.separator ''
|
35
|
+
opts.separator 'Unified receipt style options:'
|
36
|
+
|
37
|
+
opts.on('-c', '--cert FILE',
|
38
|
+
'SSL certificate file to create P7 payload') do |file|
|
39
|
+
options[:cert] = File.read(file)
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-k', '--key FILE',
|
43
|
+
'SSL private key file to create P7 payload') do |file|
|
44
|
+
options[:key] = File.read(file)
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.separator ''
|
48
|
+
opts.separator 'Transaction receipt style options:'
|
49
|
+
|
50
|
+
opts.on('-i', '--index N',
|
51
|
+
'Use the specific index from in_app') do |index|
|
52
|
+
options[:index] = index
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on('-m', '--no-ms-dates',
|
56
|
+
'Exclude millisecond timestamps from results') do |no_ms_dates|
|
57
|
+
options[:no_ms_dates] = no_ms_dates
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on('-p', '--no-pst-dates',
|
61
|
+
'Exclude PST timestamps from results') do |no_pst_dates|
|
62
|
+
options[:no_pst_dates] = no_pst_dates
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.separator ''
|
66
|
+
opts.separator 'Additional options:'
|
67
|
+
|
68
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
69
|
+
puts opts
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on_tail('-v', '--version', 'Display the version number') do
|
74
|
+
puts ItunesReceiptEncoder::VERSION
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
optparse.parse!
|
80
|
+
|
81
|
+
if ARGV.empty?
|
82
|
+
puts optparse.to_s
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
|
86
|
+
json = JSON.parse(File.read(ARGV.first), symbolize_names: true)
|
87
|
+
encoder = ItunesReceiptEncoder.new(json)
|
88
|
+
case options.delete(:style)
|
89
|
+
when :unified
|
90
|
+
puts encoder.to_unified(options)
|
91
|
+
when :transaction
|
92
|
+
puts encoder.to_transaction(options)
|
93
|
+
end
|
94
|
+
exit(1)
|
@@ -10,9 +10,10 @@ module ItunesReceiptEncoder
|
|
10
10
|
include Utils
|
11
11
|
|
12
12
|
attr_accessor :quantity, :product_id, :transaction_id,
|
13
|
-
:original_transaction_id, :
|
14
|
-
|
15
|
-
|
13
|
+
:original_transaction_id, :web_order_line_item_id, :item_id
|
14
|
+
|
15
|
+
timestamp_accessor :purchase_date, :original_purchase_date, :expires_date,
|
16
|
+
:cancellation_date
|
16
17
|
|
17
18
|
def initialize(attrs = {})
|
18
19
|
attrs.each { |key, val| send("#{key}=", val) }
|
@@ -24,9 +25,9 @@ module ItunesReceiptEncoder
|
|
24
25
|
asn1_product_id,
|
25
26
|
asn1_transaction_id,
|
26
27
|
asn1_original_transaction_id,
|
27
|
-
asn1_purchase_date,
|
28
|
-
asn1_original_purchase_date,
|
29
28
|
asn1_web_order_line_item_id,
|
29
|
+
(asn1_purchase_date if purchase_date),
|
30
|
+
(asn1_original_purchase_date if original_purchase_date),
|
30
31
|
(asn1_expires_date if expires_date),
|
31
32
|
(asn1_cancellation_date if cancellation_date)
|
32
33
|
]
|
@@ -36,6 +37,7 @@ module ItunesReceiptEncoder
|
|
36
37
|
hash = {
|
37
38
|
'quantity' => quantity,
|
38
39
|
'product-id' => product_id,
|
40
|
+
'item-id' => item_id,
|
39
41
|
'transaction-id' => transaction_id,
|
40
42
|
'original_transaction-id' => original_transaction_id,
|
41
43
|
'purchase-date' => gmt_time(purchase_date),
|
@@ -74,23 +76,23 @@ module ItunesReceiptEncoder
|
|
74
76
|
end
|
75
77
|
|
76
78
|
def asn1_web_order_line_item_id
|
77
|
-
ASN1.sequence web_order_line_item_id, 1711, :integer
|
79
|
+
ASN1.sequence web_order_line_item_id || 0, 1711, :integer
|
78
80
|
end
|
79
81
|
|
80
82
|
def asn1_purchase_date
|
81
|
-
ASN1.sequence
|
83
|
+
ASN1.sequence asn1_time(purchase_date), 1704, :ia5_string
|
82
84
|
end
|
83
85
|
|
84
86
|
def asn1_original_purchase_date
|
85
|
-
ASN1.sequence
|
87
|
+
ASN1.sequence asn1_time(original_purchase_date), 1706, :ia5_string
|
86
88
|
end
|
87
89
|
|
88
90
|
def asn1_expires_date
|
89
|
-
ASN1.sequence
|
91
|
+
ASN1.sequence asn1_time(expires_date), 1708, :ia5_string
|
90
92
|
end
|
91
93
|
|
92
94
|
def asn1_cancellation_date
|
93
|
-
ASN1.sequence
|
95
|
+
ASN1.sequence asn1_time(cancellation_date), 1712, :ia5_string
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
@@ -11,9 +11,10 @@ module ItunesReceiptEncoder
|
|
11
11
|
include Utils
|
12
12
|
|
13
13
|
attr_accessor :environment, :bundle_id, :application_version,
|
14
|
-
:original_application_version, :
|
15
|
-
:
|
16
|
-
|
14
|
+
:original_application_version, :opaque_value, :sha1_hash,
|
15
|
+
:in_app, :unique_vendor_identifier
|
16
|
+
|
17
|
+
timestamp_accessor :creation_date, :expiration_date
|
17
18
|
|
18
19
|
def initialize(attrs = {})
|
19
20
|
attrs.each { |key, val| send("#{key}=", val) }
|
@@ -27,7 +28,7 @@ module ItunesReceiptEncoder
|
|
27
28
|
asn1_bundle_id,
|
28
29
|
asn1_application_version,
|
29
30
|
asn1_original_application_version,
|
30
|
-
asn1_creation_date,
|
31
|
+
(asn1_creation_date if creation_date),
|
31
32
|
(asn1_opaque_value if opaque_value),
|
32
33
|
(asn1_sha1_hash if sha1_hash),
|
33
34
|
(asn1_expiration_date if expiration_date)
|
@@ -40,7 +41,7 @@ module ItunesReceiptEncoder
|
|
40
41
|
'bid' => bundle_id.to_s,
|
41
42
|
'bvrs' => application_version.to_s,
|
42
43
|
'unique-vendor-identifier' => unique_vendor_identifier.to_s
|
43
|
-
}.merge(transaction.to_plist_hash(options))
|
44
|
+
}.merge(transaction.to_plist_hash(options)).delete_if { |_, v| v.nil? }
|
44
45
|
end
|
45
46
|
|
46
47
|
private
|
@@ -70,11 +71,11 @@ module ItunesReceiptEncoder
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def asn1_creation_date
|
73
|
-
ASN1.sequence
|
74
|
+
ASN1.sequence asn1_time(creation_date), 12, :ia5_string
|
74
75
|
end
|
75
76
|
|
76
77
|
def asn1_expiration_date
|
77
|
-
ASN1.sequence
|
78
|
+
ASN1.sequence asn1_time(expiration_date), 21, :ia5_string
|
78
79
|
end
|
79
80
|
|
80
81
|
def asn1_in_app
|
@@ -1,20 +1,61 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
1
3
|
##
|
2
4
|
# ItunesReceiptEncoder
|
3
5
|
module ItunesReceiptEncoder
|
4
6
|
##
|
5
|
-
# ItunesReceiptEncoder::
|
7
|
+
# ItunesReceiptEncoder::Utils
|
6
8
|
module Utils
|
9
|
+
##
|
10
|
+
# ItunesReceiptEncoder::Utils::ClassMethods
|
11
|
+
module ClassMethods
|
12
|
+
private
|
13
|
+
|
14
|
+
def timestamp_writer(*attrs)
|
15
|
+
attrs.each do |attr|
|
16
|
+
define_method("#{attr}=".to_sym) do |value|
|
17
|
+
instance_variable_set "@#{attr}".to_sym, parse_timestamp(value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def timestamp_accessor(*attrs)
|
23
|
+
attr_reader(*attrs)
|
24
|
+
timestamp_writer(*attrs)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def self.included(base)
|
31
|
+
base.extend(ClassMethods)
|
32
|
+
end
|
33
|
+
|
7
34
|
def gmt_time(time)
|
8
|
-
time.utc.strftime('%F %T
|
35
|
+
time && time.utc.strftime('%F %T Etc/GMT')
|
9
36
|
end
|
10
37
|
|
11
38
|
def pst_time(time)
|
12
|
-
(time + Time.zone_offset('PST'))
|
13
|
-
.strftime('%F %T
|
39
|
+
time && (time + Time.zone_offset('PST'))
|
40
|
+
.strftime('%F %T America/Los_Angeles')
|
14
41
|
end
|
15
42
|
|
16
43
|
def ms_time(time)
|
17
|
-
|
44
|
+
time && time.to_i * 1000
|
45
|
+
end
|
46
|
+
|
47
|
+
def asn1_time(time)
|
48
|
+
time && time.utc.strftime('%FT%TZ')
|
49
|
+
end
|
50
|
+
|
51
|
+
def parse_timestamp(value)
|
52
|
+
if value.is_a?(Time)
|
53
|
+
value
|
54
|
+
elsif value.is_a?(Integer)
|
55
|
+
Time.at(value)
|
56
|
+
else
|
57
|
+
Time.parse(value)
|
58
|
+
end
|
18
59
|
end
|
19
60
|
end
|
20
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes_receipt_encoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mbaasy.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: CFPropertyList
|
@@ -168,10 +168,12 @@ description: |2
|
|
168
168
|
Encodes receipt data into iTunes encoded receipts and exports as
|
169
169
|
appStoreReceiptURL or transactionReceipt formats.
|
170
170
|
email: hello@mbaasy.com
|
171
|
-
executables:
|
171
|
+
executables:
|
172
|
+
- itunes_receipt_encoder
|
172
173
|
extensions: []
|
173
174
|
extra_rdoc_files: []
|
174
175
|
files:
|
176
|
+
- bin/itunes_receipt_encoder
|
175
177
|
- lib/itunes_receipt_encoder.rb
|
176
178
|
- lib/itunes_receipt_encoder/asn1.rb
|
177
179
|
- lib/itunes_receipt_encoder/asn1/sequence.rb
|