Code Monkey home page Code Monkey logo

chapa-in-app-purchase's Introduction

Chapa-In-App-Purchase

Unoffical Android In-App Purchase Library using Chapa

View Documentation

Download Sample App

Getting Started

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.1'
    ...
}

Initialize Configuration

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

val config = ChapaConfiguration()
config.key = "YOUR-CHAPA-SECRET-KEY" // (Required)
// for security purpose it is better to use encrypt key
// to get encrypted key use Cipher class,
// Log.d("Chapa-key",Cipher.encrypt(this,"YOUR CHAPA-SECRET-KEY"))
// config.key = Cipher.decrypt(this, "DECRYPTED_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","[email protected]") (Optional)  Dialog will show to customer, to fill their infomation
// config.customization = Customization("title","description","logo-url")

Chapa.init(applicationContext, config)

Basic Usage

Step 4 : To process simple basic payment

// 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
 }

})

chapa-in-app-purchase's People

Contributors

yosefw1221 avatar

Stargazers

 avatar

chapa-in-app-purchase's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.