Getting Started

Welcome, This guide will help you to get started with Unofficial Chapa In-App Purchase Android Library.

Installation

minSdk : 19

Step 1 : Open setting.gradle file add maven jetpack repository:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}





 


Step 2 : On your build.gradle file add the following dependency:

dependencies {
    implementation 'com.github.yosefw1221:Chapa-In-App-Purchase:1.0.0-beta'
    ...
}

 


Initialize Configuration

Step 2 : Initialize chapa configuration on your app's MainActivity or Application class

ChapaConfiguration config = new ChapaConfiguration();
config.setKey("YOUR-CHAPA-SECRET-KEY"); // (Required)
// for security purpose it is better to use encrypted key
// to get encrypt key use Cipher class,
// Log.d("Chapa-key",Cipher.encrypt(this,"YOUR-CHAPA-SECRET-KEY"))
// config.key = Cipher.decrypt(this, "ENCRYPTED_CHAPA-SECRET-KEY")

config.setCurrency(Currency.ETB); // Currency.USD --Default ETB

// config.setCallbackUrl("https://example.com/api/callback");  (Optional)

// config.setCustomer(new Customer("first_name","last_name","example@mail.com")); (Optional)  Dialog will show to customer, to fill their infomation
// config.setCustomization(new Customization("title","description","logo-url"));

Chapa.init(getApplicationContext(), config);
val config = ChapaConfiguration()
config.key = "YOUR-CHAPA-SECRET-KEY" // (Required)
// for security purpose it is better to use encrypted key
// to get encrypt key use Cipher class,
// Log.d("Chapa-key",Cipher.encrypt(this,"YOUR CHAPA-SECRET-KEY"))
// config.key = Cipher.decrypt(this, "ENCRYPTED_CHAPA-SECRET-KEY")
config.currency = Currency.ETB // Currency.USD --Default ETB

// config.callbackUrl = "https://example.com/api/callback"  (Optional)

// config.customer = Customer("first_name","last_name","example@mail.com") (Optional)  Dialog will show to customer, to fill their infomation
// config.customization = Customization("title","description","logo-url")

Chapa.init(applicationContext, config)

Basic Usage

Step 3 : To process simple basic payment

try {
    // get chapa instance
   Chapa chapa = Chapa.getInstance();
   // setup basic payment type
   BasicPayment basicPayment = new BasicPayment(/*amount*/ 9.99);
   chapa.pay(/* activityContext */ this, basicPayment, new ChapaPaymentCallback<BasicPayment>() {

     /**
       * Called when payment is successful
       *
       * @param paymentType PaymentType object
       * @param tx_ref      Transaction reference of the payment
       */

       @Override
       public void onSuccess(@NonNull String tx_ref, @NonNull BasicPayment paymentType) {
          // TODO your code here          
       }

    /**
      * Called when error occurred in payment
      */
       @Override
       public void onError(@NonNull ChapaError chapaError) {
          // TODO your code here
        }

       @Override
       public void onCancel() {
          // TODO your code here
       }
  });
} catch (ChapaError e) {
   // throws CHAPA_NOT_INITIALIZED if chapa is not initialized
}
// get chapa instance
val chapa = Chapa.getInstance()
// setup basic payment type
val basic = BasicPayment( /*amount*/ 9.99)

chapa.pay(/* activityContext */ this, basic, object : ChapaPaymentCallback<BasicPayment> {

 /**
  * Called when payment is successful
  *
  * @param paymentType PaymentType object
  * @param tx_ref      Transaction reference of the payment
  */
 override fun onSuccess(tx_ref: String, paymentType: BasicPayment) {
  // TODO your code here
 }

 /**
  * Called when error occurred in payment
  */
 override fun onError(chapaError: ChapaError) {
  // TODO your code here
 }

 /**
  * Called when payment is canceled
  */
 override fun onCancel() {
  // TODO your code here
 }

})