Skip to content

Commit

Permalink
fix: test this out instead
Browse files Browse the repository at this point in the history
  • Loading branch information
timjackleus committed Jan 8, 2024
1 parent 2031a79 commit 00440ad
Show file tree
Hide file tree
Showing 19 changed files with 1,552 additions and 1,203 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.10.0"
- name: NPM Install
run: npm ci
env:
CI: true

- name: run pretty-php
run: |
wget -O pretty-php.phar https://github.com/lkrms/pretty-php/releases/latest/download/pretty-php.phar
chmod +x pretty-php.phar
pretty-php **/*.php --check
- name: Lint
run: npm run format:check
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": ["@prettier/plugin-php"],
"useTabs": true,
"tabWidth": 2
}
92 changes: 54 additions & 38 deletions classes/class-ledyer-om-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace LedyerOm;

\defined('ABSPATH') || die ();
\defined("ABSPATH") || die();

use LedyerOm\Requests\Order\Cancel_Order;
use LedyerOm\Requests\Order\Capture_Order;
Expand All @@ -26,48 +26,64 @@
*/
class API
{
/**
* @param $order_id
*
* @return mixed|\WP_Error
*/
public function get_payment_status($order_id)
{
return (new Payment_Status(array('orderId' => $order_id)))->request();
}
/**
* @param $order_id
*
* @return mixed|\WP_Error
*/
public function get_payment_status($order_id)
{
return (new Payment_Status(["orderId" => $order_id]))->request();
}

public function get_order($order_id)
{
return (new Get_Order(array('orderId' => $order_id)))->request();
}
public function get_order($order_id)
{
return (new Get_Order(["orderId" => $order_id]))->request();
}

public function capture_order($order_id, $data)
{
return (new Capture_Order(array('orderId' => $order_id, 'data' => $data)))->request();
}
public function capture_order($order_id, $data)
{
return (new Capture_Order([
"orderId" => $order_id,
"data" => $data,
]))->request();
}

public function refund_order($order_id, $ledger_id)
{
return (new Refund_Order(array('orderId' => $order_id, 'ledgerId' => $ledger_id)))->request();
}
public function refund_order($order_id, $ledger_id)
{
return (new Refund_Order([
"orderId" => $order_id,
"ledgerId" => $ledger_id,
]))->request();
}

public function partial_refund_order($order_id, $ledger_id, $data)
{
return (new Partial_Refund_Order(array('orderId' => $order_id, 'ledgerId' => $ledger_id, 'data' => $data)))->request();
}
public function partial_refund_order($order_id, $ledger_id, $data)
{
return (new Partial_Refund_Order([
"orderId" => $order_id,
"ledgerId" => $ledger_id,
"data" => $data,
]))->request();
}

public function cancel_order($order_id)
{
return (new Cancel_Order(array('orderId' => $order_id)))->request();
}
public function cancel_order($order_id)
{
return (new Cancel_Order(["orderId" => $order_id]))->request();
}

public function edit_order($order_id, $data)
{
return (new Edit_Order(array('orderId' => $order_id, 'data' => $data)))->request();
}
public function edit_order($order_id, $data)
{
return (new Edit_Order([
"orderId" => $order_id,
"data" => $data,
]))->request();
}

public function edit_customer($order_id, $data)
{
return (new Edit_Customer(array('orderId' => $order_id, 'data' => $data)))->request();
}
public function edit_customer($order_id, $data)
{
return (new Edit_Customer([
"orderId" => $order_id,
"data" => $data,
]))->request();
}
}
70 changes: 35 additions & 35 deletions classes/class-ledyer-om-credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace LedyerOm;

\defined('ABSPATH') || die ();
\defined("ABSPATH") || die();

/**
* Credentials class.
Expand All @@ -17,38 +17,38 @@
*/
class Credentials
{
use Singleton;

/**
* Credentials constructor.
*/
public function set_settings()
{
// First try and get credentials from Ledyer checkout
self::$settings = get_option('woocommerce_lco_settings');
// If that is not found, try and get from Ledyer Payments (to be developed)
}

/**
* Gets Ledyer API credentials
*
* @return bool|array $credentials
*/
public function get_client_credentials()
{
$test_string = 'yes' === self::$settings['testmode'] ? 'test_' : '';
$client_id = self::$settings[$test_string . 'merchant_id'];
$client_secret = self::$settings[$test_string . 'shared_secret'];

if ('' === $client_id || '' === $client_secret) {
return false;
}

$credentials = array(
'client_id' => $client_id,
'client_secret' => htmlspecialchars_decode($client_secret),
);

return $credentials;
}
use Singleton;

/**
* Credentials constructor.
*/
public function set_settings()
{
// First try and get credentials from Ledyer checkout
self::$settings = get_option("woocommerce_lco_settings");
// If that is not found, try and get from Ledyer Payments (to be developed)
}

/**
* Gets Ledyer API credentials
*
* @return bool|array $credentials
*/
public function get_client_credentials()
{
$test_string = "yes" === self::$settings["testmode"] ? "test_" : "";
$client_id = self::$settings[$test_string . "merchant_id"];
$client_secret = self::$settings[$test_string . "shared_secret"];

if ("" === $client_id || "" === $client_secret) {
return false;
}

$credentials = [
"client_id" => $client_id,
"client_secret" => htmlspecialchars_decode($client_secret),
];

return $credentials;
}
}
128 changes: 64 additions & 64 deletions classes/class-ledyer-om-customer-mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,77 @@

namespace LedyerOm;

defined('ABSPATH') || exit ();
defined("ABSPATH") || exit();

class CustomerMapper
{
/**
* WooCommerce order.
*
* @var bool|WC_Order|WC_Order_Refund
*/
public $order;
/**
* WooCommerce order.
*
* @var bool|WC_Order|WC_Order_Refund
*/
public $order;

/**
* Customer mapper constructor.
*
* @param int $order WooCommerce order
*/
public function __construct($order)
{
$this->order = $order;
}
/**
* Customer mapper constructor.
*
* @param int $order WooCommerce order
*/
public function __construct($order)
{
$this->order = $order;
}

public function woo_to_ledyer_customer()
{
return array(
'billingAddress' => $this->process_billing(),
'shippingAddress' => $this->process_shipping(),
'email' => $this->order->get_billing_email(),
'phone' => $this->order->get_billing_phone(),
);
}
public function woo_to_ledyer_customer()
{
return [
"billingAddress" => $this->process_billing(),
"shippingAddress" => $this->process_shipping(),
"email" => $this->order->get_billing_email(),
"phone" => $this->order->get_billing_phone(),
];
}

private function process_billing()
{
$attentionName = $_REQUEST['_billing_attention_name'];
$careOf = $_REQUEST['_billing_care_of'];
return array(
'companyName' => $this->order->get_billing_company(),
'streetAddress' => $this->order->get_billing_address_1(),
'postalCode' => $this->order->get_billing_postcode(),
'city' => $this->order->get_billing_city(),
'country' => $this->order->get_billing_country(),
'attentionName' => !empty($attentionName) ? $attentionName : '',
'careOf' => !empty($careOf) ? $careOf : '',
);
}
private function process_billing()
{
$attentionName = $_REQUEST["_billing_attention_name"];
$careOf = $_REQUEST["_billing_care_of"];
return [
"companyName" => $this->order->get_billing_company(),
"streetAddress" => $this->order->get_billing_address_1(),
"postalCode" => $this->order->get_billing_postcode(),
"city" => $this->order->get_billing_city(),
"country" => $this->order->get_billing_country(),
"attentionName" => !empty($attentionName) ? $attentionName : "",
"careOf" => !empty($careOf) ? $careOf : "",
];
}

private function process_shipping()
{
$attentionName = $_REQUEST['_shipping_attention_name'];
$careOf = $_REQUEST['_shipping_care_of'];
private function process_shipping()
{
$attentionName = $_REQUEST["_shipping_attention_name"];
$careOf = $_REQUEST["_shipping_care_of"];

return array(
'companyName' => $this->order->get_shipping_company(),
'streetAddress' => $this->order->get_shipping_address_1(),
'postalCode' => $this->order->get_shipping_postcode(),
'city' => $this->order->get_shipping_city(),
'country' => $this->order->get_shipping_country(),
'attentionName' => !empty($attentionName) ? $attentionName : '',
'careOf' => !empty($careOf) ? $careOf : '',
'contact' => $this->process_shipping_contact(),
);
}
return [
"companyName" => $this->order->get_shipping_company(),
"streetAddress" => $this->order->get_shipping_address_1(),
"postalCode" => $this->order->get_shipping_postcode(),
"city" => $this->order->get_shipping_city(),
"country" => $this->order->get_shipping_country(),
"attentionName" => !empty($attentionName) ? $attentionName : "",
"careOf" => !empty($careOf) ? $careOf : "",
"contact" => $this->process_shipping_contact(),
];
}

private function process_shipping_contact()
{
$shipping_email = $_REQUEST['_shipping_email'];
return array(
'firstName' => $this->order->get_shipping_first_name(),
'lastName' => $this->order->get_shipping_last_name(),
'email' => !empty($shipping_email) ? $shipping_email : '',
'phone' => $this->order->get_shipping_phone(),
);
}
private function process_shipping_contact()
{
$shipping_email = $_REQUEST["_shipping_email"];
return [
"firstName" => $this->order->get_shipping_first_name(),
"lastName" => $this->order->get_shipping_last_name(),
"email" => !empty($shipping_email) ? $shipping_email : "",
"phone" => $this->order->get_shipping_phone(),
];
}
}
Loading

0 comments on commit 00440ad

Please sign in to comment.