migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\Authenticatable;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\SAASSetting;
|
||||
use Modules\Authentication\Models\Setting;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
use Authenticatable;
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$paymentMethods = Setting::where('type', PAYMENT_CONFIG)
|
||||
->where('restaurant_id', $this->getCurrentRestaurantId())
|
||||
->where('status', '1')
|
||||
->get();
|
||||
|
||||
return $this->responseSuccess($paymentMethods, 'Payment methods list fetched successfully.');
|
||||
}
|
||||
|
||||
public function saasIndex(Request $request): JsonResponse
|
||||
{
|
||||
$paymentMethods = SAASSetting::where('type', PAYMENT_CONFIG)->where('status', '1')->get();
|
||||
|
||||
return $this->responseSuccess($paymentMethods, 'Payment methods list fetched successfully.');
|
||||
}
|
||||
|
||||
public function update(Request $request, $settingId): JsonResponse
|
||||
{
|
||||
$setting = Setting::findOrFail($settingId);
|
||||
$setting->update([
|
||||
'payment_info' => $request->payment_info,
|
||||
'mode' => $request->mode ?? 'test',
|
||||
'status' => $request->status ?? '1',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->responseSuccess($setting, 'Payment method credentials update successfully.');
|
||||
}
|
||||
|
||||
public function statusUpdate($paymentId)
|
||||
{
|
||||
$setting = Setting::findOrFail($paymentId);
|
||||
$setting->update([
|
||||
'status' => $setting->status === '1' ? '0' : '1',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->responseSuccess($setting, 'Payment method status updated successfully.');
|
||||
}
|
||||
|
||||
public function saasUpdate(Request $request, $settingId): JsonResponse
|
||||
{
|
||||
$setting = SAASSetting::findOrFail($settingId);
|
||||
$setting->update([
|
||||
'payment_info' => $request->payment_info,
|
||||
'mode' => $request->mode ?? 'test',
|
||||
'status' => $request->status ?? '1',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->responseSuccess($setting, 'Payment method credentials update successfully.');
|
||||
}
|
||||
|
||||
public function saasStatusUpdate($paymentId)
|
||||
{
|
||||
$setting = SAASSetting::findOrFail($paymentId);
|
||||
$setting->update([
|
||||
'status' => $setting->status === '1' ? '0' : '1',
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return $this->responseSuccess($setting, 'SAAS Payment method status updated successfully.');
|
||||
}
|
||||
|
||||
public function payment(Request $request): JsonResponse
|
||||
{
|
||||
// Validate request
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_method' => 'required|string',
|
||||
'payment_type' => 'required|string',
|
||||
'amount' => 'required|numeric|min:0',
|
||||
'currency' => 'required|string',
|
||||
'name' => 'nullable|string',
|
||||
'phone' => 'required|string',
|
||||
'email' => 'nullable|string',
|
||||
'package_id' => 'nullable|string',
|
||||
'notes' => 'nullable|string',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'status' => 'fail',
|
||||
'message' => $validator->errors()->first(),
|
||||
], 400);
|
||||
}
|
||||
|
||||
$paymentMethod = strtolower($request->payment_method);
|
||||
$amount = $request->amount;
|
||||
$currencyCode = $request->currency ?? 'USD'; // Set your default currency or fetch dynamically
|
||||
|
||||
$payment = new PaymentRequest;
|
||||
$payment->restaurant_id = $this->getCurrentRestaurantId();
|
||||
$payment->payment_amount = $amount;
|
||||
$payment->currency_code = $currencyCode;
|
||||
$payment->payment_method = $paymentMethod;
|
||||
$payment->payment_type = $request->payment_type;
|
||||
$payment->name = $request->name ?? null;
|
||||
$payment->phone = $request->phone ?? null;
|
||||
$payment->email = $request->email ?? null;
|
||||
$payment->package_id = $request->package_id ?? null;
|
||||
$payment->notes = $request->notes ?? null;
|
||||
$payment->gateway_callback_url = $request->gateway_callback_url ?? null;
|
||||
$payment->external_redirect_link = $request->external_redirect_link ?? null;
|
||||
$payment->success_hook = $request->success_hook ?? null;
|
||||
$payment->failure_hook = $request->failure_hook ?? null;
|
||||
$payment->payment_platform = $request->payment_platform ?? null;
|
||||
|
||||
$payment->save();
|
||||
|
||||
$paymentUrl = $this->generatePaymentUrl($payment);
|
||||
if (! $paymentUrl) {
|
||||
return response()->json([
|
||||
'status' => 'fail',
|
||||
'message' => 'Invalid payment method.',
|
||||
], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'payment_url' => $paymentUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
private function generatePaymentUrl(PaymentRequest $payment)
|
||||
{
|
||||
$routes = [
|
||||
'ssl_commerz' => 'payment/sslcommerz/pay',
|
||||
'stripe' => 'payment/stripe/pay',
|
||||
'paymob_accept' => 'payment/paymob/pay',
|
||||
'flutterwave' => 'payment/flutterwave-v3/pay',
|
||||
'paytm' => 'payment/paytm/pay',
|
||||
'paypal' => 'payment/paypal/pay',
|
||||
'paytabs' => 'payment/paytabs/pay',
|
||||
'liqpay' => 'payment/liqpay/pay',
|
||||
'razor_pay' => 'payment/razor-pay/pay',
|
||||
'senang_pay' => 'payment/senang-pay/pay',
|
||||
'mercadopago' => 'payment/mercadopago/pay',
|
||||
'bkash' => 'payment/bkash/make-payment',
|
||||
'paystack' => 'payment/paystack/pay',
|
||||
];
|
||||
|
||||
if (array_key_exists($payment->payment_method, $routes)) {
|
||||
return url("{$routes[$payment->payment_method]}?payment_id={$payment->id}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function success(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => 'Payment succeeded'], 200);
|
||||
}
|
||||
|
||||
public function fail(): JsonResponse
|
||||
{
|
||||
return response()->json(['message' => 'Payment failed'], 403);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\AdditionalClasses;
|
||||
|
||||
use stdClass;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Payment method liqpay process
|
||||
*
|
||||
* @author Liqpay <support@liqpay.ua>
|
||||
*/
|
||||
class LiqPay
|
||||
{
|
||||
const CURRENCY_EUR = 'EUR';
|
||||
|
||||
const CURRENCY_USD = 'USD';
|
||||
|
||||
const CURRENCY_UAH = 'UAH';
|
||||
|
||||
const CURRENCY_RUB = 'RUB';
|
||||
|
||||
const CURRENCY_RUR = 'RUR';
|
||||
|
||||
private $_api_url = 'https://www.liqpay.ua/api/';
|
||||
|
||||
private $_checkout_url = 'https://www.liqpay.ua/api/3/checkout';
|
||||
|
||||
protected $_supportedCurrencies = [
|
||||
self::CURRENCY_EUR,
|
||||
self::CURRENCY_USD,
|
||||
self::CURRENCY_UAH,
|
||||
self::CURRENCY_RUB,
|
||||
self::CURRENCY_RUR,
|
||||
];
|
||||
|
||||
private $_public_key;
|
||||
|
||||
private $_private_key;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|null $api_url (optional)
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(string $public_key, string $private_key, ?string $api_url = null)
|
||||
{
|
||||
if (empty($public_key)) {
|
||||
throw new InvalidArgumentException('public_key is empty');
|
||||
}
|
||||
|
||||
if (empty($private_key)) {
|
||||
throw new InvalidArgumentException('private_key is empty');
|
||||
}
|
||||
|
||||
$this->_public_key = $public_key;
|
||||
$this->_private_key = $private_key;
|
||||
|
||||
if ($api_url !== null) {
|
||||
$this->_api_url = $api_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call API
|
||||
*/
|
||||
public function api(string $path, array $params = [], int $timeout = 5): stdClass
|
||||
{
|
||||
if (! isset($params['version'])) {
|
||||
throw new InvalidArgumentException('version is null');
|
||||
}
|
||||
$url = $this->_api_url.$path;
|
||||
$public_key = $this->_public_key;
|
||||
$private_key = $this->_private_key;
|
||||
$data = $this->encode_params(array_merge(compact('public_key'), $params));
|
||||
$signature = $this->str_to_sign($private_key.$data.$private_key);
|
||||
$postfields = http_build_query([
|
||||
'data' => $data,
|
||||
'signature' => $signature,
|
||||
]);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
$this->_server_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($server_output);
|
||||
}
|
||||
|
||||
/**
|
||||
* cnb_form
|
||||
*
|
||||
*
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function cnb_form(array $params): string
|
||||
{
|
||||
$language = 'en';
|
||||
if (isset($params['language']) && $params['language'] == 'en') {
|
||||
$language = 'en';
|
||||
}
|
||||
|
||||
$params = $this->cnb_params($params);
|
||||
$data = $this->encode_params($params);
|
||||
$signature = $this->cnb_signature($params);
|
||||
|
||||
return sprintf(
|
||||
'
|
||||
<form method="POST" action="%s" accept-charset="utf-8">
|
||||
%s
|
||||
%s
|
||||
<input type="image" src="//static.liqpay.ua/buttons/p1%s.radius.png" name="btn_text" />
|
||||
</form>
|
||||
',
|
||||
$this->_checkout_url,
|
||||
sprintf('<input type="hidden" name="%s" value="%s" />', 'data', $data),
|
||||
sprintf('<input type="hidden" name="%s" value="%s" />', 'signature', $signature),
|
||||
$language
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* cnb_signature
|
||||
*/
|
||||
public function cnb_signature(array $params): string
|
||||
{
|
||||
$params = $this->cnb_params($params);
|
||||
$private_key = $this->_private_key;
|
||||
|
||||
$json = $this->encode_params($params);
|
||||
$signature = $this->str_to_sign($private_key.$json.$private_key);
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* cnb_params
|
||||
*
|
||||
*
|
||||
* @return array $params
|
||||
*/
|
||||
private function cnb_params(array $params): array
|
||||
{
|
||||
$params['public_key'] = $this->_public_key;
|
||||
|
||||
if (! isset($params['version'])) {
|
||||
throw new InvalidArgumentException('version is null');
|
||||
}
|
||||
if (! isset($params['amount'])) {
|
||||
throw new InvalidArgumentException('amount is null');
|
||||
}
|
||||
if (! isset($params['currency'])) {
|
||||
throw new InvalidArgumentException('currency is null');
|
||||
}
|
||||
if (! in_array($params['currency'], $this->_supportedCurrencies)) {
|
||||
throw new InvalidArgumentException('currency is not supported');
|
||||
}
|
||||
if ($params['currency'] == self::CURRENCY_RUR) {
|
||||
$params['currency'] = self::CURRENCY_RUB;
|
||||
}
|
||||
if (! isset($params['description'])) {
|
||||
throw new InvalidArgumentException('description is null');
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* encode_params
|
||||
*/
|
||||
private function encode_params(array $params): string
|
||||
{
|
||||
return base64_encode(json_encode($params));
|
||||
}
|
||||
|
||||
/**
|
||||
* str_to_sign
|
||||
*/
|
||||
public function str_to_sign(string $str): string
|
||||
{
|
||||
return base64_encode(sha1($str, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\AdditionalClasses;
|
||||
|
||||
use App\Traits\PaymentProcess;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class Paytabs
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private $payment;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('paytabs', PAYMENT_CONFIG, $payment);
|
||||
if (! is_null($config) && $config->mode == 'live') {
|
||||
$this->config_values = json_decode($config->live_values);
|
||||
} elseif (! is_null($config) && $config->mode == 'test') {
|
||||
$this->config_values = json_decode($config->test_values);
|
||||
}
|
||||
}
|
||||
|
||||
public function send_api_request($request_url, $data, $request_method = null)
|
||||
{
|
||||
$data['profile_id'] = $this->config_values->profile_id;
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => $this->config_values->base_url.'/'.$request_url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_CUSTOMREQUEST => isset($request_method) ? $request_method : 'POST',
|
||||
CURLOPT_POSTFIELDS => json_encode($data, true),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'authorization:'.$this->config_values->server_key,
|
||||
'Content-Type:application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$response = json_decode(curl_exec($curl), true);
|
||||
curl_close($curl);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function is_valid_redirect($post_values): bool
|
||||
{
|
||||
$serverKey = $this->config_values->server_key;
|
||||
$requestSignature = $post_values['signature'];
|
||||
unset($post_values['signature']);
|
||||
$fields = array_filter($post_values);
|
||||
ksort($fields);
|
||||
$query = http_build_query($fields);
|
||||
$signature = hash_hmac('sha256', $query, $serverKey);
|
||||
if (hash_equals($signature, $requestSignature) === true) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class BkashPaymentController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private string $base_url;
|
||||
|
||||
private $app_key;
|
||||
|
||||
private $app_secret;
|
||||
|
||||
private $username;
|
||||
|
||||
private $password;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('bkash', PAYMENT_CONFIG, $payment);
|
||||
$this->config_values = $config->payment_info;
|
||||
|
||||
if ($config) {
|
||||
$this->app_key = $this->config_values['app_key'];
|
||||
$this->app_secret = $this->config_values['app_secret'];
|
||||
$this->username = $this->config_values['username'];
|
||||
$this->password = $this->config_values['password'];
|
||||
$this->base_url = ($config->mode == 'live') ? 'https://tokenized.pay.bka.sh/v1.2.0-beta' : 'https://tokenized.sandbox.bka.sh/v1.2.0-beta';
|
||||
}
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getToken()
|
||||
{
|
||||
$post_token = [
|
||||
'app_key' => $this->app_key,
|
||||
'app_secret' => $this->app_secret,
|
||||
];
|
||||
|
||||
$url = curl_init($this->base_url.'/tokenized/checkout/token/grant');
|
||||
$post_token_json = json_encode($post_token);
|
||||
$header = [
|
||||
'Content-Type:application/json',
|
||||
'username:'.$this->username,
|
||||
'password:'.$this->password,
|
||||
];
|
||||
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $post_token_json);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
return json_decode($resultdata, true);
|
||||
}
|
||||
|
||||
public function make_tokenize_payment(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$response = self::getToken();
|
||||
$auth = $response['id_token'];
|
||||
session()->put('token', $auth);
|
||||
$callbackURL = route('bkash.callback', ['payment_id' => $request['payment_id'], 'token' => $auth]);
|
||||
|
||||
$requestbody = [
|
||||
'mode' => '0011',
|
||||
'amount' => round($data->payment_amount, 2),
|
||||
'currency' => 'BDT',
|
||||
'intent' => 'sale',
|
||||
'payerReference' => $data->phone,
|
||||
'merchantInvoiceNumber' => 'invoice_'.Str::random('15'),
|
||||
'callbackURL' => $callbackURL,
|
||||
];
|
||||
|
||||
$url = curl_init($this->base_url.'/tokenized/checkout/create');
|
||||
$requestbodyJson = json_encode($requestbody);
|
||||
|
||||
$header = [
|
||||
'Content-Type:application/json',
|
||||
'Authorization:'.$auth,
|
||||
'X-APP-Key:'.$this->app_key,
|
||||
];
|
||||
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $requestbodyJson);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
$obj = json_decode($resultdata);
|
||||
|
||||
return redirect()->away($obj->{'bkashURL'});
|
||||
}
|
||||
|
||||
public function callback(Request $request): \Illuminate\Foundation\Application|JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$paymentID = $_GET['paymentID'];
|
||||
$auth = $_GET['token'];
|
||||
$request_body = [
|
||||
'paymentID' => $paymentID,
|
||||
];
|
||||
$url = curl_init($this->base_url.'/tokenized/checkout/execute');
|
||||
|
||||
$request_body_json = json_encode($request_body);
|
||||
|
||||
$header = [
|
||||
'Content-Type:application/json',
|
||||
'Authorization:'.$auth,
|
||||
'X-APP-Key:'.$this->app_key,
|
||||
];
|
||||
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $request_body_json);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
$obj = json_decode($resultdata);
|
||||
|
||||
if ($obj->statusCode == '0000') {
|
||||
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'bkash',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $obj->trxID ?? null,
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
} else {
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class FlutterwaveV3Controller extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('flutterwave', PAYMENT_CONFIG, $payment);
|
||||
$this->config_values = $config->payment_info;
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function initialize(Request $request): JsonResponse|string|RedirectResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
if ($data['additional_data'] != null) {
|
||||
$business = json_decode($data['additional_data']);
|
||||
$business_name = $business->business_name ?? 'my_business';
|
||||
} else {
|
||||
$business_name = 'my_business';
|
||||
}
|
||||
|
||||
$request = [
|
||||
'tx_ref' => time(),
|
||||
'amount' => $data->payment_amount,
|
||||
'currency' => $data->currency_code ?? 'NGN',
|
||||
'payment_options' => 'card',
|
||||
'redirect_url' => route('flutterwave-v3.callback', ['payment_id' => $data->id]),
|
||||
'customer' => [
|
||||
'email' => $data->email,
|
||||
'name' => $data->name,
|
||||
],
|
||||
'meta' => [
|
||||
'price' => $data->payment_amount,
|
||||
],
|
||||
'customizations' => [
|
||||
'title' => $business_name,
|
||||
'description' => $data->id,
|
||||
],
|
||||
];
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => 'https://api.flutterwave.com/v3/payments',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||
CURLOPT_POSTFIELDS => json_encode($request),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: Bearer '.$this->config_values['secret_key'],
|
||||
'Content-Type: application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
$res = json_decode($response);
|
||||
if ($res->status == 'success') {
|
||||
return redirect()->away($res->data->link);
|
||||
}
|
||||
|
||||
return 'We can not process your payment';
|
||||
}
|
||||
|
||||
public function callback(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
if ($request['status'] == 'successful') {
|
||||
$txid = $request['transaction_id'];
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://api.flutterwave.com/v3/transactions/{$txid}/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 => [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: Bearer '.$this->config_values['secret_key'],
|
||||
],
|
||||
]);
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$res = json_decode($response);
|
||||
if ($res->status) {
|
||||
$amountPaid = $res->data->charged_amount;
|
||||
$amountToPay = $res->data->meta->price;
|
||||
if ($amountPaid >= $amountToPay) {
|
||||
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'flutterwave',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $txid,
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
}
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Gateways\Http\Controllers\AdditionalClasses\LiqPay;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class LiqPayController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
public function __construct(PaymentRequest $payment)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
public function payment(Request $request): JsonResponse|string|RedirectResponse
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
try {
|
||||
$config = $this->paymentConfig('liqpay', PAYMENT_CONFIG, $payment);
|
||||
$values = $config->payment_info;
|
||||
|
||||
$tran = Str::random(6).'-'.rand(1, 1000);
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$public_key = $values['public_key'];
|
||||
$private_key = $values['private_key'];
|
||||
$liqpay = new LiqPay($public_key, $private_key);
|
||||
$html = $liqpay->cnb_form([
|
||||
'action' => 'pay',
|
||||
'amount' => round($data->payment_amount, 2),
|
||||
'currency' => $data->currency_code, // USD
|
||||
'description' => 'Transaction ID: '.$tran,
|
||||
'order_id' => $data->attribute_id,
|
||||
'result_url' => route('liqpay.callback', ['payment_id' => $data->id]),
|
||||
'server_url' => route('liqpay.callback', ['payment_id' => $data->id]),
|
||||
'version' => '3',
|
||||
]);
|
||||
|
||||
return $html;
|
||||
} catch (\Exception $ex) {
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function callback(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
if ($request['status'] == 'success') {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'liqpay',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request['transaction_id'],
|
||||
]);
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use MercadoPago\Payer;
|
||||
use MercadoPago\Payment;
|
||||
use MercadoPago\SDK;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class MercadoPagoController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $paymentRequest;
|
||||
|
||||
private mixed $config;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $paymentRequest, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('mercadopago', PAYMENT_CONFIG, $payment);
|
||||
$config = $this->config->value;
|
||||
|
||||
$this->paymentRequest = $paymentRequest;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index(Request $request): View|Application|Factory|JsonResponse|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->paymentRequest::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$config = $this->config;
|
||||
|
||||
return view('Gateways::payment.payment-view-marcedo-pogo', compact('config', 'data'));
|
||||
}
|
||||
|
||||
public function make_payment(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
SDK::setAccessToken($this->config->access_token);
|
||||
$payment = new Payment;
|
||||
$payment->transaction_amount = (float) $request['transactionAmount'];
|
||||
$payment->token = $request['token'];
|
||||
$payment->description = $request['description'];
|
||||
$payment->installments = (int) $request['installments'];
|
||||
$payment->payment_method_id = $request['paymentMethodId'];
|
||||
$payment->issuer_id = (int) $request['issuer'];
|
||||
|
||||
$payer = new Payer;
|
||||
$payer->email = $request['payer']['email'];
|
||||
$payer->identification = [
|
||||
'type' => $request['payer']['identification']['type'],
|
||||
'number' => $request['payer']['identification']['number'],
|
||||
];
|
||||
$payment->payer = $payer;
|
||||
$payment->save();
|
||||
|
||||
if ($payment->status == 'approved') {
|
||||
$this->paymentRequest::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'mercadopago',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $payment->id,
|
||||
]);
|
||||
$data = $this->paymentRequest::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->paymentRequest::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class PaymobController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
private string $base_url;
|
||||
|
||||
private array $supportedCountries = [
|
||||
'egypt' => 'https://accept.paymob.com',
|
||||
'PAK' => 'https://pakistan.paymob.com',
|
||||
'KSA' => 'https://ksa.paymob.com',
|
||||
'oman' => 'https://oman.paymob.com',
|
||||
'UAE' => 'https://uae.paymob.com',
|
||||
];
|
||||
|
||||
private string $defaultBaseUrl = 'https://accept.paymob.com';
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('paymob_accept', PAYMENT_CONFIG, $payment);
|
||||
$values = $config->payment_info;
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
$country = $this->config_values['supported_country'];
|
||||
if (array_key_exists($country, $this->supportedCountries)) {
|
||||
$this->base_url = $this->supportedCountries[$country];
|
||||
} else {
|
||||
$this->base_url = $this->defaultBaseUrl;
|
||||
}
|
||||
}
|
||||
|
||||
protected function cURL($url, $json)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
|
||||
$headers = [];
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$output = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
return json_decode($output);
|
||||
}
|
||||
|
||||
public function credit(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$paymentData = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($paymentData)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
session()->put('payment_id', $paymentData->id);
|
||||
|
||||
if ($paymentData['additional_data'] != null) {
|
||||
$business = json_decode($paymentData['additional_data']);
|
||||
$business_name = $business->business_name ?? 'my_business';
|
||||
} else {
|
||||
$business_name = 'my_business';
|
||||
}
|
||||
|
||||
$payer = json_decode($paymentData['payer_information']);
|
||||
$url = $this->base_url.'/v1/intention/';
|
||||
$config = $this->config_values;
|
||||
$token = $config['secret_key']; // secret key
|
||||
|
||||
// Data for the request
|
||||
$integration_id = (int) $config['integration_id'];
|
||||
$data = [
|
||||
'amount' => round($paymentData->payment_amount * 100),
|
||||
'currency' => $paymentData->currency_code,
|
||||
'payment_methods' => [$integration_id], // integration id will be integer
|
||||
'items' => [
|
||||
[
|
||||
'name' => 'payable amount',
|
||||
'amount' => round($paymentData->payment_amount * 100),
|
||||
'description' => 'payable amount',
|
||||
'quantity' => 1,
|
||||
],
|
||||
],
|
||||
'billing_data' => [
|
||||
'apartment' => 'N/A',
|
||||
'email' => ! empty($payer->email) ? $payer->email : 'test@gmail.com',
|
||||
'floor' => 'N/A',
|
||||
'first_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'street' => 'N/A',
|
||||
'building' => 'N/A',
|
||||
'phone_number' => ! empty($payer->phone) ? $payer->phone : '0182780000000',
|
||||
'shipping_method' => 'PKG',
|
||||
'postal_code' => 'N/A',
|
||||
'city' => 'N/A',
|
||||
'country' => 'N/A',
|
||||
'last_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'state' => 'N/A',
|
||||
],
|
||||
'special_reference' => time(),
|
||||
'customer' => [
|
||||
'first_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'last_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'email' => ! empty($payer->email) ? $payer->email : 'test@gmail.com',
|
||||
'extras' => [
|
||||
're' => '22',
|
||||
],
|
||||
],
|
||||
'extras' => [
|
||||
'ee' => 22,
|
||||
],
|
||||
'redirection_url' => route('paymob.callback'),
|
||||
];
|
||||
|
||||
$ch = curl_init($url);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Authorization: Token '.$token,
|
||||
'Content-Type: application/json',
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$result = json_decode($response, true);
|
||||
if (! isset($result['client_secret'])) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$secret_key = $result['client_secret'];
|
||||
curl_close($ch);
|
||||
$publicKey = $config['public_key'];
|
||||
$urlRedirect = $this->base_url."/unifiedcheckout/?publicKey=$publicKey&clientSecret=$secret_key";
|
||||
|
||||
return redirect()->to($urlRedirect);
|
||||
}
|
||||
|
||||
public function createOrder($token, $paymentData, $business_name)
|
||||
{
|
||||
$items[] = [
|
||||
'name' => $business_name,
|
||||
'amount_cents' => round($paymentData->payment_amount * 100),
|
||||
'description' => 'payment ID :'.$paymentData->id,
|
||||
'quantity' => 1,
|
||||
];
|
||||
|
||||
$data = [
|
||||
'auth_token' => $token,
|
||||
'delivery_needed' => 'false',
|
||||
'amount_cents' => round($paymentData->payment_amount * 100),
|
||||
'currency' => $paymentData->currency_code,
|
||||
'items' => $items,
|
||||
|
||||
];
|
||||
|
||||
return $this->cURL(
|
||||
$this->base_url.'/api/ecommerce/orders',
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
public function getPaymentToken($order, $token, $paymentData, $payer)
|
||||
{
|
||||
$value = $paymentData->payment_amount;
|
||||
$billingData = [
|
||||
'apartment' => 'N/A',
|
||||
'email' => ! empty($payer->email) ? $payer->email : 'test@gmail.com',
|
||||
'floor' => 'N/A',
|
||||
'first_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'street' => 'N/A',
|
||||
'building' => 'N/A',
|
||||
'phone_number' => ! empty($payer->phone) ? $payer->phone : '0182780000000',
|
||||
'shipping_method' => 'PKG',
|
||||
'postal_code' => 'N/A',
|
||||
'city' => 'N/A',
|
||||
'country' => 'N/A',
|
||||
'last_name' => ! empty($payer->name) ? $payer->name : 'rashed',
|
||||
'state' => 'N/A',
|
||||
];
|
||||
|
||||
$data = [
|
||||
'auth_token' => $token,
|
||||
'amount_cents' => round($value * 100),
|
||||
'expiration' => 3600,
|
||||
'order_id' => $order->id,
|
||||
'billing_data' => $billingData,
|
||||
'currency' => $paymentData->currency_code,
|
||||
'integration_id' => is_array($this->config_values) ? $this->config_values['integration_id'] : $this->config_values->integration_id,
|
||||
];
|
||||
|
||||
$response = $this->cURL(
|
||||
$this->base_url.'/api/acceptance/payment_keys',
|
||||
$data
|
||||
);
|
||||
|
||||
return $response->token;
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
ksort($data);
|
||||
$hmac = $data['hmac'];
|
||||
$array = [
|
||||
'amount_cents',
|
||||
'created_at',
|
||||
'currency',
|
||||
'error_occured',
|
||||
'has_parent_transaction',
|
||||
'id',
|
||||
'integration_id',
|
||||
'is_3d_secure',
|
||||
'is_auth',
|
||||
'is_capture',
|
||||
'is_refunded',
|
||||
'is_standalone_payment',
|
||||
'is_voided',
|
||||
'order',
|
||||
'owner',
|
||||
'pending',
|
||||
'source_data_pan',
|
||||
'source_data_sub_type',
|
||||
'source_data_type',
|
||||
'success',
|
||||
];
|
||||
$connectedString = '';
|
||||
foreach ($data as $key => $element) {
|
||||
if (in_array($key, $array)) {
|
||||
$connectedString .= $element;
|
||||
}
|
||||
}
|
||||
$secret = is_array($this->config_values) ? $this->config_values['hmac'] : $this->config_values->hmac;
|
||||
$hased = hash_hmac('sha512', $connectedString, $secret);
|
||||
|
||||
if ($hased == $hmac && $data['success'] === 'true') {
|
||||
|
||||
$this->payment::where(['id' => session('payment_id')])->update([
|
||||
'payment_method' => 'paymob',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => session('payment_id'),
|
||||
]);
|
||||
|
||||
$paymentData = $this->payment::where(['id' => session('payment_id')])->first();
|
||||
|
||||
if (isset($paymentData) && function_exists($paymentData->success_hook)) {
|
||||
call_user_func($paymentData->hook, $paymentData);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($paymentData, 'success');
|
||||
}
|
||||
$paymentData = $this->payment::where(['id' => session('payment_id')])->first();
|
||||
if (isset($paymentData) && function_exists($paymentData->failure_hook)) {
|
||||
call_user_func($paymentData->hook, $paymentData);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($paymentData, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class PaypalPaymentController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private string $base_url;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
public function __construct(PaymentRequest $payment)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('paypal', PAYMENT_CONFIG, $payment);
|
||||
$values = $config->payment_info;
|
||||
|
||||
if ($config) {
|
||||
$this->base_url = ($config->mode == 'test') ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com';
|
||||
}
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
public function token(): bool|string
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->base_url.'/v1/oauth2/token');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->config_values['client_id'].':'.$this->config_values['client_secret']);
|
||||
|
||||
$headers = [];
|
||||
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$accessToken = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Error:'.curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
return $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with a welcome message with instructions
|
||||
*/
|
||||
public function payment(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
if ($data['additional_data'] != null) {
|
||||
$business = json_decode($data['additional_data']);
|
||||
$business_name = $business->business_name ?? 'my_business';
|
||||
} else {
|
||||
$business_name = 'my_business';
|
||||
}
|
||||
|
||||
$accessToken = json_decode($this->token(), true);
|
||||
|
||||
if (isset($accessToken['access_token'])) {
|
||||
$accessToken = $accessToken['access_token'];
|
||||
$payment_data = [];
|
||||
$payment_data['purchase_units'] = [
|
||||
[
|
||||
'reference_id' => $data->id,
|
||||
'name' => $business_name,
|
||||
'desc' => 'payment ID :'.$data->id,
|
||||
'amount' => [
|
||||
'currency_code' => $data->currency_code ?? 'USD',
|
||||
'value' => number_format($data->payment_amount, 2),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$payment_data['invoice_id'] = $data->id;
|
||||
$payment_data['invoice_description'] = "Order #{$payment_data['invoice_id']} Invoice";
|
||||
$payment_data['total'] = round($data->payment_amount, 2);
|
||||
$payment_data['intent'] = 'CAPTURE';
|
||||
$payment_data['application_context'] = [
|
||||
'return_url' => route('paypal.success', ['payment_id' => $data->id]),
|
||||
'cancel_url' => route('paypal.cancel', ['payment_id' => $data->id]),
|
||||
];
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->base_url.'/v2/checkout/orders');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payment_data));
|
||||
|
||||
$headers = [];
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
$headers[] = "Authorization: Bearer $accessToken";
|
||||
$headers[] = 'Paypal-Request-Id:'.Str::uuid();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Error:'.curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
} else {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$response = json_decode($response);
|
||||
|
||||
$links = $response->links;
|
||||
|
||||
return Redirect::away($links[1]->href);
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with a welcome message with instructions
|
||||
*/
|
||||
public function cancel(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
return $this->paymentResponse($data, 'cancel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with a welcome message with instructions
|
||||
*/
|
||||
public function success(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
|
||||
$accessToken = json_decode($this->token(), true);
|
||||
$accessToken = $accessToken['access_token'];
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->base_url."/v2/checkout/orders/{$request->token}/capture");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
|
||||
$headers = [];
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
$headers[] = "Authorization: Bearer $accessToken";
|
||||
$headers[] = 'Paypal-Request-Id:'.Str::uuid();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Error:'.curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
|
||||
$response = json_decode($result);
|
||||
|
||||
if ($response->status === 'COMPLETED') {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'paypal',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $response->id,
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
use Unicodeveloper\Paystack\Facades\Paystack;
|
||||
|
||||
class PaystackController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('paystack', PAYMENT_CONFIG, $payment);
|
||||
$values = $config->payment_info;
|
||||
|
||||
if ($values) {
|
||||
$config = [
|
||||
'publicKey' => env('PAYSTACK_PUBLIC_KEY', $values['public_key']),
|
||||
'secretKey' => env('PAYSTACK_SECRET_KEY', $values['secret_key']),
|
||||
'paymentUrl' => env('PAYSTACK_PAYMENT_URL', 'https://api.paystack.co'),
|
||||
'merchantEmail' => env('MERCHANT_EMAIL', $values['merchant_email']),
|
||||
];
|
||||
Config::set('paystack', $config);
|
||||
}
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index(Request $request): View|Application|Factory|JsonResponse|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$reference = Paystack::genTranxRef();
|
||||
|
||||
return view('Gateways::payment.paystack', compact('data', 'reference'));
|
||||
}
|
||||
|
||||
public function redirectToGateway(Request $request)
|
||||
{
|
||||
return Paystack::getAuthorizationUrl()->redirectNow();
|
||||
}
|
||||
|
||||
public function handleGatewayCallback(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
$paymentDetails = Paystack::getPaymentData();
|
||||
if ($paymentDetails['status'] == true) {
|
||||
$this->payment::where(['attribute_id' => $paymentDetails['data']['orderID']])->update([
|
||||
'payment_method' => 'paystack',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request['trxref'],
|
||||
]);
|
||||
$data = $this->payment::where(['attribute_id' => $paymentDetails['data']['orderID']])->first();
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
|
||||
$payment_data = $this->payment::where(['attribute_id' => $paymentDetails['data']['orderID']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Http\Controllers\AdditionalClasses\Paytabs;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class PaytabsController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function payment(Request $request)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($payment_data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$payer = json_decode($payment_data['payer_information']);
|
||||
|
||||
$plugin = new Paytabs;
|
||||
$request_url = 'payment/request';
|
||||
$data = [
|
||||
'tran_type' => 'sale',
|
||||
'tran_class' => 'ecom',
|
||||
'cart_id' => $payment_data->id,
|
||||
'cart_currency' => $payment_data->currency_code ?? 'USD',
|
||||
'cart_amount' => number_format($payment_data->payment_amount, 2),
|
||||
'cart_description' => 'products',
|
||||
'paypage_lang' => 'en',
|
||||
'callback' => route('paytabs.callback', ['payment_id' => $payment_data->id]),
|
||||
'return' => route('paytabs.callback', ['payment_id' => $payment_data->id]),
|
||||
'customer_details' => [
|
||||
'name' => $payer->name,
|
||||
'email' => $payer->email,
|
||||
'phone' => $payer->phone ?? '000000',
|
||||
'street1' => 'N/A',
|
||||
'city' => 'N/A',
|
||||
'state' => 'N/A',
|
||||
'country' => 'N/A',
|
||||
'zip' => '00000',
|
||||
],
|
||||
'shipping_details' => [
|
||||
'name' => 'N/A',
|
||||
'email' => 'N/A',
|
||||
'phone' => 'N/A',
|
||||
'street1' => 'N/A',
|
||||
'city' => 'N/A',
|
||||
'state' => 'N/A',
|
||||
'country' => 'N/A',
|
||||
'zip' => '0000',
|
||||
],
|
||||
'user_defined' => [
|
||||
'udf9' => 'UDF9',
|
||||
'udf3' => 'UDF3',
|
||||
],
|
||||
];
|
||||
|
||||
$page = $plugin->send_api_request($request_url, $data);
|
||||
if (! isset($page['redirect_url'])) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
header('Location:'.$page['redirect_url']); /* Redirect browser */
|
||||
exit();
|
||||
}
|
||||
|
||||
public function callback(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
$plugin = new Paytabs;
|
||||
$response_data = $_POST;
|
||||
$transRef = filter_input(INPUT_POST, 'tranRef');
|
||||
|
||||
if (! $transRef) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$is_valid = $plugin->is_valid_redirect($response_data);
|
||||
if (! $is_valid) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$request_url = 'payment/query';
|
||||
$data = [
|
||||
'tran_ref' => $transRef,
|
||||
];
|
||||
$verify_result = $plugin->send_api_request($request_url, $data);
|
||||
$is_success = $verify_result['payment_result']['response_status'] === 'A';
|
||||
if ($is_success) {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'paytabs',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $transRef,
|
||||
]);
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
|
||||
public function response(): JsonResponse
|
||||
{
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_200), 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class PaytmController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('paytm', PAYMENT_CONFIG, $payment);
|
||||
$paytm = $config->value;
|
||||
|
||||
if (isset($paytm)) {
|
||||
$PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw-stage.paytm.in/merchant-status/getTxnStatus';
|
||||
$PAYTM_TXN_URL = 'https://securegw-stage.paytm.in/theia/processTransaction';
|
||||
if ($config->mode == 'live') {
|
||||
$PAYTM_STATUS_QUERY_NEW_URL = 'https://securegw.paytm.in/merchant-status/getTxnStatus';
|
||||
$PAYTM_TXN_URL = 'https://securegw.paytm.in/theia/processTransaction';
|
||||
}
|
||||
|
||||
$config = [
|
||||
'PAYTM_ENVIRONMENT' => (env('APP_MODE') == 'live') ? 'PROD' : 'TEST',
|
||||
'PAYTM_MERCHANT_KEY' => env('PAYTM_MERCHANT_KEY', $paytm['merchant_key']),
|
||||
'PAYTM_MERCHANT_MID' => env('PAYTM_MERCHANT_MID', $paytm['merchant_id']),
|
||||
'PAYTM_MERCHANT_WEBSITE' => env('PAYTM_MERCHANT_WEBSITE', $paytm['merchant_website_link']),
|
||||
'PAYTM_REFUND_URL' => env('PAYTM_REFUND_URL', $paytm['refund_url'] ?? ''),
|
||||
'PAYTM_STATUS_QUERY_URL' => env('PAYTM_STATUS_QUERY_URL', $PAYTM_STATUS_QUERY_NEW_URL),
|
||||
'PAYTM_STATUS_QUERY_NEW_URL' => env('PAYTM_STATUS_QUERY_NEW_URL', $PAYTM_STATUS_QUERY_NEW_URL),
|
||||
'PAYTM_TXN_URL' => env('PAYTM_TXN_URL', $PAYTM_TXN_URL),
|
||||
];
|
||||
|
||||
Config::set('paytm_config', $config);
|
||||
}
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function encrypt_e($input, $ky): bool|string
|
||||
{
|
||||
$key = html_entity_decode($ky);
|
||||
$iv = '@@@@&&&&####$$$$';
|
||||
$data = openssl_encrypt($input, 'AES-128-CBC', $key, 0, $iv);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function decrypt_e($crypt, $ky): bool|string
|
||||
{
|
||||
$key = html_entity_decode($ky);
|
||||
$iv = '@@@@&&&&####$$$$';
|
||||
$data = openssl_decrypt($crypt, 'AES-128-CBC', $key, 0, $iv);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function generateSalt_e($length): string
|
||||
{
|
||||
$random = '';
|
||||
srand((float) microtime() * 1000000);
|
||||
|
||||
$data = 'AbcDE123IJKLMN67QRSTUVWXYZ';
|
||||
$data .= 'aBCdefghijklmn123opq45rs67tuv89wxyz';
|
||||
$data .= '0FGH45OP89';
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$random .= substr($data, (rand() % (strlen($data))), 1);
|
||||
}
|
||||
|
||||
return $random;
|
||||
}
|
||||
|
||||
public function checkString_e($value)
|
||||
{
|
||||
if ($value == 'null') {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getChecksumFromArray($arrayList, $key, $sort = 1): bool|string
|
||||
{
|
||||
if ($sort != 0) {
|
||||
ksort($arrayList);
|
||||
}
|
||||
$str = $this->getArray2Str($arrayList);
|
||||
$salt = $this->generateSalt_e(4);
|
||||
$finalString = $str.'|'.$salt;
|
||||
$hash = hash('sha256', $finalString);
|
||||
$hashString = $hash.$salt;
|
||||
$checksum = $this->encrypt_e($hashString, $key);
|
||||
|
||||
return $checksum;
|
||||
}
|
||||
|
||||
public function verifychecksum_e($arrayList, $key, $checksumvalue): string
|
||||
{
|
||||
$arrayList = $this->removeCheckSumParam($arrayList);
|
||||
ksort($arrayList);
|
||||
$str = $this->getArray2StrForVerify($arrayList);
|
||||
$paytm_hash = $this->decrypt_e($checksumvalue, $key);
|
||||
$salt = substr($paytm_hash, -4);
|
||||
|
||||
$finalString = $str.'|'.$salt;
|
||||
|
||||
$website_hash = hash('sha256', $finalString);
|
||||
$website_hash .= $salt;
|
||||
|
||||
if ($website_hash == $paytm_hash) {
|
||||
$validFlag = 'TRUE';
|
||||
} else {
|
||||
$validFlag = 'FALSE';
|
||||
}
|
||||
|
||||
return $validFlag;
|
||||
}
|
||||
|
||||
public function getArray2Str($arrayList): string
|
||||
{
|
||||
$findme = 'REFUND';
|
||||
$findmepipe = '|';
|
||||
$paramStr = '';
|
||||
$flag = 1;
|
||||
foreach ($arrayList as $key => $value) {
|
||||
$pos = strpos($value, $findme);
|
||||
$pospipe = strpos($value, $findmepipe);
|
||||
if ($pos !== false || $pospipe !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($flag) {
|
||||
$paramStr .= $this->checkString_e($value);
|
||||
$flag = 0;
|
||||
} else {
|
||||
$paramStr .= '|'.$this->checkString_e($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $paramStr;
|
||||
}
|
||||
|
||||
public function getArray2StrForVerify($arrayList): string
|
||||
{
|
||||
$paramStr = '';
|
||||
$flag = 1;
|
||||
foreach ($arrayList as $key => $value) {
|
||||
if ($flag) {
|
||||
$paramStr .= $this->checkString_e($value);
|
||||
$flag = 0;
|
||||
} else {
|
||||
$paramStr .= '|'.$this->checkString_e($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $paramStr;
|
||||
}
|
||||
|
||||
public function removeCheckSumParam($arrayList)
|
||||
{
|
||||
if (isset($arrayList['CHECKSUMHASH'])) {
|
||||
unset($arrayList['CHECKSUMHASH']);
|
||||
}
|
||||
|
||||
return $arrayList;
|
||||
}
|
||||
|
||||
public function payment(Request $request): View|Factory|JsonResponse|Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$paramList = [];
|
||||
$ORDER_ID = time();
|
||||
$INDUSTRY_TYPE_ID = $request['INDUSTRY_TYPE_ID'];
|
||||
$CHANNEL_ID = $request['CHANNEL_ID'];
|
||||
$TXN_AMOUNT = round($data->payment_amount, 2);
|
||||
|
||||
$paramList['MID'] = Config::get('paytm_config.PAYTM_MERCHANT_MID');
|
||||
$paramList['ORDER_ID'] = $ORDER_ID;
|
||||
$paramList['CUST_ID'] = $data['payer_id'];
|
||||
$paramList['INDUSTRY_TYPE_ID'] = $INDUSTRY_TYPE_ID;
|
||||
$paramList['CHANNEL_ID'] = $CHANNEL_ID;
|
||||
$paramList['TXN_AMOUNT'] = $TXN_AMOUNT;
|
||||
$paramList['WEBSITE'] = Config::get('paytm_config.PAYTM_MERCHANT_WEBSITE');
|
||||
|
||||
$paramList['CALLBACK_URL'] = route('paytm.response', ['payment_id' => $data->id]);
|
||||
$paramList['MSISDN'] = $data->phone;
|
||||
$paramList['EMAIL'] = $data->email;
|
||||
$paramList['VERIFIED_BY'] = 'EMAIL';
|
||||
$paramList['IS_USER_VERIFIED'] = 'YES';
|
||||
|
||||
$checkSum = $this->getChecksumFromArray($paramList, Config::get('paytm_config.PAYTM_MERCHANT_KEY'));
|
||||
|
||||
return view('payment.paytm', compact('checkSum', 'paramList'));
|
||||
}
|
||||
|
||||
public function callback(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$paramList = $_POST;
|
||||
$paytmChecksum = isset($_POST['CHECKSUMHASH']) ? $_POST['CHECKSUMHASH'] : '';
|
||||
|
||||
$isValidChecksum = $this->verifychecksum_e($paramList, Config::get('paytm_config.PAYTM_MERCHANT_KEY'), $paytmChecksum); // will return TRUE or FALSE string.
|
||||
|
||||
if ($isValidChecksum == 'TRUE') {
|
||||
if ($request['STATUS'] == 'TXN_SUCCESS') {
|
||||
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'paytm',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request['TXNID'],
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
use SimpleXMLElement;
|
||||
|
||||
class PvitController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private $mc_tel_merchant;
|
||||
|
||||
private $access_token;
|
||||
|
||||
private $mc_merchant_code;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
public function __construct(PaymentRequest $payment)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('pvit', PAYMENT_CONFIG, $payment);
|
||||
$this->config_values = $config->payment_info;
|
||||
|
||||
if ($config) {
|
||||
$this->mc_tel_merchant = $this->config_values['mc_tel_merchant'];
|
||||
$this->access_token = $this->config_values['access_token'];
|
||||
$this->mc_merchant_code = $this->config_values['mc_merchant_code'];
|
||||
}
|
||||
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
public function payment(Request $req): View|Application|Factory|JsonResponse|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$validator = Validator::make($req->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$payment_data = $this->payment::where(['id' => $req['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($payment_data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$config_val = $this->config_values;
|
||||
|
||||
return view('Gateways::payment.pvit', compact(['payment_data', 'config_val']));
|
||||
}
|
||||
|
||||
public function callBack(Request $request): Application|JsonResponse|Redirector|\Illuminate\Contracts\Foundation\Application|RedirectResponse
|
||||
{
|
||||
if ($request->ref || $request->statut) {
|
||||
if ($request->statut == 200) {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'pvit',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request->ref ?? $request['payment_id'],
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
$data_received = file_get_contents('php://input');
|
||||
|
||||
$data_received_xml = json_decode(json_encode(new SimpleXMLElement($data_received)), true);
|
||||
|
||||
if (isset($data_received_xml['NUM_TRANSACTION']) && isset($data_received_xml['STATUT'])) {
|
||||
if ($data_received_xml['STATUT'] == 200) {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'pvit',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $data_received_xml['NUM_TRANSACTION'],
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'fail');
|
||||
}
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
use Razorpay\Api\Api;
|
||||
|
||||
class RazorPayController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('razor_pay', PAYMENT_CONFIG, $payment);
|
||||
$razor = $config->payment_info;
|
||||
if ($razor) {
|
||||
$config = [
|
||||
'api_key' => $razor['api_key'],
|
||||
'api_secret' => $razor['api_secret'],
|
||||
];
|
||||
Config::set('razor_config', $config);
|
||||
}
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index(Request $request): View|Factory|JsonResponse|Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
if ($data['additional_data'] != null) {
|
||||
$business = json_decode($data['additional_data']);
|
||||
$business_name = $business->business_name ?? 'my_business';
|
||||
$business_logo = $business->business_logo ?? url('/');
|
||||
} else {
|
||||
$business_name = 'my_business';
|
||||
$business_logo = url('/');
|
||||
}
|
||||
|
||||
return view('payment.razor-pay', compact('data', 'business_logo', 'business_name'));
|
||||
}
|
||||
|
||||
public function payment(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$input = $request->all();
|
||||
$api = new Api(config('razor_config.api_key'), config('razor_config.api_secret'));
|
||||
$input['razorpay_payment_id'] = '7c5e8410-92b2-43a8-b27c-4fd4ea930d6c';
|
||||
$payment = $api->payment->fetch($input['razorpay_payment_id']);
|
||||
|
||||
if (count($input) && ! empty($input['razorpay_payment_id'])) {
|
||||
$response = $api->payment->fetch($input['razorpay_payment_id'])->capture(['amount' => $payment['amount'] - $payment['fee']]);
|
||||
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'razor_pay',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $input['razorpay_payment_id'],
|
||||
]);
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($data) && function_exists($data->success_hook)) {
|
||||
call_user_func($data->success_hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->failure_hook)) {
|
||||
call_user_func($payment_data->failure_hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
|
||||
public function callback(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$input = $request->all();
|
||||
$data_id = base64_decode($request?->payment_data);
|
||||
$payment_data = $this->payment::where(['id' => $data_id])->first();
|
||||
if (count($input) && ! empty($input['razorpay_payment_id'])) {
|
||||
if (isset($payment_data) && function_exists($payment_data->success_hook)) {
|
||||
$payment_data->payment_method = 'razor_pay';
|
||||
$payment_data->is_paid = 1;
|
||||
$payment_data->transaction_id = $input['razorpay_payment_id'];
|
||||
$payment_data->save();
|
||||
call_user_func($payment_data->success_hook, $payment_data);
|
||||
|
||||
return $this->paymentResponse($payment_data, 'success');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
|
||||
public function cancel(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class SenangPayController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private mixed $config_values;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private User $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('senang_pay', PAYMENT_CONFIG, $payment);
|
||||
$this->config_values = $config->payment_info;
|
||||
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index(Request $request): View|Factory|JsonResponse|Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($payment_data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$payer = json_decode($payment_data['payer_information']);
|
||||
$config = $this->config_values;
|
||||
session()->put('payment_id', $payment_data->id);
|
||||
|
||||
return view('Gateways::payment.senang-pay', compact('payment_data', 'payer', 'config'));
|
||||
}
|
||||
|
||||
public function return_senang_pay(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
if ($request['status_id'] == 1) {
|
||||
$this->payment::where(['id' => session()->get('payment_id')])->update([
|
||||
'payment_method' => 'senang_pay',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request['transaction_id'],
|
||||
]);
|
||||
$data = $this->payment::where(['id' => session()->get('payment_id')])->first();
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => session()->get('payment_id')])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->hook)) {
|
||||
call_user_func($payment_data->hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Authentication\Models\User;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
|
||||
class SslCommerzPaymentController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private $store_id;
|
||||
|
||||
private $store_password;
|
||||
|
||||
private bool $host;
|
||||
|
||||
private string $direct_api_url;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
private $user;
|
||||
|
||||
public function __construct(PaymentRequest $payment, User $user)
|
||||
{
|
||||
$paymentId = request()->query('payment_id');
|
||||
$payment = PaymentRequest::where(['id' => $paymentId])->first();
|
||||
|
||||
$config = $this->paymentConfig('ssl_commerz', 'payment_config', $payment);
|
||||
$values = $config->payment_info;
|
||||
|
||||
if ($config) {
|
||||
$this->store_id = $values['store_id'];
|
||||
$this->store_password = $values['store_password'];
|
||||
|
||||
// REQUEST SEND TO SSLCOMMERZ
|
||||
$this->direct_api_url = 'https://sandbox.sslcommerz.com/gwprocess/v4/api.php';
|
||||
$this->host = true;
|
||||
|
||||
if ($config->mode == 'live') {
|
||||
$this->direct_api_url = 'https://securepay.sslcommerz.com/gwprocess/v4/api.php';
|
||||
$this->host = false;
|
||||
}
|
||||
}
|
||||
$this->payment = $payment;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(DEFAULT_204), 200);
|
||||
}
|
||||
|
||||
$payment_amount = $data['payment_amount'];
|
||||
|
||||
$post_data = [];
|
||||
$post_data['store_id'] = $this->store_id;
|
||||
$post_data['store_passwd'] = $this->store_password;
|
||||
$post_data['total_amount'] = round($payment_amount, 2);
|
||||
$post_data['currency'] = $data['currency_code'];
|
||||
$post_data['tran_id'] = uniqid();
|
||||
|
||||
$post_data['success_url'] = url('/').'/payment/sslcommerz/success?payment_id='.$data['id'];
|
||||
$post_data['fail_url'] = url('/').'/payment/sslcommerz/failed?payment_id='.$data['id'];
|
||||
$post_data['cancel_url'] = url('/').'/payment/sslcommerz/canceled?payment_id='.$data['id'];
|
||||
|
||||
// CUSTOMER INFORMATION
|
||||
$post_data['cus_name'] = $data->name;
|
||||
$post_data['cus_email'] = $data->email ?? 'customer@gmail.com';
|
||||
$post_data['cus_add1'] = 'N/A';
|
||||
$post_data['cus_add2'] = '';
|
||||
$post_data['cus_city'] = '';
|
||||
$post_data['cus_state'] = '';
|
||||
$post_data['cus_postcode'] = '';
|
||||
$post_data['cus_country'] = '';
|
||||
$post_data['cus_phone'] = $data->phone ?? '0000000000';
|
||||
$post_data['cus_fax'] = '';
|
||||
|
||||
// SHIPMENT INFORMATION
|
||||
$post_data['ship_name'] = 'N/A';
|
||||
$post_data['ship_add1'] = 'N/A';
|
||||
$post_data['ship_add2'] = 'N/A';
|
||||
$post_data['ship_city'] = 'N/A';
|
||||
$post_data['ship_state'] = 'N/A';
|
||||
$post_data['ship_postcode'] = 'N/A';
|
||||
$post_data['ship_phone'] = '';
|
||||
$post_data['ship_country'] = 'N/A';
|
||||
|
||||
$post_data['shipping_method'] = 'NO';
|
||||
$post_data['product_name'] = 'N/A';
|
||||
$post_data['product_category'] = 'N/A';
|
||||
$post_data['product_profile'] = 'service';
|
||||
|
||||
// OPTIONAL PARAMETERS
|
||||
$post_data['value_a'] = 'ref001';
|
||||
$post_data['value_b'] = 'ref002';
|
||||
$post_data['value_c'] = 'ref003';
|
||||
$post_data['value_d'] = 'ref004';
|
||||
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, $this->direct_api_url);
|
||||
curl_setopt($handle, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
curl_setopt($handle, CURLOPT_POST, 1);
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, $post_data);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, $this->host); // KEEP IT FALSE IF YOU RUN FROM LOCAL PC
|
||||
|
||||
$content = curl_exec($handle);
|
||||
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200 && ! (curl_errno($handle))) {
|
||||
curl_close($handle);
|
||||
$sslcommerzResponse = $content;
|
||||
} else {
|
||||
curl_close($handle);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
$sslcz = json_decode($sslcommerzResponse, true);
|
||||
|
||||
if (isset($sslcz['GatewayPageURL']) && $sslcz['GatewayPageURL'] != '') {
|
||||
echo "<meta http-equiv='refresh' content='0;url=".$sslcz['GatewayPageURL']."'>";
|
||||
exit;
|
||||
} else {
|
||||
return response()->json($this->responseFormatter(DEFAULT_204), 200);
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTION TO CHECK HASH VALUE
|
||||
protected function SSLCOMMERZ_hash_verify($store_passwd, $post_data)
|
||||
{
|
||||
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 = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public function success(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
if ($request['status'] == 'VALID' && $this->SSLCOMMERZ_hash_verify($this->store_password, $request)) {
|
||||
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'ssl_commerz',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $request->input('tran_id'),
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
if (isset($data) && function_exists($data->hook)) {
|
||||
call_user_func($data->hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
return $this->paymentResponse($data, 'fail');
|
||||
}
|
||||
|
||||
public function failed(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
return $this->paymentResponse($data, 'fail');
|
||||
}
|
||||
|
||||
public function canceled(Request $request): JsonResponse|Redirector|RedirectResponse|Application
|
||||
{
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
|
||||
return $this->paymentResponse($data, 'cancel');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Http\Controllers\WEB;
|
||||
|
||||
use App\Traits\PaymentProcess;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Modules\Gateways\Models\PaymentRequest;
|
||||
use Stripe\Checkout\Session;
|
||||
use Stripe\Stripe;
|
||||
|
||||
class StripePaymentController extends Controller
|
||||
{
|
||||
use PaymentProcess;
|
||||
|
||||
private $config_values;
|
||||
|
||||
private PaymentRequest $payment;
|
||||
|
||||
public function __construct(PaymentRequest $payment)
|
||||
{
|
||||
// Skip all logic when running in console (artisan)
|
||||
if (app()->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$paymentId = request()->query('payment_id');
|
||||
|
||||
$payment = PaymentRequest::find($paymentId);
|
||||
|
||||
if (! $payment) {
|
||||
throw new \Exception('Payment not found!');
|
||||
}
|
||||
|
||||
$config = $this->paymentConfig('stripe', PAYMENT_CONFIG, $payment);
|
||||
|
||||
if (! $config) {
|
||||
throw new \Exception('Stripe payment config not found!');
|
||||
}
|
||||
|
||||
$this->config_values = $config->payment_info;
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
public function index(Request $request): View|Factory|JsonResponse|Application
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
'payment_id' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_400, null, $this->errorProcessor($validator)), 400);
|
||||
}
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$config = $this->config_values;
|
||||
|
||||
return view('payment.stripe', compact('data', 'config'));
|
||||
}
|
||||
|
||||
public function payment_process_3d(Request $request): JsonResponse
|
||||
{
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->where(['is_paid' => 0])->first();
|
||||
if (! isset($data)) {
|
||||
return response()->json($this->responseFormatter(GATEWAYS_DEFAULT_204), 200);
|
||||
}
|
||||
$payment_amount = $data['payment_amount'];
|
||||
|
||||
Stripe::setApiKey($this->config_values['api_key']);
|
||||
header('Content-Type: application/json');
|
||||
$currency_code = $data->currency_code;
|
||||
|
||||
$checkout_session = Session::create([
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [[
|
||||
'price_data' => [
|
||||
'currency' => $currency_code ?? 'usd',
|
||||
'unit_amount' => round($payment_amount, 2) * 100,
|
||||
'product_data' => [
|
||||
'name' => 'Fees Collection',
|
||||
],
|
||||
],
|
||||
'quantity' => 1,
|
||||
]],
|
||||
'mode' => 'payment',
|
||||
'success_url' => url('/').'/payment/stripe/success?session_id={CHECKOUT_SESSION_ID}&payment_id='.$data->id,
|
||||
'cancel_url' => url()->previous(),
|
||||
]);
|
||||
|
||||
return response()->json(['id' => $checkout_session->id]);
|
||||
}
|
||||
|
||||
public function success(Request $request)
|
||||
{
|
||||
Stripe::setApiKey($this->config_values['api_key']);
|
||||
$session = Session::retrieve($request->get('session_id'));
|
||||
|
||||
if ($session->payment_status == 'paid' && $session->status == 'complete') {
|
||||
$this->payment::where(['id' => $request['payment_id']])->update([
|
||||
'payment_method' => 'stripe',
|
||||
'is_paid' => 1,
|
||||
'transaction_id' => $session->payment_intent,
|
||||
]);
|
||||
|
||||
$data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($data) && function_exists($data->success_hook)) {
|
||||
call_user_func($data->success_hook, $data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($data, 'success');
|
||||
}
|
||||
$payment_data = $this->payment::where(['id' => $request['payment_id']])->first();
|
||||
if (isset($payment_data) && function_exists($payment_data->failure_hook)) {
|
||||
call_user_func($payment_data->failure_hook, $payment_data);
|
||||
}
|
||||
|
||||
return $this->paymentResponse($payment_data, 'fail');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PaymentRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'restaurant_id',
|
||||
'receiver_id',
|
||||
'payment_amount',
|
||||
'gateway_callback_url',
|
||||
'success_hook',
|
||||
'failure_hook',
|
||||
'transaction_id',
|
||||
'currency_code',
|
||||
'payment_method',
|
||||
'payment_type',
|
||||
'additional_data',
|
||||
'is_paid',
|
||||
'payer_information',
|
||||
'external_redirect_link',
|
||||
'receiver_information',
|
||||
'attribute_id',
|
||||
'package_id',
|
||||
'notes',
|
||||
'attribute',
|
||||
'payment_platform',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'payer_information' => 'array',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array<string, array<int, string>>
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* Indicates if events should be discovered.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected static $shouldDiscoverEvents = true;
|
||||
|
||||
/**
|
||||
* Configure the proper event listeners for email verification.
|
||||
*/
|
||||
protected function configureEmailVerification(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Nwidart\Modules\Traits\PathNamespace;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class GatewaysServiceProvider extends ServiceProvider
|
||||
{
|
||||
use PathNamespace;
|
||||
|
||||
protected string $name = 'Gateways';
|
||||
|
||||
protected string $nameLower = 'gateways';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/'.$this->nameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$relativeConfigPath = config('modules.paths.generator.config.path');
|
||||
$configPath = module_path($this->name, $relativeConfigPath);
|
||||
|
||||
if (is_dir($configPath)) {
|
||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if ($file->isFile() && $file->getExtension() === 'php') {
|
||||
$relativePath = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname());
|
||||
$configKey = $this->nameLower.'.'.str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
|
||||
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;
|
||||
|
||||
$this->publishes([$file->getPathname() => config_path($relativePath)], 'config');
|
||||
$this->mergeConfigFrom($file->getPathname(), $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/'.$this->nameLower);
|
||||
$sourcePath = module_path($this->name, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
|
||||
|
||||
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
|
||||
Blade::componentNamespace($componentNamespace, $this->nameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path.'/modules/'.$this->nameLower)) {
|
||||
$paths[] = $path.'/modules/'.$this->nameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Gateways\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $name = 'Gateways';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path($this->name, '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path($this->name, '/routes/api.php'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user