Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Plisio committed Apr 13, 2020
1 parent f000ec3 commit 680ea8b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 28 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 CoinGate https://coingate.com
Copyright (c) 2020 Plisio https://plisio.net

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
10 changes: 5 additions & 5 deletions upload/fields/cryptocurrencies.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
*
* Paypal payment plugin
* Plisio payment plugin
*
* @author Jeremy Magne
* @version $Id: paypal.php 7217 2013-09-18 13:42:54Z alatak $
* @author Plisio
* @version 1.0.0
* @package VirtueMart
* @subpackage payment
* Copyright (C) 2004 - 2019 Virtuemart Team. All rights reserved.
* Copyright (C) 2019 - 2020 Virtuemart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
Expand Down Expand Up @@ -43,4 +43,4 @@ protected function getOptions()

return $options;
}
}
}
69 changes: 55 additions & 14 deletions upload/plisio.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

defined('_JEXEC') or die('Restricted access');
define('PLISIO_VIRTUEMART_EXTENSION_VERSION', '1.0.0');
define('PLISIO_VIRTUEMART_EXTENSION_VERSION', '1.0.2');

require_once('lib/Plisio/PlisioClient.php');

Expand Down Expand Up @@ -160,6 +160,10 @@ function plgVmOnPaymentNotification()
$orderStatus = $method->invalid_status;
$orderComment = 'Plisio invoice has some internal error. Please contact support for details.';
break;
case 'cancelled':
$orderStatus = $method->canceled_status;
$orderComment = 'Plisio invoice is expired.';
break;
case 'expired':
if ($post['source_amount'] > 0) {
$orderStatus = $method->expired_status;
Expand All @@ -181,8 +185,10 @@ function plgVmOnPaymentNotification()
$order['virtuemart_order_id'] = $virtuemartOrderId;
$order['customer_notified'] = 1;
$order['comments'] = $orderComment;
$order['paid'] = $post['source_amount'];
$order['paid_on'] = JFactory::getDate();
if (!empty($post['source_amount']) && $post['source_amount'] > 0) {
$order['paid'] = $post['source_amount'];
$order['paid_on'] = JFactory::getDate();
}

$modelOrder->updateStatusForOneOrder($virtuemartOrderId, $order, true);

Expand Down Expand Up @@ -268,27 +274,60 @@ protected function getPluginHtml($plugin, $selectedPlugin, $pluginSalesPrice)

$html = '<input type="radio" name="' . $pluginmethod_id . '" id="' . $this->_psType . '_id_' . $plugin->$pluginmethod_id . '" value="' . $plugin->$pluginmethod_id . '" ' . $checked . ">\n"
. '<label for="' . $this->_psType . '_id_' . $plugin->$pluginmethod_id . '">' . '<span class="' . $this->_type . '">' . $plugin->$pluginName . "</span></label>\n";

$plisio = new PlisioClient('');
$currencies = $plisio->getCurrencies();
$receive_currencies = $currencies['data'];
if (empty($receive_currencies)) {
return $html;
}
$plisio_receive_currencies = $method->cryptocurrency ? $method->cryptocurrency : array();

if (empty($plisio_receive_currencies) || count($plisio_receive_currencies) > 1
|| (count($plisio_receive_currencies) === 1 && $plisio_receive_currencies[0] === '')
) {
usort($receive_currencies, function ($a, $b) use ($plisio_receive_currencies) {
$idxA = array_search($a['cid'], $plisio_receive_currencies);
$idxB = array_search($b['cid'], $plisio_receive_currencies);

$idxA = $idxA === false ? -1 : $idxA;
$idxB = $idxB === false ? -1 : $idxB;

if ($idxA < 0 && $idxB < 0) return -1;
if ($idxA < 0 && $idxB >= 0) return 1;
if ($idxA >= 0 && $idxB < 0) return -1;
return $idxA - $idxB;
});

echo '<pre>' . print_r($plisio_receive_currencies, 1) . '</pre>';
echo '<pre>' . print_r($receive_currencies, 1) . '</pre>';
die();


if ($method->cryptocurrency == '') {
$jinput = JFactory::getApplication()->input;
$plisio_currency = $jinput->getString('plisio_currency', '');

$html .= '<select name="plisio_currency">';
foreach ($currencies['data'] as $item) {
$selected = $item['cid'] == $plisio_currency ? 'selected="seleted"' : '';
$html .= '<option value="' . htmlspecialchars($item['cid']) . '" '.$selected.'>' . htmlspecialchars($item['name'] . ' (' . $item['currency'] . ')') . '</option>';

foreach ($receive_currencies as $item) {
if (empty($plisio_receive_currencies) || in_array($item['cid'], $plisio_receive_currencies)
|| (count($plisio_receive_currencies) === 1 && $plisio_receive_currencies[0] === '')
) {
$selected = $item['cid'] === $plisio_currency ? 'selected="seleted"' : '';
$html .= '<option value="' . htmlspecialchars($item['cid']) . '" ' . $selected . '>' .
htmlspecialchars($item['name'] . ' (' . $item['currency'] . ')') .
'</option>';
}
}
$html .= '</select>';
} else {
$currencies = $currencies['data'];
$selected = $method->cryptocurrency;
$currency = array_filter($currencies, function ($i) use ($selected){ return $i['cid'] == $selected;});
} else {
$currency = array_filter($receive_currencies, function ($i) use ($plisio_receive_currencies) {
return in_array($i['cid'], $plisio_receive_currencies);
});
$currency = array_values($currency);
$html .= ' with '. $currency[0]['name'] . ' (' . $currency[0]['currency'] . ')';
$html .= '<input type="hidden" name="plisio_currency" value="'.htmlspecialchars($method->cryptocurrency).'">';
$html .= '<input type="hidden" name="plisio_currency" value="'.htmlspecialchars($currency[0]['cid']).'">';
}

return $html;
}

Expand Down Expand Up @@ -364,7 +403,9 @@ function plgVmConfirmedOrder($cart, $order)
'success_url' => (JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&pm=' . $paymentMethodID)),
'description' => join($description, ', '),
'email' => $order['details']['BT']->email,
'language' => $lang->getTag()
'language' => $lang->getTag(),
'plugin' => 'virtuemart',
'version' => PLISIO_VIRTUEMART_EXTENSION_VERSION
);
$invoice = $plisio->createTransaction($request);

Expand Down
9 changes: 2 additions & 7 deletions upload/plisio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<authorUrl>https://www.plisio.net</authorUrl>
<copyright>Copyright (C) 2019</copyright>
<license>https://github.com/plisio/virtuemart-plugin/blob/master/LICENSE MIT</license>
<version status="MINOR">1.0.0</version>
<version status="MINOR">1.0.0</version>
<description>Plisio cryptocurrency payment plugin</description>

<files>
Expand Down Expand Up @@ -36,7 +36,7 @@
<fieldset name="basic" addfieldpath="/plugins/vmpayment/plisio/fields">
<field type="spacer" default="VMPAYMENT_PLISIO_CREDENTIALS_LABEL" level="level1" />
<field name="api_key" type="text" label="VMPAYMENT_PLISIO_API_KEY_LABEL" description="VMPAYMENT_PLISIO_API_KEY_DESCRIPTION"/>
<field name="cryptocurrency" type="cryptocurrencies" label="VMPAYMENT_PLISIO_CRYPTOCURRENCY_LABEL" description="VMPAYMENT_PLISIO_CRYPTOCURRENCY_DESCRIPTION" default="" />
<field name="cryptocurrency" type="cryptocurrencies" label="VMPAYMENT_PLISIO_CRYPTOCURRENCY_LABEL" description="VMPAYMENT_PLISIO_CRYPTOCURRENCY_DESCRIPTION" default="" multiple="true" />

<field type="spacer" default="VMPAYMENT_PLISIO_STATUSES_LABEL" level="level1" />
<field name="pending_status" type="vmorderstate" scope="com_virtuemart" label="VMPAYMENT_PLISIO_PENDING_STATUS_LABEL" description="VMPAYMENT_PLISIO_PENDING_STATUS_DESCRIPTION" default="P" />
Expand All @@ -46,11 +46,6 @@
<field name="refunded_status" type="vmorderstate" scope="com_virtuemart" label="VMPAYMENT_PLISIO_REFUNDED_STATUS_LABEL" description="VMPAYMENT_PLISIO_REFUNDED_STATUS_DESCRIPTION" default="R" />
<field name="invalid_status" type="vmorderstate" scope="com_virtuemart" label="VMPAYMENT_PLISIO_INVALID_STATUS_LABEL" description="VMPAYMENT_PLISIO_INVALID_STATUS_DESCRIPTION" default="D" />
<field name="overpaid_status" type="vmorderstate" scope="com_virtuemart" label="VMPAYMENT_PLISIO_OVERPAID_STATUS_LABEL" description="VMPAYMENT_PLISIO_OVERPAID_STATUS_DESCRIPTION" default="C" />
<field name="payment_logos" type="vmfiles" multiple="true" label="VMPAYMENT_PLISIO_LOGO_LABEL"
description="VMPAYMENT_PLISIO_LOGO_DESCRIPTION"
directory="/images/stories/virtuemart/payment"
default="plisio.png" hide_default="1" hide_none="1"
stripext="0" exclude="^_"/>
</fieldset>
</fields>
</config>
Expand Down

0 comments on commit 680ea8b

Please sign in to comment.