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 a product

Swift
Objective-C
Kotlin
Java
React Native
Swift
Purchasely.product(with: "PRODUCT_VENDOR_ID", success: { (product) in
// Returns a product and its available plans
}, failure: { (error) in
// Display error
})
Objective-C
[Purchasely productWith:@"PRODUCT_VENDOR_ID" success:^(PLYProduct * _Nonnull) {
// Display the product and its plans
} failure:^(NSError * _Nullable) {
// Display error
}];
Kotlin
Purchasely.getProduct("PRODUCT_VENDOR_ID",
onSuccess = { product ->
// Returns a product and its available plans
},
onError = { throwable ->
//display an error
}
)
Java
Purchasely.getProduct("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
}
});
React Native
try {
const product = await Purchasely.productWithIdentifier('PURCHASELY_PLUS');
console.log(' ==> Product');
console.log(product.vendorId);
console.log(product.name);
console.log(product.plans);
} catch (e) {
console.log(e);
}

Getting a plan

Swift
Objective-C
Kotlin
Java
React Native
Swift
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
})
Objective-C
[Purchasely planWith:@"PLAN_VENDOR_ID" success:^(PLYPlan * plan) {
// Use the plan to display a price or start a purchase
} failure:^(NSError * error) {
// Display error
}];
Kotlin
Purchasely.getPlan("PLAN_VENDOR_ID",
onSuccess = { plan ->
// Use the plan to display a price or start a purchase
},
onError = { throwable ->
//display an error
}
)
Java
Purchasely.getPlan("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
}
});
React Native
try {
const plan = await Purchasely.planWithIdentifier('PURCHASELY_PLUS_YEARLY');
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);
}

Purchasing a plan

Swift
Objective-C
Kotlin
Java
React Native
Swift
Purchasely.purchase(plan: plan, success: {
// Unlock / reload content and display a success / thank you message to user
}, failure: { (error) in
// Display error
})
Objective-C
[Purchasely purchaseWithPlan:plan success:^{
// Unlock / reload content and display a success / thank you message to user
} failure:^(NSError * error) {
// Display error
}];
Kotlin
Purchasely.purchase(this@MainActivity, plan, 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
}
}
})
Java
Purchasely.purchase(this, plan, (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
}
});
React Native
try {
const plan = await Purchasely.purchaseWithPlanVendorId(
'PURCHASELY_PLUS_MONTHLY'
);
console.log('Purchased ' + plan);
} catch (e) {
console.log(e);
}

Restoring all products

Swift
Objective-C
Kotlin
Java
React Native
Swift
Purchasely.restoreAllProducts(success: {
// Reload content and display a success / thank you message to user
}, failure: { (error) in
// Display error
})
Objective-C
[Purchasely restoreAllProductsWithSuccess:^{
// Reload content and display a success / thank you message to user
} failure:^(NSError * _Nonnull) {
// Display error
}];
Kotlin
Purchasely.restoreAllProducts(object: PurchaseListener {
override fun onPurchaseStateChanged(state: State) {
when(state) {
is State.RestorationComplete -> //Display success restoration
is State.RestorationNoProducts -> //No products to restore
is State.RestorationFailed -> //An error happened, look at state.error
else -> //look at all possible states for the one you may want to handle
}
}
})
Java
Purchasely.restoreAllProducts((PurchaseListener) state -> {
if(state instanceof State.RestorationComplete) {
//Display success restoration
} else if(state instanceof State.RestorationNoProducts) {
//No products to restore
} else if(state instanceof State.RestorationFailed) {
//An error happened, look at state.error
} else {
//look at all possible states for the one you may want to handle
}
});
React Native
try {
const restored = await Purchasely.restoreAllProducts();
console.log('Restoration success ? ' + restored);
} catch (e) {
console.log(e);
}