Started building ability to report in app purchase to server

pull/14/head
Sam Bosley 12 years ago
parent 18fa92a373
commit 89c3650afd

@ -17,9 +17,11 @@ import android.widget.Button;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmInvoker;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.billing.BillingConstants.PurchaseState;
import com.todoroo.astrid.billing.BillingConstants.ResponseCode;
@ -41,6 +43,8 @@ public class BillingActivity extends Activity {
private Button buyMonth;
private Button buyYear;
@Autowired private ActFmInvoker actFmInvoker;
@Override
protected void onCreate(Bundle savedInstanceState) {
DependencyInjectionService.getInstance().inject(this);
@ -75,8 +79,6 @@ public class BillingActivity extends Activity {
buyMonth.setEnabled(false);
buyYear.setEnabled(false);
//TODO: Figure out if we need a payload for any reason
buyMonth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -200,20 +202,28 @@ public class BillingActivity extends Activity {
Log.i(TAG, "onPurchaseStateChange() itemId: " + itemId + " " + purchaseState);
}
// if (developerPayload == null) {
// //
// } else {
// //
// }
Preferences.setString(BillingConstants.PREF_PRODUCT_ID, itemId);
Preferences.setString(BillingConstants.PREF_PURCHASE_TOKEN, purchaseToken);
if (purchaseState == PurchaseState.PURCHASED) {
// Success
// Report premium activation to server
try {
actFmInvoker.invoke("premium_update_android", "purchaseToken", purchaseToken, "productId", itemId);
Preferences.setBoolean(ActFmPreferenceService.PREF_PREMIUM, true);
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false);
} catch (Exception e) {
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, true);
// Reassure user
}
System.err.println("====== SUCCESS! ======");
} else if (purchaseState == PurchaseState.REFUNDED || purchaseState == PurchaseState.EXPIRED) {
// Subscription ended
// Report premium deactivation to server
System.err.println("====== REFUNDED ======");
try {
Preferences.setBoolean(ActFmPreferenceService.PREF_PREMIUM, false);
actFmInvoker.invoke("premium_update_android", "purchaseToken", purchaseToken, "productId", itemId);
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, false);
} catch (Exception e) {
Preferences.setBoolean(BillingConstants.PREF_NEEDS_SERVER_UPDATE, true);
}
System.err.println("====== REFUNDED OR EXPIRED ======");
}
}

@ -1,5 +1,7 @@
package com.todoroo.astrid.billing;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
@SuppressWarnings("nls")
public class BillingConstants {
@ -50,6 +52,10 @@ public class BillingConstants {
public static final String PRODUCT_ID_MONTHLY = "com.timsu.astrid.premium_monthly";
public static final String PRODUCT_ID_YEARLY = "com.timsu.astrid.premium_yearly";
public static final String PREF_PRODUCT_ID = ActFmPreferenceService.IDENTIFIER + "_inapp_product_id";
public static final String PREF_PURCHASE_TOKEN = ActFmPreferenceService.IDENTIFIER + "_inapp_purchase_token";
public static final String PREF_NEEDS_SERVER_UPDATE = ActFmPreferenceService.IDENTIFIER + "_inapp_needs_server_update";
public static final char PUB_KEY_OBFUSCATION_CHAR = '!';
public static final char PUB_KEY_REPLACE_CHAR = 'B';
public static final String PUB_KEY_OBFUSCATED = "pubkey";

Loading…
Cancel
Save