Purchasely
Rechercher…
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

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.allProducts(success: { (products) in
2
// Returns an array of products and its available plans
3
}, failure: { (error) in
4
// Display error
5
})
Copied!
1
[Purchasely allProductsWithSuccess:^(NSArray<PLYProduct *> * _Nonnull products) {
2
NSLog(@"%ld products available", products.count);
3
}
4
failure:^(NSError * _Nullable error) {
5
NSLog(@"Error %@", error);
6
}];
Copied!
1
Purchasely.allProducts(
2
onSuccess = { products ->
3
// Returns an array of products and its available plans
4
},
5
onError = {
6
// display error
7
}
8
)
Copied!
1
Purchasely.allProducts(new ProductsListener() {
2
@Override
3
public void onSuccess(@NonNull List<PLYProduct> list) {
4
// Returns an array of products and its available plans
5
}
6
7
@Override
8
public void onFailure(@NonNull Throwable throwable) {
9
// Display error
10
}
11
});
Copied!
1
const products = await Purchasely.allProducts();
2
console.log('Products', products);
Copied!
1
Purchasely.allProducts(products => {
2
console.log("Products " + products);
3
}, (error) => {
4
console.log(error);
5
}
6
);
Copied!
1
List<PLYProduct> products = await Purchasely.allProducts();
2
print('Products $products');
Copied!

Getting a product

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.product(with: "PRODUCT_VENDOR_ID", success: { (product) in
2
// Returns a product and its available plans
3
}, failure: { (error) in
4
// Display error
5
})
Copied!
1
[Purchasely productWith:@"PRODUCT_VENDOR_ID" success:^(PLYProduct * _Nonnull) {
2
// Display the product and its plans
3
} failure:^(NSError * _Nullable) {
4
// Display error
5
}];
Copied!
1
Purchasely.product("PRODUCT_VENDOR_ID",
2
onSuccess = { product ->
3
// Returns a product and its available plans
4
},
5
onError = { throwable ->
6
//display an error
7
}
8
)
Copied!
1
Purchasely.product("PRODUCT_VENDOR_ID", new ProductListener() {
2
@Override
3
public void onSuccess(@Nullable PLYProduct product) {
4
// Returns a product and its available plans
5
}
6
7
@Override
8
public void onFailure(@NotNull Throwable throwable) {
9
//display an error
10
}
11
});
Copied!
1
try {
2
const product = await Purchasely.productWithIdentifier('PRODUCT_VENDOR_ID');
3
console.log(' ==> Product');
4
console.log(product.vendorId);
5
console.log(product.name);
6
console.log(product.plans);
7
} catch (e) {
8
console.log(e);
9
}
Copied!
1
Purchasely.productWithIdentifier('PRODUCT_VENDOR_ID', (product) => {
2
console.log(' ==> Product');
3
console.log(product.vendorId);
4
console.log(product.name);
5
console.log(product.plans);
6
}, (error) => {
7
console.log(error);
8
});
Copied!
1
PLYProduct product =
2
await Purchasely.productWithIdentifier("PRODUCT_VENDOR_ID");
3
print(product.name);
Copied!

Getting a plan

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.plan(with: "PLAN_VENDOR_ID", success: { (plan) in
2
// Use the plan to display a price or start a purchase
3
}, failure: { (error) in
4
// Display error
5
})
Copied!
1
[Purchasely planWith:@"PLAN_VENDOR_ID" success:^(PLYPlan * plan) {
2
// Use the plan to display a price or start a purchase
3
} failure:^(NSError * error) {
4
// Display error
5
}];
Copied!
1
Purchasely.plan("PLAN_VENDOR_ID",
2
onSuccess = { plan ->
3
// Use the plan to display a price or start a purchase
4
},
5
onError = { throwable ->
6
//display an error
7
}
8
)
Copied!
1
Purchasely.plan("PLAN_VENDOR_ID", new PlanListener() {
2
@Override
3
public void onSuccess(@Nullable PLYPlan plan) {
4
// Use the plan to display a price or start a purchase
5
}
6
7
@Override
8
public void onFailure(@NotNull Throwable throwable) {
9
//display an error
10
}
11
});
Copied!
1
try {
2
const plan = await Purchasely.planWithIdentifier('PLAN_VENDOR_ID');
3
console.log(' ==> Plan');
4
console.log(plan.vendorId);
5
console.log(plan.name);
6
console.log(plan.price);
7
console.log(plan.amount);
8
console.log(plan.period);
9
console.log(plan.hasIntroductoryPrice);
10
console.log(plan.introPrice);
11
console.log(plan.introAmount);
12
console.log(plan.introDuration);
13
} catch (e) {
14
console.log(e);
15
}
Copied!
1
Purchasely.planWithIdentifier('PLAN_VENDOR_ID', (plan) => {
2
console.log(' ==> Plan');
3
console.log(plan.vendorId);
4
console.log(plan.name);
5
console.log(plan.price);
6
console.log(plan.amount);
7
console.log(plan.period);
8
console.log(plan.hasIntroductoryPrice);
9
console.log(plan.introPrice);
10
console.log(plan.introAmount);
11
console.log(plan.introDuration);
12
}, (error) => {
13
console.log(error);
14
});
Copied!
1
PLYPlan plan =
2
await Purchasely.plantWithIdentifier("PLAN_VENDOR_ID");
3
print(plan.name);
Copied!

Purchasing a plan

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.purchase(plan: plan, success: {
2
// Unlock / reload content and display a success / thank you message to user
3
}, failure: { (error) in
4
// Display error
5
})
Copied!
1
[Purchasely purchaseWithPlan:plan success:^{
2
// Unlock / reload content and display a success / thank you message to user
3
} failure:^(NSError * error) {
4
// Display error
5
}];
Copied!
1
Purchasely.purchase(this@MainActivity, plan, object: PurchaseListener {
2
override fun onPurchaseStateChanged(state: State) {
3
when(state) {
4
is State.PurchaseComplete -> //Display success purchase
5
is State.NotAvailable -> //Purchase is not available on this device
6
is State.Error -> //An error happened, look at state.error
7
is State.PurchaseDeferred -> //Purchase was made but verification did not happen yet
8
else -> //look at all possible states for the one you may want to handle
9
}
10
}
11
})
Copied!
1
Purchasely.purchase(this, plan, (PurchaseListener) state -> {
2
if(state instanceof State.PurchaseComplete) {
3
//Display success purchase
4
} else if(state instanceof State.NotAvailable) {
5
//Purchase is not available on this device
6
} else if(state instanceof State.Error) {
7
//An error happened, look at state.error
8
} else if(state instanceof State.PurchaseDeferred) {
9
//Purchase was made but verification did not happen yet
10
} else {
11
//look at all possible states for the one you may want to handle
12
}
13
});
Copied!
1
try {
2
const plan = await Purchasely.purchaseWithPlanVendorId(
3
'PLAN_VENDOR_ID'
4
);
5
console.log('Purchased ' + plan);
6
} catch (e) {
7
console.log(e);
8
}
Copied!
1
Purchasely.purchaseWithPlanVendorId("PLAN_VENDOR_ID", (plan) => {
2
console.log('Purchased ' + plan);
3
}, (error) => {
4
console.log(error);
5
});
Copied!
1
try {
2
Map<dynamic, dynamic> plan =
3
await Purchasely.purchaseWithPlanVendorId('PLAN_VENDOR_ID');
4
print('Purchased $plan');
5
} catch (e) {
6
print(e);
7
}
Copied!

Restoring all products

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.restoreAllProducts(success: {
2
// Reload content and display a success / thank you message to user
3
}, failure: { (error) in
4
// Display error
5
})
Copied!
1
[Purchasely restoreAllProductsWithSuccess:^{
2
// Reload content and display a success / thank you message to user
3
} failure:^(NSError * _Nonnull) {
4
// Display error
5
}];
Copied!
1
Purchasely.restoreAllProducts(
2
success = { plan ->
3
//Restored PLYPlan succesfull
4
},
5
error = { error ->
6
//Restored failed with PLYError
7
}
8
)
Copied!
1
Purchasely.restoreAllProducts((PurchaseListener) state -> {
2
if(state instanceof State.RestorationComplete) {
3
//Display success restoration
4
} else if(state instanceof State.RestorationNoProducts) {
5
//No products to restore
6
} else if(state instanceof State.RestorationFailed) {
7
//An error happened, look at state.error
8
} else {
9
//look at all possible states for the one you may want to handle
10
}
11
});
Copied!
1
try {
2
const restored = await Purchasely.restoreAllProducts();
3
console.log('Restoration success ? ' + restored);
4
} catch (e) {
5
console.log(e);
6
}
Copied!
1
Purchasely.restoreAllProducts(() => {
2
console.log("Successfully restored");
3
}, (error) => {
4
console.log("Restoration failed: " + error);
5
});
Copied!
1
bool restored = await Purchasely.restoreAllProducts();
Copied!

Getting user subscriptions

Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.userSubscriptions(success: { (subscriptions) in
2
// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
3
// Calling unsubscribe() will either switch the user to its AppStore settings
4
// or display a procedure on how to unsubscribe on Android
5
}, failure: { (error) in
6
// Display error
7
})
Copied!
1
[Purchasely userSubscriptionsWithSuccess:^(NSArray<PLYSubscription *> * _Nullable) {
2
// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
3
// Calling unsubscribe() will either switch the user to its AppStore settings
4
// or display a procedure on how to unsubscribe on Android
5
} failure:^(NSError * _Nullable) {
6
// Display error
7
}];
Copied!
1
Purchasely.userSubscriptions(
2
onSuccess = { list ->
3
// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
4
// Calling unsubscribe() will either switch the user to its Google Play settings
5
// or display a procedure on how to unsubscribe on iOS
6
},
7
onError = { throwable ->
8
//Display error
9
}
10
)
Copied!
1
Purchasely.userSubscriptions(new SubscriptionsListener() {
2
@Override
3
public void onSuccess(@NotNull List<PLYSubscriptionData> list) {
4
// Subscription object contains the plan purchased and the source it was purchased from (iOS or Android)
5
// Calling unsubscribe() will either switch the user to its Google Play settings
6
// or display a procedure on how to unsubscribe on iOS
7
}
8
9
@Override
10
public void onFailure(@NotNull Throwable throwable) {
11
//Display error
12
}
13
});
Copied!
1
try {
2
const subscriptions = await Purchasely.userSubscriptions();
3
console.log(' ==> Subscriptions');
4
if (subscriptions[0] !== undefined) {
5
console.log(subscriptions[0].plan);
6
console.log(subscriptions[0].subscriptionSource);
7
console.log(subscriptions[0].nextRenewalDate);
8
console.log(subscriptions[0].cancelledDate);
9
}
10
} catch (e) {
11
console.log(e);
12
}
Copied!
1
Purchasely.userSubscriptions(subscriptions => {
2
console.log("Subscriptions " + subscriptions);
3
}, (error) => {
4
console.log(error);
5
}
6
);
Copied!
1
try {
2
List<PLYSubscription> subscriptions =
3
await Purchasely.userSubscriptions();
4
print(' ==> Subscriptions');
5
if (subscriptions.isNotEmpty) {
6
print(subscriptions.first.plan);
7
print(subscriptions.first.subscriptionSource);
8
print(subscriptions.first.nextRenewalDate);
9
print(subscriptions.first.cancelledDate);
10
}
11
} catch (e) {
12
print(e);
13
}
Copied!