Skip to content

Commit

Permalink
Fix/wordpress compatibility (#3)
Browse files Browse the repository at this point in the history
* Deleted plugin zip from repo

* WordPress compatibility fixes

* WordPress compatibility fixes

* WordPress compatibility fixes

* Proper Internationalization, Capture method null bugfix, HTTP request headers bugfix

* v1.3.0 WordPress Compatibility
  • Loading branch information
vsrivatsa-edinburgh authored Jan 22, 2024
1 parent fed07b6 commit 6d4d37b
Show file tree
Hide file tree
Showing 7 changed files with 674 additions and 651 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hyperswitch-woocommerce-plugin.zip
534 changes: 223 additions & 311 deletions hyperswitch-payment.php

Large diffs are not rendered by default.

Binary file removed hyperswitch-woocommerce-plugin.zip
Binary file not shown.
64 changes: 34 additions & 30 deletions includes/hyperswitch-webhook.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
if (!defined('ABSPATH'))
exit; // Exit if accessed directly

require_once __DIR__ . '/../hyperswitch-payment.php';

Expand Down Expand Up @@ -38,53 +40,55 @@ class Hyperswitch_Webhook

public function __construct()
{
$this->hyperswitch = new WC_Hyperswitch_Payment();
$this->hyperswitch = new Hyperswitch_Payment();

}

public function process()
{
$post = file_get_contents('php://input');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$raw_post_data = file_get_contents('php://input');
if (!empty($raw_post_data)) {
$data = json_decode($raw_post_data, true);

$data = json_decode($post, true);
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE_512'];

$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE_512'];

if (json_last_error() !== 0) {
return;
}

if (json_last_error() !== 0) {
return;
}

$enabled = $this->hyperswitch->get_option('enable_webhook');
$enabled = $this->hyperswitch->get_option('enable_webhook');

if (($enabled === 'yes') and (empty($data['event_type']) === false)) {
// Skip the webhook if webhooks are disabled, or the event type is unrecognised
$payment_id = $data['content']['object']['payment_id'];
$this->hyperswitch->post_log("WC_WEBHOOK_RECEIVED", $data['event_type'], $payment_id);
if ($this->shouldConsumeWebhook($data, $signature, $post) === false) {
return;
}
switch ($data['event_type']) {
case self::PAYMENT_SUCCEEDED:
return $this->paymentAuthorized($data);
if (($enabled === 'yes') and (empty($data['event_type']) === false)) {
// Skip the webhook if webhooks are disabled, or the event type is unrecognised
$payment_id = $data['content']['object']['payment_id'];
$this->hyperswitch->post_log("WC_WEBHOOK_RECEIVED", $data['event_type'], $payment_id);
if ($this->shouldConsumeWebhook($data, $signature, $raw_post_data) === false) {
return;
}
switch ($data['event_type']) {
case self::PAYMENT_SUCCEEDED:
return $this->paymentAuthorized($data);

case self::PAYMENT_FAILED:
return $this->paymentHandle($data, "failed");
case self::PAYMENT_FAILED:
return $this->paymentHandle($data, "failed");

case self::PAYMENT_PROCESSING:
return $this->paymentHandle($data, "processing");
case self::PAYMENT_PROCESSING:
return $this->paymentHandle($data, "processing");

case self::ACTION_REQURIED:
return $this->paymentHandle($data, "action required");
case self::ACTION_REQURIED:
return $this->paymentHandle($data, "action required");

case self::REFUND_SUCCEEDED:
return $this->refundedCreated($data);
case self::REFUND_SUCCEEDED:
return $this->refundedCreated($data);

default:
return;
default:
return;
}
}
}
}

}

protected function paymentAuthorized(array $data)
Expand Down
Loading

0 comments on commit 6d4d37b

Please sign in to comment.