Commit ee6ef4c9 authored by Mark Harding's avatar Mark Harding
Browse files

(chore): remove unused plugins

parent 282f7f98
{
"name": "payments",
"version": "1.0.0",
"routes": {
"/gatherings": "app/src/payments"
}
}
<?php
namespace minds\plugin\payments\services;
use Minds\Core;
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
use PayPal\Api\Capture;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Api\PaymentExecution;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
class paypal extends core\base
{
protected $context;
/**
* Init
*/
public function init()
{
$this->context = new ApiContext(
new OAuthTokenCredential(
Core\Config::_()->payments['paypalKey'] ?: 'AaUOIRC8rTb2jXZtnUvjMXWH1BH-5spBnL2kILF2AEPygMxvWOqME3e06hnj',
Core\Config::_()->payments['paypalSecret'] ?: 'EOWEZBB5n4Kc84mxXQhqF1rgz0GMKXyJ_fmWi5s1sk7k_35GeWTtXIwU6p2t'
)
);
$this->context->setConfig(
array(
'mode' => Core\Config::_()->payments['paypal_mode'] ?: 'sandbox',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => '/tmp/PayPal.log',
'log.LogLevel' => 'FINE'
)
);
}
/**
* Create a credit card in the vault
*
* @param array $params
* @return CreditCard Object (paypal)
*/
public function createCard($params = array())
{
$params = array_merge(array(
'type' => null,
'number' => null,
'month' => null,
'year' => null,
'sec' => null,
'name' => null,
'name2' => null
), $params);
$card = new CreditCard();
$card->setType($params['type'])
->setNumber($params['number'])
->setExpireMonth($params['month'])
->setExpireYear($params['year'])
->setCvv2($params['sec'])
->setFirstName($params['name'])
->setLastName($params['name2']);
return $card->create($this->context);
}
/**
* Return credit card information from the vault (not the info but just what we need from paypal)
*
* @param string $id
* @return CreditCard Object (paypal)
*/
public function getCard($id)
{
return CreditCard::get($id, $this->context);
}
/**
* Perform a payment
*/
public function payment($amount_val = 0, $currency = 'USD', $description, $card)
{
/*
* FundingInstrument
* A resource representing a Payer's funding instrument.
* for example, a recurring payments system would use the stored card
*/
$fi = new FundingInstrument();
if (is_string($card)) {
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId($card);
$fi->setCreditCardToken($creditCardToken);
} else {
$fi->setCreditCard($card);
}
/** Payer **/
$payer = new Payer();
$payer->setPaymentMethod("credit_card")
->setFundingInstruments(array($fi));
/** Amount **/
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(number_format($amount_val, 2));
/**
* Transaction Object
*/
$transaction = new Transaction();
$transaction->setAmount($amount)
->setDescription("Minds: $description");
/*
* Payment object
*/
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
return $payment->create($this->context);
}
public function getPayment($id)
{
$result = Payment::get($id, $this->context);
return $result;
}
public function getAuthorization($id)
{
$result = Authorization::get($id, $this->context);
return $result;
}
public function executePayment($id)
{
$payment = Payment::get($id, $this->context);
$execution = new PaymentExecution();
$result = $payment->execute($execution, $this->context);
return $result;
}
public function capture($id, $amount)
{
$auth = Authorization::get($id, $this->context);
$amt = new Amount();
$amt->setCurrency("USD")
->setTotal($amount);
$capture = new Capture();
$capture->setAmount($amt);
return $auth->capture($capture, $this->context);
}
/**
* Factory
*/
public static function factory()
{
return new paypal();
}
}
<?php
/**
* Payments
*/
namespace minds\plugin\payments;
use Minds\Api;
use Minds\Entities;
use Minds\Components;
use Minds\Core;
use Minds\Core\Events;
class start extends Components\Plugin
{
public function init()
{
}
public static function createPayment($details, $amount, $card)
{
//$transaction = new entities\transaction();
//$transaction->amount = $amount;
//$transaction->description = $details;
//$transaction->card = $card;
//$transaction->save(); //save as pending.
$paypal_obj= services\paypal::factory()->payment($amount, $currency = 'USD', $details, $card);
//$transaction->paypal_id = $paypal_obj->getID();
//$transaction->status = 'complete';
//self::sendConfirmation(array(Core\Session::getLoggedInUser()->getEmail(), 'mark@minds.com', 'bill@minds.com', 'billing@minds.com'), $paypal_obj->getID());
return true;
//return $transaction->save();
}
public static function sendConfirmation($to, $transaction)
{
elgg_set_viewtype('email');
//\elgg_send_email('mark@minds.com', 'mark@kramnorth.com', 'New Order', '<h1>Thanks for your order..</h1> <p>Your order has been succesfully processed</p>');
if (core\plugins::isActive('phpmailer')) {
$view = elgg_view('payments/confirmation', array('transaction'=>$transaction));
\phpmailer_send('mark@minds.com', 'Minds Billing', $to, '', 'Your order: ' . $transaction, $view, null, true);
}
elgg_set_viewtype('default');
}
}
<?php
$transaction = $vars['transaction'];
?>
<h1>Thanks for your order..</h1>
<p>Your order has been succesfully placed and we are now processing payment. Your confirmation code is: <b><?= $transaction->guid ?></b></p>
<p><b><?=$transaction->description?></b> - $<?= $transaction->amount ?> USD</p>
\ No newline at end of file
<?php
/**
* Section
*/
namespace minds\plugin\cms\entities;
use minds\plugin\cms\exceptions;
use Minds\Entities;
use Minds\Core\data;
class page extends Entities\Object
{
/**
* Initialise attributes
* @return void
*/
public function initializeAttributes()
{
parent::initializeAttributes();
$this->attributes = array_merge($this->attributes, array(
'subtype' => 'cms_page',
'owner_guid' => elgg_get_logged_in_user_guid(),
'access_id' => 2, //pages are public,
'context' => 'footer',
'uri'=>null
));
}
public function __construct($guid = null)
{
if (is_string($guid) && !is_numeric($guid)) {
$guids = Data\indexes::fetch("object:cms:page:$guid", array('limit'=>1));
if (!$guids) {
throw new exceptions\notfound($guid);
}
$guid = key($guids);
}
return parent::__construct($guid);
}
/**
* Returns an array of indexes into which this entity is stored
*
* @param bool $ia - ignore access
* @return array
*/
protected function getIndexKeys($ia = false)
{
return array(
"$this->type:cms:page:$this->uri",
);
}
public function getURL()
{
return elgg_get_site_url() . 'p/'.$this->uri;
}
public function save($timebased = true)
{
$guid = parent::save($timebased);
$lu = new Data\lookup();
$lu->set("object:cms:menu:$this->context", array($this->uri => "$this->title"));
return $guid;
}
public function delete($recursive = true)
{
$lu = new Data\lookup();
$lu->removeColumn("object:cms:menu:$this->context", $this->uri);
return parent::delete($recursive);
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function setBody($body)
{
$this->body = $body;
return $this;
}
public function setUri($uri)
{
//remove the old path uri
if ($this->uri && $this->uri != $uri) {
$lu = new Data\lookup();
$lu->removeColumn("object:cms:menu:$this->context", $this->uri);
}
$this->uri = $uri;
return $this;
}
public function setForwarding($url)
{
if ($url) {
$this->forwarding = $url;
}
return $this;
}
}
<?php
/**
* Section
*/
namespace minds\plugin\cms\entities;
use Minds\Entities;
class section extends Entities\Object
{
/**
* Initialise attributes
* @return void
*/
public function initializeAttributes()
{
parent::initializeAttributes();
$this->attributes = array_merge($this->attributes, array(
'subtype' => 'cms_section',
'owner_guid' => elgg_get_logged_in_user_guid(),
'access_id' => 2 //pages are public
));
}
/**
* Returns an array of indexes into which this entity is stored
*
* @param bool $ia - ignore access
* @return array
*/
protected function getIndexKeys($ia = false)
{
return array(
"$this->type:cms:sections:$this->group",
"$this->type:cms:sections"
);
}
}
<?php
add_translation('en', array(
'icon:facebook' => '&#62221;',
'icon:twitter' => '&#62218;',
));
<?php
namespace minds\plugin\social\pages;
use Minds\Core;
use Minds\Interfaces;
use minds\plugin\social\services;
class authorize extends core\page implements Interfaces\page
{
/**
* Get requests
*/
public function get($pages)
{
if (!isset($pages[0])) {
return false;
}
if ($_REQUEST['access_token']) {
setcookie('loggedin', 1, time() + (60 * 60 * 24 * 30), '/');
$_SESSION['user'] = core\Session::getLoggedinUser(); //hate this hack..
}
try {
$service = services\build::build($pages[0]);
} catch (\Exception $e) {
return false;
}
$this->forward($service->authorizeURL());
}
public function post($pages)
{
}
public function put($pages)
{
}
public function delete($pages)
{
}
}
<?php
namespace minds\plugin\social\pages;
use Minds\Core;
use Minds\Interfaces;
use minds\plugin\social\services;
class redirect extends core\page implements Interfaces\page
{
/**
* Get requests
*/
public function get($pages)
{
if (!isset($pages[0])) {
return false;
}
if ($_REQUEST['access_token']) {
$_SESSION['user'] = core\Session::getLoggedinUser(); //hate this hack..
}
try {
$service = services\build::build($pages[0]);
} catch (\Exception $e) {
return false;
}
$service->authorizeCallback();
}
public function post($pages)
{
}
public function put($pages)
{
}
public function delete($pages)
{
}
}
<?php
/**
* Social
*/
namespace minds\plugin\social\services;
use Minds\Components;
use Minds\Core;
class build extends Components\Plugin
{
public static function build($service, $params = array())
{
$class_name = "minds\\plugin\\social\\services\\$service";
if (!class_exists($class_name)) {
throw new \Exception('Service does not exists');
}
$class = new $class_name($params);
if (isset($params['access_token'])) {
$class->access_token = $params['access_token'];
}
return $class;
}
}
<?php
/**
* Social
*/
namespace minds\plugin\social\services;
use Minds\Components;
use Minds\Core;
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookJavaScriptLoginHelper;
use Facebook\Entities\AccessToken;
class facebook extends core\base
{
protected $redirect_uri;
public $access_token;
public function init()
{
FacebookSession::setDefaultApplication(elgg_get_plugin_setting('facebook_api_key', 'social'), elgg_get_plugin_setting('facebook_api_secret', 'social'));
$this->redirect_uri = elgg_get_site_url() . 'plugin/social/redirect/facebook';
if (!$this->access_token) {
$this->access_token = \elgg_get_plugin_user_setting('facebook_access_token', core\Session::getLoggedinUser()->guid, 'social');
}
}
public function authorizeURL()
{
$helper = new FacebookRedirectLoginHelper($this->redirect_uri);
return $loginUrl = $helper->getLoginUrl(array('publish_actions'));
}
public function authorizeCallback()
{
$helper = new FacebookRedirectLoginHelper($this->redirect_uri);
try {
$session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $e) {
// When Facebook returns an error
error_log("FB ERROR:: " . $e->getMessage());
} catch (\Exception $e) {
// When validation fails or other local issues
error_log("FB ERROR:: " . $e->getMessage());
}
error_log(print_r($session, true));
if ($session) {
$accessToken = $session->getAccessToken();
$at = $accessToken->extend();
\elgg_set_plugin_user_setting('facebook', 'enabled', core\Session::getLoggedinUser()->guid, 'social');
\elgg_set_plugin_user_setting('facebook_access_token', (string) $at, core\Session::getLoggedinUser()->guid, 'social');
echo elgg_view('social/callback/facebook');
}
}
/**
* Post to facebook from a minds activity post
*
* @param array $activity