Add the below line to your build.gradle file
compile 'org.grails.plugins:paystack-grails:1.0.5'
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'
- Note:Make sure to have your webhook registered in paystack dashboard.
eg: http://paystack.dev/test/handlePaystackCallback
where:
- "test" is the controller name
- "handlePayStackCallback" is the method name
- 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)
- Complete All Api calls
- Write Unit tests
- Fork the repository, make necessary changes and send the PR.