@@ -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
7779void 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+
265285static UIViewController *godotx_revenuecat_get_root_view_controller () {
266286 UIWindow *keyWindow = nil ;
267287
0 commit comments