Added activate account API to in app purchase
This commit is contained in:
parent
2e255e0ff5
commit
b61f0018e7
3 changed files with 62 additions and 4 deletions
|
@ -333,7 +333,7 @@ public class InAppPurchaseHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recoverAccount(String productId, String sipUsername) {
|
public void recoverAccount(String sipUsername) {
|
||||||
XMLRPCClient client = null;
|
XMLRPCClient client = null;
|
||||||
try {
|
try {
|
||||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||||
|
@ -354,7 +354,7 @@ public class InAppPurchaseHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(long id, Object result) {
|
public void onResponse(long id, Object result) {
|
||||||
Log.d("[In-app purchase] Server result is " + result);
|
Log.d("[In-app purchase] recoverAccount server result is " + result);
|
||||||
mListener.onRecoverAccountSuccessful(result.equals("OK"));
|
mListener.onRecoverAccountSuccessful(result.equals("OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,6 +368,41 @@ public class InAppPurchaseHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void activateAccount(String sipUsername, String purchasedData, String signature) {
|
||||||
|
XMLRPCClient client = null;
|
||||||
|
try {
|
||||||
|
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
Log.e(e);
|
||||||
|
Log.e("[In-app purchase] Can't reach the server !");
|
||||||
|
mListener.onError(CLIENT_ERROR_SERVER_NOT_REACHABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client != null) {
|
||||||
|
client.callAsync(new XMLRPCCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServerError(long id, XMLRPCServerException error) {
|
||||||
|
Log.e(error);
|
||||||
|
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||||
|
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(long id, Object result) {
|
||||||
|
Log.d("[In-app purchase] activateAccount server result is " + result);
|
||||||
|
mListener.onActivateAccountSuccessful(result.equals("OK"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(long id, XMLRPCException error) {
|
||||||
|
Log.e(error);
|
||||||
|
Log.e("[In-app purchase] Server can't validate the payload and it's signature !");
|
||||||
|
mListener.onError(SERVER_ERROR_SIGNATURE_VERIFICATION_FAILED);
|
||||||
|
}
|
||||||
|
}, "activate_account", mGmailAccount, sipUsername, purchasedData, signature, "google");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
mContext.unbindService(mServiceConn);
|
mContext.unbindService(mServiceConn);
|
||||||
}
|
}
|
||||||
|
@ -416,6 +451,7 @@ public class InAppPurchaseHelper {
|
||||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||||
Purchasable item = new Purchasable(productId);
|
Purchasable item = new Purchasable(productId);
|
||||||
item.setExpire(longExpire);
|
item.setExpire(longExpire);
|
||||||
|
item.setPayloadAndSignature(purchasedData, signature);
|
||||||
//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) {
|
||||||
|
@ -428,7 +464,7 @@ public class InAppPurchaseHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifySignatureAndCreateAccountAsync(final VerifiedSignatureListener listener, final String purchasedData, String signature, String username) {
|
private void verifySignatureAndCreateAccountAsync(final VerifiedSignatureListener listener, final String purchasedData, final String signature, String username) {
|
||||||
XMLRPCClient client = null;
|
XMLRPCClient client = null;
|
||||||
try {
|
try {
|
||||||
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
client = new XMLRPCClient(new URL(LinphonePreferences.instance().getInAppPurchaseValidatingServerUrl()));
|
||||||
|
@ -466,6 +502,7 @@ public class InAppPurchaseHelper {
|
||||||
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
String productId = json.getString(PURCHASE_DETAILS_PRODUCT_ID);
|
||||||
Purchasable item = new Purchasable(productId);
|
Purchasable item = new Purchasable(productId);
|
||||||
item.setExpire(longExpire);
|
item.setExpire(longExpire);
|
||||||
|
item.setPayloadAndSignature(purchasedData, signature);
|
||||||
//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;
|
||||||
|
|
|
@ -49,10 +49,16 @@ public interface InAppPurchaseListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback called when the account has been recovered (or not)
|
* Callback called when the account has been recovered (or not)
|
||||||
* @param true if the recover has been successful, false otherwise
|
* @param success true if the recover has been successful, false otherwise
|
||||||
*/
|
*/
|
||||||
void onRecoverAccountSuccessful(boolean success);
|
void onRecoverAccountSuccessful(boolean success);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback called when the account has been activated (or not)
|
||||||
|
* @param success true if the activation has been successful, false otherwise
|
||||||
|
*/
|
||||||
|
void onActivateAccountSuccessful(boolean success);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback called when an error occurred.
|
* Callback called when an error occurred.
|
||||||
* @param error the error that occurred
|
* @param error the error that occurred
|
||||||
|
|
|
@ -29,6 +29,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;
|
private long expire;
|
||||||
|
private String purchasePayload, purchasePayloadSignature;
|
||||||
|
|
||||||
public Purchasable(String id) {
|
public Purchasable(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -79,4 +80,18 @@ public class Purchasable {
|
||||||
this.expire = expire;
|
this.expire = expire;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Purchasable setPayloadAndSignature(String payload, String signature) {
|
||||||
|
this.purchasePayload = payload;
|
||||||
|
this.purchasePayloadSignature = signature;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPayload() {
|
||||||
|
return this.purchasePayload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPayloadSignature() {
|
||||||
|
return this.purchasePayloadSignature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue