@@ -195,6 +195,12 @@ public static int countPurchasesNet(Context context, String itemId) {
195
195
return count ;
196
196
}
197
197
198
+ protected static void debug (String message ) {
199
+ if (debug ) {
200
+ Log .d (LOG_TAG , message );
201
+ }
202
+ }
203
+
198
204
/**
199
205
* Requests purchase information for the specified notification. Immediately
200
206
* followed by a call to
@@ -349,6 +355,8 @@ public static void onBillingChecked(boolean supported) {
349
355
* notification id.
350
356
*/
351
357
protected static void onNotify (Context context , String notifyId ) {
358
+ debug ("Notification " + notifyId + " available" );
359
+
352
360
getPurchaseInformation (context , notifyId );
353
361
}
354
362
@@ -381,6 +389,8 @@ public static void onPurchaseIntent(String itemId, PendingIntent purchaseIntent)
381
389
* data signature.
382
390
*/
383
391
protected static void onPurchaseStateChanged (Context context , String signedData , String signature ) {
392
+ debug ("Purchase state changed" );
393
+
384
394
if (TextUtils .isEmpty (signedData )) {
385
395
Log .w (LOG_TAG , "Signed data is empty" );
386
396
return ;
@@ -391,7 +401,8 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
391
401
Log .w (LOG_TAG , "Empty signature requires debug mode" );
392
402
return ;
393
403
}
394
- final ISignatureValidator validator = BillingController .validator != null ? BillingController .validator : new DefaultSignatureValidator (BillingController .configuration );
404
+ final ISignatureValidator validator = BillingController .validator != null ? BillingController .validator
405
+ : new DefaultSignatureValidator (BillingController .configuration );
395
406
if (!validator .validate (signedData , signature )) {
396
407
Log .w (LOG_TAG , "Signature does not match data." );
397
408
return ;
@@ -402,12 +413,12 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
402
413
try {
403
414
JSONObject jObject = new JSONObject (signedData );
404
415
if (!verifyNonce (jObject )) {
405
- Log .w (BillingController . class . getSimpleName () , "Invalid nonce" );
416
+ Log .w (LOG_TAG , "Invalid nonce" );
406
417
return ;
407
418
}
408
419
purchases = parsePurchases (jObject );
409
420
} catch (JSONException e ) {
410
- Log .e (BillingController . class . getSimpleName () , "JSON exception: " , e );
421
+ Log .e (LOG_TAG , "JSON exception: " , e );
411
422
return ;
412
423
}
413
424
@@ -439,10 +450,8 @@ protected static void onPurchaseStateChanged(Context context, String signedData,
439
450
* the billing request.
440
451
*/
441
452
protected static void onRequestSent (long requestId , BillingRequest request ) {
442
- if (debug ) {
443
- Log .d (BillingController .class .getSimpleName (), "Request " + requestId + " of type "
444
- + request .getRequestType () + " sent" );
445
- }
453
+ debug ("Request " + requestId + " of type " + request .getRequestType () + " sent" );
454
+
446
455
if (request .isSuccess ()) {
447
456
pendingRequests .put (requestId , request );
448
457
} else if (request .hasNonce ()) {
@@ -462,10 +471,8 @@ protected static void onRequestSent(long requestId, BillingRequest request) {
462
471
* @see net.robotmedia.billing.request.ResponseCode
463
472
*/
464
473
protected static void onResponseCode (Context context , long requestId , int responseCode ) {
465
- if (debug ) {
466
- Log .d (BillingController .class .getSimpleName (), "Request " + requestId + " received response "
467
- + ResponseCode .valueOf (responseCode ));
468
- }
474
+ debug ("Request " + requestId + " received response " + ResponseCode .valueOf (responseCode ));
475
+
469
476
final BillingRequest request = pendingRequests .get (requestId );
470
477
if (request != null ) {
471
478
pendingRequests .remove (requestId );
@@ -585,7 +592,9 @@ public static final void setDebug(boolean value) {
585
592
586
593
/**
587
594
* Sets a custom signature validator. If no custom signature validator is
588
- * provided, {@link net.robotmedia.billing.signature.DefaultSignatureValidator} will be used.
595
+ * provided,
596
+ * {@link net.robotmedia.billing.signature.DefaultSignatureValidator} will
597
+ * be used.
589
598
*
590
599
* @param validator
591
600
* signature validator instance.
0 commit comments