Skip to content

Commit

Permalink
Fix some issues with PR
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuguohua committed Dec 10, 2024
1 parent c01975a commit 23365ce
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 261 deletions.
139 changes: 5 additions & 134 deletions @types/jsb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ declare namespace jsb {
getOfferToken(): string;
getType(): string;
toStr(): string;
equals(product: Product): boolean;
equals(product: UserChoiceDetailsProduct): boolean;
}
export class UserChoiceDetails {
getExternalTransactionToken(): string;
Expand Down Expand Up @@ -501,7 +501,7 @@ declare namespace jsb {
* @zh 代表一次性或订阅产品的详细信息。
*/
export class ProductDetails {
static RecurrenceMode: jsb.RecurrenceMode;
static RecurrenceMode: typeof jsb.RecurrenceMode;
equals(other: ProductDetails): boolean;
/**
* @en Hash code
Expand Down Expand Up @@ -768,7 +768,7 @@ declare namespace jsb {
};
getResponseCode(): number;
getDebugMessage(): string;
toStr(): string;
toString(): string;
public static newBuilder(): BillingResultBuilder;
}

Expand Down Expand Up @@ -1302,7 +1302,7 @@ declare namespace jsb {
}

export interface ProductDetailsParamsBuilder {
setOfferToken: (purchaseToken: string) => ProductDetailsParamsBuilder;
setOfferToken: (offerToken: string) => ProductDetailsParamsBuilder;
setProductDetails: (productDetails: ProductDetails) => ProductDetailsParamsBuilder;
build: () => ProductDetailsParams;
}
Expand All @@ -1312,7 +1312,7 @@ declare namespace jsb {
}

export interface SubscriptionUpdateParamsBuilder {
setOldPurcchaseToken: (purchaseToken: string) => SubscriptionUpdateParamsBuilder;
setOldPurchaseToken: (purchaseToken: string) => SubscriptionUpdateParamsBuilder;
setOriginalExternalTransactionId: (externalTransactionId: string) => SubscriptionUpdateParamsBuilder;
setSubscriptionReplacementMode: (subscriptionReplacementMode: number) => SubscriptionUpdateParamsBuilder;
build: () => SubscriptionUpdateParams;
Expand Down Expand Up @@ -1411,135 +1411,6 @@ declare namespace jsb {
showExternalOfferInformationDialog: (listener: ExternalOfferInformationDialogListener) => BillingResult;
showInAppMessages: (params: InAppMessageParams, listener: InAppMessageResponseListener) => BillingResult;
}

// /**
// * @en Main interface for communication between the Google Play library and user application code.
// * @zh 产品 ID。
// */
// const googleBilling: {
// enableAlternativeBillingOnly(): void;
// enableExternalOffer(): void;
// isEnabledForOneTimeProducts(): boolean;
// isEnabledForPrepaidPlans(): boolean;
// /**
// * @en Starts up BillingClient setup process asynchronously.
// * @zh 异步启动 BillingClient 设置过程。
// */
// startConnection(): void;

// /**
// * @en Closes the connection and releases all held resources such as service connections.
// * @zh 关闭连接并释放所有持有的资源,例如服务连接。
// */
// endConnection(): void;

// /**
// * @en Get the current billing client connection state.
// * @zh 获取当前计费客户端连接状态。
// */
// getConnectionState(): number;

// /**
// * @en Checks if the client is currently connected to the service, so that requests to other methods will succeed.
// Returns true if the client is currently connected to the service, false otherwise.
// * @zh 检查客户端当前是否连接到服务,以便对其他方法的请求能够成功。
// 如果客户端当前已连接到服务,则返回 true,否则返回 false。
// */
// isReady(): boolean;

// /**
// * @en Performs a network query the details of products available for sale in your app.
// * @zh 执行网络查询您的应用中可供销售的产品的详细信息。
// */
// queryProductDetailsAsync(productId: string[], productType: string[]): void;
// /**
// * @en Initiates the billing flow for an in-app purchase or subscription.
// * @zh 启动应用内购买或订阅的计费流程。
// */
// launchBillingFlow(productDetails: ProductDetails[], selectedOfferToken: string | null): void;
// /**
// * @en Consumes a given in-app product.
// * @zh 消费指定的应用内产品。
// */
// consumeAsync(purchases: Purchase[]): void;
// /**
// * @en Returns purchases details for currently owned items bought within your app.
// * @zh 返回您应用内当前拥有的购买商品的购买详情。
// */
// queryPurchasesAsync(productType: string): void;
// /**
// * @en Acknowledges in-app purchases..
// * @zh 确认应用内购买。
// */
// acknowledgePurchase(purchases: Purchase[]): void;
// /**
// * @en Gets the billing config, which stores configuration used to perform billing operations.
// * @zh 获取计费配置,其中存储用于执行计费操作的配置。
// */
// getBillingConfigAsync(): void;

// /**
// * @en Creates alternative billing only purchase details that can be used to report a transaction made via alternative billing without user choice to use Google Play billing.
// * @zh 创建仅限替代结算的购买详情,可用于报告通过替代结算进行的交易,而无需用户选择使用 Google Play Billing。
// */
// createAlternativeBillingOnlyReportingDetailsAsync(): void;
// /**
// * @en Checks the availability of offering alternative billing without user choice to use Google Play Billing.
// * @zh 检查是否可以提供替代结算方式,而无需用户选择使用 Google Play Billing方式。
// */
// isAlternativeBillingOnlyAvailableAsync(): void;

// /**
// * @en Creates purchase details that can be used to report a transaction made via external offer.
// * @zh 创建可用于报告通过外部报价进行的交易的购买详情。
// */
// createExternalOfferReportingDetailsAsync(): void;
// /**
// * @en Checks the availability of providing external offer.
// * @zh 检查提供外部报价的可用性。
// */
// isExternalOfferAvailableAsync(): void;

// /**
// * @en Checks if the specified feature or capability is supported by the Play Store.
// * @zh 检查 Play Store 是否支持指定的功能。
// */
// isFeatureSupported(feature: string): BillingResult;

// /**
// * @en Shows the alternative billing only information dialog on top of the calling app.
// * @zh 在调用应用程序顶部显示仅显示备用计费信息对话框。
// */
// showAlternativeBillingOnlyInformationDialog(): BillingResult;

// /**
// * @en Shows the external offer information dialog on top of the calling app.
// * @zh 在调用应用程序顶部显示外部优惠信息对话框。
// */
// showExternalOfferInformationDialog(): BillingResult;

// /**
// * @en Overlays billing related messages on top of the calling app.
// * @zh 在调用应用程序上叠加与计费相关的消息。
// */
// showInAppMessages(): BillingResult;
// } | undefined;
// export let onBillingSetupFinished: (result: BillingResult) => void | undefined;
// export let onBillingServiceDisconnected: () => void | undefined;
// export let onProductDetailsResponse: (result: BillingResult, productDetailsList: ProductDetails[]) => void | undefined;
// export let onPurchasesUpdated: (result: BillingResult, purchaseList: Purchase[]) => void | undefined;
// export let userSelectedAlternativeBilling: (userChoiceDetails: UserChoiceDetails) => void;
// export let onConsumeResponse: (result: BillingResult, purchaseToken: string) => void | undefined;
// export let onAcknowledgePurchaseResponse: (result: BillingResult) => void | undefined;
// export let onQueryPurchasesResponse: (result: BillingResult, purchaseList: Purchase[]) => void | undefined;
// export let onBillingConfigResponse: (result: BillingResult, config: BillingConfig) => void | undefined;
// export let onAlternativeBillingOnlyTokenResponse: (result: BillingResult, details: AlternativeBillingOnlyReportingDetails) => void | undefined;
// export let onExternalOfferReportingDetailsResponse: (result: BillingResult, details: ExternalOfferReportingDetails) => void | undefined;
// export let onAlternativeBillingOnlyAvailabilityResponse: (result: BillingResult) => void | undefined;
// export let onExternalOfferAvailabilityResponse: (result: BillingResult) => void | undefined;
// export let onAlternativeBillingOnlyInformationDialogResponse: (result: BillingResult) => void | undefined;
// export let onExternalOfferInformationDialogResponse: (result: BillingResult) => void | undefined;
// export let onInAppMessageResponse: (result: InAppMessageResult) => void | undefined;
}

declare namespace ns {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ public boolean isReady() {
return _billingClient.isReady();
}

public boolean isConnected() {
return getConnectionState() == BillingClient.ConnectionState.CONNECTED;
}

public void createAlternativeBillingOnlyReportingDetailsAsync(@NonNull AlternativeBillingOnlyReportingDetailsListener listener) {
_billingClient.createAlternativeBillingOnlyReportingDetailsAsync(listener);
}
Expand All @@ -173,50 +169,46 @@ public void isExternalOfferAvailableAsync(@NonNull ExternalOfferAvailabilityList

public void queryProductDetailsAsync(String[] productIds, String[] productTypes,
ProductDetailsResponseListener listener) {
if(!isConnected()) {
Log.e(TAG, "Must be connected before use this interface");
return;
}
if(productIds.length == 0) {
Log.e(TAG, "Product ID cannot be empty");
Log.e(TAG, "Product id must be provided.");
return;
}
if(productIds.length != productTypes.length) {
Log.e(TAG, "Product ID does not match the number of product types");
return;
}
List<QueryProductDetailsParams.Product> products = new ArrayList<>();
for(int i = 0; i < productIds.length; ++i) {

String inputType;
if(productTypes[i].equals(BillingClient.ProductType.INAPP)) {
inputType = BillingClient.ProductType.INAPP;
} else if(productTypes[i].equals(BillingClient.ProductType.SUBS)) {
inputType = BillingClient.ProductType.SUBS;
} else {
Log.e(TAG, "Undefined product types.");
continue;
try {
List<QueryProductDetailsParams.Product> products = new ArrayList<>();
for(int i = 0; i < productIds.length; ++i) {
String inputType = "";
if(productTypes[i].equals(BillingClient.ProductType.INAPP)) {
inputType = BillingClient.ProductType.INAPP;
} else if(productTypes[i].equals(BillingClient.ProductType.SUBS)) {
inputType = BillingClient.ProductType.SUBS;
}
products.add(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(productIds[i])
.setProductType(inputType)
.build());
}
products.add(
QueryProductDetailsParams.Product.newBuilder()
.setProductId(productIds[i])
.setProductType(inputType)
.build());
QueryProductDetailsParams params =
QueryProductDetailsParams.newBuilder().setProductList(products).build();
_billingClient.queryProductDetailsAsync(params, listener);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
QueryProductDetailsParams params =
QueryProductDetailsParams.newBuilder().setProductList(products).build();
_billingClient.queryProductDetailsAsync(params, listener);
}
public void launchBillingFlow(BillingFlowParams params) {
_billingClient.launchBillingFlow(GlobalObject.getActivity(), params);
try {
_billingClient.launchBillingFlow(GlobalObject.getActivity(), params);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
}

public void queryPurchasesAsync(String type, @NonNull PurchasesResponseListener listener) {
if(!isConnected()) {
Log.w(TAG, "Must be connected before use this interface");
return;
}
String inputType;
String inputType = "";
if(type.equals(BillingClient.ProductType.INAPP)) {
inputType = BillingClient.ProductType.INAPP;
} else if(type.equals(BillingClient.ProductType.SUBS)) {
Expand All @@ -225,26 +217,42 @@ public void queryPurchasesAsync(String type, @NonNull PurchasesResponseListener
Log.w(TAG, "Undefined product types.");
return;
}
_billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder()
.setProductType(inputType)
.build(), listener);
try {
_billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder()
.setProductType(inputType)
.build(), listener);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
}

public void consumeAsync(String purchaseToken, ConsumeResponseListener listener) {
_billingClient.consumeAsync(ConsumeParams.newBuilder()
.setPurchaseToken(purchaseToken).build(),
listener);
try {
_billingClient.consumeAsync(ConsumeParams.newBuilder()
.setPurchaseToken(purchaseToken).build(),
listener);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
}

public void acknowledgePurchase(@Nullable String purchaseToken, AcknowledgePurchaseResponseListener listener) {
_billingClient.acknowledgePurchase(
AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build(),
listener);
try {
_billingClient.acknowledgePurchase(
AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchaseToken).build(),
listener);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
}

public void getBillingConfigAsync( @NonNull BillingConfigResponseListener listener) {
GetBillingConfigParams getBillingConfigParams = GetBillingConfigParams.newBuilder().build();
_billingClient.getBillingConfigAsync(getBillingConfigParams, listener);
try {
GetBillingConfigParams getBillingConfigParams = GetBillingConfigParams.newBuilder().build();
_billingClient.getBillingConfigAsync(getBillingConfigParams, listener);
} catch (RuntimeException e) {
Log.e(TAG, e.getMessage());
}
}

public BillingResult showAlternativeBillingOnlyInformationDialog(@NonNull AlternativeBillingOnlyInformationDialogListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class GoogleBillingHelper {
public static int newTag() {
return billingTag++;
}
public static void createBillingClient(int tag, BillingClient.Builder builder) {
public static void createGoogleBilling(int tag, BillingClient.Builder builder) {
GlobalObject.runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/GoogleBilling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BillingClient::BillingClient(Builder* builder) {
this->_purchasesUpdatedListener = builder->_purchasesUpdatedListener;
this->_userChoiceBillingListener = builder->_userChoiceBillingListener;

_tag = GoogleBillingHelper::createBillingClient(builder);
_tag = GoogleBillingHelper::createGoogleBilling(builder);

CC_ASSERT(_tag >= 0);
GoogleBillingManager::getInstance()->pushBillingClient(_tag, this);
Expand Down
4 changes: 2 additions & 2 deletions native/vendor/google/billing/GoogleBillingHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, Alterna
template void callJSfunc(se::Object* obj, const char*, BillingResult*&&, ExternalOfferReportingDetails*&&);
template void callJSfunc(se::Object* obj, const char*, InAppMessageResult*&&);

int GoogleBillingHelper::createBillingClient(BillingClient::Builder* builder) {
int GoogleBillingHelper::createGoogleBilling(BillingClient::Builder* builder) {
int tag = JniHelper::callStaticIntMethod(JCLS_BILLING, "newTag");
jobject buildObj = JniBilling::newBillingClientBuilderObject(tag, builder);

cc::JniMethodInfo t;
cc::JniHelper::getStaticMethodInfo(t, JCLS_BILLING, "createBillingClient", "(ILcom/android/billingclient/api/BillingClient$Builder;)V");
cc::JniHelper::getStaticMethodInfo(t, JCLS_BILLING, "createGoogleBilling", "(ILcom/android/billingclient/api/BillingClient$Builder;)V");
t.env->CallStaticVoidMethod(t.classID, t.methodID, tag, buildObj);

return tag;
Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/GoogleBillingHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AcknowledgePurchaseParams;

class CC_DLL GoogleBillingHelper {
public:
static int createBillingClient(BillingClient::Builder* builder);
static int createGoogleBilling(BillingClient::Builder* builder);
static void removeBillingClient(int tag);
static void removeProductDetails(int tag, int productDetailsID);
static void removePurchase(int tag, int purchaseID);
Expand Down
3 changes: 1 addition & 2 deletions native/vendor/google/billing/result-values/BillingResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CC_DLL BillingResult : public cc::RefCounted {
return this->_debugMessage;
}

std::string toStr() const {
std::string toString() const {
return this->_toString;
}
class Builder {
Expand Down Expand Up @@ -68,7 +68,6 @@ class CC_DLL BillingResult : public cc::RefCounted {
static Builder* newBuilder() {
return new Builder();
}

private:
friend class JniBilling;
int _responseCode{0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class CC_DLL ProductDetails : public cc::RefCounted {
return this->_title;
}

std::string toStr() const {
std::string toString() const {
return this->_toString;
}

Expand Down
2 changes: 1 addition & 1 deletion native/vendor/google/billing/result-values/Purchase.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CC_DLL Purchase : public cc::RefCounted {
return this->_signature;
}

std::string toStr() const {
std::string toString() const {
return this->_toString;
}

Expand Down
Loading

0 comments on commit 23365ce

Please sign in to comment.