2023-07-21 07:48:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2023-07-21 07:48:10 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers\CheckoutCom;
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
use App\PaymentDrivers\CheckoutComPaymentDriver;
|
2023-07-21 07:48:10 +02:00
|
|
|
use Checkout\CheckoutApiException;
|
|
|
|
use Checkout\CheckoutAuthorizationException;
|
|
|
|
|
|
|
|
class Webhook
|
|
|
|
{
|
2023-07-21 13:58:04 +02:00
|
|
|
public function __construct(public CheckoutComPaymentDriver $checkout)
|
2023-07-21 07:48:10 +02:00
|
|
|
{
|
|
|
|
$this->checkout = $checkout;
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:01:22 +02:00
|
|
|
/**
|
|
|
|
* Lists all possible events in checkout and a brief description
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-07-21 07:48:10 +02:00
|
|
|
public function getEventTypes()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$response = $this->checkout->gateway->getWorkflowsClient()->getEventTypes();
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
return $response;
|
2023-07-21 07:48:10 +02:00
|
|
|
|
|
|
|
} catch (CheckoutApiException $e) {
|
|
|
|
// API error
|
|
|
|
$error_details = $e->error_details;
|
|
|
|
nlog($error_details);
|
|
|
|
|
|
|
|
$http_status_code = isset($e->http_metadata) ? $e->http_metadata->getStatusCode() : null;
|
|
|
|
} catch (CheckoutAuthorizationException $e) {
|
|
|
|
// Bad Invalid authorization
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:01:22 +02:00
|
|
|
/**
|
|
|
|
* Lists the workflows in Checkout
|
|
|
|
*/
|
2023-07-21 07:48:10 +02:00
|
|
|
public function getWorkFlows()
|
|
|
|
{
|
|
|
|
|
|
|
|
try {
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-07-21 07:48:10 +02:00
|
|
|
$response = $this->checkout->gateway->getWorkflowsClient()->getWorkflows();
|
|
|
|
|
2023-07-21 13:58:04 +02:00
|
|
|
return $response;
|
2023-07-21 07:48:10 +02:00
|
|
|
|
|
|
|
} catch (CheckoutApiException $e) {
|
|
|
|
// API error
|
|
|
|
$error_details = $e->error_details;
|
|
|
|
$http_status_code = isset($e->http_metadata) ? $e->http_metadata->getStatusCode() : null;
|
|
|
|
} catch (CheckoutAuthorizationException $e) {
|
|
|
|
// Bad Invalid authorization
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|