Skip to content

Commit

Permalink
Merge pull request #32 from Snickser/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Snickser authored May 5, 2024
2 parents 5d95a8b + 42253fe commit 973532c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# CryptoCloud payment gateway plugin for Moodle.

v0.7
v0.8

https://cryptocloud.plus/

Expand Down
31 changes: 30 additions & 1 deletion callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,14 +57,41 @@
$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'));
if (empty($decoded->id)) {
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" => [$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.
Expand Down
2 changes: 2 additions & 0 deletions method.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -162,8 +163,8 @@
$payment->email = $USER->email;
$payment->add_fields = [
'time_to_pay' => [
'hours' => 0,
'minutes' => 10,
'hours' => 1,
'minutes' => 0,
],
];

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 973532c

Please sign in to comment.