Giter Site home page Giter Site logo

nextbss / proxypay-kotlin Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 2.0 482 KB

A Java/Kotlin library to access and interact with the ProxyPay API

Kotlin 100.00%
ango-dev-fest-2020 hacktoberfest proxypay payment-reference proxypay-api payment-integration payment-sdk-angola angola

proxypay-kotlin's Introduction

ProxyPay

A Kotlin / Java library that helps you easily interact with the ProxyPay API

Usage

Download

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file

maven

<repositories>
	<repository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</repository>
</repositories>

gradle

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

maven

<dependency>
	    <groupId>com.github.nextbss</groupId>
	    <artifactId>proxypay-kotlin</artifactId>
	    <version>1.0.2</version>
</dependency>

gradle

dependencies {
	implementation 'com.github.nextbss:proxypay-kotlin:1.0.2'
}

Configuring Authorization and environment

To interact with ProxyPay you will need to define the environment to interact with and the api key for authentication.

You have at your disposal two environments: SANDBOX and PRODUCTION

Using the SANDBOX Environment

    ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

Using the PRODUCTION Environment

    ProxyPayConfig.configure(Environment.PRODUCTION, "YOUR_API_KEY")

Get Payment References

Returns any Payment events stored on the server that were not yet Acknowledged

    ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

    val proxyPay = ProxyPayReference.ProxyReferenceBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .build()

    proxyPay.getPayments(object : TransactionCallback<List<ReferencesResponse>> {
        override fun onSuccess(response: List<ReferencesResponse>) {
            println(response)
        }

        override fun onFailure(error: String) {
            println(error)
        }
    })

Get Payments

Returns any Payment events stored on the server that were not yet Acknowledged by the client application. Optional argument: Specify the amount of references (between 1 and 100), defaults to 100.

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")
    val proxyPay = ProxyPayReference.ProxyReferenceBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .build()

    proxyPay.getPayments(object : TransactionCallback<List<ReferencesResponse>> {
        override fun onSuccess(response: List<ReferencesResponse>) {
            println(response)
        }

        override fun onFailure(error: String) {
            println(error)
        }
    }, 10)

Create Reference Id

The generateReferenceId() method allows the generation of a Reference Id

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

val proxyPay = ProxyPayPayment.PaymentTransactionBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .build()

proxyPayPayment?.generateReferenceId(object: TransactionCallback<String> {
        override fun onSuccess(response: String) {
            println(response)
        }

        override fun onFailure(error: String) { println(error) }
    })

Create Payment Reference

The generateReference method creates or updates a payment reference with given Id

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

val customFields = CustomFields()
    customFields.app_description = "YOUR APP DESCRIPTION"
    customFields.invoice = "YOUR_INVOICE_NUMBER"
    customFields.order_number = "YOUR_ORDER_NUMBER"
    customFields.proposal_number = "YOUR_PROPOSAL_NUMBER"

    val request = PaymentReferenceRequest()
    request.amount = "3000.00"
    request.custom_fields = customFields
    request.expiry_date = "10-09-2019"

val proxyPay = ProxyPayPayment.PaymentTransactionBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .addReferenceRequest(request)
        .build()

proxyPayPayment?.generateReference(object: TransactionCallback<String> {
        override fun onSuccess(response: String) { 
            println(response)
        }

        override fun onFailure(error: String) { 
            println(error)
        }
    }, referenceId)

Delete a reference with a given id

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

val proxyPay = ProxyPayPayment.PaymentTransactionBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .build()

proxyPayPayment?.deleteReference(object : TransactionCallback<String> {
        override fun onSuccess(response: String) {
            println(response)
        }

        override fun onFailure(error: String) {
            println(error)
        }
    }, referenceId)

Acknowledge a payment

This method is used to acknowledge that a payment was processed

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

val proxyPay = ProxyPayPayment.PaymentTransactionBuilder()
        .addProxyPayConfiguration(ProxyPayConfig.getInstance())
        .build()
        
    proxyPayPayment?.acknowledgePayment(object: TransactionCallback<String> {
            override fun onSuccess(response: String) {
                println(response)
            }
    
            override fun onFailure(error: String) {
                println(error)
            }
        }, referenceId)

Create a mock payment

This is only available on the Sandbox environment and produces a simulated Payment event, as if originated directly from Multicaixa. This will trigger a call to the Webhook, if configured. Otherwise the Payment will be available through a call to Get Payments.

ProxyPayConfig.configure(Environment.SANDBOX, "YOUR_API_KEY")

val mockPaymentRequest = MockPaymentRequest("2000.00", "841520000")

val proxyPay = ProxyPayPayment.PaymentTransactionBuilder()
            .addProxyPayConfiguration(ProxyPayConfig.getInstance())
            .addMockPaymentRequest(mockPaymentRequest)
            .build()

    proxyPay.mockPayment(object: TransactionCallback<MockPaymentResponse> {
        override fun onSuccess(response: MockPaymentResponse) {
            println(response.toString())
        }

        override fun onFailure(error: String) {
            println("Failure occurred: $error")
        }
    })

License

The library is available as open source under the terms of the MIT License.

proxypay-kotlin's People

Contributors

alexjuca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.