dubems / paystack-grails

Paystack Payment API Implementation in Groovy/Grails

Home Page:https://paystack.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:1.0.5'

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.getAuthUrl(params)
        redirect(url:authUrl)
    }
  }
  • Handle Paystack callback
  • params(paystack calls ur method with a reference parameter)
    def handlePaystackCallback(){
       final String reference = params.get('reference') // reference from paystack webhook
        Map<String, String> paymentDetails =  paystackService.getPaymentData(reference)
         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.

About

Paystack Payment API Implementation in Groovy/Grails

https://paystack.com/

License:Apache License 2.0


Languages

Language:Groovy 85.6%Language:Shell 9.5%Language:Batchfile 4.8%