mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
adding auto payout paypal
This commit is contained in:
parent
b688a8a989
commit
9b69fda487
13 changed files with 240 additions and 12 deletions
0
objects/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/README
Normal file → Executable file
0
objects/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/README
Normal file → Executable file
|
@ -3743,6 +3743,7 @@ function getUsageFromFilename($filename, $dir = "") {
|
|||
$filesProcessed = array();
|
||||
if (empty($files)) {
|
||||
_error_log("getUsageFromFilename: we did not find any file for {$dir}{$filename}, we will create a fake one " . json_encode(debug_backtrace()));
|
||||
make_path($dir);
|
||||
file_put_contents("{$dir}{$filename}.notfound", time());
|
||||
$totalSize = 10;
|
||||
} else {
|
||||
|
|
|
@ -41,7 +41,7 @@ global $global, $config, $advancedCustom, $advancedCustomUser;
|
|||
$global['mysqli'] = new mysqli($mysqlHost, $mysqlUser, $mysqlPass, $mysqlDatabase, @$mysqlPort);
|
||||
|
||||
if ($global['mysqli'] === false || !empty($global['mysqli']->connect_errno)) {
|
||||
error_log("MySQL connect_errno[{$global['mysqli']->connect_errno}] {$global['mysqli']->connect_error}", AVideoLog::$ERROR);
|
||||
error_log("MySQL connect_errno[{$global['mysqli']->connect_errno}] {$global['mysqli']->connect_error}");
|
||||
include $global['systemRootPath'] . 'view/include/offlinePage.php';
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -2899,7 +2899,7 @@ if (!class_exists('Video')) {
|
|||
return true;
|
||||
}
|
||||
$videosDir = self::getStoragePath();
|
||||
mkdir($paths['path'], 0755, true);
|
||||
make_path($paths['path']);
|
||||
$files = _glob($videosDir, '/' . $videoFilename . '[._][a-z0-9_]+/i');
|
||||
//var_dump($paths['path'], is_dir($paths['path']), $files);exit;
|
||||
foreach ($files as $oldname) {
|
||||
|
|
|
@ -504,4 +504,6 @@ class CustomizeUser extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ use PayPal\Api\AgreementStateDescriptor;
|
|||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Plan;
|
||||
use PayPal\Api\ShippingAddress;
|
||||
use PaypalPayoutsSDK\Payouts\PayoutsPostRequest;
|
||||
|
||||
//require_once $global['systemRootPath'] . 'plugin/PayPalYPT/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Plan.php';
|
||||
|
||||
|
@ -31,6 +32,7 @@ class PayPalYPT extends PluginAbstract {
|
|||
PluginTags::$FREE,
|
||||
);
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
return "Paypal module for several purposes<br>
|
||||
Go to Paypal developer <a href='https://developer.paypal.com/developer/applications' target='_blank'>Site here</a> (you must have Paypal account, of course)
|
||||
|
@ -59,6 +61,7 @@ class PayPalYPT extends PluginAbstract {
|
|||
$obj->paymentButtonLabel = "Pay With PayPal";
|
||||
$obj->ClientSecret = "ECxtMBsLr0cFwSCgI0uaDiVzEUbVlV3r_o_qaU-SOsQqCEOKPq4uGlr1C0mhdDmEyO30mw7-PF0bOnfo";
|
||||
$obj->disableSandbox = false;
|
||||
$obj->enablePayout = false;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
@ -216,7 +219,6 @@ class PayPalYPT extends PluginAbstract {
|
|||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0')
|
||||
->setSetupFee(new Currency(array('value' => $total, 'currency' => $currency)));
|
||||
|
||||
} else {
|
||||
$merchantPreferences->setReturnUrl($redirect_url)
|
||||
->setCancelUrl($cancel_url)
|
||||
|
@ -224,7 +226,6 @@ class PayPalYPT extends PluginAbstract {
|
|||
->setAutoBillAmount('yes')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0');
|
||||
|
||||
}
|
||||
$plan->setMerchantPreferences($merchantPreferences);
|
||||
|
||||
|
@ -531,4 +532,132 @@ class PayPalYPT extends PluginAbstract {
|
|||
curl_close($ch);
|
||||
}
|
||||
|
||||
public static function setUserReceiverEmail($users_id, $email) {
|
||||
$user = new User($users_id);
|
||||
$paramName = 'PayPalReceiverEmail';
|
||||
return $user->addExternalOptions($paramName, $email);
|
||||
}
|
||||
|
||||
public static function getUserReceiverEmail($users_id) {
|
||||
$user = new User($users_id);
|
||||
$paramName = 'PayPalReceiverEmail';
|
||||
return $user->getExternalOption($paramName);
|
||||
}
|
||||
|
||||
public function getMyAccount($users_id) {
|
||||
global $global;
|
||||
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('PayPalYPT');
|
||||
if (empty($obj) || empty($obj->enablePayout)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
include $global['systemRootPath'] . 'plugin/PayPalYPT/payOutReceiverEmailForm.php';
|
||||
}
|
||||
|
||||
public static function WalletPayout($users_id_to_be_paid, $value) {
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
$obj->msg = '';
|
||||
$obj->response = false;
|
||||
|
||||
if (empty($value)) {
|
||||
$obj->msg = 'value is empty';
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$wallet = AVideoPlugin::getDataObjectIfEnabled('YPTWallet');
|
||||
if (empty($wallet)) {
|
||||
$obj->msg = 'YPTWallet plugin is disabled';
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$user->getExternalOption($id);
|
||||
|
||||
// check if the user has a paypal email
|
||||
$receiver_email = self::getUserReceiverEmail($users_id_to_be_paid);
|
||||
if (empty($receiver_email)) {
|
||||
$obj->msg = "The user {$users_id_to_be_paid} does not have a paypal receiver email";
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// transfer money from wallet
|
||||
$description = "Paypal payout";
|
||||
$transfer = YPTWallet::transferBalanceToSiteOwner($users_id_to_be_paid, $value, $description = "", true);
|
||||
if ($transfer) {
|
||||
$email_subject = $note = "You received " . YPTWallet::formatCurrency($value) . " from " . $config->getWebSiteTitle() . " ";
|
||||
// payout using paypal
|
||||
$obj->response = self::Payout($receiver_email, $value, $wallet->currency, $note, $email_subject);
|
||||
if (empty($obj->response)) {
|
||||
$obj->msg = 'PayPal Payout error';
|
||||
return $obj;
|
||||
}
|
||||
|
||||
$obj->error = false;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public static function Payout($receiver_email, $value, $currency = 'USD', $note = '', $email_subject = '') {
|
||||
|
||||
if (empty($value)) {
|
||||
_error_log('PayPal::Payout value is empty');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($receiver_email)) {
|
||||
_error_log("PayPal::Payout The user {$users_id_to_be_paid} does not have a paypal receiver email");
|
||||
return false;
|
||||
}
|
||||
|
||||
$paypal = AVideoPlugin::getDataObjectIfEnabled('PayPalYPT');
|
||||
if (empty($paypal) || $paypal->enablePayout) {
|
||||
_error_log('PayPal::Payout plugin or payout is disabled');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$request = new PayoutsPostRequest();
|
||||
$request->body = new stdClass();
|
||||
$request->body->sender_batch_header = new stdClass();
|
||||
$request->body->sender_batch_header->email_subject = $email_subject;
|
||||
$item = new stdClass();
|
||||
$item->recipient_type = 'EMAIL';
|
||||
$item->receiver = $receiver_email;
|
||||
$item->note = $note;
|
||||
$item->amount = new stdClass();
|
||||
$item->amount->currency = $currency;
|
||||
$item->amount->value = $value;
|
||||
$request->body->items = array($item);
|
||||
|
||||
$request->body = self::buildRequestBody();
|
||||
$client = PayPalClient::client();
|
||||
$response = $client->execute($request);
|
||||
if ($debug) {
|
||||
$msg = '';
|
||||
$msg .= "Status Code: {$response->statusCode}\n";
|
||||
$msg .= "Status: {$response->result->batch_header->batch_status}\n";
|
||||
$msg .= "Batch ID: {$response->result->batch_header->payout_batch_id}\n";
|
||||
$msg .= "Links:\n";
|
||||
foreach ($response->result->links as $link) {
|
||||
$msg .= "\t{$link->rel}: {$link->href}\tCall Type: {$link->method}\n";
|
||||
}
|
||||
// To toggle printing the whole response body comment/uncomment below line
|
||||
$msg .= json_encode($response->result, JSON_PRETTY_PRINT) . "\n";
|
||||
_error_log('PayPal::Payout ' . $msg);
|
||||
}
|
||||
return $response;
|
||||
} catch (HttpException $e) {
|
||||
$msg = '';
|
||||
//Parse failure response
|
||||
$msg .= $e->getMessage() . "\n";
|
||||
$error = json_decode($e->getMessage());
|
||||
$msg .= $error->message . "\n";
|
||||
$msg .= $error->name . "\n";
|
||||
$msg .= $error->debug_id . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
46
plugin/PayPalYPT/payOutReceiverEmailForm.php
Normal file
46
plugin/PayPalYPT/payOutReceiverEmailForm.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
$uid = uniqid();
|
||||
?>
|
||||
<div class="form-group">
|
||||
<label class="col-md-4 control-label"><?php echo __("PayPal payout email"); ?></label>
|
||||
<div class="col-md-8 inputGroupContainer">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">
|
||||
<i class="fab fa-paypal"></i>
|
||||
</span>
|
||||
<input id="PayPalReceiverEmail"
|
||||
placeholder="<?php echo __("PayPal payout email"); ?>"
|
||||
class="form-control"
|
||||
type="email"
|
||||
value="<?php echo PayPalYPT::getUserReceiverEmail(User::getId()); ?>" >
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var PayPalReceiverEmailTimeout;
|
||||
$(document).ready(function () {
|
||||
$('#PayPalReceiverEmail').keyup(function (e) {
|
||||
clearTimeout(PayPalReceiverEmailTimeout);
|
||||
PayPalReceiverEmailTimeout = setTimeout(function(){
|
||||
savePayPalReceiverEmail();
|
||||
},500);
|
||||
});
|
||||
});
|
||||
|
||||
function savePayPalReceiverEmail() {
|
||||
var PayPalReceiverEmail = $('#PayPalReceiverEmail').val();
|
||||
if(PayPalReceiverEmail !== '' && !isEmailValid(PayPalReceiverEmail)){
|
||||
console.log('savePayPalReceiverEmail', 'invalid email');
|
||||
return false;
|
||||
}
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: '<?php echo $global['webSiteRootURL']; ?>plugin/PayPalYPT/savePayPalReceiverEmail.json.php',
|
||||
data: {"PayPalReceiverEmail": PayPalReceiverEmail},
|
||||
type: 'post',
|
||||
success: function (response) {
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
28
plugin/PayPalYPT/savePayPalReceiverEmail.json.php
Normal file
28
plugin/PayPalYPT/savePayPalReceiverEmail.json.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
require_once '../../videos/configuration.php';
|
||||
session_write_close();
|
||||
header('Content-Type: application/json');
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
$obj->msg = "";
|
||||
if(!User::isLogged()){
|
||||
$obj->msg = "Not logged";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if(!isset($_POST['PayPalReceiverEmail'])){
|
||||
$obj->msg = "PayPalReceiverEmail is empty";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
$pp = AVideoPlugin::loadPluginIfEnabled('PayPalYPT');
|
||||
|
||||
if(empty($pp)){
|
||||
$obj->msg = "Plugin not enabled";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
$obj->error = false;
|
||||
|
||||
PayPalYPT::setUserReceiverEmail(User::getId(), $_POST['PayPalReceiverEmail']);
|
||||
|
||||
die(json_encode($obj));
|
|
@ -74,6 +74,7 @@ class YPTWallet extends PluginAbstract
|
|||
$obj->manualAddFundsTransferFromUserId = 1;
|
||||
// sell funds
|
||||
$obj->enableManualWithdrawFundsPage = true;
|
||||
$obj->enableAutoWithdrawFundsPage = false;
|
||||
$obj->withdrawFundsOptions = "[5,10,20,50,100,1000]";
|
||||
$obj->manualWithdrawFundsMenuTitle = "Withdraw Funds";
|
||||
$obj->manualWithdrawFundsPageButton = "Request Withdraw";
|
||||
|
|
6
plugin/YPTWallet/view/autoWithdrawFunds.php
Normal file
6
plugin/YPTWallet/view/autoWithdrawFunds.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
$autoWithdraw = 1;
|
||||
|
||||
require_once './manualAddFunds.php';
|
||||
|
||||
?>
|
|
@ -97,7 +97,8 @@ $options = _json_decode($obj->addFundsOptions);
|
|||
type: "POST",
|
||||
data: {
|
||||
value: $('#value').val(),
|
||||
information: $('#information').val()
|
||||
information: $('#information').val(),
|
||||
autoWithdraw: <?php echo empty($autoWithdraw)?0:1; ?>
|
||||
},
|
||||
success: function (response) {
|
||||
modal.hidePleaseWait();
|
||||
|
|
|
@ -45,6 +45,16 @@ $balance = $plugin->getBalance(User::getId());
|
|||
</li>
|
||||
<?php
|
||||
}
|
||||
if($obj->enableAutoWithdrawFundsPage){
|
||||
?>
|
||||
<li class="dropdown-submenu">
|
||||
<a tabindex="-1" href="<?php echo $global['webSiteRootURL']; ?>plugin/YPTWallet/view/autoWithdrawFunds.php">
|
||||
<i class="far fa-money-bill-alt" aria-hidden="true"></i>
|
||||
<?php echo $obj->manualWithdrawFundsMenuTitle; ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<li class="dropdown-submenu">
|
||||
<a tabindex="-1" href="<?php echo $global['webSiteRootURL']; ?>plugin/YPTWallet/view/transferFunds.php">
|
||||
|
|
|
@ -336,6 +336,10 @@ function validateEmail(email) {
|
|||
return re.test(email);
|
||||
}
|
||||
|
||||
function isEmailValid(email){
|
||||
return validateEmail(email);
|
||||
}
|
||||
|
||||
function subscribe(email, user_id) {
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'objects/subscribe.json.php',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue