From 247909522bd52d887d81fb7c3556dc4d4ece2fb7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 5 May 2024 09:53:31 +0300 Subject: [PATCH 1/3] add --- callback.php | 31 ++++++++++++++++++++++++++++++- pay.php | 11 ++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/callback.php b/callback.php index 9c0d12f..941a933 100644 --- a/callback.php +++ b/callback.php @@ -29,6 +29,8 @@ require("../../../config.php"); global $CFG, $USER, $DB; +require_once($CFG->libdir . '/filelib.php'); + defined('MOODLE_INTERNAL') || die(); $status = required_param('status', PARAM_TEXT); @@ -55,7 +57,7 @@ $paymentid = $payment->id; $userid = $payment->userid; -// Get secretkey. +// Get apikey and secretkey. $config = (object) helper::get_gateway_configuration($component, $paymentarea, $itemid, 'cryptocloud'); $decoded = JWT::decode($token, new Key($config->secretkey, 'HS256')); @@ -63,6 +65,33 @@ die('FAIL. Invalid token.'); } +// Check invoice on site. +$location = 'https://api.cryptocloud.plus/v2/invoice/merchant/info'; +$options = [ + 'CURLOPT_RETURNTRANSFER' => true, + 'CURLOPT_TIMEOUT' => 30, + 'CURLOPT_HTTPHEADER' => [ + 'Content-Type: application/json', + 'Authorization: Token ' . $config->apikey, + ], +]; +$jsondata = json_encode(["uuids" => array($invoiceid)]); + +$curl = new curl(); +$jsonresponse = $curl->post($location, $jsondata, $options); +$response = json_decode($jsonresponse, false); + +// Check invoice status. +if ($response->status !== 'success') { + die('FAIL. Invoice check not successed.'); +} +if ($response->result[0]->invoice_status !== 'success'){ + die('FAIL. Invoice not successed.'); +} +if ($response->result[0]->status !== 'paid'){ + die('FAIL. Invoice not paid.'); +} + helper::deliver_order($component, $paymentarea, $itemid, $paymentid, $userid); // Write to DB. diff --git a/pay.php b/pay.php index f0b2c45..105251e 100644 --- a/pay.php +++ b/pay.php @@ -26,12 +26,12 @@ use core_payment\helper; require_once(__DIR__ . '/../../../config.php'); +global $CFG, $USER, $DB; + require_once($CFG->libdir . '/filelib.php'); require_login(); -global $CFG, $USER, $DB; - $userid = $USER->id; $component = required_param('component', PARAM_ALPHANUMEXT); @@ -43,7 +43,8 @@ $skipmode = optional_param('skipmode', 0, PARAM_INT); $costself = optional_param('costself', null, PARAM_TEXT); -$description = json_decode('"' . $description . '"'); +$description = json_decode("\"$description\""); + $config = (object) helper::get_gateway_configuration($component, $paymentarea, $itemid, 'cryptocloud'); $payable = helper::get_payable($component, $paymentarea, $itemid);// Get currency and payment amount. @@ -162,8 +163,8 @@ $payment->email = $USER->email; $payment->add_fields = [ 'time_to_pay' => [ - 'hours' => 0, - 'minutes' => 10, + 'hours' => 1, + 'minutes' => 0, ], ]; From b6bf2b91998e30588f53a4f1d2378a50055369da Mon Sep 17 00:00:00 2001 From: root Date: Sun, 5 May 2024 09:55:19 +0300 Subject: [PATCH 2/3] version --- README.md | 2 +- version.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7347f81..54f27a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # CryptoCloud payment gateway plugin for Moodle. -v0.7 +v0.8 https://cryptocloud.plus/ diff --git a/version.php b/version.php index 18ca722..5c273a0 100644 --- a/version.php +++ b/version.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024050400; +$plugin->version = 2024050500; $plugin->requires = 2023100900; $plugin->component = 'paygw_cryptocloud'; -$plugin->release = '0.7'; +$plugin->release = '0.8'; $plugin->maturity = MATURITY_STABLE; From 42253fec2a6770acb2fce99abb4452be539212e6 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 5 May 2024 10:01:15 +0300 Subject: [PATCH 3/3] fix --- callback.php | 6 +++--- method.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/callback.php b/callback.php index 941a933..d37d71c 100644 --- a/callback.php +++ b/callback.php @@ -75,7 +75,7 @@ 'Authorization: Token ' . $config->apikey, ], ]; -$jsondata = json_encode(["uuids" => array($invoiceid)]); +$jsondata = json_encode(["uuids" => [$invoiceid]]); $curl = new curl(); $jsonresponse = $curl->post($location, $jsondata, $options); @@ -85,10 +85,10 @@ if ($response->status !== 'success') { die('FAIL. Invoice check not successed.'); } -if ($response->result[0]->invoice_status !== 'success'){ +if ($response->result[0]->invoice_status !== 'success') { die('FAIL. Invoice not successed.'); } -if ($response->result[0]->status !== 'paid'){ +if ($response->result[0]->status !== 'paid') { die('FAIL. Invoice not paid.'); } diff --git a/method.php b/method.php index 486cf59..6015a66 100644 --- a/method.php +++ b/method.php @@ -39,6 +39,8 @@ $itemid = required_param('itemid', PARAM_INT); $description = required_param('description', PARAM_TEXT); +$description = json_decode('"' . $description . '"'); + $params = [ 'component' => $component, 'paymentarea' => $paymentarea,