Paystack Payment API Implementation in Groovy/Grails
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gradle/wrapper
grails-app
src
.gitignore
LICENSE
Readme.md
build.gradle
gradle.properties
gradlew
gradlew.bat
grails-wrapper.jar
grailsw
grailsw.bat

Readme.md

Grails Paystack Plugin

A Grails plugin to allow communication to paystack API

Installation

Add the below line to your build.gradle file

compile 'org.grails.plugins:paystack-grails:0.3.2'

Configuration

Include Paystack keys(in application.yml) gotten from your dashboard as follows
paystack: 
    liveSecretKey: '${PAYSTACK_LIVE_SECRET_KEY}'
    testSecretKey: '${PAYSTACK_TEST_SECRET_KEY}'
    livePublicKey: '${PAYSTACK_LIVE_PUBLIC_KEY}'
    testPublicKey: '${PAYSTACK_TEST_PUBLIC_KEY}'
    endpoint:      'https://api.paystack.co'

Usage

  • Make Payment Request
  • params
    • email (required)
    • amount (required)
    • plan
    • first_name
    • last_name
    • metadata
    • callback_url
class TestController {

    PaystackService paystackService

    def index() { }

    def makePaymentRequest(){
        String authUrl =  paystackService.validate(params).getAuthUrl(params)
        redirect(url:authUrl)
    }
    }
  • Handle Paystack callback
  • params(paystack calls ur method with a reference parameter)
    def handlePaystackCallback(){
        def paymentDetails =  paystackService.getPaymentData(params)
         println($paymentDetails)
        // Now you have the payment details,
        // you can store the authorization_code in your db to allow for recurrent subscriptions
        // you can then redirect or do whatever you want
    }
  • Other useful methods that implement Paystack endpoints can be found below
  • NB: Methods not listed below can be found in the PaystackService Class
    // Injecting PaystackService 
    PaystackService paystackService
    
    /**
     * Return all customers on your Paystack account
     * @returns Map
     */
    paystackService.getAllCustomers()
    
     /**
     * Return all transactions on Your Paystack account
     * @returns Map
     */
    paystackService.listTransactions()

     /**
     * Fetch a particular transaction
     * @param  int id : identifier of transaction to fetch
     * @return Map
     */
    paystackService.fetchTransaction(id)
    
    /**
     * Return a single customer given its id
     * @param customerId
     * @return Map
     */
    paystackService.fetchCustomer(customerId)
    
    /**
     * Return all plans on your paystack account
     * @return Map
     */
    paystackService.getAllPlans()
        
    /**
     * Get a particular plan given the plan id
     * @param planId
     * @return Map
     */
    paystackService.fetchPlan(planId)
    

TODO

  • Complete All Api calls
  • Write Unit tests

CONTRIBUTING

  • Fork the repository, make necessary changes and send the PR.