Welcome to nextpay-kt ?

Version

Documentation


License: MIT


Twitter: iarcxxi

Connect to NextPay.ir payment gateway in easy way.

? Homepage

Setup

Kotlin KTS

1- Add mavenCentral() to your repositories section of build.gradle.kts

repositories {
    mavenCentral()
}

2- Add dependency to your project.

dependencies {
    implementation("dev.falhad:nextpay:1.0.2")
}

Groovy

1- Add maven() to your repositories section of build.gradle.kts

repositories {
    maven()
}

2- Add dependency to your project.

dependencies {
    implementation 'dev.falhad:nextpay:1.0.2'
}

? Basic Usage

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

Initialize Nextpay-KT

val nextPay = NextPay(apiKey = NEXTPAY_API_KEY, logging = false)

Step 1 – Generate Token

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

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

  • you also can modify autoVerify, currency, customerPhone, allowedCard and customJsonFields if you needed.
  • If you set autoVerify = true the transaction will be auto verify, and you don’t need to verify the transaction
    manually.

Step 2 – Verify/Reject 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

nextPay.verifyPayment("tranId", 1000)
    .fold({ response ->
        println("payment verified.\n$response")
    }, { error ->
        when (error) {
            is NextPayException -> println("${error.msg} | ${error.code}")
            else -> println("something went wrong. ${error.message}")
        }
    })

Reject Payment

    nextPay.rejectPayment("tranId", 1000)
    .fold({ response ->
        println("payment rejected.\n$response")
    }, { error ->
        when (error) {
            is NextPayException -> println("${error.msg} | ${error.code}")
            else -> println("something went wrong. ${error.message}")
        }
    })

Checkout / Other Apis

See Nextpay-KT Wiki for docs and more examples.

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

GitHub

View Github