mirror of
https://github.com/godotengine/godot.git
synced 2024-11-12 23:24:26 +00:00
Complete the implementation of the GodotPayment plugin.
Move the remaining plugin components within the plugin source code.
This commit is contained in:
parent
6c74f38f0b
commit
99173c5fc4
@ -95,7 +95,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.godotengine.godot.input.GodotEditText;
|
||||
import org.godotengine.godot.payments.PaymentsManager;
|
||||
import org.godotengine.godot.plugin.GodotPlugin;
|
||||
import org.godotengine.godot.plugin.GodotPluginRegistry;
|
||||
import org.godotengine.godot.utils.GodotNetUtils;
|
||||
@ -174,21 +173,17 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
|
||||
}
|
||||
public ResultCallback result_callback;
|
||||
|
||||
private PaymentsManager mPaymentsManager = null;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE) {
|
||||
mPaymentsManager.processPurchaseResponse(resultCode, data);
|
||||
} else if (result_callback != null) {
|
||||
if (result_callback != null) {
|
||||
result_callback.callback(requestCode, resultCode, data);
|
||||
result_callback = null;
|
||||
};
|
||||
}
|
||||
|
||||
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
||||
plugin.onMainActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
@ -445,8 +440,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
|
||||
|
||||
result_callback = null;
|
||||
|
||||
mPaymentsManager = PaymentsManager.createManager(this).initService();
|
||||
|
||||
godot_initialized = true;
|
||||
}
|
||||
|
||||
@ -603,7 +596,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
|
||||
if (mPaymentsManager != null) mPaymentsManager.destroy();
|
||||
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
|
||||
plugin.onMainDestroy();
|
||||
}
|
||||
@ -938,10 +930,6 @@ public abstract class Godot extends FragmentActivity implements SensorEventListe
|
||||
return true;
|
||||
}
|
||||
|
||||
public PaymentsManager getPaymentsManager() {
|
||||
return mPaymentsManager;
|
||||
}
|
||||
|
||||
public boolean requestPermission(String p_name) {
|
||||
return PermissionsUtil.requestPermission(p_name, this);
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
/*************************************************************************/
|
||||
/* GodotPaymentInterface.java */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
|
||||
public interface GodotPaymentInterface {
|
||||
void purchase(String sku, String transactionId);
|
||||
|
||||
void consumeUnconsumedPurchases();
|
||||
|
||||
String getSignature();
|
||||
|
||||
void callbackSuccess(String ticket, String signature, String sku);
|
||||
|
||||
void callbackSuccessProductMassConsumed(String ticket, String signature, String sku);
|
||||
|
||||
void callbackSuccessNoUnconsumedPurchases();
|
||||
|
||||
void callbackFailConsume(String message);
|
||||
|
||||
void callbackFail(String message);
|
||||
|
||||
void callbackCancel();
|
||||
|
||||
void callbackAlreadyOwned(String sku);
|
||||
|
||||
int getPurchaseCallbackId();
|
||||
|
||||
void setPurchaseCallbackId(int purchaseCallbackId);
|
||||
|
||||
String getPurchaseValidationUrlPrefix();
|
||||
|
||||
void setPurchaseValidationUrlPrefix(String url);
|
||||
|
||||
String getAccessToken();
|
||||
|
||||
void setAccessToken(String accessToken);
|
||||
|
||||
void setTransactionId(String transactionId);
|
||||
|
||||
String getTransactionId();
|
||||
|
||||
// request purchased items are not consumed
|
||||
void requestPurchased();
|
||||
|
||||
// callback for requestPurchased()
|
||||
void callbackPurchased(String receipt, String signature, String sku);
|
||||
|
||||
void callbackDisconnected();
|
||||
|
||||
void callbackConnected();
|
||||
|
||||
// true if connected, false otherwise
|
||||
boolean isConnected();
|
||||
|
||||
// consume item automatically after purchase. default is true.
|
||||
void setAutoConsume(boolean autoConsume);
|
||||
|
||||
// consume a specific item
|
||||
void consume(String sku);
|
||||
|
||||
// query in app item detail info
|
||||
void querySkuDetails(String[] list);
|
||||
|
||||
void addSkuDetail(String itemJson);
|
||||
|
||||
void completeSkuDetail();
|
||||
|
||||
void errorSkuDetail(String errorMessage);
|
||||
}
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
@ -30,6 +30,7 @@
|
||||
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import java.util.ArrayList;
|
||||
@ -38,28 +39,40 @@ import java.util.List;
|
||||
import org.godotengine.godot.Dictionary;
|
||||
import org.godotengine.godot.Godot;
|
||||
import org.godotengine.godot.GodotLib;
|
||||
import org.godotengine.godot.payments.GodotPaymentInterface;
|
||||
import org.godotengine.godot.payments.PaymentsManager;
|
||||
import org.godotengine.godot.plugin.GodotPlugin;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
public class GodotPayment extends GodotPlugin {
|
||||
|
||||
private Integer purchaseCallbackId = 0;
|
||||
private String accessToken;
|
||||
private String purchaseValidationUrlPrefix;
|
||||
private String transactionId;
|
||||
private PaymentsManager mPaymentManager;
|
||||
private Dictionary mSkuDetails = new Dictionary();
|
||||
private final PaymentsManager mPaymentManager;
|
||||
private final Dictionary mSkuDetails = new Dictionary();
|
||||
|
||||
public GodotPayment(Godot godot) {
|
||||
super(godot);
|
||||
mPaymentManager = godot.getPaymentsManager();
|
||||
mPaymentManager.setBaseSingleton(this);
|
||||
mPaymentManager = new PaymentsManager(godot, this);
|
||||
mPaymentManager.initService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMainActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE) {
|
||||
mPaymentManager.processPurchaseResponse(resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMainDestroy() {
|
||||
super.onMainDestroy();
|
||||
if (mPaymentManager != null) {
|
||||
mPaymentManager.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public void purchase(final String sku, final String transactionId) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -69,7 +82,6 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consumeUnconsumedPurchases() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -81,89 +93,72 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
|
||||
private String signature;
|
||||
|
||||
@Override
|
||||
public String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackSuccess(String ticket, String signature, String sku) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_success", new Object[] { ticket, signature, sku });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackSuccessProductMassConsumed(String ticket, String signature, String sku) {
|
||||
Log.d(this.getClass().getName(), "callbackSuccessProductMassConsumed > " + ticket + "," + signature + "," + sku);
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_success", new Object[] { ticket, signature, sku });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackSuccessNoUnconsumedPurchases() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_not_required", new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackFailConsume(String message) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "consume_fail", new Object[] { message });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackFail(String message) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_fail", new Object[] { message });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackCancel() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_cancel", new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackAlreadyOwned(String sku) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "purchase_owned", new Object[] { sku });
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPurchaseCallbackId() {
|
||||
return purchaseCallbackId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPurchaseCallbackId(int purchaseCallbackId) {
|
||||
this.purchaseCallbackId = purchaseCallbackId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPurchaseValidationUrlPrefix() {
|
||||
return this.purchaseValidationUrlPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPurchaseValidationUrlPrefix(String url) {
|
||||
this.purchaseValidationUrlPrefix = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionId(String transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransactionId() {
|
||||
return this.transactionId;
|
||||
}
|
||||
|
||||
// request purchased items are not consumed
|
||||
@Override
|
||||
public void requestPurchased() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -174,41 +169,34 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
}
|
||||
|
||||
// callback for requestPurchased()
|
||||
@Override
|
||||
public void callbackPurchased(String receipt, String signature, String sku) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "has_purchased", new Object[] { receipt, signature, sku });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackDisconnected() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_disconnected", new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callbackConnected() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "iap_connected", new Object[] {});
|
||||
}
|
||||
|
||||
// true if connected, false otherwise
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return mPaymentManager.isConnected();
|
||||
}
|
||||
|
||||
// consume item automatically after purchase. default is true.
|
||||
@Override
|
||||
public void setAutoConsume(boolean autoConsume) {
|
||||
mPaymentManager.setAutoConsume(autoConsume);
|
||||
}
|
||||
|
||||
// consume a specific item
|
||||
@Override
|
||||
public void consume(String sku) {
|
||||
mPaymentManager.consume(sku);
|
||||
}
|
||||
|
||||
// query in app item detail info
|
||||
@Override
|
||||
public void querySkuDetails(String[] list) {
|
||||
List<String> nKeys = Arrays.asList(list);
|
||||
List<String> cKeys = Arrays.asList(mSkuDetails.get_keys());
|
||||
@ -225,7 +213,6 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSkuDetail(String itemJson) {
|
||||
JSONObject o = null;
|
||||
try {
|
||||
@ -244,12 +231,10 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeSkuDetail() {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_complete", new Object[] { mSkuDetails });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void errorSkuDetail(String errorMessage) {
|
||||
GodotLib.calldeferred(purchaseCallbackId, "sku_details_error", new Object[] { errorMessage });
|
||||
}
|
||||
@ -263,6 +248,8 @@ public class GodotPayment extends GodotPlugin implements GodotPaymentInterface {
|
||||
@NonNull
|
||||
@Override
|
||||
public List<String> getPluginMethods() {
|
||||
return Arrays.asList("purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails", "isConnected");
|
||||
return Arrays.asList("purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix",
|
||||
"setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased",
|
||||
"setAutoConsume", "consume", "querySkuDetails", "isConnected");
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
@ -28,11 +28,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
public class PaymentsCache {
|
||||
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
@ -52,20 +52,13 @@ public class PaymentsManager {
|
||||
public static final int REQUEST_CODE_FOR_PURCHASE = 0x1001;
|
||||
private static boolean auto_consume = true;
|
||||
|
||||
private Activity activity;
|
||||
private final Activity activity;
|
||||
private final GodotPayment godotPayment;
|
||||
IInAppBillingService mService;
|
||||
|
||||
public void setActivity(Activity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public static PaymentsManager createManager(Activity activity) {
|
||||
PaymentsManager manager = new PaymentsManager(activity);
|
||||
return manager;
|
||||
}
|
||||
|
||||
private PaymentsManager(Activity activity) {
|
||||
PaymentsManager(Activity activity, GodotPayment godotPayment) {
|
||||
this.activity = activity;
|
||||
this.godotPayment = godotPayment;
|
||||
}
|
||||
|
||||
public PaymentsManager initService() {
|
||||
@ -409,10 +402,4 @@ public class PaymentsManager {
|
||||
}))
|
||||
.start();
|
||||
}
|
||||
|
||||
private GodotPaymentInterface godotPayment;
|
||||
|
||||
public void setBaseSingleton(GodotPaymentInterface godotPaymentInterface) {
|
||||
this.godotPayment = godotPaymentInterface;
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
@ -28,7 +28,7 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
package org.godotengine.godot.payments;
|
||||
package org.godotengine.godot.plugin.payment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
@ -42,7 +42,7 @@ import org.json.JSONObject;
|
||||
abstract public class ValidateTask {
|
||||
|
||||
private Activity context;
|
||||
private GodotPaymentInterface godotPayments;
|
||||
private GodotPayment godotPayments;
|
||||
private ProgressDialog dialog;
|
||||
private String mSku;
|
||||
|
||||
@ -79,7 +79,7 @@ abstract public class ValidateTask {
|
||||
}
|
||||
}
|
||||
|
||||
public ValidateTask(Activity context, GodotPaymentInterface godotPayments) {
|
||||
public ValidateTask(Activity context, GodotPayment godotPayments) {
|
||||
this.context = context;
|
||||
this.godotPayments = godotPayments;
|
||||
}
|
Loading…
Reference in New Issue
Block a user