use of com.google.api.services.androidpublisher.model.SubscriptionPurchase in project OsmAnd-tools by osmandapp.
the class UpdateSubscriptionImpl method queryPurchases.
private static void queryPurchases(AndroidPublisher publisher, Connection conn, ResultSet rs) throws SQLException {
PreparedStatement ps = conn.prepareStatement("INSERT INTO supporters_subscription(userid, sku, purchaseToken, checktime, autorenewing, starttime, expiretime, kind) " + " VALUES(?, ?, ?, ?, ?, ?, ?, ?)");
PreparedStatement updateStatement = conn.prepareStatement("UPDATE supporters_subscription SET kind=?" + " WHERE userid =?");
AndroidPublisher.Purchases purchases = publisher.purchases();
int changes = 0;
int deletions = 0;
while (rs.next()) {
if (rs.getString("kind") != null) {
if (rs.getString("kind").equals(INVALID_PURCHASE)) {
continue;
}
}
String userid = rs.getString("userid");
String pt = rs.getString("purchasetoken");
String subscriptionId = rs.getString("sku");
SubscriptionPurchase subscription;
try {
if (subscriptionId.startsWith("osm_free")) {
subscription = purchases.subscriptions().get(GOOGLE_PACKAGE_NAME_FREE, subscriptionId, pt).execute();
} else {
subscription = purchases.subscriptions().get(GOOGLE_PACKAGE_NAME, subscriptionId, pt).execute();
}
} catch (Exception e) {
if (!pt.contains(".AO")) {
updateStatement.setString(1, INVALID_PURCHASE);
updateStatement.setString(2, userid);
updateStatement.addBatch();
deletions++;
System.out.println("Clearing invalid subscription: userid=" + userid + " sku=" + subscriptionId);
} else {
System.err.println("Error updating userid " + userid + " and sku " + subscriptionId);
e.printStackTrace();
}
continue;
}
long tm = System.currentTimeMillis();
ps.setString(1, userid);
ps.setString(2, subscriptionId);
ps.setString(3, pt);
ps.setLong(4, tm);
ps.setString(5, subscription.getAutoRenewing() + "");
ps.setLong(6, subscription.getStartTimeMillis());
ps.setLong(7, subscription.getExpiryTimeMillis());
ps.setString(8, subscription.getKind());
System.out.println("Update " + userid + " time " + tm + " expire " + subscription.getExpiryTimeMillis());
ps.addBatch();
changes++;
}
if (changes > 0) {
ps.executeBatch();
if (deletions > 0) {
updateStatement.executeBatch();
}
if (!conn.getAutoCommit()) {
conn.commit();
}
}
}
use of com.google.api.services.androidpublisher.model.SubscriptionPurchase in project OsmAnd-tools by osmandapp.
the class UpdateSubscriptionImpl method test.
private static void test(AndroidPublisher publisher, String subscriptionId, String purchaseToken) {
try {
com.google.api.services.androidpublisher.AndroidPublisher.Inappproducts.List lst = publisher.inappproducts().list(GOOGLE_PACKAGE_NAME_FREE);
InappproductsListResponse response = lst.execute();
for (InAppProduct p : response.getInappproduct()) {
System.out.println("SKU=" + p.getSku() + " type=" + p.getPurchaseType() + " LNG=" + p.getDefaultLanguage() + // " P="+p.getPrices()+
" Period=" + p.getSubscriptionPeriod() + " Status=" + p.getStatus());
}
AndroidPublisher.Purchases purchases = publisher.purchases();
SubscriptionPurchase subscription = purchases.subscriptions().get(GOOGLE_PACKAGE_NAME_FREE, subscriptionId, purchaseToken).execute();
System.out.println(subscription.getUnknownKeys());
System.out.println(subscription.getAutoRenewing());
System.out.println(subscription.getKind());
System.out.println(new Date(subscription.getExpiryTimeMillis()));
System.out.println(new Date(subscription.getStartTimeMillis()));
// return subscription.getExpiryTimeMillis();
// return subscripcion.getValidUntilTimestampMsec();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations