Changes in xmlrpc API to be able to retrieve the expiration date for subscriptions
This commit is contained in:
parent
081d12a571
commit
8d0e7c549b
3 changed files with 33 additions and 22 deletions
|
@ -75,7 +75,7 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
|
||||||
image.setOnClickListener(this);
|
image.setOnClickListener(this);
|
||||||
|
|
||||||
for (Purchasable purchasedItem : purchasedItems) {
|
for (Purchasable purchasedItem : purchasedItems) {
|
||||||
Log.d("[In-app purchase] Found already bought item");
|
Log.d("[In-app purchase] Found already bought item, expires " + purchasedItem.getExpireDate());
|
||||||
if (purchasedItem.getId().equals(item.getId())) {
|
if (purchasedItem.getId().equals(item.getId())) {
|
||||||
image.setEnabled(false);
|
image.setEnabled(false);
|
||||||
text.setEnabled(false);
|
text.setEnabled(false);
|
||||||
|
|
|
@ -126,7 +126,6 @@ public class InAppPurchaseHelper {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
mService = null;
|
mService = null;
|
||||||
Log.d("[In-app purchase] service disconnected");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,7 +137,6 @@ public class InAppPurchaseHelper {
|
||||||
if (response != RESPONSE_RESULT_OK) {
|
if (response != RESPONSE_RESULT_OK) {
|
||||||
Log.e("[In-app purchase] Error: Subscriptions aren't supported!");
|
Log.e("[In-app purchase] Error: Subscriptions aren't supported!");
|
||||||
} else {
|
} else {
|
||||||
Log.d("[In-app purchase] service connected and subsciptions are available");
|
|
||||||
mListener.onServiceAvailableForQueries();
|
mListener.onServiceAvailableForQueries();
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -153,8 +151,6 @@ public class InAppPurchaseHelper {
|
||||||
boolean ok = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
|
boolean ok = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
Log.e("[In-app purchase] Error: Bind service failed");
|
Log.e("[In-app purchase] Error: Bind service failed");
|
||||||
} else {
|
|
||||||
Log.d("[In-app purchase] service bound");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e("[In-app purchase] Error: Billing service unavailable on device.");
|
Log.e("[In-app purchase] Error: Billing service unavailable on device.");
|
||||||
|
@ -178,7 +174,6 @@ public class InAppPurchaseHelper {
|
||||||
if (skuDetails != null) {
|
if (skuDetails != null) {
|
||||||
int response = skuDetails.getInt(RESPONSE_CODE);
|
int response = skuDetails.getInt(RESPONSE_CODE);
|
||||||
if (response == RESPONSE_RESULT_OK) {
|
if (response == RESPONSE_RESULT_OK) {
|
||||||
Log.d("[In-app purchase] response is OK");
|
|
||||||
ArrayList<String> responseList = skuDetails.getStringArrayList(SKU_DETAILS_LIST);
|
ArrayList<String> responseList = skuDetails.getStringArrayList(SKU_DETAILS_LIST);
|
||||||
for (String thisResponse : responseList) {
|
for (String thisResponse : responseList) {
|
||||||
try {
|
try {
|
||||||
|
@ -187,7 +182,6 @@ public class InAppPurchaseHelper {
|
||||||
String price = object.getString(SKU_DETAILS_PRICE);
|
String price = object.getString(SKU_DETAILS_PRICE);
|
||||||
String title = object.getString(SKU_DETAILS_TITLE);
|
String title = object.getString(SKU_DETAILS_TITLE);
|
||||||
String desc = object.getString(SKU_DETAILS_DESC);
|
String desc = object.getString(SKU_DETAILS_DESC);
|
||||||
Log.d("[In-app purchase] found purchasable " + title + " (" + desc + ") for " + price + " with id " + id);
|
|
||||||
|
|
||||||
Purchasable purchasable = new Purchasable(id).setTitle(title).setDescription(desc).setPrice(price);
|
Purchasable purchasable = new Purchasable(id).setTitle(title).setDescription(desc).setPrice(price);
|
||||||
products.add(purchasable);
|
products.add(purchasable);
|
||||||
|
@ -235,7 +229,6 @@ public class InAppPurchaseHelper {
|
||||||
if (purchasedItems != null) {
|
if (purchasedItems != null) {
|
||||||
int response = purchasedItems.getInt(RESPONSE_CODE);
|
int response = purchasedItems.getInt(RESPONSE_CODE);
|
||||||
if (response == RESPONSE_RESULT_OK) {
|
if (response == RESPONSE_RESULT_OK) {
|
||||||
Log.d("[In-app purchase] response is OK");
|
|
||||||
ArrayList<String> purchaseDataList = purchasedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
|
ArrayList<String> purchaseDataList = purchasedItems.getStringArrayList(RESPONSE_INAPP_PURCHASE_DATA_LIST);
|
||||||
ArrayList<String> signatureList = purchasedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);
|
ArrayList<String> signatureList = purchasedItems.getStringArrayList(RESPONSE_INAPP_SIGNATURE_LIST);
|
||||||
continuationToken = purchasedItems.getString(RESPONSE_INAPP_CONTINUATION_TOKEN);
|
continuationToken = purchasedItems.getString(RESPONSE_INAPP_CONTINUATION_TOKEN);
|
||||||
|
@ -243,9 +236,9 @@ public class InAppPurchaseHelper {
|
||||||
for (int i = 0; i < purchaseDataList.size(); ++i) {
|
for (int i = 0; i < purchaseDataList.size(); ++i) {
|
||||||
String purchaseData = purchaseDataList.get(i);
|
String purchaseData = purchaseDataList.get(i);
|
||||||
String signature = signatureList.get(i);
|
String signature = signatureList.get(i);
|
||||||
Log.d("[In-app purchase] Found purchase data: " + purchaseData);
|
Log.d("[In-app purchase] " + purchaseData);
|
||||||
|
|
||||||
Purchasable item = verifySignature(purchaseData, signature);
|
Purchasable item = verifySignatureAndGetExpire(purchaseData, signature);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
@ -300,7 +293,6 @@ public class InAppPurchaseHelper {
|
||||||
String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
|
String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
|
||||||
|
|
||||||
if (resultCode == Activity.RESULT_OK && responseCode == RESPONSE_RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK && responseCode == RESPONSE_RESULT_OK) {
|
||||||
Log.d("[In-app purchase] response is OK");
|
|
||||||
verifySignatureAndCreateAccountAsync(new VerifiedSignatureListener() {
|
verifySignatureAndCreateAccountAsync(new VerifiedSignatureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsedAndVerifiedSignatureQueryFinished(Purchasable item) {
|
public void onParsedAndVerifiedSignatureQueryFinished(Purchasable item) {
|
||||||
|
@ -317,7 +309,7 @@ public class InAppPurchaseHelper {
|
||||||
mContext.unbindService(mServiceConn);
|
mContext.unbindService(mServiceConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Purchasable verifySignature(String purchasedData, String signature) {
|
private Purchasable verifySignatureAndGetExpire(String purchasedData, String signature) {
|
||||||
XMLRPCClient client = null;
|
XMLRPCClient client = null;
|
||||||
try {
|
try {
|
||||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||||
|
@ -327,13 +319,12 @@ public class InAppPurchaseHelper {
|
||||||
|
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
try {
|
try {
|
||||||
Object result = client.call("check_signature", purchasedData, signature, "google");
|
Object result = client.call("get_expiration_date", purchasedData, signature, "google");
|
||||||
String object = (String)result;
|
String expire = (String)result;
|
||||||
JSONObject json = new JSONObject(object);
|
JSONObject json = new JSONObject(purchasedData);
|
||||||
Log.d("[In-app purchase] JSON received is " + json);
|
|
||||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||||
Log.d("[In-app purchase] Purchasable verified by server: " + productId);
|
|
||||||
Purchasable item = new Purchasable(productId);
|
Purchasable item = new Purchasable(productId);
|
||||||
|
item.setExpire(Long.parseLong(expire));
|
||||||
//TODO parse JSON result to get the purchasable in it
|
//TODO parse JSON result to get the purchasable in it
|
||||||
return item;
|
return item;
|
||||||
} catch (XMLRPCException e) {
|
} catch (XMLRPCException e) {
|
||||||
|
@ -346,7 +337,7 @@ public class InAppPurchaseHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifySignatureAndCreateAccountAsync(final VerifiedSignatureListener listener, String purchasedData, String signature) {
|
private void verifySignatureAndCreateAccountAsync(final VerifiedSignatureListener listener, final String purchasedData, String signature) {
|
||||||
XMLRPCClient client = null;
|
XMLRPCClient client = null;
|
||||||
try {
|
try {
|
||||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||||
|
@ -366,12 +357,11 @@ public class InAppPurchaseHelper {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(long id, Object result) {
|
public void onResponse(long id, Object result) {
|
||||||
try {
|
try {
|
||||||
String object = (String)result;
|
String expire = (String)result;
|
||||||
JSONObject json = new JSONObject(object);
|
JSONObject json = new JSONObject(purchasedData);
|
||||||
Log.d("[In-app purchase] JSON received is " + json);
|
|
||||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||||
Log.d("[In-app purchase] Purchasable verified by server: " + productId);
|
|
||||||
Purchasable item = new Purchasable(productId);
|
Purchasable item = new Purchasable(productId);
|
||||||
|
item.setExpire(Long.parseLong(expire));
|
||||||
//TODO parse JSON result to get the purchasable in it
|
//TODO parse JSON result to get the purchasable in it
|
||||||
listener.onParsedAndVerifiedSignatureQueryFinished(item);
|
listener.onParsedAndVerifiedSignatureQueryFinished(item);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
package org.linphone.purchase;
|
package org.linphone.purchase;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Locale;
|
||||||
/*
|
/*
|
||||||
Purchasable.java
|
Purchasable.java
|
||||||
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
Copyright (C) 2015 Belledonne Communications, Grenoble, France
|
||||||
|
@ -23,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
public class Purchasable {
|
public class Purchasable {
|
||||||
private String id, title, description, price;
|
private String id, title, description, price;
|
||||||
|
private long expire;
|
||||||
|
|
||||||
public Purchasable(String id) {
|
public Purchasable(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -58,4 +64,19 @@ public class Purchasable {
|
||||||
this.price = price;
|
this.price = price;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getExpire() {
|
||||||
|
return expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpireDate() {
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.getDefault());
|
||||||
|
Date date = new Date(expire);
|
||||||
|
return dateFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Purchasable setExpire(long expire) {
|
||||||
|
this.expire = expire;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue