ProMotion-iap 0.2.0 → 0.2.1.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a58cbbb9a1bfea9bed76bf23bcf61cb8c538bc17
4
- data.tar.gz: 2dd27741089d27722aa8a4e7e4fa2fb1153cf75c
3
+ metadata.gz: 04b7803087c35db767148574597a8ab7ab362330
4
+ data.tar.gz: 6e75db90ae31c40bc2ba8559202e8e12c4ef8a75
5
5
  SHA512:
6
- metadata.gz: a15d8be62ab306ff6fb4fa1ac41736a62f92db1c66e27a1c7a330ec510293c8549c020e459575372c6cd1deaded3cc7709e57e0193c51756524afb727e49140c
7
- data.tar.gz: c681697056432c9dee095f61392f4dd7b60bb10a4d9da50f13c081364cda6b26ac89444bcbf375757c3b609d98dc14cd06f78914367ec9be51e44716750a0a46
6
+ metadata.gz: 5f62e32f616300fcce8a2b39e40a74fcb7464af606eb950554f44c14adeb1fbd92f25386675d56de58dc19d28d78f6ca614c86f4c351e4c32285889d239ac0fd
7
+ data.tar.gz: 64d667a643c98e2c8bb0b64dec33ab25e019edfcc2db8432def098d79e8dc61a1d7886a10bcabfc08eeb7a39d6bfa7295d8819e343cb22c793f49dd0bd6b9c22
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # ProMotion-iap
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/ProMotion-iap.svg)](http://badge.fury.io/rb/ProMotion-iap)
4
- [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion-iap.svg)](https://travis-ci.org/clearsightstudio/ProMotion-iap)
4
+ [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion-iap.svg)](https://travis-ci.org/clearsightstudio/ProMotion-iap)
5
5
 
6
6
  ProMotion-iap is in-app purchase notification support for the
7
7
  popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion).
@@ -42,7 +42,7 @@ class PurchaseScreen < PM::Screen
42
42
  }
43
43
  end
44
44
 
45
- product.purchase do |status, transaction|
45
+ product.purchase do |status, data|
46
46
  case status
47
47
  when :in_progress
48
48
  # Usually do nothing, maybe a spinner
@@ -54,13 +54,16 @@ class PurchaseScreen < PM::Screen
54
54
  # They just canceled, no big deal.
55
55
  when :error
56
56
  # Failed to purchase
57
- transaction.error.localizedDescription # => error message
57
+ data[:error].localizedDescription # => error message
58
58
  end
59
59
  end
60
60
 
61
- product.restore do |status, product|
61
+ product.restore do |status, data|
62
62
  if status == :restored
63
63
  # Update your UI, notify the user
64
+ # data is a hash with :product_id, :error, and :transaction
65
+ else
66
+ # Tell the user it failed to restore
64
67
  end
65
68
  end
66
69
 
@@ -113,7 +116,7 @@ class PurchaseScreen < PM::Screen
113
116
  }, {...}]
114
117
  end
115
118
 
116
- purchase_iap "productid" do |status, transaction|
119
+ purchase_iaps [ "productid" ], username: User.current.username do |status, transaction|
117
120
  case status
118
121
  when :in_progress
119
122
  # Usually do nothing, maybe a spinner
@@ -129,9 +132,16 @@ class PurchaseScreen < PM::Screen
129
132
  end
130
133
  end
131
134
 
132
- restore_iaps "productid" do |status, products|
135
+ restore_iaps [ "productid" ], username: User.current.username do |status, data|
133
136
  if status == :restored
134
137
  # Update your UI, notify the user
138
+ # This is called once for each product you're trying to restore.
139
+ data[:product_id] # => "productid"
140
+ elsif status == :error
141
+ # Update your UI to show that there was an error.
142
+ # This will only be called once, no matter how many products you are trying to restore.
143
+ # You'll get an NSError in your `data` hash.
144
+ data[:error].localizedDescription # => description of error
135
145
  end
136
146
  end
137
147
 
@@ -155,7 +165,7 @@ Prompts the user to login to their Apple ID and complete the purchase. The callb
155
165
  #### restore_iaps(`*`product_ids, &callback)
156
166
 
157
167
  Restores a previously purchased IAP to the user (for example if they have upgraded their device). This relies on the Apple ID the user
158
- enters at the prompt. Unfortunately, if there is no purchase to restore for the signed-in account, no error message is generated and
168
+ enters at the prompt. Unfortunately, if there is no purchase to restore for the signed-in account, no error message is generated and
159
169
  will fail silently.
160
170
 
161
171
 
@@ -4,9 +4,9 @@ unless defined?(Motion::Project::Config)
4
4
  raise "ProMotion-iap must be required within a RubyMotion project."
5
5
  end
6
6
 
7
- Motion::Project::App.setup do |app|
7
+ Motion::Project::App.pre_setup do |app|
8
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
9
- app.files << File.join(lib_dir_path, "ProMotion/iap.rb")
10
- app.files << File.join(lib_dir_path, "ProMotion/product.rb")
9
+ app.files.unshift File.join(lib_dir_path, "ProMotion/product.rb")
10
+ app.files.unshift File.join(lib_dir_path, "ProMotion/iap.rb")
11
11
  app.frameworks << "StoreKit"
12
12
  end
@@ -2,23 +2,32 @@ module ProMotion
2
2
  module IAP
3
3
  attr_accessor :completion_handlers
4
4
 
5
- def purchase_iaps(*product_ids, &callback)
5
+ def purchase_iaps(product_ids, options={}, &callback)
6
6
  iap_setup
7
7
  retrieve_iaps product_ids do |products|
8
8
  products.each do |product|
9
9
  self.completion_handlers["purchase-#{product[:product_id]}"] = callback
10
- payment = SKPayment.paymentWithProduct(product[:product])
10
+
11
+ payment = SKMutablePayment.paymentWithProduct(product[:product])
12
+ payment.applicationUsername = options[:username] if options[:username]
13
+
11
14
  SKPaymentQueue.defaultQueue.addPayment(payment)
12
15
  end
13
16
  end
14
17
  end
15
18
  alias purchase_iap purchase_iaps
16
19
 
17
- def restore_iaps(*product_ids, &callback)
20
+ def restore_iaps(product_ids, options={}, &callback)
18
21
  iap_setup
19
- retrieve_iaps product_ids do |products|
22
+ retrieve_iaps Array(product_ids) do |products|
20
23
  products.each do |product|
21
24
  self.completion_handlers["restore-#{product[:product_id]}"] = callback
25
+ end
26
+ self.completion_handlers["restore-all"] = callback # In case of error
27
+
28
+ if options[:username]
29
+ SKPaymentQueue.defaultQueue.restoreCompletedTransactionsWithApplicationUsername(options[:username])
30
+ else
22
31
  SKPaymentQueue.defaultQueue.restoreCompletedTransactions
23
32
  end
24
33
  end
@@ -47,6 +56,7 @@ module ProMotion
47
56
  end
48
57
 
49
58
  def iap_shutdown
59
+ @completion_handlers = nil
50
60
  SKPaymentQueue.defaultQueue.removeTransactionObserver(self)
51
61
  end
52
62
 
@@ -79,18 +89,41 @@ module ProMotion
79
89
  end
80
90
 
81
91
  def iap_callback(status, transaction, finish=false)
82
- product_id = transaction.payment.productIdentifier
92
+ product_id = transaction_product_id(transaction)
93
+
83
94
  if self.completion_handlers["purchase-#{product_id}"]
84
- self.completion_handlers["purchase-#{product_id}"].call status, transaction
95
+ self.completion_handlers["purchase-#{product_id}"].call status, mapped_transaction(transaction)
85
96
  self.completion_handlers["purchase-#{product_id}"] = nil if finish
86
97
  end
98
+
87
99
  if self.completion_handlers["restore-#{product_id}"]
88
- self.completion_handlers["restore-#{product_id}"].call status, transaction
100
+ self.completion_handlers["restore-#{product_id}"].call status, mapped_transaction(transaction)
89
101
  self.completion_handlers["restore-#{product_id}"] = nil if finish
90
102
  end
103
+
91
104
  SKPaymentQueue.defaultQueue.finishTransaction(transaction) if finish
92
105
  end
93
106
 
107
+ def mapped_transaction(transaction)
108
+ if transaction.respond_to?(:payment)
109
+ {
110
+ product_id: transaction.payment.productIdentifier,
111
+ error: transaction.error,
112
+ transaction: transaction
113
+ }
114
+ else
115
+ {
116
+ product_id: nil,
117
+ error: transaction,
118
+ transaction: nil
119
+ }
120
+ end
121
+ end
122
+
123
+ def transaction_product_id(transaction)
124
+ transaction.respond_to?(:payment) ? transaction.payment.productIdentifier : "all"
125
+ end
126
+
94
127
  public
95
128
 
96
129
  # SKProductsRequestDelegate methods
@@ -99,7 +132,6 @@ module ProMotion
99
132
  unless response.invalidProductIdentifiers.empty?
100
133
  red = "\e[0;31m"
101
134
  color_off = "\e[0m"
102
- puts "#{red}PM::IAP Error - invalid product identifier(s) '#{response.invalidProductIdentifiers.join("', '")}' for application identifier #{NSBundle.mainBundle.infoDictionary['CFBundleIdentifier'].inspect}#{color_off}"
103
135
  end
104
136
  retrieved_iaps_handler(response.products, &self.completion_handlers["retrieve_iaps"]) if self.completion_handlers["retrieve_iaps"]
105
137
  @products_request = nil
@@ -132,6 +164,10 @@ module ProMotion
132
164
  end
133
165
  end
134
166
 
167
+ def paymentQueue(_, restoreCompletedTransactionsFailedWithError:error)
168
+ iap_callback(:error, error)
169
+ end
170
+
135
171
  end
136
172
  end
137
- ::PM = ProMotion unless defined?(::PM)
173
+ ::PM = ProMotion unless defined?(PM)
@@ -1,6 +1,6 @@
1
1
  module ProMotion
2
2
  class IAP::Product
3
- include PM::IAP
3
+ include ProMotion::IAP
4
4
 
5
5
  attr_reader :product_id
6
6
 
@@ -24,4 +24,5 @@ module ProMotion
24
24
  end
25
25
  end
26
26
  end
27
- end
27
+ end
28
+ ::PM = ProMotion unless defined?(PM)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion-iap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-12 00:00:00.000000000 Z
12
+ date: 2015-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: motion-stump
@@ -80,12 +80,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - ">="
83
+ - - ">"
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 1.3.1
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.4.5
88
+ rubygems_version: 2.4.6
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Adds in-app purchase support to ProMotion.