Compare commits

...

15 Commits

Author SHA1 Message Date
Nicolas Dorier
2e4673c832
Update README.md 2021-01-11 11:34:33 +09:00
Nicolas Dorier
7ba9816e25
Update README.md 2021-01-11 11:31:45 +09:00
Adrien Bensaïbi
8e088c737a
Merge pull request #11 from btcpayserver/improvments
Improvments
2019-02-04 16:48:16 +01:00
Adrien Bensaïbi
257724c584 fix: rm old logs 2019-02-04 16:47:21 +01:00
Adrien Bensaïbi
4a5ce954dc fix: respect class convention 2019-02-03 02:07:25 +01:00
Adrien Bensaïbi
04658e4e92 fix: add some sleep to let order_bitcoin update 2019-02-02 22:45:29 +01:00
Adrien Bensaïbi
c6bb530fa2 chore: dump version 2019-02-02 19:18:31 +01:00
Adrien Bensaïbi
87092e062f feat: cleaning and links 2019-02-02 19:16:50 +01:00
Adrien Bensaïbi
96601c9222 doc: resolve #8 small notice about servers access 2019-02-02 18:34:09 +01:00
Adrien Bensaïbi
67dba23743
Merge pull request #10 from btcpayserver/fix-currency
fix: multi currency instead of euro only
2019-02-02 18:17:40 +01:00
Adrien Bensaïbi
04ec130145 fix: multi currency instead of euro only 2019-02-02 18:03:12 +01:00
Adrien Bensaïbi
e523d46703
Merge pull request #9 from btcpayserver/fix-syntax-associative-array
Fix syntax associative array
2019-02-02 17:17:57 +01:00
Adrien B
dcccf8903c doc: add bcmath deps to GUIDE.md 2019-02-02 17:09:43 +01:00
Adrien Bensaïbi
cf09154f25 fix #7: string instead of constante in ipn 2019-01-11 23:48:41 +01:00
Adrien Bensaïbi
85ea627829
doc(README): update TODOs 2018-09-18 09:54:41 +02:00
9 changed files with 77 additions and 51 deletions

View File

@ -5,8 +5,8 @@
1.7.0 (19 June 2017)
* Now compatible with PrestaShop 1.6 and 1.7
1.5.0 (11 March 2015)
1.5.0 (11 March 2015)
* Now compatible with PrestaShop 1.5+
Version 0.5
* Tested against PrestaShop v1.5.4.1 and 1.6.0.5
* Tested against PrestaShop v1.5.4.1 and 1.6.0.5

View File

@ -16,11 +16,14 @@ If you want to test in test mode, just paste an other btcpayserver url with test
+ PHP 5+
+ Curl PHP Extension
+ JSON PHP Extension
+ Install PHP bcmath module
+ be sure your BTCPay server is whitelisted by Prestashop server
+ be sure your Prestashop server is whitelisted by BTCPay server
## Plugin Configuration
### For Prestashop versions 1.7:
1. Download the latest release from https://github.com/adapp-tech/prestashop-plugin/releases
1. Download the latest release from https://github.com/btcpayserver/prestashop-plugin/releases
2. Go to your PrestaShop administration. Under "Modules and services" select "Upload a module" (v1.7)
3. Go to your "installed modules" -> "BTCPay" and click [Configure]<br />
4. Go on your BTCPay server, in your store and display access tokens.

View File

@ -1,3 +1,5 @@
> :warning: THIS PLUGIN IS FUNCTIONING BUT DEPRECATED, USE https://github.com/btcpayserver/prestashop-plugin INSTEAD
# Prestashop Plugin for BTCPay server, an opensource Payment processor
Warning this is an Beta version
@ -14,7 +16,7 @@ and if you want, some companies provide hosting services.
## Quick Start Guide
To get up and running with our plugin quickly, see the GUIDE here: https://github.com/adapp-tech/prestashop-plugin/blob/master/GUIDE.md
To get up and running with our plugin quickly, see the GUIDE here: https://github.com/btcpayserver/prestashop-plugin/blob/master/GUIDE.md
# Internals
@ -25,13 +27,19 @@ Prestashop design ensure customer is ready to pay, with a checkbox, when he is f
# TODO
Their is still a lot's of place for improvement.
* ~~on/off postponed order~~
* ~~direct configuration for block confirmations~~
* composer with php-bitpay-client
* on/off postponed order
* direct configuration for block confirmations
* docker for testing
* travis integration
* check 1.6.X compatibility
* ensure stats are correctly displayed in prestashop
* share the same order number BTCPay server and prestashop, or give insight in order details
* give bitcoin rate in local currency in order details
* still in order details, give exact time of payment and bitcoin transaction
* find a way to not override order state numbers currently used in case another plugin use it.
e.g: plugin use order state id: 39,40,41,42. Should use 49,50,51,52 if other plugins use the first one.
* refactoring in ipn.php
# Support
@ -42,7 +50,7 @@ Their is still a lot's of place for improvement.
## Contribute
To contribute to this project, please fork and submit a pull request.
* [GitHub Issues](https://github.com/adapptech/prestashop-plugin/issues)
* [GitHub Issues](https://github.com/btcpayserver/prestashop-plugin/issues)
## PrestaShop Support

View File

@ -37,7 +37,7 @@ if (!defined('_PS_VERSION_')) {
exit;
}
class btcpay extends PaymentModule {
class BTCpay extends PaymentModule {
private $_html = '';
private $key;
protected $_postErrors = array();
@ -70,9 +70,9 @@ class btcpay extends PaymentModule {
$this->name = 'btcpay';
$this->tab = 'payments_gateways';
$this->version = '0.3.1';
$this->version = '0.3.2';
$this->author = 'ADAPP';
$this->className = 'btcpay';
$this->className = 'BTCpay';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
$this->display = 'view';
@ -503,8 +503,15 @@ class btcpay extends PaymentModule {
// Get shopping currency, currently tested with be EUR
$currency = Currency::getCurrencyInstance((int)$cart->id_currency);
if (true === empty($currency)) {
$currency = Currency::getDefaultCurrency();
return;
}
$transaction_speed = Configuration::get('btcpay_TXSPEED');
if (true === empty($transaction_speed)) {
$transaction_speed = 'default';
}
// get the cart id to fetch cart information
$cart_id = $cart->id;
@ -517,7 +524,7 @@ class btcpay extends PaymentModule {
$cart_total = $cart->getOrderTotal(true);
// This is the callback url for invoice paid
$notification_url = 'https://'.htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/ipn.php';
$notification_url = Tools::getShopDomainSsl(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/ipn.php';
// Get a BitPay Client to prepare for invoice creation
$client = new \Bitpay\Client\Client();
@ -568,12 +575,11 @@ class btcpay extends PaymentModule {
PrestaShopLogger::addLog('[Error] The BTCPay payment plugin was called to process a payment but could not instantiate an Invoice object.', 3);
}
$btcpay_currency = new \Bitpay\Currency('EUR');
$btcpay_currency = new \Bitpay\Currency($currency->iso_code);
$invoice->setOrderId((string)$cart_id);
$invoice->setCurrency($btcpay_currency);
$invoice->setFullNotifications(true);
$invoice->setExtendedNotifications(true);
// Add a priced item to the invoice
$item = new \Bitpay\Item();
if (false === isset($item) || true === empty($item)) {
@ -702,7 +708,7 @@ class btcpay extends PaymentModule {
if(isset($redirect) && !empty($redirect))
{
$result_invoice_id = $this->get_order_field($cart_id, 'invoice_id');
$invoice = $client->getInvoice($result_invoice_id['invoice_id']);
$invoice = $client->getInvoice($result_invoice_id);
$status = $invoice->getStatus();
if($status === 'invalid' || $status === 'expired')
{

View File

@ -2,7 +2,7 @@
<module>
<name>btcpay</name>
<displayName><![CDATA[BTCPay]]></displayName>
<version><![CDATA[0.3.1]]></version>
<version><![CDATA[0.3.2]]></version>
<description><![CDATA[Accepts Bitcoin payments via BTCPay.]]></description>
<author><![CDATA[ADAPP]]></author>
<tab><![CDATA[payments_gateways]]></tab>

View File

@ -2,7 +2,7 @@
<module>
<name>btcpay</name>
<displayName><![CDATA[btcpay]]></displayName>
<version><![CDATA[0.3.1]]></version>
<version><![CDATA[0.3.2]]></version>
<description><![CDATA[Acceptez les paiements en bitcoin via BTCPay.]]></description>
<author><![CDATA[ADAPP]]></author>
<tab><![CDATA[payments_gateways]]></tab>

View File

@ -1,7 +1,7 @@
<?php
class btcpayPaymentModuleFrontController extends ModuleFrontController
class BTCpayPaymentModuleFrontController extends ModuleFrontController
{
public $ssl = true;
public $display_column_left = false;

View File

@ -1,7 +1,7 @@
<?php
class btcpayValidationModuleFrontController extends ModuleFrontController
class BTCpayValidationModuleFrontController extends ModuleFrontController
{
/**
* @see FrontController::postProcess()

View File

@ -29,7 +29,7 @@
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/btcpay.php');
$btcpay = new btcpay();
$btcpay = new BTCpay();
$post = file_get_contents('php://input');
if (!$post) {
@ -74,7 +74,7 @@ $event= array();
// extended notification type
if(true === array_key_exists('event', $json) ) {
$event = $json[event];
$event = $json['event'];
} else {
//nothing to do
exit(1);
@ -82,7 +82,7 @@ if(true === array_key_exists('event', $json) ) {
$data = array();
if(true === array_key_exists('data', $json)) {
$data = $json[data];
$data = $json['data'];
}
if (empty($json->event->code)) {
@ -96,9 +96,13 @@ $btcpay_ordermode = Configuration::get('btcpay_ORDERMODE');
### ----------------
# Invoice created
if (true == array_key_exists('name', $event)
&& $event[name] === "invoice_created"
&& $event['name'] === "invoice_created"
&& $btcpay_ordermode === "beforepayment" ) {
// sleep to not receive ipn notification
// before the update of bitcoin order table
sleep(15);
// check if we have needed data
if (true === empty($data)) {
PrestaShopLogger::addLog('[Error] No data',3);
@ -116,7 +120,7 @@ if (true == array_key_exists('name', $event)
}
// get invoice id, to go back on cart and check the amount
$invoice_id = (string)$data[id];
$invoice_id = (string)$data['id'];
if ( false === isset($invoice_id)) {
PrestaShopLogger::addLog('[Error] No invoice id',3);
exit(1);
@ -134,14 +138,14 @@ if (true == array_key_exists('name', $event)
$display_name = $btcpay->displayName;
// fetch secure key, used to check cart comes from your prestashop
$secure_key = $data[posData];
$secure_key = $data['posData'];
if ( false === isset($secure_key)) {
PrestaShopLogger::addLog('[Error] No securekey',3);
exit(1);
}
// rate in fiat currency
$rate = $data[rate];
$rate = $data['rate'];
if ( false === isset($rate)) {
PrestaShopLogger::addLog('[Error] No rate',3);
exit(1);
@ -159,8 +163,8 @@ if (true == array_key_exists('name', $event)
$status_btcpay,
$cart_total,
$display_name, //bitcoin btcpay
$rate, //message
array(), //extravars
null, //message should be new Message
array(), //extravars for mail
null, //currency special
false, // don't touch amount
$secure_key
@ -206,9 +210,13 @@ if (true == array_key_exists('name', $event)
# ----------------
# Payment Received
if (true == array_key_exists('name', $event)
&& $event[name] === 'invoice_receivedPayment'
&& $event['name'] === 'invoice_receivedPayment'
&& $btcpay_ordermode === 'afterpayment' ) {
// sleep to not receive ipn notification
// before the update of bitcoin order table
sleep(15);
// check if we have needed data
if (true === empty($data)) {
PrestaShopLogger::addLog('[Error] No data',3);
@ -226,7 +234,7 @@ if (true == array_key_exists('name', $event)
}
// get invoice id, to go back on cart and check the amount
$invoice_id = (string)$data[id];
$invoice_id = (string)$data['id'];
if ( false === isset($invoice_id)) {
PrestaShopLogger::addLog('[Error] No invoice id',3);
exit;
@ -244,14 +252,14 @@ if (true == array_key_exists('name', $event)
$display_name = $btcpay->displayName;
// fetch secure key, used to check cart comes from your prestashop
$secure_key = $data[posData];
$secure_key = $data['posData'];
if ( false === isset($secure_key)) {
PrestaShopLogger::addLog('[Error] No securekey',3);
exit;
}
// rate in fiat currency
$rate = $data[rate];
$rate = $data['rate'];
if ( false === isset($rate)) {
PrestaShopLogger::addLog('[Error] No rate',3);
exit;
@ -287,7 +295,7 @@ if (true == array_key_exists('name', $event)
// update order_bitcoin paid amount
$db = Db::getInstance();
$query = 'UPDATE `' . _DB_PREFIX_ . "order_bitcoin` SET `btc_paid`='".$data[btcPaid]."' WHERE `id_order`=" . intval($order_id) . ';';
$query = 'UPDATE `' . _DB_PREFIX_ . "order_bitcoin` SET `btc_paid`='".$data['btcPaid']."' WHERE `id_order`=" . intval($order_id) . ';';
$result = array();
$result = $db->Execute($query);
@ -313,7 +321,7 @@ if (true == array_key_exists('name', $event)
}
if (true == array_key_exists('name', $event)
&& $event[name] === 'invoice_receivedPayment'
&& $event['name'] === 'invoice_receivedPayment'
&& $btcpay_ordermode === 'beforepayment' ) {
PrestaShopLogger::addLog('[Info] payment received', 1);
@ -329,7 +337,7 @@ if (true == array_key_exists('name', $event)
}
// get invoice id, to go back on cart and check the amount
$invoice_id = (string)$data[id];
$invoice_id = (string)$data['id'];
if ( false === isset($invoice_id)) {
PrestaShopLogger::addLog('[Error] No invoice id',3);
exit(1);
@ -340,8 +348,8 @@ if (true == array_key_exists('name', $event)
$result = array();
$order_id = null;
$result = $db->ExecuteS("SELECT `id_order` FROM `" . _DB_PREFIX_ . "order_bitcoin` WHERE `invoice_id`='" . $invoice_id . "';");
if (count($result) > 0 && $result[0] !== null && $result[0][id_order] !== null) {
$order_id = $result[0][id_order];
if (count($result) > 0 && $result[0] !== null && $result[0]['id_order'] !== null) {
$order_id = $result[0]['id_order'];
} else {
PrestaShopLogger::addLog('[Error] IPN order id not found', 3);
exit(1);
@ -354,7 +362,7 @@ if (true == array_key_exists('name', $event)
// update order_bitcoin paid amount
$db = Db::getInstance();
$query = 'UPDATE `' . _DB_PREFIX_ . "order_bitcoin` SET `btc_paid`='".$data[btcPaid]."' WHERE `id_order`=" . intval($order_id) . ';';
$query = 'UPDATE `' . _DB_PREFIX_ . "order_bitcoin` SET `btc_paid`='".$data['btcPaid']."' WHERE `id_order`=" . intval($order_id) . ';';
$result = array();
$result = $db->Execute($query);
@ -380,13 +388,14 @@ if (true == array_key_exists('name', $event)
# 1 to 6 confirmation depending on your setup
# see TX speed
if (true === array_key_exists('name', $event)
&& $event[name] === 'invoice_paidInFull' ) {
&& $event['name'] === 'invoice_paidInFull' ) {
PrestaShopLogger::addLog('[Error] Paid in FULL',3);
exit;
}
if (true === array_key_exists('name', $event)
&& $event[name] === 'invoice_failedToConfirm' or $event[name] === 'invoice_markedInvalid' ) {
&& $event['name'] === 'invoice_failedToConfirm'
or $event['name'] === 'invoice_markedInvalid' ) {
if (true === empty($data)) {
PrestaShopLogger::addLog('[Error] invalide json', 3);
@ -463,9 +472,9 @@ if (true === array_key_exists('name', $event)
$db = Db::getInstance();
$result = array();
$order_id = "";
$result = $db->ExecuteS("SELECT `id_order` FROM `" . _DB_PREFIX_ . "order_bitcoin` WHERE `invoice_id`='" . (string)$data[id] . "';");
if (count($result)>0 && $result[0] !== null && $result[0][id_order] !== null) {
$order_id = $result[0][id_order];
$result = $db->ExecuteS("SELECT `id_order` FROM `" . _DB_PREFIX_ . "order_bitcoin` WHERE `invoice_id`='" . (string)$data['id'] . "';");
if (count($result)>0 && $result[0] !== null && $result[0]['id_order'] !== null) {
$order_id = $result[0]['id_order'];
} else {
PrestaShopLogger::addLog('[Error] IPN order id not found', 3);
exit;
@ -476,7 +485,7 @@ if (true === array_key_exists('name', $event)
// wait for confirm
$status_btcpay = 41;
if($data[status] === 'invalid' || $data[status] === 'expired')
if($data['status'] === 'invalid' || $data['status'] === 'expired')
{
// time setup on invoice is expired
$status_btcpay = 41;
@ -505,7 +514,7 @@ if (true === array_key_exists('name', $event)
# confirmed then completed
# see TX speed
if (true === array_key_exists('name', $event)
&& $event[name] === 'invoice_confirmed' ) {
&& $event['name'] === 'invoice_confirmed' ) {
if (true === empty($data)) {
PrestaShopLogger::addLog('[Error] invalide json', 3);
@ -589,9 +598,9 @@ if (true === array_key_exists('name', $event)
$db = Db::getInstance();
$result = array();
$order_id = "";
$result = $db->ExecuteS("SELECT `id_order` FROM `" . _DB_PREFIX_ . "order_bitcoin` WHERE `invoice_id`='" . (string)$data[id] . "';");
if (count($result)>0 && $result[0] !== null && $result[0][id_order] !== null) {
$order_id = $result[0][id_order];
$result = $db->ExecuteS("SELECT `id_order` FROM `" . _DB_PREFIX_ . "order_bitcoin` WHERE `invoice_id`='" . (string)$data['id'] . "';");
if (count($result)>0 && $result[0] !== null && $result[0]['id_order'] !== null) {
$order_id = $result[0]['id_order'];
} else {
PrestaShopLogger::addLog('[Error] IPN order id not found', 3);
exit;
@ -602,19 +611,19 @@ if (true === array_key_exists('name', $event)
// wait for confirm
$status_btcpay = 40;
if($data[status] === 'invalid' || $data[status] === 'expired')
if($data['status'] === 'invalid' || $data['status'] === 'expired')
{
// time setup on invoice is expired
$status_btcpay = 41;
}
if($data[status] === 'paid')
if($data['status'] === 'paid')
{
// TX received but we have to wait some confirmation
$status_btcpay = 40;
}
if($data[status] === 'confirmed' || $data[status] === 'complete')
if($data['status'] === 'confirmed' || $data['status'] === 'complete')
{
//Transaction confirmed
$status_btcpay = 42;