migrate to gtea from bistbucket
This commit is contained in:
204
app/Library/Flutterwave.php
Normal file
204
app/Library/Flutterwave.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
class Flutterwave
|
||||
{
|
||||
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/flutterwave');
|
||||
}
|
||||
return url('payment/flutterwave');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
|
||||
$data['secret_key'] = $array['secret_key'];
|
||||
$data['public_key'] = $array['public_key'];
|
||||
$data['payment_options'] = $array['payment_options'];
|
||||
$data['encryption_key'] = $array['encryption_key'];
|
||||
$data['payment_mode'] = 'flutterwave';
|
||||
$mode = $array['mode'];
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
$data['is_fallback'] = $array['is_fallback'] ?? 0;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
|
||||
Session::put('flutterwave_credentials', $data);
|
||||
|
||||
if ($mode == true) {
|
||||
$url = 'https://api.flutterwave.com/v3/payments';
|
||||
} else {
|
||||
$url = 'https://api.flutterwave.com/v3/payments';
|
||||
}
|
||||
|
||||
$logo = asset(get_option('general')['admin_logo'] ?? 'assets/images/logo/backend_logo.png');
|
||||
|
||||
try {
|
||||
$params = [
|
||||
"tx_ref" => Str::random(10),
|
||||
"currency" => $data['currency'],
|
||||
"amount" => $amount,
|
||||
"payment_options" => $data['payment_options'],
|
||||
"redirect_url" => Flutterwave::fallback(),
|
||||
"customer" => [
|
||||
"email" => $data['email'],
|
||||
"phonenumber" => $data['phone'],
|
||||
"name" => $data['name'],
|
||||
],
|
||||
"customizations" => [
|
||||
"title" => $data['billName'],
|
||||
"description" => "",
|
||||
"logo" => $logo,
|
||||
],
|
||||
];
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $data['secret_key'],
|
||||
])->post($url, $params);
|
||||
|
||||
$responseData = $response->json();
|
||||
|
||||
if (isset($responseData['status']) && in_array($responseData['status'], ['success', 'successful']) && isset($responseData['data']['link'])) {
|
||||
$url = $responseData['data']['link'];
|
||||
|
||||
return request()->expectsJson() ?
|
||||
$url : redirect($url);
|
||||
} else {
|
||||
Session::forget('flutterwave_credentials');
|
||||
return request()->expectsJson() ?
|
||||
Flutterwave::redirect_if_payment_faild() :
|
||||
redirect(Flutterwave::redirect_if_payment_faild());
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Session::forget('flutterwave_credentials');
|
||||
return request()->expectsJson() ?
|
||||
Flutterwave::redirect_if_payment_faild() :
|
||||
redirect(Flutterwave::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
if (!Session::has('flutterwave_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
$response = Request()->all();
|
||||
$payment_id = $response['transaction_id'] ?? $response['tx_ref'];
|
||||
$info = Session::get('flutterwave_credentials');
|
||||
$cred['secret_key'] = $info['secret_key'];
|
||||
$cred['payment_id'] = $payment_id;
|
||||
|
||||
$status = Flutterwave::isfraud($cred);
|
||||
if ($status == 1) {
|
||||
|
||||
$data['payment_id'] = $payment_id;
|
||||
$data['payment_method'] = "flutterwave";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
|
||||
Session::forget('flutterwave_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Flutterwave::redirect_if_payment_success() :
|
||||
redirect(Flutterwave::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('flutterwave_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Flutterwave::redirect_if_payment_faild() :
|
||||
redirect(Flutterwave::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public static function isfraud($cred)
|
||||
{
|
||||
$secret_key = $cred['secret_key'];
|
||||
$payment_id = $cred['payment_id'];
|
||||
try {
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => "https://api.flutterwave.com/v3/transactions/" . $payment_id . "/verify",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer " . $secret_key,
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
$arr = json_decode($response, true);
|
||||
return $arr['status'] === "success" ? 1 : 0;
|
||||
} catch (Throwable $th) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
188
app/Library/Instamojo.php
Normal file
188
app/Library/Instamojo.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Instamojo
|
||||
{
|
||||
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/instamojo');
|
||||
}
|
||||
return url('payment/instamojo');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$regex = "/^(0|91|\+91)?[789]\d{9}$/";
|
||||
if ($array['phone'] == "") {
|
||||
return redirect()->back()->with('warning', 'Phone Number not given!')->with('type', 'alert-danger');
|
||||
}
|
||||
if (!preg_match($regex, $array['phone'])) {
|
||||
return redirect()->back()->with('warning', 'Phone Number not valid!')->with('type', 'alert-danger');
|
||||
}
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
|
||||
$mode = $array['mode'];
|
||||
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['x_auth_token'] = $array['x_auth_token'];
|
||||
$data['x_api_key'] = $array['x_api_key'];
|
||||
$data['payment_mode'] = 'instamojo';
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
Session::put('instamojo_credentials', $data);
|
||||
|
||||
if ($mode == true) {
|
||||
$url = 'https://test.instamojo.com/api/1.1/payment-requests/';
|
||||
} else {
|
||||
$url = 'https://www.instamojo.com/api/1.1/payment-requests/';
|
||||
}
|
||||
|
||||
try {
|
||||
$params = [
|
||||
'purpose' => $data['billName'],
|
||||
'amount' => $amount,
|
||||
'phone' => $data['phone'],
|
||||
'buyer_name' => $name,
|
||||
'redirect_url' => Instamojo::fallback(),
|
||||
'send_email' => true,
|
||||
'send_sms' => true,
|
||||
'email' => $email,
|
||||
'allow_repeated_payments' => false,
|
||||
];
|
||||
$response = Http::asForm()->withHeaders([
|
||||
'X-Api-Key' => $data['x_api_key'],
|
||||
'X-Auth-Token' => $data['x_auth_token'],
|
||||
])->post($url, $params);
|
||||
|
||||
if (isset($response['payment_request'])) {
|
||||
$url = $response['payment_request']['longurl'];
|
||||
return redirect($url);
|
||||
} else {
|
||||
Session::flash('error', $response->reason());
|
||||
Session::forget('instamojo_credentials');
|
||||
return redirect(Instamojo::redirect_if_payment_faild());
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
Session::flash('error', $th->getMessage());
|
||||
Session::forget('instamojo_credentials');
|
||||
return redirect(Instamojo::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
if (!Session::has('instamojo_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
$response = Request()->all();
|
||||
$payment_id = $response['payment_id'];
|
||||
$info = Session::get('instamojo_credentials');
|
||||
|
||||
if ($response['payment_status'] == 'Credit') {
|
||||
$data['payment_id'] = $payment_id;
|
||||
$data['payment_method'] = "instamojo";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
|
||||
Session::forget('instamojo_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
|
||||
return redirect(Instamojo::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('instamojo_credentials');
|
||||
return redirect(Instamojo::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public static function isfraud($creds)
|
||||
{
|
||||
$payment_id = $creds['payment_id'];
|
||||
$api = $creds['x_api_key'];
|
||||
$is_test = $creds['is_test'];
|
||||
$auth_token = $creds['x_auth_token'];
|
||||
|
||||
if ($is_test == 1) {
|
||||
$url = 'https://test.instamojo.com/api/1.1/payments/' . $payment_id . '/';
|
||||
} else {
|
||||
$url = 'https://www.instamojo.com/api/1.1/payments/' . $payment_id . '/';
|
||||
}
|
||||
|
||||
try {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
"Content-Type: application/json",
|
||||
"X-Api-Key:" . $api,
|
||||
"X-Auth-Token:" . $auth_token));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$arr = json_decode($response, true);
|
||||
return $arr['success'] === true ? 1 : 0;
|
||||
} catch (\Throwable $th) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
156
app/Library/Mercado.php
Normal file
156
app/Library/Mercado.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use Throwable;
|
||||
use MercadoPago;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Mercado
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('user/payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('user/payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
// $gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
|
||||
$data['secret_key'] = $array['secret_key'];
|
||||
$data['public_key'] = $array['public_key'];
|
||||
$data['payment_mode'] = 'mercadopago';
|
||||
$mode = $array['mode'];
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try {
|
||||
//Payment
|
||||
MercadoPago\SDK::setAccessToken($data['secret_key']);
|
||||
$payment = new MercadoPago\Payment();
|
||||
$preference = new MercadoPago\Preference();
|
||||
$payer = new MercadoPago\Payer();
|
||||
$payer->name = $name;
|
||||
$payer->email = $email;
|
||||
$payer->date_created = Carbon::now();
|
||||
|
||||
if (Session::get('without_auth')){
|
||||
$url = route('mercadopago.status');
|
||||
}else{
|
||||
$url = route('user.mercadopago.status');
|
||||
}
|
||||
|
||||
$preference->back_urls = array(
|
||||
"success" => $url,
|
||||
"failure" => Mercado::redirect_if_payment_faild(),
|
||||
"pending" => $url,
|
||||
);
|
||||
|
||||
$preference->auto_return = "approved";
|
||||
|
||||
// Create a preference item
|
||||
$item = new MercadoPago\Item();
|
||||
$item->title = $billName;
|
||||
$item->quantity = 1;
|
||||
$item->unit_price = $amount;
|
||||
$preference->items = array($item);
|
||||
$preference->payer = $payer;
|
||||
$preference->save();
|
||||
$data['preference_id'] = $preference->id;
|
||||
$redirectUrl = $mode == 1 ? $preference->sandbox_init_point : $preference->init_point;
|
||||
|
||||
Session::put('mercadopago_credentials', $data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
$redirectUrl :
|
||||
redirect($redirectUrl);
|
||||
|
||||
} catch (Throwable $th) {
|
||||
Session::flash('error', $th->getMessage());
|
||||
return request()->expectsJson() ?
|
||||
Mercado::redirect_if_payment_faild() :
|
||||
redirect(Mercado::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
if (!Session::has('mercadopago_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
$response = Request()->all();
|
||||
|
||||
$info = Session::get('mercadopago_credentials');
|
||||
|
||||
if ($response['status'] == 'approved' || $response['status'] == 'pending') {
|
||||
$data['payment_id'] = $response['payment_id'];
|
||||
$data['payment_method'] = "mercadopago";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = $response['status'] == 'pending' ? 2 : 1;
|
||||
$data['payment_status'] = $response['status'] == 'pending' ? 2 : 1;
|
||||
|
||||
|
||||
Session::forget('mercadopago_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
return request()->expectsJson() ?
|
||||
Mercado::redirect_if_payment_success() :
|
||||
redirect(Mercado::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('flutterwave_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Mercado::redirect_if_payment_faild() :
|
||||
redirect(Mercado::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
}
|
||||
126
app/Library/Mollie.php
Normal file
126
app/Library/Mollie.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Mollie\Api\MollieApiClient;
|
||||
|
||||
class Mollie
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/mollie');
|
||||
}
|
||||
return url('payment/mollie');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$total_amount = str_replace(',', '', number_format($array['pay_amount'], 2));
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $total_amount;
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
$mode = $array['mode'];
|
||||
$data['api_key'] = $array['api_key'];
|
||||
$data['payment_mode'] = 'mollie';
|
||||
$data['amount'] = $amount;
|
||||
$data['is_fallback'] = $array['is_fallback'] ?? 0;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['payment_type'] = $array['payment_type'] ?? '';
|
||||
$data['mode'] = $mode;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
Session::put('mollie_credentials', $data);
|
||||
try {
|
||||
$mollie = new MollieApiClient();
|
||||
$mollie->setApiKey($array['api_key']);
|
||||
$payment = $mollie->payments->create([
|
||||
"amount" => [
|
||||
"currency" => strtoupper($currency),
|
||||
"value" => $amount,
|
||||
],
|
||||
"description" => $billName,
|
||||
"redirectUrl" => Mollie::fallback(),
|
||||
]);
|
||||
|
||||
Session::put('pay_id', $payment->id);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
$payment->getCheckoutUrl() : redirect($payment->getCheckoutUrl());
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
return request()->expectsJson() ? Mollie::redirect_if_payment_faild() : redirect(Mollie::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
if (Session::has('pay_id') && Session::has('mollie_credentials')) {
|
||||
$info = Session::get('mollie_credentials');
|
||||
|
||||
$mollie = new MollieApiClient();
|
||||
$mollie->setApiKey($info['api_key']);
|
||||
$pay_id = Session::get('pay_id');
|
||||
$payment = $mollie->payments->get($pay_id);
|
||||
|
||||
if ($payment->isPaid()) {
|
||||
$data['payment_id'] = Session::get('pay_id');
|
||||
$data['payment_method'] = "mollie";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
$data['payment_type'] = $info['payment_type'];
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
$data['is_fallback'] = $info['is_fallback'];
|
||||
|
||||
Session::forget('pay_id');
|
||||
Session::forget('mollie_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
|
||||
return request()->expectsJson() ? Mollie::redirect_if_payment_success() : redirect(Mollie::redirect_if_payment_success());
|
||||
}
|
||||
|
||||
Session::forget('pay_id');
|
||||
Session::forget('mollie_credentials');
|
||||
return request()->expectsJson() ? Mollie::redirect_if_payment_faild() : redirect(Mollie::redirect_if_payment_faild());
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
136
app/Library/Paypal.php
Normal file
136
app/Library/Paypal.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Omnipay\Omnipay;
|
||||
|
||||
class Paypal
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/paypal');
|
||||
}
|
||||
return url('payment/paypal');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$client_id = $array['client_id'];
|
||||
$client_secret = $array['client_secret'];
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = round($array['pay_amount']);
|
||||
$name = $array['name'];
|
||||
$mode = $array['mode'] == 'Live' ? 0 : 1;
|
||||
$billName = $array['billName'];
|
||||
$data['client_id'] = $client_id;
|
||||
$data['client_secret'] = $client_secret;
|
||||
$data['payment_mode'] = 'paypal';
|
||||
|
||||
$data['amount'] = $amount;
|
||||
$data['mode'] = $mode;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['payment_type'] = $array['payment_type'] ?? '';
|
||||
|
||||
Session::put('paypal_credentials', $data);
|
||||
$gateway = Omnipay::create('PayPal_Rest');
|
||||
$gateway->setClientId($client_id);
|
||||
$gateway->setSecret($client_secret);
|
||||
$gateway->setTestMode($mode);
|
||||
|
||||
$response = $gateway->purchase(array(
|
||||
'amount' => $amount,
|
||||
'currency' => strtoupper($currency),
|
||||
'returnUrl' => Paypal::fallback(),
|
||||
'cancelUrl' => Paypal::redirect_if_payment_faild(),
|
||||
))->send();
|
||||
|
||||
if ($response->isRedirect()) {
|
||||
if (request()->expectsJson()) {
|
||||
return $response->getRedirectUrl();
|
||||
}
|
||||
$response->redirect(); // this will automatically forward the customer
|
||||
} else {
|
||||
// not successful
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Paypal::redirect_if_payment_faild() :
|
||||
redirect(Paypal::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
abort_if(!Session::has('paypal_credentials'), 404);
|
||||
|
||||
$credentials = Session::get('paypal_credentials');
|
||||
$gateway = Omnipay::create('PayPal_Rest');
|
||||
$gateway->setClientId($credentials['client_id']);
|
||||
$gateway->setSecret($credentials['client_secret']);
|
||||
$gateway->setTestMode($credentials['mode']);
|
||||
|
||||
$request = $request->all();
|
||||
|
||||
$transaction = $gateway->completePurchase(array(
|
||||
'payer_id' => $request['PayerID'],
|
||||
'transactionReference' => $request['paymentId'],
|
||||
));
|
||||
|
||||
$response = $transaction->send();
|
||||
|
||||
if ($response->isSuccessful()) {
|
||||
$arr_body = $response->getData();
|
||||
$data['payment_id'] = $arr_body['id'];
|
||||
$data['payment_method'] = "paypal";
|
||||
$data['gateway_id'] = $credentials['gateway_id'];
|
||||
|
||||
$data['amount'] = $credentials['main_amount'];
|
||||
$data['charge'] = $credentials['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('paypal_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Paypal::redirect_if_payment_success() :
|
||||
redirect(Paypal::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('paypal_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Paypal::redirect_if_payment_faild() :
|
||||
redirect(Paypal::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
}
|
||||
187
app/Library/Paystack.php
Normal file
187
app/Library/Paystack.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Throwable;
|
||||
|
||||
class Paystack
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/paystack');
|
||||
} else {
|
||||
return url('payment/paystack');
|
||||
}
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
if (Session::has('paystack_credentials')) {
|
||||
$Info = Session::get('paystack_credentials');
|
||||
$gateway = Gateway::where('status', 1)->findOrFail($Info['gateway_id']);
|
||||
$promotion = Session::get('promotion');
|
||||
$product = Session::get('product');
|
||||
return view('payments.paystack', compact('Info', 'gateway'));
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
|
||||
$data['public_key'] = $array['public_key'];
|
||||
$data['secret_key'] = $array['secret_key'];
|
||||
$data['payment_mode'] = 'paystack';
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['payment_type'] = $array['payment_type'] ?? '';
|
||||
$mode = $array['mode'];
|
||||
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
$data['is_fallback'] = $array['is_fallback'] ?? 0;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
|
||||
Session::put('paystack_credentials', $data);
|
||||
|
||||
return request()->expectsJson() ? route('paystack.view') : redirect()->route('paystack.view');
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
if (!Session::has('paystack_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
$info = Session::get('paystack_credentials');
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => "https://api.paystack.co/transaction/verify/" . $request->ref_id,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Authorization: Bearer " . $info['secret_key'] . "",
|
||||
"Cache-Control: no-cache",
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
Session::forget('paystack_credentials');
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
return redirect(Paystack::redirect_if_payment_faild());
|
||||
} else {
|
||||
$data = json_decode($response);
|
||||
if ($data->status == true && $data->data->status == 'success') {
|
||||
$ref_id = $data->data->reference;
|
||||
$amount = $data->data->amount / 100;
|
||||
|
||||
abort_unless($amount == $info['amount'], 404);
|
||||
|
||||
$pay_data['payment_id'] = $ref_id;
|
||||
$pay_data['payment_method'] = "paystack";
|
||||
$pay_data['gateway_id'] = $info['gateway_id'];
|
||||
$pay_data['amount'] = $info['main_amount'];
|
||||
$pay_data['charge'] = $info['charge'];
|
||||
$pay_data['status'] = 1;
|
||||
$pay_data['payment_status'] = 1;
|
||||
$pay_data['is_fallback'] = $info['is_fallback'];
|
||||
|
||||
Session::forget('paystack_credentials');
|
||||
Session::put('payment_info', $pay_data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Paystack::redirect_if_payment_success() :
|
||||
redirect(Paystack::redirect_if_payment_success());
|
||||
}
|
||||
}
|
||||
Session::forget('paystack_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Paystack::redirect_if_payment_faild() :
|
||||
redirect(Paystack::redirect_if_payment_faild());
|
||||
}
|
||||
|
||||
public static function isfraud($cred)
|
||||
{
|
||||
$secret_key = $cred['secret_key'];
|
||||
$reference = $cred['payment_id'];
|
||||
try {
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => "https://api.paystack.co/transaction/verify/" . $reference,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Authorization: Bearer " . $secret_key,
|
||||
"Cache-Control: no-cache",
|
||||
),
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
$arr = json_decode($response, true);
|
||||
if (array_key_exists('data', $arr)) {
|
||||
return $arr['data']['status'] === "success" ? 1 : 0;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
app/Library/Paytm.php
Normal file
86
app/Library/Paytm.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use paytm\paytmchecksum\PaytmChecksum;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Paytm
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$paytmParams = [
|
||||
"MID" => $array['merchant_id'],
|
||||
"WEBSITE" => $array['website'] ?? 'WEBSTAGING',
|
||||
"INDUSTRY_TYPE_ID"=> $array['industry_type'],
|
||||
"CHANNEL_ID" => 'WEB',
|
||||
"ORDER_ID" => rand(10000, 99999),
|
||||
"CUST_ID" => $user->email,
|
||||
"TXN_AMOUNT" => $array['pay_amount'],
|
||||
"CALLBACK_URL" => route('paytm.status', ['email' => $user->email, 'merchant_key' => $array['merchant_key'], 'plan_id' => $array['plan_id'], 'gateway_id' => $array['gateway_id'], 'business_id' => $array['business_id'], 'platform' => $array['platform']]),
|
||||
];
|
||||
|
||||
// Generate the Checksum
|
||||
$paytmParams["CHECKSUMHASH"] = PaytmChecksum::generateSignature($paytmParams, $array['merchant_key']); // Replace with your Merchant Key
|
||||
|
||||
// Paytm transaction URL
|
||||
$paytmUrl = $array['mode'] == 'Live' ? "https://securegw.paytm.in/theia/processTransaction" : "https://securegw-stage.paytm.in/theia/processTransaction";
|
||||
|
||||
// Pass data to the blade view
|
||||
return view('payments.paytm', compact('paytmParams', 'paytmUrl'));
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
// Capture callback data
|
||||
$paytmParams = $request->all();
|
||||
|
||||
$user = User::where('email', request('email'))->first();
|
||||
Auth::login($user);
|
||||
|
||||
session()->put('plan_id', request('plan_id'));
|
||||
session()->put('platform', request('platform'));
|
||||
session()->put('gateway_id', request('gateway_id'));
|
||||
session()->put('business_id', request('business_id'));
|
||||
|
||||
// Verify the checksum
|
||||
if (!isset($paytmParams['CHECKSUMHASH'])) {
|
||||
// Payment failed logic
|
||||
session()->put('payment_msg', __('Invalid checksum, Please verify your credentials or contact with paytm support.'));
|
||||
return redirect(Paytm::redirect_if_payment_faild());
|
||||
}
|
||||
|
||||
$isValidChecksum = PaytmChecksum::verifySignature($paytmParams, request('merchant_key'), $paytmParams['CHECKSUMHASH']); // Replace with your Merchant Key
|
||||
|
||||
if ($isValidChecksum && $paytmParams['STATUS'] === 'TXN_SUCCESS') {
|
||||
return redirect(Paytm::redirect_if_payment_success());
|
||||
}
|
||||
|
||||
// Payment failed logic
|
||||
session()->put('payment_msg', $paytmParams['RESPMSG']);
|
||||
return redirect(Paytm::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
157
app/Library/PhonePe.php
Normal file
157
app/Library/PhonePe.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PhonePe
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
$clientId = $array['key_id'];
|
||||
$clientSecret = $array['key_secret'];
|
||||
|
||||
$urlForToken = $array['mode'] == 'Live' ? 'https://api.phonepe.com/apis/identity-manager/v1/oauth/token' : 'https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token';
|
||||
|
||||
$urlForCreatePayment = $array['mode'] == 'Live' ? 'https://api.phonepe.com/apis/pg/checkout/v2/pay' : 'https://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/pay';
|
||||
|
||||
$transactionId = 'txn_' . Str::random(8);
|
||||
|
||||
// Step 1: Generate Access Token
|
||||
$tokenResponse = Http::asForm()->post($urlForToken, [
|
||||
'client_version' => 1,
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret,
|
||||
'grant_type' => 'client_credentials'
|
||||
]);
|
||||
|
||||
$tokenData = $tokenResponse->json();
|
||||
|
||||
if (!isset($tokenData['access_token'])) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Unable to get access token',
|
||||
'data' => $tokenData
|
||||
]);
|
||||
}
|
||||
|
||||
$accessToken = $tokenData['access_token'];
|
||||
|
||||
// Step 2: Create Payment
|
||||
$payload = [
|
||||
"merchantOrderId" => $transactionId,
|
||||
"amount" => $array['pay_amount'] * 100,
|
||||
"expireAfter" => 1200,
|
||||
"metaInfo" => [
|
||||
"udf1" => $array['payment_type']
|
||||
],
|
||||
"paymentFlow" => [
|
||||
"type" => "PG_CHECKOUT",
|
||||
"message" => "Payment message used for collect requests",
|
||||
"merchantUrls" => [
|
||||
"redirectUrl" => route('phonepe.status')
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$paymentResponse = Http::withHeaders([
|
||||
'Authorization' => 'O-Bearer ' . $accessToken,
|
||||
'Content-Type' => 'application/json'
|
||||
])->post($urlForCreatePayment, $payload);
|
||||
|
||||
$paymentData = $paymentResponse->json();
|
||||
|
||||
Session::put('phonepe_credentials', [
|
||||
'mode' => $array['mode'],
|
||||
'clientId' => $clientId,
|
||||
'clientSecret' => $clientSecret,
|
||||
'merchantOrderId' => $transactionId,
|
||||
]);
|
||||
|
||||
// Redirect to PhonePe payment page
|
||||
if (isset($paymentData['redirectUrl'])) {
|
||||
return redirect()->away($paymentData['redirectUrl']);
|
||||
}
|
||||
|
||||
return $paymentData; // fallback for debugging
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
$phonepe_credentials = Session('phonepe_credentials');
|
||||
|
||||
if (!$phonepe_credentials) {
|
||||
session()->put('payment_msg', __('Invalid request, Please contact with admin.'));
|
||||
return redirect(Paytm::redirect_if_payment_faild());
|
||||
}
|
||||
|
||||
$mode = $phonepe_credentials['mode'];
|
||||
$clientId = $phonepe_credentials['clientId'];
|
||||
$clientSecret = $phonepe_credentials['clientSecret'];
|
||||
$merchantOrderId = $phonepe_credentials['merchantOrderId'];
|
||||
|
||||
$urlForToken = $mode == 'Live' ? 'https://api.phonepe.com/apis/identity-manager/v1/oauth/token' : 'https://api-preprod.phonepe.com/apis/pg-sandbox/v1/oauth/token';
|
||||
|
||||
$statusUrl = $phonepe_credentials['mode'] == 'Live' ? 'https://api.phonepe.com/apis/pg/checkout/v2/order/' . $merchantOrderId . '/status' : 'https://api-preprod.phonepe.com/apis/pg-sandbox/checkout/v2/order/' . $merchantOrderId . '/status';
|
||||
|
||||
// Step 1: Get Access Token (asForm)
|
||||
$tokenResponse = Http::asForm()->post($urlForToken, [
|
||||
'client_version' => 1,
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret,
|
||||
'grant_type' => 'client_credentials'
|
||||
]);
|
||||
|
||||
$tokenData = $tokenResponse->json();
|
||||
$accessToken = $tokenData['access_token'] ?? null;
|
||||
|
||||
if (!$accessToken) {
|
||||
return response()->json(['error' => 'Unable to get access token', 'data' => $tokenData], 400);
|
||||
}
|
||||
|
||||
// Step 2: Check Order Status
|
||||
$statusResponse = Http::withHeaders([
|
||||
'Authorization' => 'O-Bearer ' . $accessToken,
|
||||
'Content-Type' => 'application/json'
|
||||
])->get($statusUrl);
|
||||
|
||||
$statusData = $statusResponse->json();
|
||||
|
||||
session()->forget('phonepe_credentials');
|
||||
|
||||
// Step 3: Handle Payment State
|
||||
if (isset($statusData['state'])) {
|
||||
if ($statusData['state'] === 'COMPLETED') {
|
||||
|
||||
return redirect(Paytm::redirect_if_payment_success());
|
||||
} else {
|
||||
|
||||
session()->put('payment_msg', __('Payment failed, Please verify your credentials or contact with admin.'));
|
||||
return redirect(Paytm::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
session()->put('payment_msg', 'Payment failed.');
|
||||
return redirect(Paytm::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
210
app/Library/Razorpay.php
Normal file
210
app/Library/Razorpay.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use Razorpay\Api\Api;
|
||||
use Throwable;
|
||||
|
||||
class Razorpay
|
||||
{
|
||||
protected static $payment_id;
|
||||
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
if (Session::has('razorpay_credentials')) {
|
||||
$Info = Session::get('razorpay_credentials');
|
||||
$gateway = Gateway::where('status', 1)->findOrFail($Info['gateway_id']);
|
||||
$response = Session::get('razorpay_response');
|
||||
$promotion = Session::get('promotion');
|
||||
$product = Session::get('product');
|
||||
|
||||
return view('payments.razorpay', compact('response', 'Info', 'gateway'));
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
$data['key_id'] = $array['key_id'];
|
||||
$data['key_secret'] = $array['key_secret'];
|
||||
$data['payment_mode'] = 'razorpay';
|
||||
$data['payment_type'] = $array['payment_type'];
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['is_fallback'] = $array['is_fallback'] ?? 0;
|
||||
$data['main_amount'] = $array['amount'];
|
||||
$mode = $array['mode'];
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
|
||||
Session::put('razorpay_credentials', $data);
|
||||
|
||||
$response = Razorpay::get_response();
|
||||
|
||||
Session::put('razorpay_response', $response);
|
||||
|
||||
return request()->expectsJson() ? route('razorpay.view') : redirect()->route('razorpay.view');
|
||||
}
|
||||
|
||||
public static function get_response()
|
||||
{
|
||||
$array = Session::get('razorpay_credentials');
|
||||
$amount = $array['amount'];
|
||||
|
||||
$phone = $array['phone'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['amount'];
|
||||
$gateway_id = $array['gateway_id'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
|
||||
$razorpay_credentials = Session::get('razorpay_credentials');
|
||||
|
||||
$api = new Api($razorpay_credentials['key_id'], $razorpay_credentials['key_secret']);
|
||||
$referance_id = Str::random(12);
|
||||
$order = $api->order->create(array(
|
||||
'receipt' => $referance_id,
|
||||
'amount' => $amount * 100,
|
||||
'currency' => $razorpay_credentials['currency'],
|
||||
)
|
||||
);
|
||||
|
||||
// Return response on payment page
|
||||
$response = [
|
||||
'orderId' => $order['id'],
|
||||
'razorpayId' => $razorpay_credentials['key_id'],
|
||||
'amount' => $amount * 100,
|
||||
'name' => $name,
|
||||
'currency' => $razorpay_credentials['currency'],
|
||||
'email' => $email,
|
||||
'contactNumber' => $phone,
|
||||
'address' => "",
|
||||
'description' => $billName,
|
||||
];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
if (Session::has('razorpay_credentials')) {
|
||||
$order_info = Session::get('razorpay_credentials');
|
||||
|
||||
// Now verify the signature is correct . We create the private function for verify the signature
|
||||
$signatureStatus = Razorpay::SignatureVerify(
|
||||
$request->all()['rzp_signature'],
|
||||
$request->all()['rzp_paymentid'],
|
||||
$request->all()['rzp_orderid']
|
||||
);
|
||||
|
||||
// If Signature status is true We will save the payment response in our database
|
||||
// In this tutorial we send the response to Success page if payment successfully made
|
||||
if ($signatureStatus == true) {
|
||||
//for success
|
||||
$data['payment_id'] = Razorpay::$payment_id;
|
||||
$data['payment_method'] = "razorpay";
|
||||
$data['payment_type'] = $order_info['payment_type'];
|
||||
$data['gateway_id'] = $order_info['gateway_id'];
|
||||
$data['amount'] = $order_info['amount'];
|
||||
$data['billName'] = $order_info['billName'];
|
||||
$data['charge'] = $order_info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
$data['is_fallback'] = $order_info['is_fallback'];
|
||||
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('razorpay_credentials');
|
||||
return request()->expectsJson() ?
|
||||
Razorpay::redirect_if_payment_success() :
|
||||
redirect(Razorpay::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('razorpay_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Razorpay::redirect_if_payment_faild() :
|
||||
redirect(Razorpay::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In this function we return boolean if signature is correct
|
||||
private static function SignatureVerify($_signature, $_paymentId, $_orderId)
|
||||
{
|
||||
try {
|
||||
$razorpay_credentials = Session::get('razorpay_credentials');
|
||||
// Create an object of razorpay class
|
||||
$api = new Api($razorpay_credentials['key_id'], $razorpay_credentials['key_secret']);
|
||||
$attributes = array('razorpay_signature' => $_signature, 'razorpay_payment_id' => $_paymentId, 'razorpay_order_id' => $_orderId);
|
||||
$order = $api->utility->verifyPaymentSignature($attributes);
|
||||
Razorpay::$payment_id = $_paymentId;
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
// If Signature is not correct its give a excetption so we use try catch
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isfraud($creds)
|
||||
{
|
||||
$payment_id = $creds['payment_id'];
|
||||
$key = $creds['key_id'];
|
||||
$secret = $creds['key_secret'];
|
||||
try {
|
||||
$api = new Api($key, $secret);
|
||||
$payment = $api->payment->fetch($payment_id);
|
||||
if ($payment) {
|
||||
return $payment['status'] === "captured" ? 1 : 0;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
71
app/Library/SslCommerz.php
Normal file
71
app/Library/SslCommerz.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use App\Library\SslCommerz\SslCommerzNotification;
|
||||
|
||||
class SslCommerz
|
||||
{
|
||||
public static function make_payment($array)
|
||||
{
|
||||
# Here you have to receive all the order data to initate the payment.
|
||||
# Let's say, your oder transaction informations are saving in a table called "orders"
|
||||
# In "orders" table, order unique identity is "transaction_id". "status" field contain status of the transaction, "amount" is the order amount to be paid and "currency" is for storing Site Currency which will be checked with paid currency.
|
||||
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
|
||||
$post_data = array();
|
||||
$post_data['total_amount'] = $array['pay_amount']; # You cant not pay less than 10
|
||||
$post_data['currency'] = "BDT";
|
||||
$post_data['tran_id'] = uniqid(); // tran_id must be unique
|
||||
|
||||
# CUSTOMER INFORMATION
|
||||
$post_data['cus_name'] = 'Customer Name';
|
||||
$post_data['cus_email'] = 'customer@mail.com';
|
||||
$post_data['cus_add1'] = 'Customer Address';
|
||||
$post_data['cus_add2'] = "";
|
||||
$post_data['cus_city'] = "";
|
||||
$post_data['cus_state'] = "";
|
||||
$post_data['cus_postcode'] = "";
|
||||
$post_data['cus_country'] = "Bangladesh";
|
||||
$post_data['cus_phone'] = '0564654156';
|
||||
$post_data['cus_fax'] = "";
|
||||
|
||||
# SHIPMENT INFORMATION
|
||||
$post_data['ship_name'] = "Store Test";
|
||||
$post_data['ship_add1'] = "Dhaka";
|
||||
$post_data['ship_add2'] = "Dhaka";
|
||||
$post_data['ship_city'] = "Dhaka";
|
||||
$post_data['ship_state'] = "Dhaka";
|
||||
$post_data['ship_postcode'] = "1000";
|
||||
$post_data['ship_phone'] = "";
|
||||
$post_data['ship_country'] = "Bangladesh";
|
||||
|
||||
$post_data['shipping_method'] = "NO";
|
||||
$post_data['product_name'] = $array['billName'];
|
||||
$post_data['product_category'] = "Goods";
|
||||
$post_data['product_profile'] = "physical-goods";
|
||||
|
||||
$post_data['value_a'] = session('plan')->id ?? session('amount');
|
||||
$post_data['value_b'] = $gateway->id;
|
||||
$post_data['value_c'] = auth()->id();
|
||||
|
||||
if ($array['payment_type'] == 'plan_payment') {
|
||||
$success_url = '/ssl-commerz/payment/success';
|
||||
$failed_url = '/ssl-commerz/payment/failed';
|
||||
} else {
|
||||
$success_url = '/ssl-commerz/recharge/success';
|
||||
$failed_url = '/ssl-commerz/recharge/failed';
|
||||
}
|
||||
|
||||
$sslc = new SslCommerzNotification($gateway, $success_url, $failed_url);
|
||||
# initiate(Transaction Data , false: Redirect to SSLCOMMERZ gateway/ true: Show all the Payement gateway here )
|
||||
$payment_options = $sslc->makePayment($post_data, 'hosted');
|
||||
|
||||
if (!is_array($payment_options)) {
|
||||
print_r($payment_options);
|
||||
$payment_options = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
128
app/Library/SslCommerz/AbstractSslCommerz.php
Normal file
128
app/Library/SslCommerz/AbstractSslCommerz.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
namespace App\Library\SslCommerz;
|
||||
|
||||
abstract class AbstractSslCommerz implements SslCommerzInterface
|
||||
{
|
||||
protected $apiUrl;
|
||||
protected $storeId;
|
||||
protected $storePassword;
|
||||
|
||||
protected function setStoreId($storeID)
|
||||
{
|
||||
$this->storeId = $storeID;
|
||||
}
|
||||
|
||||
protected function getStoreId()
|
||||
{
|
||||
return $this->storeId;
|
||||
}
|
||||
|
||||
protected function setStorePassword($storePassword)
|
||||
{
|
||||
$this->storePassword = $storePassword;
|
||||
}
|
||||
|
||||
protected function getStorePassword()
|
||||
{
|
||||
return $this->storePassword;
|
||||
}
|
||||
|
||||
protected function setApiUrl($url)
|
||||
{
|
||||
$this->apiUrl = $url;
|
||||
}
|
||||
|
||||
protected function getApiUrl()
|
||||
{
|
||||
return $this->apiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param array $header
|
||||
* @param bool $setLocalhost
|
||||
* @return bool|string
|
||||
*/
|
||||
public function callToApi($data, $header = [], $setLocalhost = false)
|
||||
{
|
||||
$curl = curl_init();
|
||||
|
||||
if (!$setLocalhost) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // The default value for this option is 2. It means, it has to have the same name in the certificate as is in the URL you operate against.
|
||||
} else {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // When the verify value is 0, the connection succeeds regardless of the names in the certificate.
|
||||
}
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $this->getApiUrl());
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
$curlErrorNo = curl_errno($curl);
|
||||
curl_close($curl);
|
||||
|
||||
if ($code == 200 & !($curlErrorNo)) {
|
||||
return $response;
|
||||
} else {
|
||||
return "FAILED TO CONNECT WITH SSLCOMMERZ API";
|
||||
//return "cURL Error #:" . $err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $response
|
||||
* @param string $type
|
||||
* @param string $pattern
|
||||
* @return false|mixed|string
|
||||
*/
|
||||
public function formatResponse($response, $type = 'checkout', $pattern = 'json')
|
||||
{
|
||||
$sslcz = json_decode($response, true);
|
||||
|
||||
if ($type != 'checkout') {
|
||||
return $sslcz;
|
||||
} else {
|
||||
if (!empty($sslcz['GatewayPageURL'])) {
|
||||
// this is important to show the popup, return or echo to send json response back
|
||||
if(!empty($this->getApiUrl()) && $this->getApiUrl() == 'https://securepay.sslcommerz.com') {
|
||||
$response = json_encode(['status' => 'SUCCESS', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo']]);
|
||||
} else {
|
||||
$response = json_encode(['status' => 'success', 'data' => $sslcz['GatewayPageURL'], 'logo' => $sslcz['storeLogo']]);
|
||||
}
|
||||
} else {
|
||||
if (strpos($sslcz['failedreason'],'Store Credential') === false) {
|
||||
$message = $sslcz['failedreason'];
|
||||
} else {
|
||||
$message = "Check the SSLCZ_TESTMODE and SSLCZ_STORE_PASSWORD value in your .env; DO NOT USE MERCHANT PANEL PASSWORD HERE.";
|
||||
}
|
||||
$response = json_encode(['status' => 'fail', 'data' => null, 'message' => $message]);
|
||||
}
|
||||
|
||||
if ($pattern == 'json') {
|
||||
return $response;
|
||||
} else {
|
||||
echo $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param bool $permanent
|
||||
*/
|
||||
public function redirect($url, $permanent = false)
|
||||
{
|
||||
header('Location: ' . $url, true, $permanent ? 301 : 302);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
23
app/Library/SslCommerz/SslCommerzInterface.php
Normal file
23
app/Library/SslCommerz/SslCommerzInterface.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace App\Library\SslCommerz;
|
||||
|
||||
interface SslCommerzInterface
|
||||
{
|
||||
public function makePayment(array $data);
|
||||
|
||||
public function orderValidate($requestData, $trxID, $amount, $currency);
|
||||
|
||||
public function setParams($data);
|
||||
|
||||
public function setRequiredInfo(array $data);
|
||||
|
||||
// public function setCustomerInfo(array $data);
|
||||
|
||||
// public function setShipmentInfo(array $data);
|
||||
|
||||
// public function setProductInfo(array $data);
|
||||
|
||||
// public function setAdditionalInfo(array $data);
|
||||
|
||||
public function callToApi($data, $header = [], $setLocalhost = false);
|
||||
}
|
||||
466
app/Library/SslCommerz/SslCommerzNotification.php
Normal file
466
app/Library/SslCommerz/SslCommerzNotification.php
Normal file
@@ -0,0 +1,466 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\SslCommerz;
|
||||
|
||||
class SslCommerzNotification extends AbstractSslCommerz
|
||||
{
|
||||
protected $data = [];
|
||||
protected $config = [];
|
||||
|
||||
private $successUrl;
|
||||
private $cancelUrl;
|
||||
private $failedUrl;
|
||||
private $ipnUrl;
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* SslCommerzNotification constructor.
|
||||
*/
|
||||
public function __construct($gateway, $success_url, $failed_url)
|
||||
{
|
||||
$apiDomain = $gateway->mode == 1 ? "https://sandbox.sslcommerz.com" : "https://securepay.sslcommerz.com";
|
||||
$this->config = [
|
||||
'apiCredentials' => [
|
||||
'store_id' => $gateway->data['store_id'],
|
||||
'store_password' => $gateway->data['store_password'],
|
||||
],
|
||||
'apiUrl' => [
|
||||
'make_payment' => "/gwprocess/v4/api.php",
|
||||
'transaction_status' => "/validator/api/merchantTransIDvalidationAPI.php",
|
||||
'order_validate' => "/validator/api/validationserverAPI.php",
|
||||
'refund_payment' => "/validator/api/merchantTransIDvalidationAPI.php",
|
||||
'refund_status' => "/validator/api/merchantTransIDvalidationAPI.php",
|
||||
],
|
||||
'apiDomain' => $apiDomain,
|
||||
'connect_from_localhost' => env("IS_LOCALHOST", true), // For Sandbox, use "true", For Live, use "false"
|
||||
'success_url' => $success_url,
|
||||
'failed_url' => $failed_url,
|
||||
'cancel_url' => $failed_url,
|
||||
'ipn_url' => '/ipn',
|
||||
];
|
||||
|
||||
$this->setStoreId($this->config['apiCredentials']['store_id']);
|
||||
$this->setStorePassword($this->config['apiCredentials']['store_password']);
|
||||
}
|
||||
|
||||
public function orderValidate($post_data, $trx_id = '', $amount = 0, $currency = "BDT")
|
||||
{
|
||||
if ($post_data == '' && $trx_id == '' && !is_array($post_data)) {
|
||||
$this->error = "Please provide valid transaction ID and post request data";
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
return $this->validate($trx_id, $amount, $currency, $post_data);
|
||||
}
|
||||
|
||||
|
||||
# VALIDATE SSLCOMMERZ TRANSACTION
|
||||
protected function validate($merchant_trans_id, $merchant_trans_amount, $merchant_trans_currency, $post_data)
|
||||
{
|
||||
# MERCHANT SYSTEM INFO
|
||||
if (!empty($merchant_trans_id) && !empty($merchant_trans_amount)) {
|
||||
|
||||
# CALL THE FUNCTION TO CHECK THE RESULT
|
||||
$post_data['store_id'] = $this->getStoreId();
|
||||
$post_data['store_pass'] = $this->getStorePassword();
|
||||
|
||||
$val_id = urlencode($post_data['val_id']);
|
||||
$store_id = urlencode($this->getStoreId());
|
||||
$store_passwd = urlencode($this->getStorePassword());
|
||||
$requested_url = ($this->config['apiDomain'] . $this->config['apiUrl']['order_validate'] . "?val_id=" . $val_id . "&store_id=" . $store_id . "&store_passwd=" . $store_passwd . "&v=1&format=json");
|
||||
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, $requested_url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
if ($this->config['connect_from_localhost']) {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
} else {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 2);
|
||||
}
|
||||
|
||||
|
||||
$result = curl_exec($handle);
|
||||
|
||||
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code == 200 && !(curl_errno($handle))) {
|
||||
|
||||
# TO CONVERT AS ARRAY
|
||||
# $result = json_decode($result, true);
|
||||
# $status = $result['status'];
|
||||
|
||||
# TO CONVERT AS OBJECT
|
||||
$result = json_decode($result);
|
||||
$this->sslc_data = $result;
|
||||
|
||||
# TRANSACTION INFO
|
||||
$status = $result->status;
|
||||
$tran_date = $result->tran_date;
|
||||
$tran_id = $result->tran_id;
|
||||
$val_id = $result->val_id;
|
||||
$amount = $result->amount;
|
||||
$store_amount = $result->store_amount;
|
||||
$bank_tran_id = $result->bank_tran_id;
|
||||
$card_type = $result->card_type;
|
||||
$currency_type = $result->currency_type;
|
||||
$currency_amount = $result->currency_amount;
|
||||
|
||||
# ISSUER INFO
|
||||
$card_no = $result->card_no;
|
||||
$card_issuer = $result->card_issuer;
|
||||
$card_brand = $result->card_brand;
|
||||
$card_issuer_country = $result->card_issuer_country;
|
||||
$card_issuer_country_code = $result->card_issuer_country_code;
|
||||
|
||||
# API AUTHENTICATION
|
||||
$APIConnect = $result->APIConnect;
|
||||
$validated_on = $result->validated_on;
|
||||
$gw_version = $result->gw_version;
|
||||
|
||||
# GIVE SERVICE
|
||||
if ($status == "VALID" || $status == "VALIDATED") {
|
||||
if ($merchant_trans_currency == "BDT") {
|
||||
if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $amount) < 1) && trim($merchant_trans_currency) == trim('BDT')) {
|
||||
return true;
|
||||
} else {
|
||||
# DATA TEMPERED
|
||||
$this->error = "Data has been tempered";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//echo "trim($merchant_trans_id) == trim($tran_id) && ( abs($merchant_trans_amount-$currency_amount) < 1 ) && trim($merchant_trans_currency)==trim($currency_type)";
|
||||
if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $currency_amount) < 1) && trim($merchant_trans_currency) == trim($currency_type)) {
|
||||
return true;
|
||||
} else {
|
||||
# DATA TEMPERED
|
||||
$this->error = "Data has been tempered";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# FAILED TRANSACTION
|
||||
$this->error = "Failed Transaction";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
# Failed to connect with SSLCOMMERZ
|
||||
$this->error = "Faile to connect with SSLCOMMERZ";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
# INVALID DATA
|
||||
$this->error = "Invalid data";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# FUNCTION TO CHECK HASH VALUE
|
||||
protected function SSLCOMMERZ_hash_verify($post_data, $store_passwd = "")
|
||||
{
|
||||
if (isset($post_data) && isset($post_data['verify_sign']) && isset($post_data['verify_key'])) {
|
||||
# NEW ARRAY DECLARED TO TAKE VALUE OF ALL POST
|
||||
$pre_define_key = explode(',', $post_data['verify_key']);
|
||||
|
||||
$new_data = array();
|
||||
if (!empty($pre_define_key)) {
|
||||
foreach ($pre_define_key as $value) {
|
||||
// if (isset($post_data[$value])) {
|
||||
$new_data[$value] = ($post_data[$value]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
# ADD MD5 OF STORE PASSWORD
|
||||
$new_data['store_passwd'] = md5($store_passwd);
|
||||
|
||||
# SORT THE KEY AS BEFORE
|
||||
ksort($new_data);
|
||||
|
||||
$hash_string = "";
|
||||
foreach ($new_data as $key => $value) {
|
||||
$hash_string .= $key . '=' . ($value) . '&';
|
||||
}
|
||||
$hash_string = rtrim($hash_string, '&');
|
||||
|
||||
if (md5($hash_string) == $post_data['verify_sign']) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "Verification signature not matched";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = 'Required data mission. ex: verify_key, verify_sign';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $requestData
|
||||
* @param string $type
|
||||
* @param string $pattern
|
||||
* @return false|mixed|string
|
||||
*/
|
||||
public function makePayment(array $requestData, $type = 'checkout', $pattern = 'json')
|
||||
{
|
||||
if (empty($requestData)) {
|
||||
return "Please provide a valid information list about transaction with transaction id, amount, success url, fail url, cancel url, store id and pass at least";
|
||||
}
|
||||
|
||||
$header = [];
|
||||
|
||||
$this->setApiUrl($this->config['apiDomain'] . $this->config['apiUrl']['make_payment']);
|
||||
|
||||
// Set the required/additional params
|
||||
$this->setParams($requestData);
|
||||
|
||||
// Set the authentication information
|
||||
$this->setAuthenticationInfo();
|
||||
|
||||
// Now, call the Gateway API
|
||||
$response = $this->callToApi($this->data, $header, $this->config['connect_from_localhost']);
|
||||
|
||||
$formattedResponse = $this->formatResponse($response, $type, $pattern); // Here we will define the response pattern
|
||||
|
||||
if ($type == 'hosted') {
|
||||
if (!empty($formattedResponse['GatewayPageURL'])) {
|
||||
$formattedResponse['GatewayPageURL'];
|
||||
$this->redirect($formattedResponse['GatewayPageURL']);
|
||||
} else {
|
||||
if (strpos($formattedResponse['failedreason'], 'Store Credential') === false) {
|
||||
$message = $formattedResponse['failedreason'];
|
||||
} else {
|
||||
$message = "Check the SSLCZ_TESTMODE and SSLCZ_STORE_PASSWORD value in your .env; DO NOT USE MERCHANT PANEL PASSWORD HERE.";
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
} else {
|
||||
return $formattedResponse;
|
||||
}
|
||||
}
|
||||
|
||||
protected function setSuccessUrl()
|
||||
{
|
||||
$this->successUrl = rtrim(env('APP_URL'), '/') . $this->config['success_url'];
|
||||
}
|
||||
|
||||
protected function getSuccessUrl()
|
||||
{
|
||||
return $this->successUrl;
|
||||
}
|
||||
|
||||
protected function setFailedUrl()
|
||||
{
|
||||
$this->failedUrl = rtrim(env('APP_URL'), '/') . $this->config['failed_url'];
|
||||
}
|
||||
|
||||
protected function getFailedUrl()
|
||||
{
|
||||
return $this->failedUrl;
|
||||
}
|
||||
|
||||
protected function setCancelUrl()
|
||||
{
|
||||
$this->cancelUrl = rtrim(env('APP_URL'), '/') . $this->config['cancel_url'];
|
||||
}
|
||||
|
||||
protected function getCancelUrl()
|
||||
{
|
||||
return $this->cancelUrl;
|
||||
}
|
||||
|
||||
protected function setIPNUrl()
|
||||
{
|
||||
$this->ipnUrl = rtrim(env('APP_URL'), '/') . $this->config['ipn_url'];
|
||||
}
|
||||
|
||||
protected function getIPNUrl()
|
||||
{
|
||||
return $this->ipnUrl;
|
||||
}
|
||||
|
||||
public function setParams($requestData)
|
||||
{
|
||||
## Integration Required Parameters
|
||||
$this->setRequiredInfo($requestData);
|
||||
|
||||
## Customer Information
|
||||
$this->setCustomerInfo($requestData);
|
||||
|
||||
## Shipment Information
|
||||
$this->setShipmentInfo($requestData);
|
||||
|
||||
## Product Information
|
||||
$this->setProductInfo($requestData);
|
||||
|
||||
## Customized or Additional Parameters
|
||||
$this->setAdditionalInfo($requestData);
|
||||
}
|
||||
|
||||
public function setAuthenticationInfo()
|
||||
{
|
||||
$this->data['store_id'] = $this->getStoreId();
|
||||
$this->data['store_passwd'] = $this->getStorePassword();
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setRequiredInfo(array $info)
|
||||
{
|
||||
$this->data['total_amount'] = $info['total_amount']; // decimal (10,2) Mandatory - The amount which will process by SSLCommerz. It shall be decimal value (10,2). Example : 55.40. The transaction amount must be from 10.00 BDT to 500000.00 BDT
|
||||
$this->data['currency'] = $info['currency']; // string (3) Mandatory - The currency type must be mentioned. It shall be three characters. Example : BDT, USD, EUR, SGD, INR, MYR, etc. If the transaction currency is not BDT, then it will be converted to BDT based on the current convert rate. Example : 1 USD = 82.22 BDT.
|
||||
$this->data['tran_id'] = $info['tran_id']; // string (30) Mandatory - Unique transaction ID to identify your order in both your end and SSLCommerz
|
||||
|
||||
// Set the SUCCESS, FAIL, CANCEL Redirect URL before setting the other parameters
|
||||
$this->setSuccessUrl();
|
||||
$this->setFailedUrl();
|
||||
$this->setCancelUrl();
|
||||
$this->setIPNUrl();
|
||||
|
||||
$this->data['success_url'] = $this->getSuccessUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect after successful payment (Length: 255)
|
||||
$this->data['fail_url'] = $this->getFailedUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect after any failure occure during payment (Length: 255)
|
||||
$this->data['cancel_url'] = $this->getCancelUrl(); // string (255) Mandatory - It is the callback URL of your website where user will redirect if user canceled the transaction (Length: 255)
|
||||
|
||||
/*
|
||||
* IPN is very important feature to integrate with your site(s).
|
||||
* Some transaction could be pending or customer lost his/her session, in such cases back-end IPN plays a very important role to update your backend office.
|
||||
*
|
||||
* Type: string (255)
|
||||
* Important! Not mandatory, however better to use to avoid missing any payment notification - It is the Instant Payment Notification (IPN) URL of your website where SSLCOMMERZ will send the transaction's status (Length: 255).
|
||||
* The data will be communicated as SSLCOMMERZ Server to your Server. So, customer session will not work.
|
||||
*/
|
||||
$this->data['ipn_url'] = $this->getIPNUrl();
|
||||
|
||||
/*
|
||||
* Type: string (30)
|
||||
* Do not Use! If you do not customize the gateway list - You can control to display the gateway list at SSLCommerz gateway selection page by providing this parameters.
|
||||
* Multi Card:
|
||||
brac_visa = BRAC VISA
|
||||
dbbl_visa = Dutch Bangla VISA
|
||||
city_visa = City Bank Visa
|
||||
ebl_visa = EBL Visa
|
||||
sbl_visa = Southeast Bank Visa
|
||||
brac_master = BRAC MASTER
|
||||
dbbl_master = MASTER Dutch-Bangla
|
||||
city_master = City Master Card
|
||||
ebl_master = EBL Master Card
|
||||
sbl_master = Southeast Bank Master Card
|
||||
city_amex = City Bank AMEX
|
||||
qcash = QCash
|
||||
dbbl_nexus = DBBL Nexus
|
||||
bankasia = Bank Asia IB
|
||||
abbank = AB Bank IB
|
||||
ibbl = IBBL IB and Mobile Banking
|
||||
mtbl = Mutual Trust Bank IB
|
||||
bkash = Bkash Mobile Banking
|
||||
dbblmobilebanking = DBBL Mobile Banking
|
||||
city = City Touch IB
|
||||
upay = Upay
|
||||
tapnpay = Tap N Pay Gateway
|
||||
* GROUP GATEWAY
|
||||
internetbank = For all internet banking
|
||||
mobilebank = For all mobile banking
|
||||
othercard = For all cards except visa,master and amex
|
||||
visacard = For all visa
|
||||
mastercard = For All Master card
|
||||
amexcard = For Amex Card
|
||||
* */
|
||||
$this->data['multi_card_name'] = (isset($info['multi_card_name'])) ? $info['multi_card_name'] : null;
|
||||
|
||||
/*
|
||||
* Type: string (255)
|
||||
* Do not Use! If you do not control on transaction - You can provide the BIN of card to allow the transaction must be completed by this BIN. You can declare by coma ',' separate of these BIN.
|
||||
* Example: 371598,371599,376947,376948,376949
|
||||
* */
|
||||
$this->data['allowed_bin'] = (isset($info['allowed_bin'])) ? $info['allowed_bin'] : null;
|
||||
|
||||
## Parameters to Handle EMI Transaction ##
|
||||
$this->data['emi_option'] = (isset($info['emi_option'])) ? $info['emi_option'] : null; // integer (1) Mandatory - This is mandatory if transaction is EMI enabled and Value must be 1/0. Here, 1 means customer will get EMI facility for this transaction
|
||||
$this->data['emi_max_inst_option'] = (isset($info['emi_max_inst_option'])) ? $info['emi_max_inst_option'] : null; // integer (2) Max instalment Option, Here customer will get 3,6, 9 instalment at gateway page
|
||||
$this->data['emi_selected_inst'] = (isset($info['emi_selected_inst'])) ? $info['emi_selected_inst'] : null; // integer (2) Customer has selected from your Site, So no instalment option will be displayed at gateway page
|
||||
$this->data['emi_allow_only'] = (isset($info['emi_allow_only'])) ? $info['emi_allow_only'] : 0;
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setCustomerInfo(array $info)
|
||||
{
|
||||
$this->data['cus_name'] = (isset($info['cus_name'])) ? $info['cus_name'] : null; // string (50) Mandatory - Your customer name to address the customer in payment receipt email
|
||||
$this->data['cus_email'] = (isset($info['cus_email'])) ? $info['cus_email'] : null; // string (50) Mandatory - Valid email address of your customer to send payment receipt from SSLCommerz end
|
||||
$this->data['cus_add1'] = (isset($info['cus_add1'])) ? $info['cus_add1'] : null; // string (50) Mandatory - Address of your customer. Not mandatory but useful if provided
|
||||
// $this->data['cus_add2'] = (isset($info['cus_add2'])) ? $info['cus_add2'] : null; // string (50) Address line 2 of your customer. Not mandatory but useful if provided
|
||||
$this->data['cus_city'] = (isset($info['cus_city'])) ? $info['cus_city'] : null; // string (50) Mandatory - City of your customer. Not mandatory but useful if provided
|
||||
// $this->data['cus_state'] = (isset($info['cus_state'])) ? $info['cus_state'] : null; // string (50) State of your customer. Not mandatory but useful if provided
|
||||
// $this->data['cus_postcode'] = (isset($info['cus_postcode'])) ? $info['cus_postcode'] : null; // string (30) Mandatory - Postcode of your customer. Not mandatory but useful if provided
|
||||
$this->data['cus_country'] = (isset($info['cus_country'])) ? $info['cus_country'] : null; // string (50) Mandatory - Country of your customer. Not mandatory but useful if provided
|
||||
$this->data['cus_phone'] = (isset($info['cus_phone'])) ? $info['cus_phone'] : null; // string (20) Mandatory - The phone/mobile number of your customer to contact if any issue arises
|
||||
// $this->data['cus_fax'] = (isset($info['cus_fax'])) ? $info['cus_fax'] : null; // string (20) Fax number of your customer. Not mandatory but useful if provided
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setShipmentInfo(array $info)
|
||||
{
|
||||
|
||||
$this->data['shipping_method'] = isset($info['shipping_method']) ? $info['shipping_method'] : null; // string (50) Mandatory - Shipping method of the order. Example: YES or NO or Courier
|
||||
$this->data['num_of_item'] = isset($info['num_of_item']) ? $info['num_of_item'] : 1; // integer (1) Mandatory - No of product will be shipped. Example: 1 or 2 or etc
|
||||
$this->data['ship_name'] = isset($info['ship_name']) ? $info['ship_name'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping Address of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_add1'] = isset($info['ship_add1']) ? $info['ship_add1'] : null; // string (50) Mandatory, if shipping_method is YES - Additional Shipping Address of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_add2'] = (isset($info['ship_add2'])) ? $info['ship_add2'] : null; // string (50) Additional Shipping Address of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_city'] = isset($info['ship_city']) ? $info['ship_city'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping city of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_state'] = (isset($info['ship_state'])) ? $info['ship_state'] : null; // string (50) Shipping state of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_postcode'] = (isset($info['ship_postcode'])) ? $info['ship_postcode'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping postcode of your order. Not mandatory but useful if provided
|
||||
$this->data['ship_country'] = (isset($info['ship_country'])) ? $info['ship_country'] : null; // string (50) Mandatory, if shipping_method is YES - Shipping country of your order. Not mandatory but useful if provided
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setProductInfo(array $info)
|
||||
{
|
||||
|
||||
$this->data['product_name'] = (isset($info['product_name'])) ? $info['product_name'] : ''; // String (256) Mandatory - Mention the product name briefly. Mention the product name by coma separate. Example: Computer,Speaker
|
||||
$this->data['product_category'] = (isset($info['product_category'])) ? $info['product_category'] : ''; // String (256) Mandatory - Mention the product name briefly. Mention the product name by coma separate. Example: Computer,Speaker
|
||||
|
||||
$this->data['product_profile'] = (isset($info['product_profile'])) ? $info['product_profile'] : '';
|
||||
|
||||
$this->data['hours_till_departure'] = (isset($info['hours_till_departure'])) ? $info['hours_till_departure'] : null; // string (30) Mandatory, if product_profile is airline-tickets - Provide the remaining time of departure of flight till at the time of purchasing the ticket. Example: 12 hrs or 36 hrs
|
||||
$this->data['flight_type'] = (isset($info['flight_type'])) ? $info['flight_type'] : null; // string (30) Mandatory, if product_profile is airline-tickets - Provide the flight type. Example: Oneway or Return or Multistop
|
||||
$this->data['pnr'] = (isset($info['pnr'])) ? $info['pnr'] : null; // string (50) Mandatory, if product_profile is airline-tickets - Provide the PNR.
|
||||
$this->data['journey_from_to'] = (isset($info['journey_from_to'])) ? $info['journey_from_to'] : null; // string (256) - Mandatory, if product_profile is airline-tickets - Provide the journey route. Example: DAC-CGP or DAC-CGP CGP-DAC
|
||||
$this->data['third_party_booking'] = (isset($info['third_party_booking'])) ? $info['third_party_booking'] : null; // string (20) Mandatory, if product_profile is airline-tickets - No/Yes. Whether the ticket has been taken from third party booking system.
|
||||
$this->data['hotel_name'] = (isset($info['hotel_name'])) ? $info['hotel_name'] : null; // string (256) Mandatory, if product_profile is travel-vertical - Please provide the hotel name. Example: Sheraton
|
||||
$this->data['length_of_stay'] = (isset($info['length_of_stay'])) ? $info['length_of_stay'] : null; // string (30) Mandatory, if product_profile is travel-vertical - How long stay in hotel. Example: 2 days
|
||||
$this->data['check_in_time'] = (isset($info['check_in_time'])) ? $info['check_in_time'] : null; // string (30) Mandatory, if product_profile is travel-vertical - Checking hours for the hotel room. Example: 24 hrs
|
||||
$this->data['hotel_city'] = (isset($info['hotel_city'])) ? $info['hotel_city'] : null; // string (50) Mandatory, if product_profile is travel-vertical - Location of the hotel. Example: Dhaka
|
||||
$this->data['product_type'] = (isset($info['product_type'])) ? $info['product_type'] : null; // string (30) Mandatory, if product_profile is telecom-vertical - For mobile or any recharge, this information is necessary. Example: Prepaid or Postpaid
|
||||
$this->data['topup_number'] = (isset($info['topup_number'])) ? $info['topup_number'] : null; // string (150) Mandatory, if product_profile is telecom-vertical - Provide the mobile number which will be recharged. Example: 8801700000000 or 8801700000000,8801900000000
|
||||
$this->data['country_topup'] = (isset($info['country_topup'])) ? $info['country_topup'] : null; // string (30) Mandatory, if product_profile is telecom-vertical - Provide the country name in where the service is given. Example: Bangladesh
|
||||
|
||||
/*
|
||||
* Type: JSON
|
||||
* JSON data with two elements. product : Max 255 characters, quantity : Quantity in numeric value and amount : Decimal (12,2)
|
||||
* Example:
|
||||
[{"product":"DHK TO BRS AC A1","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A2","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A3","quantity":"1","amount":"200.00"},{"product":"DHK TO BRS AC A4","quantity":"2","amount":"200.00"}]
|
||||
* */
|
||||
$this->data['cart'] = (isset($info['cart'])) ? $info['cart'] : null;
|
||||
$this->data['product_amount'] = (isset($info['product_amount'])) ? $info['product_amount'] : null; // decimal (10,2) Product price which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 50.40
|
||||
$this->data['vat'] = (isset($info['vat'])) ? $info['vat'] : null; // decimal (10,2) The VAT included on the product price which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 4.00
|
||||
$this->data['discount_amount'] = (isset($info['discount_amount'])) ? $info['discount_amount'] : null; // decimal (10,2) Discount given on the invoice which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 2.00
|
||||
$this->data['convenience_fee'] = (isset($info['convenience_fee'])) ? $info['convenience_fee'] : null; // decimal (10,2) Any convenience fee imposed on the invoice which will be displayed in your merchant panel and will help you to reconcile the transaction. It shall be decimal value (10,2). Example : 3.00
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setAdditionalInfo(array $info)
|
||||
{
|
||||
$this->data['value_a'] = (isset($info['value_a'])) ? $info['value_a'] : null; // value_a [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory]
|
||||
$this->data['value_b'] = (isset($info['value_b'])) ? $info['value_b'] : null; // value_b [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory]
|
||||
$this->data['value_c'] = (isset($info['value_c'])) ? $info['value_c'] : null; // value_c [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory]
|
||||
$this->data['value_d'] = (isset($info['value_d'])) ? $info['value_d'] : null; // value_d [ string (255) - Extra parameter to pass your meta data if it is needed. Not mandatory]
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
37
app/Library/StripeGateway.php
Normal file
37
app/Library/StripeGateway.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use Stripe\Stripe;
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class StripeGateway
|
||||
{
|
||||
public static function make_payment($array)
|
||||
{
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
Stripe::setApiKey($gateway->data['stripe_secret']);
|
||||
$amount = $array['pay_amount'] * 100;
|
||||
|
||||
$session = \Stripe\Checkout\Session::create([
|
||||
'line_items' => [
|
||||
[
|
||||
'price_data' => [
|
||||
'currency' => 'USD',
|
||||
'product_data' => [
|
||||
"name" => $array['billName'],
|
||||
],
|
||||
'unit_amount' => $amount,
|
||||
],
|
||||
'quantity' => 1,
|
||||
],
|
||||
],
|
||||
'mode' => 'payment',
|
||||
'success_url' => route('payment.success'),
|
||||
'cancel_url' => route('payment.failed'),
|
||||
]);
|
||||
|
||||
return redirect()->away($session->url);
|
||||
}
|
||||
}
|
||||
103
app/Library/TapPayment.php
Normal file
103
app/Library/TapPayment.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class TapPayment
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
$data = [
|
||||
'amount' => $array['pay_amount'],
|
||||
'currency' => $array['currency'] ?? 'SAR',
|
||||
'threeDSecure' => true,
|
||||
'save_card' => false,
|
||||
'description' => $array['billName'],
|
||||
'customer' => [
|
||||
'first_name' => $array['name'],
|
||||
'email' => $array['email'],
|
||||
],
|
||||
'source' => [
|
||||
'id' => 'src_all',
|
||||
],
|
||||
'redirect' => [
|
||||
'url' => route('tap-payment.status'),
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
$client = new Client(['base_uri' => 'https://api.tap.company/v2/']);
|
||||
$response = $client->post('charges', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $array['secret_key'],
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => $data,
|
||||
]);
|
||||
|
||||
session()->put('secret_key', $array['secret_key']);
|
||||
|
||||
$responseBody = json_decode($response->getBody(), true);
|
||||
|
||||
// Redirect the user to Tap's payment page
|
||||
return redirect($responseBody['transaction']['url']);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
// Extract the parameters from the request
|
||||
$paymentId = $request->query('tap_id'); // Tap Payment ID
|
||||
|
||||
if (!$paymentId) {
|
||||
return response()->json(['error' => 'Invalid callback response'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
// Verify the payment status using the Tap API
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$response = $client->get('https://api.tap.company/v2/' . 'charges/' . $paymentId, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . session('secret_key'),
|
||||
],
|
||||
]);
|
||||
|
||||
$paymentDetails = json_decode($response->getBody(), true);
|
||||
session()->forget('secret_key');
|
||||
|
||||
// Check the status
|
||||
if ($paymentDetails['status'] === 'CAPTURED') {
|
||||
return redirect(TapPayment::redirect_if_payment_success());
|
||||
} else {
|
||||
session()->put('payment_msg', $paymentDetails['response']['message']);
|
||||
return redirect(TapPayment::redirect_if_payment_faild());
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
session()->put('payment_msg', $e->getMessage());
|
||||
return redirect(TapPayment::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
}
|
||||
246
app/Library/Thawani.php
Normal file
246
app/Library/Thawani.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Throwable;
|
||||
|
||||
class Thawani
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/thawani');
|
||||
}
|
||||
return url('payment/thawani');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
$data['secret_key'] = $array['secret_key'];
|
||||
$data['public_key'] = $array['publishable_key'];
|
||||
$data['payment_mode'] = 'thawani';
|
||||
$mode = $array['mode'];
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
|
||||
$productJson = json_encode([
|
||||
'name' => $billName,
|
||||
'unit_amount' => (float) ceil($array['pay_amount'] * 1000),
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://uatcheckout.thawani.om/api/v1/checkout/session",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Content-Type: application/json",
|
||||
"thawani-api-key: " . $data['secret_key'],
|
||||
],
|
||||
CURLOPT_POSTFIELDS => '{"client_reference_id": ' . strtotime(Carbon::now()) . ',
|
||||
"products": [' . $productJson . '],
|
||||
"success_url": "' . Thawani::fallback() . '",
|
||||
"cancel_url": "' . Thawani::redirect_if_payment_faild() . '"}',
|
||||
]);
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if ($response['success'] == true) {
|
||||
$session_id = $response['data']['session_id'];
|
||||
$data['response'] = $response;
|
||||
if ($mode == true) {
|
||||
$url = "https://uatcheckout.thawani.om/pay/" . $session_id . "?key=" . $array['publishable_key'];
|
||||
} else {
|
||||
$url = "https://checkout.thawani.om/pay/" . $session_id . "?key=" . $array['publishable_key'];
|
||||
}
|
||||
Session::put('thawani_credentials', $data);
|
||||
} else {
|
||||
Session::has('thawani_credentials') ? Session::forget('thawani_credentials') : '';
|
||||
$url = Thawani::redirect_if_payment_faild();
|
||||
}
|
||||
|
||||
Session::put('thawani_credentials', $data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
$url :
|
||||
redirect($url);
|
||||
}
|
||||
|
||||
public function status(Request $request)
|
||||
{
|
||||
if (!Session::has('thawani_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
$info = Session::get('thawani_credentials');
|
||||
$mode = Session::get('thawani_credentials')['mode'];
|
||||
$secret_key = Session::get('thawani_credentials')['secret_key'];
|
||||
$invoice = Session::get('thawani_credentials')['response']['data']['invoice'];
|
||||
$response = $this->getResponse($mode, $invoice, $secret_key);
|
||||
$responseArr = json_decode($response, true);
|
||||
|
||||
if (array_key_exists('success', $responseArr) && $responseArr['success'] == true) {
|
||||
$data['payment_id'] = $responseArr['data'][0]['payment_id'];
|
||||
$data['payment_method'] = "thawani";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
|
||||
Session::forget('thawani_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
thawani::redirect_if_payment_success() :
|
||||
redirect(thawani::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('thawani_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
thawani::redirect_if_payment_faild() :
|
||||
redirect(thawani::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
private function getResponse($mode, $invoice_id, $api_key)
|
||||
{
|
||||
if ($mode == 1) {
|
||||
$url = "https://uatcheckout.thawani.om/api/v1/payments/?checkout_invoice=$invoice_id";
|
||||
} else {
|
||||
$url = "https://checkout.thawani.om/api/v1/payments/?checkout_invoice=$invoice_id";
|
||||
}
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_POSTFIELDS => "",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Content-Type: application/json",
|
||||
"thawani-api-key: " . $api_key,
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err) {
|
||||
return $err;
|
||||
} else {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isfraud($creds)
|
||||
{
|
||||
$invoice_id = $creds['payment_id'];
|
||||
$api_key = $creds['secret_key'];
|
||||
$mode = $creds['is_test'];
|
||||
|
||||
if ($mode == 1) {
|
||||
$url = "https://uatcheckout.thawani.om/api/v1/payments/?checkout_invoice=$invoice_id";
|
||||
} else {
|
||||
$url = "https://checkout.thawani.om/api/v1/payments/?checkout_invoice=$invoice_id";
|
||||
}
|
||||
|
||||
try {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "GET",
|
||||
CURLOPT_POSTFIELDS => "",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"Content-Type: application/json",
|
||||
"thawani-api-key: " . $api_key,
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
$arr = json_decode($response, true);
|
||||
if (array_key_exists('success', $arr) && $arr['success'] == true) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
} catch (Throwable $th) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
154
app/Library/Toyyibpay.php
Normal file
154
app/Library/Toyyibpay.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use App\Models\Gateway;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Str;
|
||||
use Throwable;
|
||||
|
||||
class Toyyibpay
|
||||
{
|
||||
public static function redirect_if_payment_success()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['success_url']);
|
||||
} else {
|
||||
return url('payment/success');
|
||||
}
|
||||
}
|
||||
|
||||
public static function redirect_if_payment_faild()
|
||||
{
|
||||
if (Session::has('fund_callback')) {
|
||||
return url(Session::get('fund_callback')['cancel_url']);
|
||||
} else {
|
||||
return url('payment/failed');
|
||||
}
|
||||
}
|
||||
|
||||
public static function fallback()
|
||||
{
|
||||
if (Session::get('without_auth')) {
|
||||
return url('payment/toyyibpay');
|
||||
}
|
||||
return url('payment/toyyibpay');
|
||||
}
|
||||
|
||||
public static function make_payment($array)
|
||||
{
|
||||
//Checking Minimum/Maximum amount
|
||||
$gateway = Gateway::findOrFail($array['gateway_id']);
|
||||
$amount = $array['pay_amount'];
|
||||
|
||||
$currency = $array['currency'];
|
||||
$email = $array['email'];
|
||||
$amount = $array['pay_amount'];
|
||||
$name = $array['name'];
|
||||
$billName = $array['billName'];
|
||||
$mode = $array['mode'];
|
||||
$data['mode'] = $mode;
|
||||
|
||||
$data['user_secret_key'] = $array['user_secret_key'];
|
||||
$data['cateogry_code'] = $array['cateogry_code'];
|
||||
$data['payment_mode'] = 'toyyibpay';
|
||||
$data['amount'] = $amount;
|
||||
$data['charge'] = $array['charge'];
|
||||
$data['phone'] = $array['phone'];
|
||||
$data['gateway_id'] = $array['gateway_id'];
|
||||
$data['main_amount'] = $array['amount'];
|
||||
|
||||
$data['billName'] = $billName;
|
||||
$data['name'] = $name;
|
||||
$data['email'] = $email;
|
||||
$data['currency'] = $currency;
|
||||
|
||||
if ($mode == 0) {
|
||||
$data['env'] = false;
|
||||
$mode = false;
|
||||
} else {
|
||||
$data['env'] = true;
|
||||
$mode = true;
|
||||
}
|
||||
|
||||
Session::put('toyyibpay_credentials', $data);
|
||||
|
||||
if ($mode == false) {
|
||||
$url = 'https://toyyibpay.com/';
|
||||
} else {
|
||||
$url = 'https://dev.toyyibpay.com/';
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'userSecretKey' => $array['user_secret_key'],
|
||||
'categoryCode' => $array['cateogry_code'],
|
||||
'billName' => $billName,
|
||||
'billDescription' => "Thank you for order",
|
||||
'billPriceSetting' => 1,
|
||||
'billPayorInfo' => 1,
|
||||
'billAmount' => $amount * 100,
|
||||
'billReturnUrl' => Toyyibpay::fallback(),
|
||||
'billCallbackUrl' => Toyyibpay::fallback(),
|
||||
'billExternalReferenceNo' => Str::random(5) . rand(100, 200),
|
||||
'billTo' => $name,
|
||||
'billEmail' => $email,
|
||||
'billPhone' => $array['phone'],
|
||||
'billSplitPayment' => 0,
|
||||
'billSplitPaymentArgs' => '',
|
||||
'billPaymentChannel' => '2',
|
||||
'billDisplayMerchant' => 1,
|
||||
'billContentEmail' => "",
|
||||
'billChargeToCustomer' => 2,
|
||||
);
|
||||
$f_url = $url . 'index.php/api/createBill';
|
||||
|
||||
try {
|
||||
$response = Http::asForm()->post($f_url, $data);
|
||||
$billcode = $response[0]['BillCode'];
|
||||
$url = $url . $billcode;
|
||||
return request()->expectsJson() ? $url : redirect($url);
|
||||
} catch (Throwable $th) {
|
||||
return request()->expectsJson() ?
|
||||
Toyyibpay::redirect_if_payment_faild() :
|
||||
redirect(Toyyibpay::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
if (!Session::has('toyyibpay_credentials')) {
|
||||
return abort(404);
|
||||
}
|
||||
$response = Request()->all();
|
||||
$status = $response['status_id'];
|
||||
$payment_id = $response['billcode'];
|
||||
|
||||
$info = Session::get('toyyibpay_credentials');
|
||||
|
||||
if ($status == 1) {
|
||||
$data['payment_id'] = $payment_id;
|
||||
$data['payment_method'] = "toyyibpay";
|
||||
$data['gateway_id'] = $info['gateway_id'];
|
||||
|
||||
$data['amount'] = $info['main_amount'];
|
||||
$data['charge'] = $info['charge'];
|
||||
$data['status'] = 1;
|
||||
$data['payment_status'] = 1;
|
||||
|
||||
Session::forget('toyyibpay_credentials');
|
||||
Session::put('payment_info', $data);
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Toyyibpay::redirect_if_payment_success() :
|
||||
redirect(Toyyibpay::redirect_if_payment_success());
|
||||
} else {
|
||||
$data['payment_status'] = 0;
|
||||
Session::put('payment_info', $data);
|
||||
Session::forget('toyyibpay_credentials');
|
||||
|
||||
return request()->expectsJson() ?
|
||||
Toyyibpay::redirect_if_payment_faild() :
|
||||
redirect(Toyyibpay::redirect_if_payment_faild());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user