@@ -150,14 +150,8 @@ def configure_product_for_billing(self, webpay_trans_id,
150
150
seller_product__external_id = product_id
151
151
)
152
152
if res ['meta' ]['total_count' ] == 0 :
153
- # TODO(Kumar) create products on the fly. bug 820164
154
- raise NotImplementedError (
155
- 'this product does not exist and must be created' )
156
-
157
- # Create the product on the fly.
158
- # This case exists for in-app purchases where the
159
- # seller is selling a new item for the first time.
160
-
153
+ bango_product_uri = self .create_product (product_id ,
154
+ product_name , currency , amount , res ['objects' ][0 ])
161
155
else :
162
156
bango_product_uri = res ['objects' ][0 ]['resource_uri' ]
163
157
log .info ('transaction %s: bango product: %s'
@@ -174,6 +168,39 @@ def configure_product_for_billing(self, webpay_trans_id,
174
168
% (webpay_trans_id , bill_id ))
175
169
return bill_id
176
170
171
+ def create_product (self , external_id , product_name , currency , amount , seller ):
172
+ """
173
+ Creates a product and a Bango ID on the fly in solitude.
174
+ """
175
+ if not seller ['bango' ]:
176
+ raise ValueError ('No bango account set up for %s' %
177
+ seller ['resource_pk' ])
178
+
179
+ product = self .slumber .generic .product .post ({
180
+ 'external_id' : external_id ,
181
+ 'seller' : seller ['bango' ]['seller' ]
182
+ })
183
+ bango = self .slumber .bango .product .post ({
184
+ 'seller_bango' : seller ['bango' ]['resource_uri' ],
185
+ 'seller_product' : product ['resource_uri' ],
186
+ 'name' : product_name ,
187
+ 'categoryId' : 1 ,
188
+ 'secret' : 'n' # This is likely going to be removed.
189
+ })
190
+ self .slumber .bango .premium .post ({
191
+ 'price' : amount ,
192
+ 'currencyIso' : currency ,
193
+ 'seller_product_bango' : bango ['resource_uri' ]
194
+ })
195
+
196
+ self .slumber .bango .rating .post ({
197
+ 'rating' : 'UNIVERSAL' ,
198
+ 'ratingScheme' : 'GLOBAL' ,
199
+ 'seller_product_bango' : bango ['resource_uri' ]
200
+ })
201
+ return bango ['resource_uri' ]
202
+
203
+
177
204
178
205
if getattr (settings , 'SOLITUDE_URL' , False ):
179
206
client = SolitudeAPI (settings .SOLITUDE_URL )
0 commit comments