mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Add Webhooks for Checkout.com
This commit is contained in:
parent
6355220387
commit
47a8e4fe6a
@ -228,7 +228,7 @@ class CreditCard implements MethodInterface
|
|||||||
$paymentRequest->amount = $this->checkout->payment_hash->data->value;
|
$paymentRequest->amount = $this->checkout->payment_hash->data->value;
|
||||||
$paymentRequest->reference = substr($this->checkout->getDescription(), 0, 49);
|
$paymentRequest->reference = substr($this->checkout->getDescription(), 0, 49);
|
||||||
$paymentRequest->customer = $this->checkout->getCustomer();
|
$paymentRequest->customer = $this->checkout->getCustomer();
|
||||||
$paymentRequest->metadata = ['udf1' => 'Invoice Ninja'];
|
$paymentRequest->metadata = ['udf1' => 'Invoice Ninja', 'udf2' => $this->checkout->payment_hash->hash];
|
||||||
$paymentRequest->currency = $this->checkout->client->getCurrencyCode();
|
$paymentRequest->currency = $this->checkout->client->getCurrencyCode();
|
||||||
|
|
||||||
$this->checkout->payment_hash->data = array_merge((array) $this->checkout->payment_hash->data, ['checkout_payment_ref' => $paymentRequest]);
|
$this->checkout->payment_hash->data = array_merge((array) $this->checkout->payment_hash->data, ['checkout_payment_ref' => $paymentRequest]);
|
||||||
|
128
app/PaymentDrivers/CheckoutCom/Webhook.php
Normal file
128
app/PaymentDrivers/CheckoutCom/Webhook.php
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\PaymentDrivers\CheckoutCom;
|
||||||
|
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Checkout\CheckoutApiException;
|
||||||
|
use Checkout\CheckoutAuthorizationException;
|
||||||
|
use Checkout\Workflows\CreateWorkflowRequest;
|
||||||
|
use App\PaymentDrivers\Common\MethodInterface;
|
||||||
|
use App\PaymentDrivers\CheckoutComPaymentDriver;
|
||||||
|
use Checkout\Workflows\Actions\WebhookSignature;
|
||||||
|
use Checkout\Workflows\Actions\WebhookWorkflowActionRequest;
|
||||||
|
use Checkout\Workflows\Conditions\EventWorkflowConditionRequest;
|
||||||
|
use Checkout\Workflows\Conditions\EntityWorkflowConditionRequest;
|
||||||
|
use Checkout\Workflows\Conditions\ProcessingChannelWorkflowConditionRequest;
|
||||||
|
|
||||||
|
class Webhook
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CheckoutComPaymentDriver
|
||||||
|
*/
|
||||||
|
public $checkout;
|
||||||
|
|
||||||
|
private string $authentication_webhook_name = 'Invoice_Ninja_3DS_Workflow';
|
||||||
|
|
||||||
|
public function __construct(CheckoutComPaymentDriver $checkout)
|
||||||
|
{
|
||||||
|
$this->checkout = $checkout;
|
||||||
|
|
||||||
|
$this->checkout->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkStatus()
|
||||||
|
{
|
||||||
|
// $this->checkout->company_gateway->webhookUrl()
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createAuthenticationWorkflow()
|
||||||
|
{
|
||||||
|
|
||||||
|
$signature = new WebhookSignature();
|
||||||
|
$signature->key = "1234567890";
|
||||||
|
$signature->method = "HMACSHA256";
|
||||||
|
|
||||||
|
$actionRequest = new WebhookWorkflowActionRequest();
|
||||||
|
$actionRequest->url = $this->checkout->company_gateway->webhookUrl();
|
||||||
|
$actionRequest->signature = $signature;
|
||||||
|
|
||||||
|
$eventWorkflowConditionRequest = new EventWorkflowConditionRequest();
|
||||||
|
$eventWorkflowConditionRequest->events = [
|
||||||
|
"gateway" => ["payment_approved"],
|
||||||
|
"issuing" => ["authorization_approved","authorization_declined"],
|
||||||
|
];
|
||||||
|
|
||||||
|
$request = new CreateWorkflowRequest();
|
||||||
|
$request->actions = [$actionRequest];
|
||||||
|
$request->conditions = [$eventWorkflowConditionRequest];
|
||||||
|
$request->name = $this->authentication_webhook_name;
|
||||||
|
$request->active = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->checkout->gateway->getWorkflowsClient()->createWorkflow($request);
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
|
} catch (CheckoutApiException $e) {
|
||||||
|
// API error
|
||||||
|
$error_details = $e->error_details;
|
||||||
|
$http_status_code = isset($e->http_metadata) ? $e->http_metadata->getStatusCode() : null;
|
||||||
|
nlog($error_details);
|
||||||
|
} catch (CheckoutAuthorizationException $e) {
|
||||||
|
// Bad Invalid authorization
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventTypes()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->checkout->gateway->getWorkflowsClient()->getEventTypes();
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWorkFlows()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->checkout->gateway->getWorkflowsClient()->getWorkflows();
|
||||||
|
|
||||||
|
nlog($response);
|
||||||
|
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -334,7 +334,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
$paymentRequest->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
|
$paymentRequest->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
|
||||||
$paymentRequest->reference = '#'.$invoice->number.' - '.now();
|
$paymentRequest->reference = '#'.$invoice->number.' - '.now();
|
||||||
$paymentRequest->customer = $this->getCustomer();
|
$paymentRequest->customer = $this->getCustomer();
|
||||||
$paymentRequest->metadata = ['udf1' => 'Invoice Ninja'];
|
$paymentRequest->metadata = ['udf1' => 'Invoice Ninja', 'udf2' => $payment_hash->hash];
|
||||||
$paymentRequest->currency = $this->client->getCurrencyCode();
|
$paymentRequest->currency = $this->client->getCurrencyCode();
|
||||||
|
|
||||||
$request = new PaymentResponseRequest();
|
$request = new PaymentResponseRequest();
|
||||||
@ -421,6 +421,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
public function processWebhookRequest(PaymentWebhookRequest $request)
|
public function processWebhookRequest(PaymentWebhookRequest $request)
|
||||||
{
|
{
|
||||||
|
nlog($request->all());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user