Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,993,321 members, 7,292,707 topics. Date: Monday, 06 February 2023 at 01:02 PM

How To Integrate Paystack Payment Gateway In Website Using PHP and Mysql - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How To Integrate Paystack Payment Gateway In Website Using PHP and Mysql (554 Views)

Five Important Rules In Website Design / Drupal: How To Integrate Bulk SMS To Work In Website? / What Is The Best Online Payment Gateway In Nigeria? (2) (3) (4)

(1) (Reply)

How To Integrate Paystack Payment Gateway In Website Using PHP and Mysql by mavigold: 10:23pm On Feb 06, 2022
How to integrate Paystack payment gateway in Website Using PHP and save in database
What is Paystack?
Paystack is an African payment gateway used by enterprises to accept payments from their customers. It is one of the most popular payment gateways in Africa, especially in Nigeria, Ghana and Kenya. It assists most E-commerce platforms, Educational Organizations and lots more to accept payment from their customers.

To seamlessly integrate Paystack into PHP Applications, we must ensure our environment has the following in place:
Paystack Account.
Your Paystack account public key.
A little knowledge of HTML, CSS & JavaScript
Step 1: Sign Up with Paystack

The first thing is to register your business account on Paystack’s website and verify your sign up using a verification link sent to your email. The next thing is to sign in to your new Paystack account. On your dashboard you will find your public and secret key. We will make use of the public and secret key for this tutorial.
Step 2: Creating Our HTML, CSS Files

Our HTML file will be the markup for our checkout page where customer pays for our product. This page will display the summary of what the customer purchased with a pay button. We also link our CSS and JavaScript file.

The key element in our index. html file is the Pay Button with on-click attribute that triggers our JavaScript function payWithPaystack() .

CheckOut with Paystack

We also link the Paystack’s javascript library and our own javascript to this html file.

Like this:

">">https://js.paystack.co/v1/inline.js">;

You can find the structure of the checkout for and Css styles in the Source Code after Download
Step 3: Creating Our JavaScript File

JavaScript is is very important when connecting your website with paystack.

Lets create our payWithPaystack() function. This function is were we finalize our payment setup before calling the Paystack’s payment modal.

Setup includes adding your public key, your customer’s email, phone number and the amount the customer is supposed to pay.
Remember to add/replace your own Paystack public key

const paymentForm = document.getElementById('paymentForm');

paymentForm.addEventListener("submit", payWithPaystack, false);

function payWithPaystack(e) {

e.preventDefault();

let handler = PaystackPop.setup({

key: 'pk_live_4446f9704a9a592421a27cc0cd131f9dc0a982d5', // Replace with your public key

email: document.getElementById("email"wink.value,

amount: document.getElementById("amount"wink.value * 100,

firstname: document.getElementById("firstname"wink.value,

lastname: document.getElementById("lastname"wink.value,

ref: 'VS'+Math.floor((Math.random() * 1000000000) + 1), // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you

// label: "Optional string that replaces customer email"

onClose: function(){

window.location = "index.php?transaction=cancel";

alert('Transaction Cancelled.');

},

callback: function(response){

let message = 'Payment complete! Take note of your Access Code: ' + response.reference;

alert(message);

window.location = "verify_transaction.php?reference=" + response.reference;

}

});

handler.openIframe();

}



Lets talk about callback function. Inside this function is where we check if a customer was charged successfully or not by sending jquery post request using the transaction reference. Every transaction has its own unique key generated by the Paystack API. This callback function can be found in the verify_transaction.php file.

After the Payment is successful. we will save the Payment information retrieved from Paystack in the database.


Link to the Source Code: https://mavigoldsolutions.com/article/5/how-to-integrate-paystack-payment-gateway-in-website-using-php-and-verify-payment-transaction

(1) (Reply)

When Will Google Adsense Pay Me / How To Make Money Online Easily! / How To Use A Webhost

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2023 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.