mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
parent
bc8925858e
commit
32815076fc
2 changed files with 202 additions and 134 deletions
|
@ -28,35 +28,42 @@ use PayPal\Api\WebhookEvent;
|
|||
|
||||
require_once $global['systemRootPath'] . 'plugin/PayPalYPT/PayPalClient.php';
|
||||
|
||||
class PayPalYPT extends PluginAbstract {
|
||||
class PayPalYPT extends PluginAbstract
|
||||
{
|
||||
|
||||
public function getTags() {
|
||||
public function getTags()
|
||||
{
|
||||
return [
|
||||
PluginTags::$MONETIZATION,
|
||||
PluginTags::$FREE,
|
||||
];
|
||||
}
|
||||
|
||||
public function getDescription() {
|
||||
public function getDescription()
|
||||
{
|
||||
$txt = "Paypal module for several purposes";
|
||||
$help = "<br><small><a href='https://github.com/WWBN/AVideo/wiki/PayPalYPT-Plugin' target='_blank'><i class='fas fa-question-circle'></i> Help</a></small>";
|
||||
|
||||
return $txt . $help;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return "PayPalYPT";
|
||||
}
|
||||
|
||||
public function getUUID() {
|
||||
public function getUUID()
|
||||
{
|
||||
return "5f613a09-c0b6-4264-85cb-47ae076d949f";
|
||||
}
|
||||
|
||||
public function getPluginVersion() {
|
||||
public function getPluginVersion()
|
||||
{
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
public function getEmptyDataObject() {
|
||||
public function getEmptyDataObject()
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->ClientID = "ASUkHFpWX0T8sr8EiGdLZ05m-RAb8l-hdRxoq-OXWmua2i7EUfqFkMZvSoGgH2LhK7zAqt29IiS2oRTn";
|
||||
$obj->ClientSecret = "ECxtMBsLr0cFwSCgI0uaDiVzEUbVlV3r_o_qaU-SOsQqCEOKPq4uGlr1C0mhdDmEyO30mw7-PF0bOnfo";
|
||||
|
@ -67,7 +74,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $obj;
|
||||
}
|
||||
|
||||
public function setUpPayment($invoiceNumber, $redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $description = "") {
|
||||
public function setUpPayment($invoiceNumber, $redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $description = "")
|
||||
{
|
||||
global $global;
|
||||
$total = parseToFloat($total);
|
||||
if ($total < 1) {
|
||||
|
@ -91,13 +99,13 @@ class PayPalYPT extends PluginAbstract {
|
|||
|
||||
$redirectUrls = new \PayPal\Api\RedirectUrls();
|
||||
$redirectUrls->setReturnUrl($redirect_url)
|
||||
->setCancelUrl($cancel_url);
|
||||
->setCancelUrl($cancel_url);
|
||||
|
||||
$payment = new \PayPal\Api\Payment();
|
||||
$payment->setIntent('sale')
|
||||
->setPayer($payer)
|
||||
->setTransactions([$transaction])
|
||||
->setRedirectUrls($redirectUrls);
|
||||
->setPayer($payer)
|
||||
->setTransactions([$transaction])
|
||||
->setRedirectUrls($redirectUrls);
|
||||
|
||||
// After Step 3
|
||||
try {
|
||||
|
@ -111,7 +119,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getPlanDetails($plan_id) {
|
||||
public function getPlanDetails($plan_id)
|
||||
{
|
||||
global $global;
|
||||
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
|
@ -123,7 +132,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $plan;
|
||||
}
|
||||
|
||||
private function executePayment() {
|
||||
private function executePayment()
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
// ### Approval Status
|
||||
|
@ -172,7 +182,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $payment;
|
||||
}
|
||||
|
||||
private function createBillingPlan($redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = 'Base Agreement', $plans_id = 0) {
|
||||
private function createBillingPlan($redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = 'Base Agreement', $plans_id = 0)
|
||||
{
|
||||
global $global;
|
||||
_error_log("createBillingPlan: start: " . json_encode([$redirect_url, $cancel_url, $total, $currency, $frequency, $interval, $name]));
|
||||
if ($total < 1) {
|
||||
|
@ -183,8 +194,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
// Create a new billing plan
|
||||
$plan = new Plan();
|
||||
$plan->setName(substr(cleanString($name), 0, 126))
|
||||
->setDescription(substr(cleanString($name), 0, 126))
|
||||
->setType('INFINITE');
|
||||
->setDescription(substr(cleanString($name), 0, 126))
|
||||
->setType('INFINITE');
|
||||
|
||||
$paymentDefinitionArray = [];
|
||||
|
||||
|
@ -194,11 +205,11 @@ class PayPalYPT extends PluginAbstract {
|
|||
if (!empty($trialDays)) {
|
||||
$trialPaymentDefinition = new PaymentDefinition();
|
||||
$trialPaymentDefinition->setName('Trial Payment')
|
||||
->setType('TRIAL')
|
||||
->setFrequency('Day')
|
||||
->setFrequencyInterval($trialDays)
|
||||
->setCycles("1")
|
||||
->setAmount(new Currency(['value' => 0, 'currency' => $currency]));
|
||||
->setType('TRIAL')
|
||||
->setFrequency('Day')
|
||||
->setFrequencyInterval($trialDays)
|
||||
->setCycles("1")
|
||||
->setAmount(new Currency(['value' => 0, 'currency' => $currency]));
|
||||
$paymentDefinitionArray[] = $trialPaymentDefinition;
|
||||
}
|
||||
}
|
||||
|
@ -206,11 +217,11 @@ class PayPalYPT extends PluginAbstract {
|
|||
// Set billing plan definitions
|
||||
$paymentDefinition = new PaymentDefinition();
|
||||
$paymentDefinition->setName('Regular Payments')
|
||||
->setType('REGULAR')
|
||||
->setFrequency($frequency)
|
||||
->setFrequencyInterval($interval)
|
||||
->setCycles('0')
|
||||
->setAmount(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
->setType('REGULAR')
|
||||
->setFrequency($frequency)
|
||||
->setFrequencyInterval($interval)
|
||||
->setCycles('0')
|
||||
->setAmount(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
$paymentDefinitionArray[] = $paymentDefinition;
|
||||
|
||||
$plan->setPaymentDefinitions($paymentDefinitionArray);
|
||||
|
@ -220,19 +231,19 @@ class PayPalYPT extends PluginAbstract {
|
|||
// if there is a trial do not charge a setup fee
|
||||
if (empty($trialDays)) {
|
||||
$merchantPreferences->setReturnUrl($redirect_url)
|
||||
->setCancelUrl($cancel_url)
|
||||
//->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('yes')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0')
|
||||
->setSetupFee(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
->setCancelUrl($cancel_url)
|
||||
//->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('yes')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0')
|
||||
->setSetupFee(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
} else {
|
||||
$merchantPreferences->setReturnUrl($redirect_url)
|
||||
->setCancelUrl($cancel_url)
|
||||
//->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('yes')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0');
|
||||
->setCancelUrl($cancel_url)
|
||||
//->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('yes')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0');
|
||||
}
|
||||
$plan->setMerchantPreferences($merchantPreferences);
|
||||
|
||||
|
@ -244,8 +255,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
$patch = new Patch();
|
||||
$value = new PayPalModel('{"state":"ACTIVE"}');
|
||||
$patch->setOp('replace')
|
||||
->setPath('/')
|
||||
->setValue($value);
|
||||
->setPath('/')
|
||||
->setValue($value);
|
||||
$patchRequest = new PatchRequest();
|
||||
$patchRequest->addPatch($patch);
|
||||
$createdPlan->update($patchRequest, $apiContext);
|
||||
|
@ -267,7 +278,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function getPlanId() {
|
||||
private function getPlanId()
|
||||
{
|
||||
global $global;
|
||||
if (!empty($_POST['plans_id'])) {
|
||||
$s = new SubscriptionPlansTable($_POST['plans_id']);
|
||||
|
@ -285,7 +297,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function setUpSubscription($invoiceNumber, $redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = 'Base Agreement') {
|
||||
public function setUpSubscription($invoiceNumber, $redirect_url, $cancel_url, $total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = 'Base Agreement')
|
||||
{
|
||||
global $global;
|
||||
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
|
@ -325,8 +338,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
}
|
||||
$agreement = new Agreement();
|
||||
$agreement->setName(substr(cleanString($name), 0, 126))
|
||||
->setDescription(substr(cleanString($name), 0, 126))
|
||||
->setStartDate($startDate);
|
||||
->setDescription(substr(cleanString($name), 0, 126))
|
||||
->setStartDate($startDate);
|
||||
|
||||
$plan = new Plan();
|
||||
$plan->setId($planId);
|
||||
|
@ -351,7 +364,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public function setUpSubscriptionV2($total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = '', $json = '', $trialDays = 0) {
|
||||
public function setUpSubscriptionV2($total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = '', $json = '', $trialDays = 0)
|
||||
{
|
||||
global $global;
|
||||
|
||||
if ($total < 1) {
|
||||
|
@ -376,8 +390,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
}
|
||||
$agreement = new Agreement();
|
||||
$agreement->setName(substr(cleanString($name), 0, 126))
|
||||
->setDescription(substr(cleanString($json), 0, 126))
|
||||
->setStartDate($startDate);
|
||||
->setDescription(substr(cleanString($json), 0, 126))
|
||||
->setStartDate($startDate);
|
||||
|
||||
$plan = new Plan();
|
||||
$plan->setId($planId);
|
||||
|
@ -402,7 +416,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function createBillingPlanV2($total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = '', $json = '', $trialDays = 0) {
|
||||
private function createBillingPlanV2($total = '1.00', $currency = "USD", $frequency = "Month", $interval = 1, $name = '', $json = '', $trialDays = 0)
|
||||
{
|
||||
global $global;
|
||||
if ($total < 1) {
|
||||
$total = 1;
|
||||
|
@ -420,30 +435,30 @@ class PayPalYPT extends PluginAbstract {
|
|||
// Create a new billing plan
|
||||
$plan = new Plan();
|
||||
$plan->setName(substr(cleanString($name), 0, 126))
|
||||
->setDescription(substr(json_encode(User::getId()), 0, 126))
|
||||
->setType('INFINITE');
|
||||
->setDescription(substr(json_encode(User::getId()), 0, 126))
|
||||
->setType('INFINITE');
|
||||
|
||||
$paymentDefinitionArray = [];
|
||||
|
||||
if (!empty($trialDays)) {
|
||||
$trialPaymentDefinition = new PaymentDefinition();
|
||||
$trialPaymentDefinition->setName('Trial Payment')
|
||||
->setType('TRIAL')
|
||||
->setFrequency('Day')
|
||||
->setFrequencyInterval($trialDays)
|
||||
->setCycles("1")
|
||||
->setAmount(new Currency(['value' => 0, 'currency' => $currency]));
|
||||
->setType('TRIAL')
|
||||
->setFrequency('Day')
|
||||
->setFrequencyInterval($trialDays)
|
||||
->setCycles("1")
|
||||
->setAmount(new Currency(['value' => 0, 'currency' => $currency]));
|
||||
$paymentDefinitionArray[] = $trialPaymentDefinition;
|
||||
}
|
||||
|
||||
// Set billing plan definitions
|
||||
$paymentDefinition = new PaymentDefinition();
|
||||
$paymentDefinition->setName('Regular Payments')
|
||||
->setType('REGULAR')
|
||||
->setFrequency($frequency)
|
||||
->setFrequencyInterval($interval)
|
||||
->setCycles('0')
|
||||
->setAmount(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
->setType('REGULAR')
|
||||
->setFrequency($frequency)
|
||||
->setFrequencyInterval($interval)
|
||||
->setCycles('0')
|
||||
->setAmount(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
$paymentDefinitionArray[] = $paymentDefinition;
|
||||
|
||||
$plan->setPaymentDefinitions($paymentDefinitionArray);
|
||||
|
@ -453,19 +468,19 @@ class PayPalYPT extends PluginAbstract {
|
|||
// if there is a trial do not charge a setup fee
|
||||
if (empty($trialDays)) {
|
||||
$merchantPreferences->setReturnUrl($success_url)
|
||||
->setCancelUrl($cancel_url)
|
||||
->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('YES')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0')
|
||||
->setSetupFee(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
->setCancelUrl($cancel_url)
|
||||
->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('YES')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0')
|
||||
->setSetupFee(new Currency(['value' => $total, 'currency' => $currency]));
|
||||
} else {
|
||||
$merchantPreferences->setReturnUrl($success_url)
|
||||
->setCancelUrl($cancel_url)
|
||||
->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('YES')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0');
|
||||
->setCancelUrl($cancel_url)
|
||||
->setNotifyUrl($notify_url)
|
||||
->setAutoBillAmount('YES')
|
||||
->setInitialFailAmountAction('CONTINUE')
|
||||
->setMaxFailAttempts('0');
|
||||
}
|
||||
$plan->setMerchantPreferences($merchantPreferences);
|
||||
|
||||
|
@ -477,8 +492,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
$patch = new Patch();
|
||||
$value = new PayPalModel('{"state":"ACTIVE"}');
|
||||
$patch->setOp('replace')
|
||||
->setPath('/')
|
||||
->setValue($value);
|
||||
->setPath('/')
|
||||
->setValue($value);
|
||||
$patchRequest = new PatchRequest();
|
||||
$patchRequest->addPatch($patch);
|
||||
$createdPlan->update($patchRequest, $apiContext);
|
||||
|
@ -500,10 +515,11 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
private function executeBillingAgreement() {
|
||||
|
||||
private function executeBillingAgreement()
|
||||
{
|
||||
|
||||
self::getOrCreateWebhook();
|
||||
|
||||
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
$token = $_GET['token'];
|
||||
|
@ -522,13 +538,15 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function getBillingAgreement($agreement_id) {
|
||||
public static function getBillingAgreement($agreement_id)
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
return Agreement::get($agreement_id, $apiContext);
|
||||
}
|
||||
|
||||
public static function cancelAgreement($agreement_id) {
|
||||
public static function cancelAgreement($agreement_id)
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
|
||||
|
@ -547,7 +565,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
public function execute()
|
||||
{
|
||||
if (!empty($_GET['paymentId'])) {
|
||||
_error_log("PayPal Execute payment ");
|
||||
return $this->executePayment();
|
||||
|
@ -559,7 +578,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function getAmountFromPayment($payment) {
|
||||
public static function getAmountFromPayment($payment)
|
||||
{
|
||||
if (!is_object($payment)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -586,7 +606,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
public function sendToPayPal($invoiceNumber, $redirect_url, $cancel_url, $total, $currency) {
|
||||
public function sendToPayPal($invoiceNumber, $redirect_url, $cancel_url, $total, $currency)
|
||||
{
|
||||
if ($total < 1) {
|
||||
$total = 1;
|
||||
}
|
||||
|
@ -597,7 +618,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
public static function updateBillingPlan($plan_id, $total = '1.00', $currency = "USD", $interval = 1, $name = 'Base Agreement') {
|
||||
public static function updateBillingPlan($plan_id, $total = '1.00', $currency = "USD", $interval = 1, $name = 'Base Agreement')
|
||||
{
|
||||
global $global;
|
||||
if (empty($plan_id)) {
|
||||
return false;
|
||||
|
@ -609,8 +631,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
try {
|
||||
$patch1 = new Patch();
|
||||
$patch1->setOp('replace')
|
||||
->setPath('/')
|
||||
->setValue(_json_decode('{"name": "' . $name . '"}'));
|
||||
->setPath('/')
|
||||
->setValue(_json_decode('{"name": "' . $name . '"}'));
|
||||
|
||||
$paymentDefinitions = $createdPlan->getPaymentDefinitions();
|
||||
$paymentDefinition = $paymentDefinitions[0];
|
||||
|
@ -618,8 +640,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
|
||||
$patch2 = new Patch();
|
||||
$patch2->setOp('replace')
|
||||
->setPath('/payment-definitions/' . $paymentDefinitionId)
|
||||
->setValue(_json_decode('{
|
||||
->setPath('/payment-definitions/' . $paymentDefinitionId)
|
||||
->setValue(_json_decode('{
|
||||
"amount": {
|
||||
"currency": "' . $currency . '",
|
||||
"value": "' . $total . '"
|
||||
|
@ -639,7 +661,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function IPNcheck() {
|
||||
public static function IPNcheck()
|
||||
{
|
||||
$obj = AVideoPlugin::getDataObject('PayPalYPT');
|
||||
|
||||
$raw_post_data = file_get_contents('php://input');
|
||||
|
@ -705,19 +728,22 @@ class PayPalYPT extends PluginAbstract {
|
|||
curl_close($ch);
|
||||
}
|
||||
|
||||
public static function setUserReceiverEmail($users_id, $email) {
|
||||
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) {
|
||||
public static function getUserReceiverEmail($users_id)
|
||||
{
|
||||
$user = new User($users_id);
|
||||
$paramName = 'PayPalReceiverEmail';
|
||||
return $user->getExternalOption($paramName);
|
||||
}
|
||||
|
||||
public function getMyAccount($users_id) {
|
||||
public function getMyAccount($users_id)
|
||||
{
|
||||
global $global;
|
||||
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('YPTWallet');
|
||||
|
@ -728,7 +754,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
include $global['systemRootPath'] . 'plugin/PayPalYPT/payOutReceiverEmailForm.php';
|
||||
}
|
||||
|
||||
public static function WalletPayout($users_id_to_be_paid, $value) {
|
||||
public static function WalletPayout($users_id_to_be_paid, $value)
|
||||
{
|
||||
global $config, $global;
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
|
@ -781,7 +808,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $obj;
|
||||
}
|
||||
|
||||
public static function Payout($receiver_email, $value, $currency = 'USD', $note = '', $email_subject = '') {
|
||||
public static function Payout($receiver_email, $value, $currency = 'USD', $note = '', $email_subject = '')
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->msg = '';
|
||||
$obj->error = true;
|
||||
|
@ -845,7 +873,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $obj;
|
||||
}
|
||||
|
||||
public static function getPayoutInfo($payout_batch_id) {
|
||||
public static function getPayoutInfo($payout_batch_id)
|
||||
{
|
||||
try {
|
||||
$request = new PaypalPayoutsSDK\Payouts\PayoutsGetRequest($payout_batch_id);
|
||||
$client = PayPalClient::client();
|
||||
|
@ -865,43 +894,56 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $obj;
|
||||
}
|
||||
|
||||
public function getWalletConfigurationHTML($users_id, $wallet, $walletDataObject) {
|
||||
public function getWalletConfigurationHTML($users_id, $wallet, $walletDataObject)
|
||||
{
|
||||
global $global;
|
||||
$obj = AVideoPlugin::getDataObjectIfEnabled('YPTWallet');
|
||||
if (empty($obj->enableAutoWithdrawFundsPagePaypal)) {
|
||||
if (User::isAdmin()) {
|
||||
YPTWallet::showAdminMessage();
|
||||
echo '<div class="alert alert-warning" role="alert">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
<strong>Admin Notice:</strong> PayPal YPT configuration will only appear if <strong>enableAutoWithdrawFundsPagePaypal</strong> is checked in the plugin parameters.
|
||||
</div>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
include_once $global['systemRootPath'] . 'plugin/PayPalYPT/getWalletConfigurationHTML.php';
|
||||
}
|
||||
|
||||
public function getPluginMenu() {
|
||||
public function getPluginMenu()
|
||||
{
|
||||
global $global;
|
||||
return '<button onclick="avideoModalIframeLarge(webSiteRootURL+\'plugin/PayPalYPT/View/editor.php\')" class="btn btn-primary btn-sm btn-xs btn-block"><i class="fa fa-edit"></i> Edit</button>';
|
||||
}
|
||||
|
||||
public static function isTokenUsed($token) {
|
||||
public static function isTokenUsed($token)
|
||||
{
|
||||
$row = PayPalYPT_log::getFromToken($token);
|
||||
return !empty($row);
|
||||
}
|
||||
|
||||
public static function isRecurringPaymentIdUsed($recurring_payment_id) {
|
||||
public static function isRecurringPaymentIdUsed($recurring_payment_id)
|
||||
{
|
||||
$row = PayPalYPT_log::getFromRecurringPaymentId($recurring_payment_id);
|
||||
return !empty($row);
|
||||
}
|
||||
|
||||
public static function getAllLogsFromUser($users_id) {
|
||||
public static function getAllLogsFromUser($users_id)
|
||||
{
|
||||
$rows = PayPalYPT_log::getAllFromUser($users_id);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function getOrCreateWebhook() {
|
||||
public static function getOrCreateWebhook()
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
$url = self::getWebhookURL();
|
||||
try {
|
||||
$output = \PayPal\Api\Webhook::getAll($apiContext);
|
||||
foreach ($output->getWebhooks() as $webhook) {
|
||||
if($url === $webhook->getUrl()){
|
||||
if ($url === $webhook->getUrl()) {
|
||||
return $webhook;
|
||||
}
|
||||
}
|
||||
|
@ -913,7 +955,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static function createWebhook() {
|
||||
public static function createWebhook()
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
$webhook = new \PayPal\Api\Webhook();
|
||||
|
@ -958,7 +1001,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return $output;
|
||||
}
|
||||
|
||||
static function deleteAllWebhooks() {
|
||||
static function deleteAllWebhooks()
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
try {
|
||||
|
@ -974,7 +1018,8 @@ class PayPalYPT extends PluginAbstract {
|
|||
return true;
|
||||
}
|
||||
|
||||
static function validateWebhook() {
|
||||
static function validateWebhook()
|
||||
{
|
||||
global $global;
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
// # Validate Webhook
|
||||
|
@ -989,10 +1034,10 @@ class PayPalYPT extends PluginAbstract {
|
|||
* All header keys as UPPERCASE, but I receive the header key as the example array, First letter as UPPERCASE
|
||||
*/
|
||||
$headers = array_change_key_case($headers, CASE_UPPER);
|
||||
|
||||
$webhook = self::getOrCreateWebhook();
|
||||
|
||||
$webhook = self::getOrCreateWebhook();
|
||||
$webhookId = $webhook->getId();
|
||||
_error_log("PayPal::validateWebhook start webhookId={$webhookId} ".__LINE__.' '.json_encode($requestBody).' '.json_encode($headers));
|
||||
_error_log("PayPal::validateWebhook start webhookId={$webhookId} " . __LINE__ . ' ' . json_encode($requestBody) . ' ' . json_encode($headers));
|
||||
$signatureVerification = new VerifyWebhookSignature();
|
||||
$signatureVerification->setAuthAlgo($headers['PAYPAL-AUTH-ALGO']);
|
||||
$signatureVerification->setTransmissionId($headers['PAYPAL-TRANSMISSION-ID']);
|
||||
|
@ -1007,62 +1052,63 @@ class PayPalYPT extends PluginAbstract {
|
|||
try {
|
||||
/** @var \PayPal\Api\VerifyWebhookSignatureResponse $output */
|
||||
$output = $signatureVerification->post($apiContext);
|
||||
_error_log("PayPal::validateWebhook ".__LINE__.' '.json_encode($output->getVerificationStatus()).' '.$request->toJSON().' '.json_encode($output));
|
||||
_error_log("PayPal::validateWebhook " . __LINE__ . ' ' . json_encode($output->getVerificationStatus()) . ' ' . $request->toJSON() . ' ' . json_encode($output));
|
||||
//verification_statusenum
|
||||
//Possible values: SUCCESS,FAILURE.
|
||||
if($output->getVerificationStatus()==='SUCCESS'){
|
||||
if ($output->getVerificationStatus() === 'SUCCESS') {
|
||||
return json_decode($request->toJSON());
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
_error_log("PayPal::validateWebhook ".__LINE__.' '.json_encode($request->toJSON()).' '.json_encode($ex->getMessage()));
|
||||
|
||||
var_dump($request->toJSON(),$output, $ex->getMessage());
|
||||
_error_log("PayPal::validateWebhook " . __LINE__ . ' ' . json_encode($request->toJSON()) . ' ' . json_encode($ex->getMessage()));
|
||||
|
||||
var_dump($request->toJSON(), $output, $ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
_error_log("PayPal::validateWebhook ".__LINE__.' '.json_encode($output->getVerificationStatus()).' '.json_encode($request->toJSON()).' '.json_encode($output));
|
||||
|
||||
_error_log("PayPal::validateWebhook " . __LINE__ . ' ' . json_encode($output->getVerificationStatus()) . ' ' . json_encode($request->toJSON()) . ' ' . json_encode($output));
|
||||
|
||||
//var_dump($output->getVerificationStatus(),$request->toJSON(),$output);
|
||||
return true;
|
||||
}
|
||||
|
||||
static function getWebhookURL(){
|
||||
|
||||
static function getWebhookURL()
|
||||
{
|
||||
global $global;
|
||||
$url = "{$global['webSiteRootURL']}plugin/PayPalYPT/webhook.php";
|
||||
$url = str_replace('http://', 'https://', $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function resendWebhook($event_id){
|
||||
|
||||
public static function resendWebhook($event_id)
|
||||
{
|
||||
global $global;
|
||||
_error_log("PayPal::resendWebhook ".__LINE__.' '.json_encode($event_id));
|
||||
|
||||
_error_log("PayPal::resendWebhook " . __LINE__ . ' ' . json_encode($event_id));
|
||||
|
||||
require $global['systemRootPath'] . 'plugin/PayPalYPT/bootstrap.php';
|
||||
$webhookEvent = new WebhookEvent();
|
||||
$webhookEvent->setId($event_id);
|
||||
_error_log("PayPal::resendWebhook ".__LINE__.' '.json_encode($event_id));
|
||||
_error_log("PayPal::resendWebhook " . __LINE__ . ' ' . json_encode($event_id));
|
||||
|
||||
try {
|
||||
$output = $webhookEvent->resend($apiContext);
|
||||
_error_log("PayPal::resendWebhook ".json_encode($output));
|
||||
_error_log("PayPal::resendWebhook " . json_encode($output));
|
||||
return json_decode($output->toJSON());
|
||||
} catch (Exception $ex) {
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
_error_log("PayPal::resendWebhook ".__LINE__.' '.json_encode($ex->getMessage()));
|
||||
|
||||
var_dump($request->toJSON(),$output, $ex->getMessage());
|
||||
_error_log("PayPal::resendWebhook " . __LINE__ . ' ' . json_encode($ex->getMessage()));
|
||||
|
||||
var_dump($request->toJSON(), $output, $ex->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
|
||||
_error_log("PayPal::resendWebhook ".__LINE__.' '.json_encode($output));
|
||||
|
||||
_error_log("PayPal::resendWebhook " . __LINE__ . ' ' . json_encode($output));
|
||||
|
||||
//var_dump($output->getVerificationStatus(),$request->toJSON(),$output);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -453,12 +453,12 @@ class YPTWallet extends PluginAbstract
|
|||
_error_log("transferBalance: $users_id_from, $users_id_to, $value, $forceDescription, $forceTransfer");
|
||||
if (!User::isAdmin()) {
|
||||
if ($users_id_from != User::getId() && !$forceTransfer) {
|
||||
_error_log("transferBalance: you are not admin, $users_id_from,$users_id_to, $value ".json_encode(debug_backtrace()));
|
||||
_error_log("transferBalance: you are not admin, $users_id_from,$users_id_to, $value " . json_encode(debug_backtrace()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!User::idExists($users_id_from) || !User::idExists($users_id_to)) {
|
||||
_error_log("transferBalance: user does not exists, $users_id_from,$users_id_to, $value ".json_encode(debug_backtrace()));
|
||||
_error_log("transferBalance: user does not exists, $users_id_from,$users_id_to, $value " . json_encode(debug_backtrace()));
|
||||
return false;
|
||||
}
|
||||
$value = floatval($value);
|
||||
|
@ -469,7 +469,7 @@ class YPTWallet extends PluginAbstract
|
|||
$balance = $wallet->getBalance();
|
||||
$newBalance = $balance - $value;
|
||||
if ($newBalance < 0) {
|
||||
_error_log("transferBalance: you dont have balance, $users_id_from,$users_id_to, $value (Balance: {$balance}) (New Balance: {$newBalance}) ".json_encode(debug_backtrace()));
|
||||
_error_log("transferBalance: you dont have balance, $users_id_from,$users_id_to, $value (Balance: {$balance}) (New Balance: {$newBalance}) " . json_encode(debug_backtrace()));
|
||||
return false;
|
||||
}
|
||||
$identificationFrom = User::getNameIdentificationById($users_id_from);
|
||||
|
@ -716,7 +716,7 @@ class YPTWallet extends PluginAbstract
|
|||
switch ($status) {
|
||||
case 'pending':
|
||||
$title = 'Transaction Pending';
|
||||
$msg = 'Your have a pending transaction of ' . $valueFormated ;
|
||||
$msg = 'Your have a pending transaction of ' . $valueFormated;
|
||||
$icon = 'fa-solid fa-hourglass-half'; // Icon for pending
|
||||
$type = UserNotifications::type_warning;
|
||||
$href = "{$global['webSiteRootURL']}plugin/YPTWallet/view/pendingRequests.php";
|
||||
|
@ -736,14 +736,14 @@ class YPTWallet extends PluginAbstract
|
|||
case 'credit':
|
||||
// If it is a credit
|
||||
$title = 'Funds Received';
|
||||
$msg = 'You have received a credit of ' . $valueFormated . ' from ' . $identification ;
|
||||
$msg = 'You have received a credit of ' . $valueFormated . ' from ' . $identification;
|
||||
$icon = 'fa-solid fa-hand-holding-usd'; // Credit icon
|
||||
$type = UserNotifications::type_success;
|
||||
break;
|
||||
case 'debit':
|
||||
// If it is a debit
|
||||
$title = 'Funds Deducted';
|
||||
$msg = 'A debit of ' . $valueFormated . ' has been processed to ' . $identification ;
|
||||
$msg = 'A debit of ' . $valueFormated . ' has been processed to ' . $identification;
|
||||
$icon = 'fa-solid fa-money-bill-wave'; // Debit icon
|
||||
$type = UserNotifications::type_danger;
|
||||
break;
|
||||
|
@ -885,10 +885,32 @@ class YPTWallet extends PluginAbstract
|
|||
self::setAddFundsSuccessRedirectURL(getRedirectToVideo($videos_id));
|
||||
}
|
||||
|
||||
public static function showAdminMessage(){
|
||||
global $global;
|
||||
if (User::isAdmin()) {
|
||||
if (empty($global['getWalletConfigurationHTMLAdminMessageShowed'])) {
|
||||
echo '<div class="alert alert-info" role="alert">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
<strong>Admin Notice:</strong> This message is visible only to administrators.
|
||||
</div>';
|
||||
$global['getWalletConfigurationHTMLAdminMessageShowed'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getWalletConfigurationHTML($users_id, $wallet, $walletDataObject)
|
||||
{
|
||||
global $global;
|
||||
if (empty($walletDataObject->CryptoWalletEnabled)) {
|
||||
if (User::isAdmin()) {
|
||||
YPTWallet::showAdminMessage();
|
||||
echo '<div class="alert alert-warning" role="alert">
|
||||
<i class="fa fa-exclamation-triangle"></i>
|
||||
YPTWallet configuration will only appear if <strong>CryptoWalletEnabled</strong> is enabled in the plugin parameters.
|
||||
<br>If you have an empty configuration menu, please hide this button by checking the <strong>hideConfiguration</strong> option in the YPTWallet parameters.
|
||||
</div>';
|
||||
|
||||
}
|
||||
return '';
|
||||
}
|
||||
include_once $global['systemRootPath'] . 'plugin/YPTWallet/getWalletConfigurationHTML.php';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue