Purchasely
4.4
4.4
  • Welcome page
  • General
    • Presentation
    • Release notes
  • Quick start
    • Console Configuration
    • SDK Implementation
    • Testing
    • Sample
  • Basic configuration
    • Console Configuration
      • Creating a new application
      • Creating your Products
        • App Store
        • Play Store
        • Huawei App Gallery
        • Amazon App Store
        • Products & Plans
      • Design your Paywalls
      • Design your Paywalls-Latest
        • Carousel
        • Carousel Flow
        • Features List
        • Features List & Plan Picker with 2 & 3 columns
        • Feature list overlay
        • Plan picker horizontal
        • Plan picker with 2 and 3 Column
    • SDK installation
      • iOS SDK
      • Android SDK
      • React Native SDK
      • Cordova SDK
      • Flutter SDK
      • Unity SDK
    • SDK configurations
      • Paywall observer mode
      • Full mode
      • StoreKit 2
      • Appendices
        • Start the SDK
        • Set User Id
        • Notify when the app is ready
        • Present paywalls
        • Unlock content / service
        • Close SDK (Android only)
    • Stripe
    • Purchasely with RevenueCat
  • S2S notifications
    • Server-to-server notifications ?
    • Apple App Store
    • Google Play Store
    • Huawei App Gallery
  • Analytics
    • Dashboards
      • Introduction
      • Live
      • Subscriptions
      • Cohorts
      • Trials
      • Events
    • Events
      • Webhook events
        • Subscription events
        • Subscription events attributes
      • SDK events
        • UI events
        • UI attributes
  • Integrations
    • Webhook
      • Receiving and understanding messages
      • Managing entitlements
      • Detailed sequence diagrams
    • Airship
    • Amplitude
    • AppsFlyer
    • Adjust
    • Piano analytics(ex AT Internet)
    • Batch
    • Branch
    • Braze
    • Clevertap
    • Customer.io
    • Firebase
    • Iterable
    • Mixpanel
    • MoEngage
    • OneSignal
    • Segment
    • Brevo(ex Sendinblue)
  • Advanced Features
    • Asynchronous paywalls
    • NEW: Promotional offers
    • Anonymous user
    • Associating content
    • Audiences
    • Customising UI
      • Errors & alerts
      • Controllers (iOS) / Fragments (Android)
    • Deeplinks automations
    • Disable placements
    • Displaying users subscriptions
    • Localization
    • Lottie animations
    • Non-subscription products
    • Paywall action interceptor
    • Promoting your products
      • Self-promotion
      • Promoting In-App Purchases
    • Purchase manually
    • Subscription status
    • Use your own paywall
  • Others
    • Frequently Asked Questions
    • Migration guides
      • Migrate to Purchasely
      • Webhook
        • Migrate to Webhook v3.0
      • SDK
        • Migrate to SDK v3.0
          • v2.2.0
          • v2.1.3
        • Migrate to SDK v3.1
        • Migrate to SDK v3.2
        • Migrate to SDK v4.0.0
  • TESTING
    • Testing Cycle Durations
Powered by GitBook

© Purchasely 2020-2023

On this page
  • Getting all products
  • Getting a product
  • Getting a plan
  • Purchasing a plan
  • Restoring all products
  • Getting user subscriptions

Was this helpful?

Edit on GitHub
  1. Advanced Features

Purchase manually

Purchasely provides customizable presentation templates you but if you want to create your own and only use Purchasely for handling the purchase process you can. We offer methods to:

  • Get a product

  • Get a plan

  • Get a users subscriptions

  • Purchase a product

  • Restore all products

Getting all products

Purchasely.allProducts(success: { (products) in
	// Returns an array of products and its available plans
}, failure: { (error) in
	// Display error
})
[Purchasely allProductsWithSuccess:^(NSArray<PLYProduct *> * _Nonnull products) {
	NSLog(@"%ld products available", products.count);
}
						   failure:^(NSError * _Nullable error) {
	NSLog(@"Error %@", error);
}];
Purchasely.allProducts(
    onSuccess = { products ->
       // Returns an array of products and its available plans 
    },
    onError = {
       // display error
    }
)
Purchasely.allProducts(new ProductsListener() {
    @Override
    public void onSuccess(@NonNull List<PLYProduct> list) {
        // Returns an array of products and its available plans 
    }

    @Override
    public void onFailure(@NonNull Throwable throwable) {
        // Display error
    }
});
const products = await Purchasely.allProducts();
console.log('Products', products);
Purchasely.allProducts(products => {
       console.log("Products " + products);
		}, (error) => {
		   console.log(error);
		}
);
List<PLYProduct> products = await Purchasely.allProducts();
print('Products $products');
private PurchaselyRuntime.Purchasely _purchasely;

...
_purchasely.GetAllProducts(OnGetAllProductsSuccess, Log);
...

private void OnGetAllProductsSuccess(List<Product> products)
{
	Log($"Get All Products Success. Products fetched: {products.Count}.");
	foreach (var product in products)
	{
		LogProduct(product);
	}
}

Getting a product

Purchasely.product(with: "PRODUCT_VENDOR_ID", success: { (product) in
	// Returns a product and its available plans
}, failure: { (error) in
	// Display error
})
[Purchasely productWith:@"PRODUCT_VENDOR_ID" success:^(PLYProduct * _Nonnull) {
	// Display the product and its plans
} failure:^(NSError * _Nullable) {
	// Display error
}];
Purchasely.product("PRODUCT_VENDOR_ID",
    onSuccess = { product ->
        // Returns a product and its available plans
    },
    onError = { throwable ->
        //display an error
    }
)
Purchasely.product("PRODUCT_VENDOR_ID", new ProductListener() {
    @Override
    public void onSuccess(@Nullable PLYProduct product) {
        // Returns a product and its available plans
    }

    @Override
    public void onFailure(@NotNull Throwable throwable) {
        //display an error
    }
});
try {
  const product = await Purchasely.productWithIdentifier('PRODUCT_VENDOR_ID');
  console.log(' ==> Product');
  console.log(product.vendorId);
  console.log(product.name);
  console.log(product.plans);
} catch (e) {
  console.log(e);
}
Purchasely.productWithIdentifier('PRODUCT_VENDOR_ID', (product) => {
	console.log(' ==> Product');
	console.log(product.vendorId);
	console.log(product.name);
	console.log(product.plans);
}, (error) => {
	console.log(error);
});
PLYProduct product =
          await Purchasely.productWithIdentifier("PRODUCT_VENDOR_ID");
print(product.name);
private PurchaselyRuntime.Purchasely _purchasely;

...
_purchasely.GetProduct("productId", LogProduct, Log);
...

private void LogProduct(Product product)
{
	Log($"Product name: {product.name}. ID: {product.vendorId}");
}

Getting a plan

Purchasely.plan(with: "PLAN_VENDOR_ID", success: { (plan) in
	// Use the plan to display a price or start a purchase
}, failure: { (error) in
	// Display error
})
[Purchasely planWith:@"PLAN_VENDOR_ID" success:^(PLYPlan * plan) {
	// Use the plan to display a price or start a purchase
} failure:^(NSError * error) {
	// Display error
}];
Purchasely.plan("PLAN_VENDOR_ID",
    onSuccess = { plan ->
        // Use the plan to display a price or start a purchase
    },
    onError = { throwable ->
        //display an error
    }
)
Purchasely.plan("PLAN_VENDOR_ID", new PlanListener() {
    @Override
    public void onSuccess(@Nullable PLYPlan plan) {
        // Use the plan to display a price or start a purchase
    }

    @Override
    public void onFailure(@NotNull Throwable throwable) {
        //display an error
    }
});
try {
  const plan = await Purchasely.planWithIdentifier('PLAN_VENDOR_ID');
  console.log(' ==> Plan');
  console.log(plan.vendorId);
  console.log(plan.name);
  console.log(plan.price);
  console.log(plan.amount);
  console.log(plan.period);
  console.log(plan.hasIntroductoryPrice);
  console.log(plan.introPrice);
  console.log(plan.introAmount);
  console.log(plan.introDuration);
} catch (e) {
  console.log(e);
}
Purchasely.planWithIdentifier('PLAN_VENDOR_ID', (plan) => {
	console.log(' ==> Plan');
	console.log(plan.vendorId);
	console.log(plan.name);
	console.log(plan.price);
	console.log(plan.amount);
	console.log(plan.period);
	console.log(plan.hasIntroductoryPrice);
	console.log(plan.introPrice);
	console.log(plan.introAmount);
	console.log(plan.introDuration);
}, (error) => {
	console.log(error);
});
PLYPlan plan =
          await Purchasely.plantWithIdentifier("PLAN_VENDOR_ID");
print(plan.name);
private PurchaselyRuntime.Purchasely _purchasely;

...
_purchasely.GetPlan("planId", LogPlan, Log);
...

private void LogPlan(Plan plan)
{
    Log($"Plan name: {plan.name}. ID: {plan.vendorId}");
}

Purchasing a plan

Purchasely.purchase(plan: plan, success: {
	// Unlock / reload content and display a success / thank you message to user
}, failure: { (error) in
	// Display error
})
[Purchasely purchaseWithPlan:plan success:^{
	// Unlock / reload content and display a success / thank you message to user
} failure:^(NSError * error) {
	// Display error
}];
Purchasely.purchase(this@MainActivity, plan, offer, object: PurchaseListener {
    override fun onPurchaseStateChanged(state: State) {
        when(state) {
            is State.PurchaseComplete -> //Display success purchase
            is State.NotAvailable -> //Purchase is not available on this device
            is State.Error -> //An error happened, look at state.error
            is State.PurchaseDeferred -> //Purchase was made but verification did not happen yet
            else -> //look at all possible states for the one you may want to handle
        }
    }
})
Purchasely.purchase(this, plan, offer, (PurchaseListener) state -> {
    if(state instanceof State.PurchaseComplete) {
        //Display success purchase           
    } else if(state instanceof State.NotAvailable) {
        //Purchase is not available on this device
    } else if(state instanceof State.Error) {
        //An error happened, look at state.error
    } else if(state instanceof State.PurchaseDeferred) {
        //Purchase was made but verification did not happen yet
    } else {
        //look at all possible states for the one you may want to handle
    }
});
try {
  const plan = await Purchasely.purchaseWithPlanVendorId(
    'PLAN_VENDOR_ID'
  );
  console.log('Purchased ' + plan);
} catch (e) {
  console.log(e);
}
Purchasely.purchaseWithPlanVendorId("PLAN_VENDOR_ID", (plan) => {
	console.log('Purchased ' + plan);
}, (error) => {
	console.log(error);
});
try {
    Map<dynamic, dynamic> plan =
        await Purchasely.purchaseWithPlanVendorId('PLAN_VENDOR_ID');
    print('Purchased $plan');
} catch (e) {
    print(e);
}
private PurchaselyRuntime.Purchasely _purchasely;

_purchasely.Purchase("planId", LogPlan, Log, "contentId");

Restoring all products

Purchasely.restoreAllProducts(success: {
	// Reload content and display a success / thank you message to user
}, failure: { (error) in
	// Display error
})
[Purchasely restoreAllProductsWithSuccess:^{
	// Reload content and display a success / thank you message to user
} failure:^(NSError * _Nonnull) {
	// Display error
}];
Purchasely.restoreAllProducts(
    success = { plan ->
        //Restored PLYPlan succesfull
    },
    error = { error ->
        //Restored failed with PLYError
    }
)
Purchasely.restoreAllProducts(
        plan -> {
            if(plan != null) {
                // plan was restored
                Log.d("Purchasely", "Plan restored: " + plan.getVendorId());
            }
            return null;
        }, 
        error -> null
);
try {
  const restored = await Purchasely.restoreAllProducts();
  console.log('Restoration success ? ' + restored);
} catch (e) {
  console.log(e);
}
Purchasely.restoreAllProducts(() => {
	console.log("Successfully restored");
}, (error) => {
	console.log("Restoration failed: " + error);
});
bool restored = await Purchasely.restoreAllProducts();
private PurchaselyRuntime.Purchasely _purchasely;

_purchasely.RestoreAllProducts(false, LogPlan, Log);

Getting user subscriptions

Purchasely.userSubscriptions(success: { (subscriptions) in
	// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
	// Calling unsubscribe() will either switch the user to its AppStore settings 
	// or display a procedure on how to unsubscribe on Android
}, failure: { (error) in
	// Display error
})
[Purchasely userSubscriptionsWithSuccess:^(NSArray<PLYSubscription *> * _Nullable) {
	// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
	// Calling unsubscribe() will either switch the user to its AppStore settings 
	// or display a procedure on how to unsubscribe on Android
} failure:^(NSError * _Nullable) {
	// Display error
}];
Purchasely.userSubscriptions(
    onSuccess = { list ->
        // Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
        // Calling unsubscribe() will either switch the user to its Google Play settings
        // or display a procedure on how to unsubscribe on iOS
    },
    onError = { throwable ->
        //Display error
    }
)
Purchasely.userSubscriptions(new SubscriptionsListener() {
    @Override
    public void onSuccess(@NotNull List<PLYSubscriptionData> list) {
        // Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
        // Calling unsubscribe() will either switch the user to its Google Play settings
        // or display a procedure on how to unsubscribe on iOS
    }

    @Override
    public void onFailure(@NotNull Throwable throwable) {
        //Display error
    }
});
try {
  const subscriptions = await Purchasely.userSubscriptions();
  console.log(' ==> Subscriptions');
  if (subscriptions[0] !== undefined) {
    console.log(subscriptions[0].plan);
    console.log(subscriptions[0].subscriptionSource);
    console.log(subscriptions[0].nextRenewalDate);
    console.log(subscriptions[0].cancelledDate);
  }
} catch (e) {
  console.log(e);
}
Purchasely.userSubscriptions(subscriptions => {
       console.log("Subscriptions " + subscriptions);
		}, (error) => {
		   console.log(error);
		}
);
try {
  List<PLYSubscription> subscriptions =
      await Purchasely.userSubscriptions();
  print(' ==> Subscriptions');
  if (subscriptions.isNotEmpty) {
    print(subscriptions.first.plan);
    print(subscriptions.first.subscriptionSource);
    print(subscriptions.first.nextRenewalDate);
    print(subscriptions.first.cancelledDate);
  }
} catch (e) {
  print(e);
}
private PurchaselyRuntime.Purchasely _purchasely;

...
_purchasely.GetUserSubscriptions(OnGetSubscriptionsSuccess, Log);
...

private void OnGetSubscriptionsSuccess(List<SubscriptionData> subscriptionData)
{
	Log("Get Subscription Data Success.");

	foreach (var subscription in subscriptionData)
	{
		Log($"Subscription ID: {subscription.id}");

		var plan = subscription.plan;
		if (plan != null)
			LogPlan(plan);

		var product = subscription.product;
		if (product != null)
			LogProduct(product);
	}
}

PreviousPromoting In-App PurchasesNextSubscription status

Last updated 1 year ago

Was this helpful?