App Payment
It is a payment type that allow you to charge your customers to use your app.
Features:
Secure
: Payment information is encrypted withAES-256
algorithm using device unique id.Payment per Device
: although its encrypted with device id one Payment is only valid for one device.Multiple App Plan
: you can setup multiple plan for your app. e.g.Premium
,Standard
, etc.Restore Purchase
: The user doesn't repay for the same app and the same plan in case the user reinstalls the app.
Setup App Payment
Only premium feature
It's for App's that requires user to purchase to use it's content/feature.
Step 1: Create PaymentActivity
class and change to launcher activity in AndroidManifest.xml
MainActivity
is the activity that will be launched after payment is successful.
<activity
android:name=".PaymentActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
Step 2: In PaymentActivity
class
// create your own app plan
AppPayment premiumPlan = new AppPayment(/* activity context */ this,/* amount */ 19.99, "Premium", MainActivity.class);
try {
Chapa chapa = Chapa.getInstance();
// simply call pay method without callback
chapa.pay(this, premiumPlan);
// or with callback
// chapa.pay(this, premiumPlan, new ChapaPaymentCallback<AppPayment>() {
// @Override
// public void onSuccess(@NonNull String tx_ref, @NonNull AppPayment paymentType) {
// // TODO your code here
// }
// @Override
// public void onError(@NonNull ChapaError chapaError) {
// // TODO your code here
// }
// @Override
// public void onCancel() {
// // TODO your code here
// }
// });
} catch (ChapaError e) {
// CHAPA_NOT_INITIALIZED error
}
// create your own app plan
val premiumPlan = AppPayment(/* activity context */ this,/* amount */ 19.99, "Premium", MainActivity::class.java)
val chapa = Chapa.getInstance()
// simply call pay method without callback
chapa.pay(this,premiumPlan)
// or with callback
//chapa.pay(this,premiumPlan,object : ChapaPaymentCallback<AppPayment>{
// override fun onSuccess(tx_ref: String, paymentType: AppPayment) {
// // TODO your code here
// }
// override fun onError(chapaError: ChapaError) {
// // TODO your code here
// }
// override fun onCancel() {
// // TODO your code here
// }
//})
Both premium and freemium feature
It's for App's that has both free and paid feature.
Step 1: Simply create AppPayment
object as below without appMainActivity
parameter
// create your own app plan
AppPayment premiumPlan = new AppPayment(/* activity context */ this,/* amount */ 19.99, "Premium");
try {
Chapa chapa = Chapa.getInstance();
// simply call pay method without callback
// chapa.pay(this, premiumPlan);
// or with callback
chapa.pay(this, premiumPlan, new ChapaPaymentCallback<AppPayment>() {
@Override
public void onSuccess(@NonNull String tx_ref, @NonNull AppPayment paymentType) {
// TODO your code here
}
@Override
public void onError(@NonNull ChapaError chapaError) {
// TODO your code here
}
@Override
public void onCancel() {
// TODO your code here
}
});
} catch (ChapaError e) {
// CHAPA_NOT_INITIALIZED error
}
val premiumPlan = AppPayment(/* context */ this,/* amount */ 19.99, "Premium")
val chapa = Chapa.getInstance()
// simply call pay method without callback
// chapa.pay(this,premiumPlan)
// or with callback
chapa.pay(this,premiumPlan,object : ChapaPaymentCallback<AppPayment>{
override fun onSuccess(tx_ref: String, paymentType: AppPayment) {
// TODO your code here
}
override fun onError(chapaError: ChapaError) {
// TODO your code here
}
override fun onCancel() {
// TODO your code here
}
})
Retrieve Payment Plan
To retrieve payment plan you need to call getPaymentPlan
method
// returns users payment plan if user has paid for your app otherwise returns null
String userPlan = Chapa.getCurrentUserAppPlan();
/**
* Checks if current user plan is in the given plan list
*
* @param plans app plan(s) to be checked in
* @return true if current user app plan is in the given app plan list or if you pass null it checks user is a premium user of any app plan
*/
boolean hasAccess = ChapaUtil.isCurrentPlanIn("Premium","Standard")
//boolean isStandardPlan = ChapaUtil.isCurrentPlanIn("Standard")
// returns users payment plan if user has paid for your app otherwise returns null
val userPlan = Chapa.getCurrentUserAppPlan()
/**
* Checks if current user plan is in the given plan list
*
* @param plans app plan(s) to be checked in
* @return true if current user app plan is in the given app plan list or if you pass null it checks user is a premium user of any app plan
*/
val hasAccess = ChapaUtil.isCurrentPlanIn("Premium","Standard")
//val isStandardPlan = ChapaUtil.isCurrentPlanIn("Standard")