Skip to content

falhad/idpay-kt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IDPay Logo

Welcome to IDPay-kt 👋

Version Documentation License: MIT Twitter: iarcxxi

Connect to IDPay.ir payment gateway from Kotlin/Java code base in easy way.

Setup

we ⚡ Replace $idpayKTVersion with the latest version in Maven Repository or Maven Central.

Kotlin (build.gradle.kts)

1- Add mavenCentral() to your repositories section of build.gradle.kts if not already exists.

repositories {
    mavenCentral()
}

2- Add dependency to your project.

dependencies {
    implementation("dev.falhad:idpay:$idpayKTVersion")
}

Groovy

1- Add maven() to your repositories section of build.gradle if not already exists.

repositories {
    maven()
}

2- Add dependency to your project.

dependencies {
    implementation 'dev.falhad:idpay:$idpayKTVersion'
}

🚀 Basic Usage

If you are not familiar with the transaction processing flow its good to see IDPay.ir documents first.

Initialize IDPay-KT

val idPay = IDPay(apiKey = IDPAY_API_KEY, sandbox = true, logging = false)

Step 1 - Generate Token

idPay
    .requestToken("your-order-id", 1000, "your-website-callback-api")
    .fold(onSuccess = { response ->
        println("hooray! transaction (${response.id} generated.")
        println("redirect user to ${response.link}")
    }, onFailure = { error ->
        when (error) {
            is IDPayException -> println("${error.msg} | ${error.code}")
            else -> println("something went wrong. ${error.message}")
        }
    })

You may want to save id, orderId and amount for prevent Double-spending problem.

Step 2 - Verify Payment

If you set autoVerify to false in step 1 you should verify the transaction within 10 minutes or transaction will be reverted automatically.

Verify Payment

idPay.verify("id", "orderId")
    .fold({ response ->
        println("payment verified.\n$response")
    }, { error ->
        when (error) {
            is IDPayException -> println("${error.msg} | ${error.code}")
            else -> println("something went wrong. ${error.message}")
        }
    })

Author

👤 Farhad Navayazdan

Show your support

Give a ⭐️ if this project helped you!

My Public Address to Receive USDT (TRC20) is TQ43UdYtFAHQCNVciNCd9ndE4TQaMMzboX

📝 License

Copyright © 2021 Farhad Navayazdan.

This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

About

IDPay Kotlin SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages