<?php
namespace extras\plugins\offlinepayment;
use App\Helpers\Number;
use App\Models\Permission;
use App\Models\Post;
use App\Models\PaymentMethod;
use App\Models\User;
use extras\plugins\offlinepayment\app\Notifications\PaymentNotification;
use extras\plugins\offlinepayment\app\Notifications\PaymentSent;
use Illuminate\Http\Request;
use App\Helpers\Payment;
use App\Models\Package;
use App\Models\Payment as PaymentModel;
use Illuminate\Support\Facades\Notification;
class Offlinepayment extends Payment
{
/**
* Send Payment
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Post $post
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public static function sendPayment(Request $request, Post $post)
{
// Messages
self::$msg['checkout']['success'] = trans('offlinepayment::messages.We have received your offline payment request.') . ' ' .
trans('offlinepayment::messages.We will wait to receive your payment to process your request.');
// Set URLs
parent::$uri['previousUrl'] = str_replace(['#entryToken', '#entryId'], [$post->tmp_token, $post->id], parent::$uri['previousUrl']);
parent::$uri['nextUrl'] = str_replace(['#entryToken', '#entryId', '#entrySlug'], [$post->tmp_token, $post->id, $post->slug], parent::$uri['nextUrl']);
parent::$uri['paymentCancelUrl'] = str_replace(['#entryToken', '#entryId'], [$post->tmp_token, $post->id], parent::$uri['paymentCancelUrl']);
parent::$uri['paymentReturnUrl'] = str_replace(['#entryToken', '#entryId'], [$post->tmp_token, $post->id], parent::$uri['paymentReturnUrl']);
// Get the Package
$package = Package::find($request->input('package_id'));
// Don't make a payment if 'price' = 0 or null
if (empty($package) || $package->price <= 0) {
if (isFromApi()) {
return self::error(400);
} else {
return redirect(parent::$uri['previousUrl'] . '?error=package')->withInput();
}
}
// API Parameters
$params = [
'cancelUrl' => parent::$uri['paymentCancelUrl'],
'returnUrl' => parent::$uri['paymentReturnUrl'],
'payment_method_id' => $request->input('payment_method_id'),
'post_id' => $post->id,
'package_id' => $package->id,
'name' => $package->name,
'description' => trans('offlinepayment::messages.Ad') . ' #' . $post->id . ' - ' . $package->name,
'amount' => Number::toFloat($package->price),
'currency' => $package->currency_code,
];
// Save the Payment in database
$payment = self::register($post, $params);
if (isFromApi()) {
// Transform Entity using its Eloquent Resource
if (config('larapen.core.itemId') == '16458425') {
// LaraClassified
$payment = (new \extras\plugins\api\app\Http\Resources\PaymentResource($payment))->toArray($request);
} else {
// JobClass
$payment = (new \extras\plugins\apijc\app\Http\Resources\PaymentResource($payment))->toArray($request);
}
$msg = self::$msg['checkout']['success'];
return self::response($payment, $msg);
} else {
// Successful transaction
flash(self::$msg['checkout']['success'])->success();
// Redirect
session()->flash('message', self::$msg['post']['success']);
return redirect(self::$uri['nextUrl']);
}
}
/**
* Save the payment and Send payment confirmation email
*
* @param Post $post
* @param $params
* @return PaymentModel|\Illuminate\Http\JsonResponse|null
*/
public static function register(Post $post, $params)
{
if (empty($post)) {
return null;
}
// Update ad 'reviewed' & 'featured' fields
$post->reviewed = ($post->reviewed == 1) ? 1 : 0;
$post->featured = ($post->featured == 1) ? 1 : 0;
$post->save();
// Save the payment
$paymentInfo = [
'post_id' => $post->id,
'package_id' => $params['package_id'],
'payment_method_id' => $params['payment_method_id'],
'transaction_id' => (isset($params['transaction_id'])) ? $params['transaction_id'] : null,
'amount' => (isset($params['amount'])) ? $params['amount'] : 0,
'active' => 0,
];
$payment = new PaymentModel($paymentInfo);
$payment->save();
// SEND EMAILS
// Get all admin users
if (Permission::checkDefaultPermissions()) {
$admins = User::permission(Permission::getStaffPermissions())->get();
} else {
$admins = User::where('is_admin', 1)->get();
}
// Send Payment Email Notifications
if (config('settings.mail.payment_notification') == 1) {
// Send Confirmation Email
try {
$post->notify(new PaymentSent($payment, $post));
} catch (\Exception $e) {
if (isFromApi()) {
self::$errors[] = $e->getMessage();
return self::error(400);
} else {
flash($e->getMessage())->error();
}
}
// Send to Admin the Payment Notification Email
try {
if ($admins->count() > 0) {
Notification::send($admins, new PaymentNotification($payment, $post));
}
} catch (\Exception $e) {
if (isFromApi()) {
self::$errors[] = $e->getMessage();
return self::error(400);
} else {
flash($e->getMessage())->error();
}
}
}
return $payment;
}
/**
* @return array
*/
public static function getOptions()
{
$options = [];
$paymentMethod = PaymentMethod::active()->where('name', 'offlinepayment')->first();
if (!empty($paymentMethod)) {
$options[] = (object)[
'name' => mb_ucfirst(trans('admin.settings')),
'url' => admin_url('payment_methods/' . $paymentMethod->id . '/edit'),
'btnClass' => 'btn-info',
];
}
return $options;
}
/**
* @return bool
*/
public static function installed()
{
$paymentMethod = PaymentMethod::active()->where('name', 'offlinepayment')->first();
if (empty($paymentMethod)) {
return false;
}
return true;
}
/**
* @return bool
*/
public static function install()
{
// Remove the plugin entry
self::uninstall();
// Plugin data
$data = [
'id' => 5,
'name' => 'offlinepayment',
'display_name' => 'Offline Payment',
'description' => null,
'has_ccbox' => 0,
'is_compatible_api' => 1,
'lft' => 5,
'rgt' => 5,
'depth' => 1,
'active' => 1,
];
try {
// Create plugin data
$paymentMethod = PaymentMethod::create($data);
if (empty($paymentMethod)) {
return false;
}
} catch (\Exception $e) {
return false;
}
return true;
}
/**
* @return bool
*/
public static function uninstall()
{
$uninstalled = false;
$paymentMethod = PaymentMethod::where('name', 'offlinepayment')->first();
if (!empty($paymentMethod)) {
$deleted = $paymentMethod->delete();
if ($deleted > 0) {
$uninstalled = true;
}
}
if ($uninstalled) {
try {
$payments = PaymentModel::where('transaction_id', 'featured');
if ($payments->count() > 0) {
foreach ($payments->cursor() as $payment) {
$post = Post::find($payment->post_id);
if (!empty($post)) {
$post->featured = 0;
$post->save();
}
$payment->delete();
}
}
} catch (\Exception $e) {}
}
return $uninstalled;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
【WordPress插件】2022年最新版完整功能demo+插件V2.3 (Nulled).zip
共17个文件
php:13个
png:2个
html:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 34 浏览量
2022-04-15
21:47:33
上传
评论
收藏 48KB ZIP 举报
温馨提示
"【WordPress插件】2022年最新版完整功能demo+插件V2.3 (Nulled) Offline Payment Gateway Plugin for LaraClassified and JobClass 脱机支付Gateway插件用于Laraclassification和Jobclass" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,更有超10000个资源可供选择,如有需要请站内联系。
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress插件】2022年最新版完整功能demo+插件V2.3 (Nulled).zip (17个子文件)
OfflinepaymentServiceProvider.php 879B
config.php 254B
Offlinepayment.php 7KB
resources
lang
en
sms.php 239B
messages.php 1KB
mail.php 1KB
fr
sms.php 239B
messages.php 1KB
mail.php 2KB
views
offlinepayment.blade.php 4KB
app
Helpers
OpTools.php 3KB
Notifications
PaymentNotification.php 2KB
PaymentSent.php 2KB
public
images
logo-offlinepayment.png 38KB
payment.png 27KB
documentation.html 4KB
init.json 273B
共 17 条
- 1
资源评论
Lee达森
- 粉丝: 966
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功