API Operation
REST APIs are supported in two environments. Use the Sandbox environment for testing purposes, then move to the live environment for production processing. When testing, generate an order url with your test credentials to make calls to the Sandbox URIs. When you’re set to go live, use the live credentials assigned to your new signature key to generate a live order url to be used with the live URIs. Your server has to support cURL system. For HTML Form submit please review after cURL part we provide HTML Post method URL also
Live API End Point (Using cURL):
https://pay.Greenpaybd.com/checkout.php
Live API End Point (Using cURL):
https://pay.greenpaybd.com/woocommerce_checkout.php
Parameter Details
Variables Need to POST to Initialize Payment Process in gateway URL
Field Name |
Description |
Required |
Example Values |
apikey |
Api Key will be provided by Greenpaybd |
Yes |
dc0c2802bf04 |
clientkey |
Client Key will be provided by Greenpaybd |
Yes |
d2ab3336ec |
secretkey |
Secret Key will be provided by Greenpaybd |
Yes |
123456789 |
amount |
The total amount payable. Please note that you should skip the the trailing zeros in case the amount is a natural number. |
Yes |
10 or 10.50 or 10.6 |
cus_name |
Customer Full Name |
Yes |
Mr. ABC |
cus_email |
Email address of the customer who is making the payment. |
Yes |
abc@gmail.com |
success_url |
URL to which the customer will be returned when the payment is made successfully. The customer will be returned to the last page on the Merchant's website where he should be notify the payment successful. |
Yes |
https://yourdomain.com/sucess.php |
cancel_url |
URL to return customer to your product page or home page. |
Yes |
https://yourdomain.com/cancel.php |
Sample Request
Sample Request
'https://pay.greenpaybd.com/checkout.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array(
'api' => $apikey,
'client' => $clientkey,
'secret' => $secretkey,
'amount' => $amount,
'success_url' => $success_url,
'cancel_url' => $cancel_url,
'cus_name' => $cus_name,
'cus_email' => $cus_email
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
Sample Request
Sample Request
'https://pay.greenpaybd.com/checkout.php',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('api' => $apikey,'client' => $clientkey,'secret' => $secretkey,'amount' => $amount,'position' => $hostname,'success_url' => $success_url,'cancel_url' => $cancel_url,'cus_name' => $cus_name,'cus_email' => $cus_email),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
Sample Laravel Request
processPayment Method Documentation
This method handles the payment processing for a user. It validates the incoming request, creates order and payment records, and redirects the user to the payment gateway.
Parameters
- Request $request: The incoming HTTP request containing payment details.
Validation
The method validates the request to ensure the following fields are present:
- amount: Required and must be a numeric value.
- package: Required and must be a string.
Workflow
- Retrieve API Credentials: Hardcoded values for API, client, and secret.
- Generate Transaction ID: Creates a unique transaction identifier.
- Database Transaction:
- Starts a transaction to ensure data integrity.
- Creates an order record in the database.
- Creates a payment record associated with the order.
- Updates the order with the payment ID.
- Redirect to Payment URL: Constructs a payment URL and redirects the user.
- Error Handling:
- Rolls back the transaction on failure.
- Redirects with an error message if payment processing fails.
Code Example
public function processPayment(Request $request)
{
$request->validate([
'amount' => 'required|numeric',
'package' => 'required|string',
]);
$api = '2545345A';
$client = 'AFFSDFSDF';
$secret = 'DSFSDF';
$amount = $request->input('amount');
$customer = auth()->user()->name;
$customerEmail = auth()->user()->email;
$successUrl = route('successPage', ['package' => $request->input('package'), 'amount' => $amount]);
$cancelUrl = route('greenpay.cancel');
// Generate a unique transaction ID
$transactionId = uniqid();
// Initialize notification variable
$notification = [];
DB::beginTransaction(); // Start the transaction
try {
// Create the order
$order = Order::create([
'user_id' => auth()->id(),
'package_type' => $request->input('package'),
'amount' => $amount,
'payment_status' => 'pending',
'transaction_id' => $transactionId,
]);
session(['payment_idx' => $order->id]);
// Create payment record
$payment = Payment::create([
'order_id' => $order->id,
'user_id' => auth()->id(),
'amount' => $amount,
'payment_status' => 'pending',
'package_type' => $request->input('package'),
'transaction_id' => $transactionId,
]);
// Update the order with the payment ID
$order->update(['payment_id' => $payment->id]);
// Commit the transaction
DB::commit();
// Redirect to payment URL
$paymentUrl = "https://pay.greenpaybd.com/woocommerce_checkout.php?api=$api&client=$client&secret=$secret&amount=$amount&position=https://gstopup.com&success_url=$successUrl&cancel_url=$cancelUrl&cus_name=" . urlencode($customer) . "&cus_email=" . urlencode($customerEmail);
$notification = [
'message' => 'Payment record created successfully.',
'alert-type' => 'success'
];
return redirect()->away($paymentUrl)->with($notification);
} catch (\Exception $e) {
// Rollback the transaction if something went wrong
DB::rollback();
// Set failure notification
$notification = [
'message' => 'Payment process failed: ' . $e->getMessage(),
'alert-type' => 'error'
];
return redirect()->route('buy.package')->with($notification);
}
}
successPage Method Documentation
This method handles the successful verification of a payment transaction. It updates the order and payment records and manages the user's package credits.
Parameters
- Request $request: The incoming HTTP request containing transaction details.
Workflow
- Retrieve Transaction Details: Extracts
transactionId
, paymentAmount
, and paymentFee
from the query parameters.
- Verify Payment: Sends a request to the payment gateway for verification.
-
Check Verification Response:
- If successful, process the payment.
- If failed, redirect with an error message.
-
Database Transaction:
- Starts a transaction to ensure data integrity.
- Updates order and payment records.
- Inserts the user's package plan and updates credits.
- Commit or Rollback: Commits if successful, rolls back on failure.
- Redirect: Redirects the user with a success message or error.
Error Handling
The method provides feedback to the user in case of errors during the purchase process.
Code Example
public function successPage(Request $request)
{
// Retrieve the transaction ID and other details from the query parameters
$transactionId = $request->query('transactionId');
$paymentAmount = $request->query('paymentAmount');
$paymentFee = $request->query('paymentFee');
// Verify the transaction using the API
$response = Http::asForm()->post('https://pay.greenpaybd.com/verify.php', [
'transaction_id' => $transactionId
]);
// Check if the response is successful and valid
if ($response->successful() && $response->body() == 1) {
$paymentId = session()->get('payment_idx');
if ($paymentId) {
DB::beginTransaction(); // Start the transaction
try {
$order = Order::find($paymentId);
if ($order) {
// Update order payment status
$order->payment_status = 'completed';
$order->transaction_id = $transactionId;
$order->save(); // Save the order details
// Update the corresponding payment record
$payment = Payment::where('order_id', $order->id)->first();
if ($payment) {
$payment->payment_status = 'completed';
$payment->transaction_id = $transactionId;
$payment->save();
}
// Insert the package plan for the user
PackagePlan::insert([
'user_id' => auth()->id(),
'package_name' => $order->package_type,
'package_credits' => $this->getCreditsForPackage($order->package_type),
'invoice' => 'ERS' . mt_rand(10000000, 99999999),
'package_amount' => $order->amount,
'created_at' => now(),
]);
// Optional: Update user credits if necessary
$user = auth()->user();
$creditsToAdd = $this->getCreditsForPackage($order->package_type);
$user->credit += $creditsToAdd;
$user->save();
}
// Clear the session payment index
session()->forget('payment_idx');
DB::commit(); // Commit the transaction
$notification = [
'message' => 'You have purchased the Professional Package Successfully',
'alert-type' => 'success'
];
return redirect()->route('agent.dashboard')->with($notification);
} catch (\Exception $e) {
DB::rollback(); // Rollback the transaction if something went wrong
return redirect()->route('buy.pack')->withErrors(['error' => 'An error occurred while processing your purchase.']);
}
}
} else {
return redirect()->route('buy.pack')->withErrors(['error' => 'Payment verification failed']);
}
}
public function cancel()
{
return view('payment.cancel');
}
Payment Routes Documentation
This section outlines the routes related to payment processing in the Laravel application. Each route is associated with a specific method in the PaymentController
.
Routes Overview
-
POST /process-payment:
This route handles the payment processing request.
Method: processPayment
Route Name: payment.process
-
GET /success:
This route is triggered when a payment is successfully completed.
Method: successPage
Route Name: successPage
-
GET /cancel:
This route is triggered when a payment is canceled by the user.
Method: cancel
Route Name: greenpay.cancel
Route Definitions
// Web.php Route
Route::post('/process-payment', [PaymentController::class, 'processPayment'])->name('payment.process');
Route::get('/success', [PaymentController::class, 'successPage'])->name('successPage');
Route::get('/cancel', [PaymentController::class, 'cancel'])->name('greenpay.cancel');
Download Module-->
-->
Download Module-->
Download Module-->
Download Module-->
-->
Woocomerce Plugin 1.6 - Ecommerce Type Website
See Setup Video: Youtube Video
Woocomerce Plugin 1.6 - Digital Product Selling Type Website
See Setup Video: YouTube Video
SmmPanel Module (DREAM PANEL All Panel Supported) 1.8
See Setup Video: Video here/
SmmPanel Module (Perfect Panel) 1.5
See Setup Video: Video Here