Pass the purchase token through the various layers of the billing system

pull/14/head
Sam Bosley 14 years ago
parent 8147986fb1
commit fea5fb275d

@ -195,7 +195,7 @@ public class BillingActivity extends Activity {
@Override @Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId, public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
int quantity, long purchaseTime, String developerPayload) { int quantity, long purchaseTime, String developerPayload, String purchaseToken) {
if (Constants.DEBUG) { if (Constants.DEBUG) {
Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState); Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
} }

@ -551,7 +551,7 @@ public class BillingService extends Service implements ServiceConnection {
notifyList.add(vp.notificationId); notifyList.add(vp.notificationId);
} }
ResponseHandler.purchaseResponse(this, vp.purchaseState, vp.productId, ResponseHandler.purchaseResponse(this, vp.purchaseState, vp.productId,
vp.orderId, vp.purchaseTime, vp.developerPayload); vp.orderId, vp.purchaseTime, vp.developerPayload, vp.purchaseToken);
} }
if (!notifyList.isEmpty()) { if (!notifyList.isEmpty()) {
String[] notifyIds = notifyList.toArray(new String[notifyList.size()]); String[] notifyIds = notifyList.toArray(new String[notifyList.size()]);

@ -66,7 +66,7 @@ public abstract class PurchaseObserver {
* milliseconds since the epoch (Jan 1, 1970) * milliseconds since the epoch (Jan 1, 1970)
*/ */
public abstract void onPurchaseStateChange(PurchaseState purchaseState, public abstract void onPurchaseStateChange(PurchaseState purchaseState,
String itemId, int quantity, long purchaseTime, String developerPayload); String itemId, int quantity, long purchaseTime, String developerPayload, String purchaseToken);
/** /**
* This is called when we receive a response code from Market for a * This is called when we receive a response code from Market for a
@ -150,12 +150,12 @@ public abstract class PurchaseObserver {
* @param quantity the quantity of items in this purchase * @param quantity the quantity of items in this purchase
*/ */
void postPurchaseStateChange(final PurchaseState purchaseState, final String itemId, void postPurchaseStateChange(final PurchaseState purchaseState, final String itemId,
final int quantity, final long purchaseTime, final String developerPayload) { final int quantity, final long purchaseTime, final String developerPayload, final String purchaseToken) {
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
onPurchaseStateChange( onPurchaseStateChange(
purchaseState, itemId, quantity, purchaseTime, developerPayload); purchaseState, itemId, quantity, purchaseTime, developerPayload, purchaseToken);
} }
}); });
} }

@ -104,7 +104,7 @@ public class ResponseHandler {
*/ */
public static void purchaseResponse( public static void purchaseResponse(
final Context context, final PurchaseState purchaseState, final String productId, final Context context, final PurchaseState purchaseState, final String productId,
final String orderId, final long purchaseTime, final String developerPayload) { final String orderId, final long purchaseTime, final String developerPayload, final String purchaseToken) {
// Update the database with the purchase state. We shouldn't do that // Update the database with the purchase state. We shouldn't do that
// from the main thread so we do the work in a background thread. // from the main thread so we do the work in a background thread.
@ -118,15 +118,15 @@ public class ResponseHandler {
// int quantity = db.updatePurchase( // int quantity = db.updatePurchase(
// orderId, productId, purchaseState, purchaseTime, developerPayload); // orderId, productId, purchaseState, purchaseTime, developerPayload);
// db.close(); // db.close();
//
// // This needs to be synchronized because the UI thread can change the // This needs to be synchronized because the UI thread can change the
// // value of sPurchaseObserver. // value of sPurchaseObserver.
// synchronized(ResponseHandler.class) { synchronized(ResponseHandler.class) {
// if (sPurchaseObserver != null) { if (sPurchaseObserver != null) {
// sPurchaseObserver.postPurchaseStateChange( sPurchaseObserver.postPurchaseStateChange(
// purchaseState, productId, quantity, purchaseTime, developerPayload); purchaseState, productId, 1, purchaseTime, developerPayload, purchaseToken);
// } }
// } }
} }
}).start(); }).start();
} }

@ -62,15 +62,17 @@ public class Security {
public String orderId; public String orderId;
public long purchaseTime; public long purchaseTime;
public String developerPayload; public String developerPayload;
public String purchaseToken;
public VerifiedPurchase(PurchaseState purchaseState, String notificationId, public VerifiedPurchase(PurchaseState purchaseState, String notificationId,
String productId, String orderId, long purchaseTime, String developerPayload) { String productId, String orderId, long purchaseTime, String developerPayload, String purchaseToken) {
this.purchaseState = purchaseState; this.purchaseState = purchaseState;
this.notificationId = notificationId; this.notificationId = notificationId;
this.productId = productId; this.productId = productId;
this.orderId = orderId; this.orderId = orderId;
this.purchaseTime = purchaseTime; this.purchaseTime = purchaseTime;
this.developerPayload = developerPayload; this.developerPayload = developerPayload;
this.purchaseToken = purchaseToken;
} }
} }
@ -169,6 +171,7 @@ public class Security {
if (jElement.has("notificationId")) { if (jElement.has("notificationId")) {
notifyId = jElement.getString("notificationId"); notifyId = jElement.getString("notificationId");
} }
String purchaseToken = jElement.optString("purchaseToken");
String developerPayload = jElement.optString("developerPayload", null); String developerPayload = jElement.optString("developerPayload", null);
// If the purchase state is PURCHASED, then we require a // If the purchase state is PURCHASED, then we require a
@ -177,7 +180,7 @@ public class Security {
continue; continue;
} }
purchases.add(new VerifiedPurchase(purchaseState, notifyId, productId, purchases.add(new VerifiedPurchase(purchaseState, notifyId, productId,
orderId, purchaseTime, developerPayload)); orderId, purchaseTime, developerPayload, purchaseToken));
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "JSON exception: ", e); Log.e(TAG, "JSON exception: ", e);

Loading…
Cancel
Save