diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 6aefc0845180..116123e16796 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -228,7 +228,7 @@ class CreditCard implements MethodInterface $paymentRequest->amount = $this->checkout->payment_hash->data->value; $paymentRequest->reference = substr($this->checkout->getDescription(), 0, 49); $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(); $this->checkout->payment_hash->data = array_merge((array) $this->checkout->payment_hash->data, ['checkout_payment_ref' => $paymentRequest]); diff --git a/app/PaymentDrivers/CheckoutCom/Webhook.php b/app/PaymentDrivers/CheckoutCom/Webhook.php new file mode 100644 index 000000000000..5fe59b00d6e6 --- /dev/null +++ b/app/PaymentDrivers/CheckoutCom/Webhook.php @@ -0,0 +1,128 @@ +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 + } + + + + } + +} \ No newline at end of file diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 77b258661c39..310c31a9afbc 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -334,7 +334,7 @@ class CheckoutComPaymentDriver extends BaseDriver $paymentRequest->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode()); $paymentRequest->reference = '#'.$invoice->number.' - '.now(); $paymentRequest->customer = $this->getCustomer(); - $paymentRequest->metadata = ['udf1' => 'Invoice Ninja']; + $paymentRequest->metadata = ['udf1' => 'Invoice Ninja', 'udf2' => $payment_hash->hash]; $paymentRequest->currency = $this->client->getCurrencyCode(); $request = new PaymentResponseRequest(); @@ -421,6 +421,7 @@ class CheckoutComPaymentDriver extends BaseDriver public function processWebhookRequest(PaymentWebhookRequest $request) { + nlog($request->all()); return true; }