Skip to content

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

Notifications You must be signed in to change notification settings

nextbss/proxypay-kotlin

Repository files navigation

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.