Пользовательская функция WHMCS - Ошибка шлюза оплаты чеков - PullRequest
0 голосов
/ 29 марта 2020

Я пытаюсь добавить пользовательскую функцию в WHMCS, создав файл addstripecard.php, идея основана на данном токене клиента (что-то вроде cus_1GPkTFJEegxX3y3c123456), а затем попытаться прикрепить его к карте. Доступ к пользовательской функции осуществляется через API.

Сначала я пытаюсь получить доступ к библиотеке Stripe, используя следующие команды:

$gateway = new \WHMCS\Module\Gateway();
$gateway->load("stripe");

PS: коды были взяты из https://github.com/WHMCSCare/WHMCS-7.8.0-decoded/blob/e7446479de49a28c8801d4c0c95f4cae22dcff33/modules/gateways/stripe/lib/StripeController.php

Но после выполнения вышеприведенных команд я получил следующее сообщение об ошибке:

FastCGI sent in stderr: "PHP message: [WHMCS Application] ERROR: TypeError: Argument 2 passed to WHMCS\Api\ApplicationSupport\Http\ResponseFactory::factory() must be of the type array, string given,

called in /www/xxxxxx.xxx/billing/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Route/Middleware/HandleProcessor.php on line 0 

and defined in /www/xxxxxx.xxx/billing/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Http/ResponseFactory.php:0

Stack trace: #0 /www/xxxxxx.xxx/billing/vendor/whmcs/whmcs-foundation/lib/Api/ApplicationSupport/Route/Middleware/HandleProcessor.php(0): WHMCS\Api\ApplicationSupport\Http\ResponseFactory::factory(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), '{"legacyGateway...') #1 /www/xxxxxx.xxx/billing/vendor/whmcs/whmcs-foundation/lib/Route/Middleware/Strategy/DelegatingMiddlewareTrait.php(0): WHMCS\Api\ApplicationSupport\Route\Middleware\HandleProcessor->_process(Object(WHMCS\Api\ApplicationSupport\Http\ServerRequest), Object(Middlewares\Utils\Delegate)) #2 /www/dat" while reading response header from upstream, client: 172.81.129.13, 

server: xxxxxx.xxx.net, 

request: "POST /billing/includes/api.php HTTP/1.1",

upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:",

host: "xxxxxx.xxx"

Полные коды:

<?php

if (!defined("WHMCS")) {
    die("This file cannot be access directly!");
}

function addStripeCard()
{
    // card parameters
    $cardNumber       = $_POST['cardnumber'];
    $cardExpiryDate   = $_POST['cardexpirydate'];
    $remoteToken      = $_POST['remotetoken'];
    $billingContactId = $_POST['billingcontactid'];
    $description      = $_POST['description'];
    $cardType         = $_POST['cardtype'];
    $cardStartDate    = $_POST['cardstartdate'];
    $cardIssueNumber  = $_POST['cardissuenumber'];
    $clientId         = $_POST['clientid'];

    try {
        $gateway = new \WHMCS\Module\Gateway();

        $gateway->load("stripe");

        return json_encode($gateway);
    } catch (Exception $e) {
        $error = [
            'result'  => 'error',
            'message' => $e->getMessage(),
            'file'    => $e->getFile(),
            'line'    => $e->getLine(),
        ];

        return $error;
    }
}

try {
    $data = addStripeCard();

    $apiresults = $data;

} catch (Exception $e) {
    $error = [
        'result'  => 'error',
        'message' => $e->getMessage(),
        'file'    => $e->getFile(),
        'line'    => $e->getLine(),
    ];

    $apiresults = $error;
}

Кто-нибудь знает, что происходит на? Я много раз пробовал гуглить, но не смог найти ответов.

1 Ответ

0 голосов
/ 29 марта 2020

Я нашел ответ.

При возврате ответа клиенту мы должны как минимум придерживаться этого формата:

$apiresults = array('result' => $result, 'message' => $message);

его можно расширить до:

$apiresults = array('result' => $result, 'message' => $message, 'data' => $data);

поэтому я изменил вышеуказанные коды на:

<?php

if (!defined("WHMCS")) {
    die("This file cannot be access directly!");
}

function addStripeCard()
{
    // card parameters
    $cardNumber       = $_POST['cardnumber'];
    $cardExpiryDate   = $_POST['cardexpirydate'];
    $remoteToken      = $_POST['remotetoken'];
    $billingContactId = $_POST['billingcontactid'];
    $description      = $_POST['description'];
    $cardType         = $_POST['cardtype'];
    $cardStartDate    = $_POST['cardstartdate'];
    $cardIssueNumber  = $_POST['cardissuenumber'];
    $clientId         = $_POST['clientid'];

    try {
        $gateway = new \WHMCS\Module\Gateway();

        $gateway->load("stripe");

        return json_encode($gateway);
    } catch (Exception $e) {
        $error = [
            'result'  => 'error',
            'message' => $e->getMessage(),
            'file'    => $e->getFile(),
            'line'    => $e->getLine(),
        ];

        return $error;
    }
}

try {
    $data = addStripeCard();

    $apiresults = array('result' => 'success', 'message' => 'success message', 'data' => $data);
} catch (Exception $e) {
    $error = [
        'result'  => 'error',
        'message' => $e->getMessage(),
        'file'    => $e->getFile(),
        'line'    => $e->getLine(),
    ];

    $apiresults = $error;
}

, после того как ошибка исчезла, конечная точка API, которая обращается к пользовательской функции, получает 200 ответ.

...