Skip to content

Commit 14bdb1d

Browse files
project updated
1 parent 8540d6e commit 14bdb1d

6 files changed

Lines changed: 71 additions & 9 deletions

File tree

export_presets.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ application/code_sign_identity_release=""
3030
application/provisioning_profile_specifier_debug=""
3131
application/provisioning_profile_specifier_release=""
3232
application/export_method_release=0
33-
application/bundle_identifier=""
33+
application/bundle_identifier="com.castoria.app"
3434
application/signature=""
3535
application/short_version=""
3636
application/version=""
@@ -300,7 +300,7 @@ architectures/x86=false
300300
architectures/x86_64=false
301301
version/code=1
302302
version/name="1.0.0"
303-
package/unique_name=""
303+
package/unique_name="com.castoria.app"
304304
package/name=""
305305
package/signed=true
306306
package/app_category=2

scenes/Main.tscn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ theme_override_colors/font_color = Color(1, 1, 1, 1)
187187
theme_override_font_sizes/font_size = 28
188188
text = "Purchase"
189189

190+
[node name="RestorePurchasesButton" type="Button" parent="VBoxContainer/ScrollContainer/Content/SectionPurchases/SectionPurchasesVBox"]
191+
custom_minimum_size = Vector2(0, 70)
192+
layout_mode = 2
193+
size_flags_horizontal = 3
194+
theme_override_colors/font_color = Color(1, 1, 1, 1)
195+
theme_override_font_sizes/font_size = 28
196+
text = "Restore Purchases"
197+
190198
[node name="SectionOfferings" type="PanelContainer" parent="VBoxContainer/ScrollContainer/Content"]
191199
layout_mode = 2
192200
theme_override_styles/panel = SubResource("StyleBoxFlat_1")
@@ -438,6 +446,7 @@ text = "Clear Log"
438446
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionInitialize/SectionInitializeVBox/InitializeButton" to="." method="_on_initialize_pressed"]
439447
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionCustomerInfo/SectionCustomerInfoVBox/GetCustomerInfoButton" to="." method="_on_get_customer_info_pressed"]
440448
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionPurchases/SectionPurchasesVBox/PurchaseButton" to="." method="_on_purchase_pressed"]
449+
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionPurchases/SectionPurchasesVBox/RestorePurchasesButton" to="." method="_on_restore_purchases_pressed"]
441450
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionOfferings/SectionOfferingsVBox/FetchOfferingsButton" to="." method="_on_fetch_offerings_pressed"]
442451
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionProducts/SectionProductsVBox/FetchProductsHBox/FetchProductsButton" to="." method="_on_fetch_products_pressed"]
443452
[connection signal="pressed" from="VBoxContainer/ScrollContainer/Content/SectionLogin/SectionLoginVBox/LoginHBox/LoginButton" to="." method="_on_login_pressed"]

scripts/Main.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func connect_signals() -> void:
8484
revenuecat.subscriber.connect(_on_subscriber_result)
8585
revenuecat.entitlement.connect(_on_entitlement_result)
8686
revenuecat.paywall_result.connect(_on_paywall_result)
87+
revenuecat.restore_result.connect(_on_restore_result)
8788

8889
log_message("🔌 Connected all RevenueCat signals")
8990

@@ -213,6 +214,13 @@ func _on_present_paywall_pressed():
213214
log_message("➡️ present_paywall(%s)" % off_id)
214215

215216

217+
func _on_restore_purchases_pressed():
218+
if revenuecat == null:
219+
return
220+
revenuecat.restore_purchases()
221+
log_message("➡️ restore_purchases()")
222+
223+
216224
func _on_clear_log_pressed():
217225
log_output.text = ""
218226

@@ -277,3 +285,8 @@ func _on_entitlement_result(ent_id, active):
277285
func _on_paywall_result(data):
278286
log_message("🔔 SIGNAL: paywall_result")
279287
log_message(dict_to_string(data))
288+
289+
290+
func _on_restore_result(data):
291+
log_message("🔔 SIGNAL: restore_result")
292+
log_message(dict_to_string(data))

source/android/revenue_cat/src/main/java/com/godotx/revenuecat/RevenueCatPlugin.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.revenuecat.purchases.interfaces.ReceiveCustomerInfoCallback
1919
import com.revenuecat.purchases.interfaces.ReceiveOfferingsCallback
2020
import com.revenuecat.purchases.models.StoreProduct
2121
import com.revenuecat.purchases.models.StoreTransaction
22+
import com.revenuecat.purchases.restorePurchasesWith
2223
import org.godotengine.godot.Dictionary
2324
import org.godotengine.godot.Godot
2425
import org.godotengine.godot.plugin.GodotPlugin
@@ -49,7 +50,8 @@ class RevenueCatPlugin(godot: Godot) : GodotPlugin(godot) {
4950
SignalInfo("logout_finished", Dictionary::class.java),
5051
SignalInfo("subscriber", Boolean::class.javaObjectType),
5152
SignalInfo("entitlement", String::class.java, Boolean::class.javaObjectType),
52-
SignalInfo("paywall_result", Dictionary::class.java)
53+
SignalInfo("paywall_result", Dictionary::class.java),
54+
SignalInfo("restore_finished", Dictionary::class.java)
5355
)
5456
}
5557

@@ -221,6 +223,23 @@ class RevenueCatPlugin(godot: Godot) : GodotPlugin(godot) {
221223
})
222224
}
223225

226+
@UsedByGodot
227+
fun restore_purchases() {
228+
Purchases.sharedInstance.restorePurchasesWith() { customerInfo ->
229+
currentCustomerInfo = customerInfo
230+
231+
val restoredCount = customerInfo.entitlements.active.size
232+
233+
emitOnMain(
234+
"restore_finished",
235+
dictOf(
236+
"active_entitlements" to restoredCount,
237+
"restored" to (restoredCount > 0)
238+
)
239+
)
240+
}
241+
}
242+
224243
@UsedByGodot
225244
fun fetch_offerings() {
226245
Purchases.sharedInstance.getOfferings(

source/ios/revenue_cat/Sources/godotx_revenuecat.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
class GodotxRevenueCat : public Object {
88
GDCLASS(GodotxRevenueCat, Object);
9-
9+
1010
protected:
1111
static void _bind_methods();
12-
12+
1313
public:
1414
static GodotxRevenueCat *instance;
1515
static GodotxRevenueCat *get_singleton();
16-
16+
1717
void initialize(String api_key, String user_id, bool debug);
1818
void get_customer_info();
1919
void purchase(String product_id);
@@ -22,10 +22,11 @@ class GodotxRevenueCat : public Object {
2222
void login(String user_id);
2323
void logout();
2424
void is_subscriber();
25+
bool has_entitlement(String entitlement_id);
2526
void check_entitlement(String entitlement_id);
2627
void present_paywall(String offering_id);
27-
bool has_entitlement(String entitlement_id);
28-
28+
void restore_purchases();
29+
2930
GodotxRevenueCat();
3031
~GodotxRevenueCat();
3132
};

source/ios/revenue_cat/Sources/godotx_revenuecat.mm

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ - (void)purchases:(RCPurchases *)purchases receivedUpdatedCustomerInfo:(RCCustom
6060
ADD_SIGNAL(MethodInfo("subscriber", PropertyInfo(Variant::BOOL, "value")));
6161
ADD_SIGNAL(MethodInfo("entitlement", PropertyInfo(Variant::STRING, "id"), PropertyInfo(Variant::BOOL, "active")));
6262
ADD_SIGNAL(MethodInfo("paywall_result", PropertyInfo(Variant::DICTIONARY, "data")));
63-
63+
ADD_SIGNAL(MethodInfo("restore_finished", PropertyInfo(Variant::DICTIONARY, "data")));
64+
6465
ClassDB::bind_method(D_METHOD("initialize", "api_key", "user_id", "debug"), &GodotxRevenueCat::initialize);
6566
ClassDB::bind_method(D_METHOD("get_customer_info"), &GodotxRevenueCat::get_customer_info);
6667
ClassDB::bind_method(D_METHOD("purchase", "product_id"), &GodotxRevenueCat::purchase);
@@ -72,6 +73,7 @@ - (void)purchases:(RCPurchases *)purchases receivedUpdatedCustomerInfo:(RCCustom
7273
ClassDB::bind_method(D_METHOD("has_entitlement", "entitlement_id"), &GodotxRevenueCat::has_entitlement);
7374
ClassDB::bind_method(D_METHOD("present_paywall", "offering_id"), &GodotxRevenueCat::present_paywall);
7475
ClassDB::bind_method(D_METHOD("check_entitlement", "entitlement_id"), &GodotxRevenueCat::check_entitlement);
76+
ClassDB::bind_method(D_METHOD("restore_purchases"), &GodotxRevenueCat::restore_purchases);
7577
}
7678

7779
void GodotxRevenueCat::initialize(String api_key, String user_id, bool debug) {
@@ -262,6 +264,24 @@ - (void)purchases:(RCPurchases *)purchases receivedUpdatedCustomerInfo:(RCCustom
262264
return ent && ent.isActive;
263265
}
264266

267+
void GodotxRevenueCat::restore_purchases() {
268+
[[RCPurchases sharedPurchases] restorePurchasesWithCompletion:^(RCCustomerInfo *info, NSError *error) {
269+
currentCustomerInfo = info;
270+
271+
int count = info ? (int)info.entitlements.active.count : 0;
272+
String err = error ? String(error.localizedDescription.UTF8String) : "";
273+
bool success = error == nil;
274+
275+
dispatch_async(dispatch_get_main_queue(), ^{
276+
Dictionary d;
277+
d["success"] = success;
278+
d["active_entitlements"] = count;
279+
if (error) d["error"] = err;
280+
emit_signal("restore_finished", d);
281+
});
282+
}];
283+
}
284+
265285
static UIViewController *godotx_revenuecat_get_root_view_controller() {
266286
UIWindow *keyWindow = nil;
267287

0 commit comments

Comments
 (0)