Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ibernhardf committed Nov 15, 2024
1 parent 5da8a0c commit 31134d4
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions classes/external/transaction_complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class_alias(pu_interface_transaction_complete::class, interface_transaction_comp
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class transaction_complete extends external_api implements interface_transaction_complete {

/**
* Returns description of method parameters.
*
Expand Down Expand Up @@ -92,8 +91,17 @@ public static function execute_parameters(): external_function_parameters {
* @param int $userid
* @return array
*/
public static function execute(string $component, string $paymentarea, int $itemid, string $tid, string $token = '0',
string $customer = '0', bool $ischeckstatus = false, string $resourcepath = '', int $userid = 0): array {
public static function execute(
string $component,
string $paymentarea,
int $itemid,
string $tid,
string $token = '0',
string $customer = '0',
bool $ischeckstatus = false,
string $resourcepath = '',
int $userid = 0
): array {
global $USER, $DB, $CFG;

$success = false;
Expand Down Expand Up @@ -126,10 +134,15 @@ public static function execute(string $component, string $paymentarea, int $item
}

// We need to prevent duplicates, so check if the payment already exists!
if ($DB->get_records('payments', [
'component' => 'local_shopping_cart',
'itemid' => $itemid,
])) {
if (
$DB->get_records(
'payments',
[
'component' => 'local_shopping_cart',
'itemid' => $itemid,
]
)
) {
return [
'url' => $successurl ?? $serverurl,
'success' => true,
Expand Down Expand Up @@ -165,7 +178,7 @@ public static function execute(string $component, string $paymentarea, int $item
$surcharge = helper::get_gateway_surcharge('payone');
$amount = helper::get_rounded_cost($payable->get_amount(), $currency, $surcharge);

$sdk = new payone_sdk($config->clientid, $config->secret, $config->brandname, $sandbox );
$sdk = new payone_sdk($config->clientid, $config->secret, $config->brandname, $sandbox);
$orderdetails = $sdk->check_status($tid);
$statusorder = $orderdetails->getStatus();
if ($orderdetails && $statusorder == 'PAYMENT_CREATED') {
Expand Down Expand Up @@ -221,9 +234,16 @@ public static function execute(string $component, string $paymentarea, int $item
$success = true;

try {
$paymentid = payment_helper::save_payment($payable->get_account_id(), $component, $paymentarea,
$itemid, (int) $userid, $amount, $currency, 'payone');

$paymentid = payment_helper::save_payment(
$payable->get_account_id(),
$component,
$paymentarea,
$itemid,
(int) $userid,
$amount,
$currency,
'payone'
);
// Store payone extra information.
$record = new \stdClass();
$record->paymentid = $paymentid;
Expand All @@ -232,7 +252,7 @@ public static function execute(string $component, string $paymentarea, int $item
$paymentoutput = $orderdetails->getCreatedPaymentOutput()->getPayment()->getPaymentOutput();

if ($redirectedmethod = $paymentoutput->getRedirectPaymentMethodSpecificOutput()) {
$brandcode = $redirectedmethod->getPaymentProductId();
$brandcode = $redirectedmethod->getPaymentProductId();
} else if ($cardpaymentmethod = $paymentoutput->getCardPaymentMethodSpecificOutput()) {
$brandcode = $cardpaymentmethod->getPaymentProductId();
} else {
Expand All @@ -252,8 +272,12 @@ public static function execute(string $component, string $paymentarea, int $item
$DB->insert_record('paygw_payone', $record);

// Set status in open_orders to complete.
if ($existingrecord = $DB->get_record('paygw_payone_openorders',
['tid' => $tid])) {
if (
$existingrecord = $DB->get_record(
'paygw_payone_openorders',
['tid' => $tid]
)
) {
$existingrecord->status = 3;
$DB->update_record('paygw_payone_openorders', $existingrecord);

Expand Down Expand Up @@ -281,8 +305,15 @@ public static function execute(string $component, string $paymentarea, int $item
$event->trigger();

// If the delivery was not successful, we trigger an event.
if (!payment_helper::deliver_order($component, $paymentarea, $itemid, $paymentid, (int) $userid)) {

if (
!payment_helper::deliver_order(
$component,
$paymentarea,
$itemid,
$paymentid,
(int) $userid
)
) {
$context = context_system::instance();
$event = delivery_error::create([
'context' => $context,
Expand All @@ -306,7 +337,6 @@ public static function execute(string $component, string $paymentarea, int $item
. " resultcode: " . $orderdetails->getCreatedPaymentOutput()
->getPayment()->getStatusOutput()->getStatusCode() ?? ' noresultcode';
}

} else {
$success = false;
// Get the payment output only once to avoid multiple calls.
Expand All @@ -315,9 +345,7 @@ public static function execute(string $component, string $paymentarea, int $item
$statuscode = $payment ? $payment->getStatusOutput()->getStatusCode() : 'noresultcode';

$message = get_string('paymentnotcleared', 'paygw_payone') . " resultcode: " . $statuscode;

}

} else {
// Could not capture authorization!
$success = false;
Expand All @@ -327,10 +355,13 @@ public static function execute(string $component, string $paymentarea, int $item

// If there is no success, we trigger this event.
if (!$success) {

if ($setfailed) {
if ($existingrecord = $DB->get_record('paygw_payone_openorders',
['tid' => $tid])) {
if (
$existingrecord = $DB->get_record(
'paygw_payone_openorders',
['tid' => $tid]
)
) {
$existingrecord->status = 2;
$DB->update_record('paygw_payone_openorders', $existingrecord);
}
Expand Down

0 comments on commit 31134d4

Please sign in to comment.