Skip to content

Commit

Permalink
bill payment integration
Browse files Browse the repository at this point in the history
  • Loading branch information
netzkollektiv committed Oct 11, 2024
1 parent 3370706 commit 6bc9b62
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 145 deletions.
3 changes: 2 additions & 1 deletion src/wc-easycredit/includes/Admin/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Netzkollektiv\EasyCredit\Admin;

use Netzkollektiv\EasyCredit\Plugin;
use Netzkollektiv\EasyCredit\Pages\ReviewPage;

class RequirementsChecker
{
Expand Down Expand Up @@ -57,7 +58,7 @@ public function check_review_page_exists()
return;
}

$page_path = current($this->plugin->get_review_page_data())['name'];
$page_path = ReviewPage::PAGE_SLUG;
if (get_page_by_path($page_path, OBJECT)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wc-easycredit/includes/Api/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __call(string $name, array $arguments)
return;
}
\wc_get_logger()->{$name}($arguments[0], [
'source' => WC_EASYCREDIT_ID,
'source' => $this->plugin->id,
]);
}
}
12 changes: 1 addition & 11 deletions src/wc-easycredit/includes/Api/Quote/CustomerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@

namespace Netzkollektiv\EasyCredit\Api\Quote;

use Teambank\EasyCreditApiV3\Integration\Util\PrefixConverter;

class CustomerBuilder
{
protected $quote;
protected $customer;
protected $prefixConverter;

public function __construct(PrefixConverter $prefixConverter)
{
$this->prefixConverter = $prefixConverter;
}

public function getPrefix(): ?string
{
return $this->prefixConverter->convert(
$this->quote->get_meta('easycredit-prefix')
);
return null;
}

public function getFirstname()
Expand Down
3 changes: 2 additions & 1 deletion src/wc-easycredit/includes/Api/Quote/ItemBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Netzkollektiv\EasyCredit\Api\Quote;

use Teambank\EasyCreditApiV3\Model\ShoppingCartInformationItem;
use Teambank\EasyCreditApiV3\Model\ArticleNumberItem;

class ItemBuilder
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public function build(\WC_Order_Item_Product $item)
'price' => $item->get_subtotal(),
'manufacturer' => '',
'productCategory' => $this->getCategory(),
'articleNumber' => [new \Teambank\EasyCreditApiV3\Model\ArticleNumberItem([
'articleNumber' => [new ArticleNumberItem([
'numberType' => 'sku',
'number' => $item->get_product_id(),
])],
Expand Down
5 changes: 2 additions & 3 deletions src/wc-easycredit/includes/Api/QuoteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Netzkollektiv\EasyCredit\Api;

use Teambank\EasyCreditApiV3\Integration\Util\PrefixConverter;
use Teambank\EasyCreditApiV3\Model\InvoiceAddress;
use Teambank\EasyCreditApiV3\Model\ShippingAddress;
use Teambank\EasyCreditApiV3\Model\Transaction;
Expand Down Expand Up @@ -36,7 +35,7 @@ public function __construct(

$this->systemBuilder = new SystemBuilder();
$this->addressBuilder = new Quote\AddressBuilder();
$this->customerBuilder = new Quote\CustomerBuilder(new PrefixConverter());
$this->customerBuilder = new Quote\CustomerBuilder();
$this->itemBuilder = new Quote\ItemBuilder();
}

Expand Down Expand Up @@ -72,7 +71,7 @@ public function getIsClickAndCollect()

public function getFinancingTerm(): ?string
{
return $this->storage->get('financingTerm');
return (string) intval($this->storage->get('numberOfInstallments'));
}

public function getGrandTotal()
Expand Down
19 changes: 15 additions & 4 deletions src/wc-easycredit/includes/Helper/TemporaryOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ class TemporaryOrder

private $plugin;

public function __construct($plugin)
{
private $integration;

public function __construct(
$plugin,
$integration
) {
$this->plugin = $plugin;
$this->integration = $integration;
}

public function get_order($paymentType = null)
Expand All @@ -30,10 +35,16 @@ public function get_order($paymentType = null)
$postData = $_POST;
}

if (isset($_REQUEST['easycredit']['paymentType'])) {
$paymentType = $_REQUEST['easycredit']['paymentType'];
$params = isset($_REQUEST['easycredit']) ? $_REQUEST['easycredit'] : [];
if (isset($params['paymentType'])) {
$paymentType = $params['paymentType'];
$postData['payment_method'] = $this->plugin->get_method_by_payment_type($paymentType)->id;
}
if (isset($params['numberOfInstallments'])) {
$this->integration
->storage()
->set('numberOfInstallments', intval($params['numberOfInstallments']));
}

$wc_checkout = \WC_Checkout::instance();
$wc_checkout->create_order($postData);
Expand Down
8 changes: 5 additions & 3 deletions src/wc-easycredit/includes/Pages/ReviewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ReviewPage

const PAGE_ID = 'woocommerce_easycredit_checkout_review_page_id';

const PAGE_SLUG = 'easycredit-checkout-review';

private $plugin;

private $integration;
Expand Down Expand Up @@ -42,8 +44,8 @@ public static function get_page_data()
{
return [
self::PAGE_ID => [
'name' => _x('easycredit-checkout-review', 'Page slug', 'woocommerce'),
'title' => _x('Review Order', 'Page title', 'woocommerce'),
'name' => self::PAGE_SLUG,
'title' => _x('Review Order', 'Page title', 'wc-easycredit'),
'content' => '[' . self::SHORT_CODE . ']',
],
];
Expand Down Expand Up @@ -102,7 +104,7 @@ private function get_page_uri()
private function get_confirm_url()
{
$query_args = [
'woo-' . WC_EASYCREDIT_ID . '-return' => true,
'woo-' . $this->plugin->id . '-return' => true,
];
return add_query_arg($query_args, $this->get_page_uri());
}
Expand Down
10 changes: 3 additions & 7 deletions src/wc-easycredit/includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,24 +383,20 @@ public function load_template($tpl, $data = [])
load_template($template, false);
}

public function add_module_nomodule_attribute($tag, $handle, $src)
public function add_module_module_attribute($tag, $handle, $src)
{
if ($handle === 'easycredit-components-module') {
$src = remove_query_arg('ver', $src);
return '<script type="module" src="' . esc_url($src) . '"></script>';
}
if ($handle === 'easycredit-components-nomodule') {
$src = remove_query_arg('ver', $src);
return '<script nomodule src="' . esc_url($src) . '"></script>';
}
return $tag;
}

public function enqueue_easycredit_components()
{
wp_register_script('easycredit-components-module', 'https://invoice.easycredit-ratenkauf-webcomponents.pages.dev/easycredit-components/easycredit-components.esm.js', [], '1.0');
wp_register_script('easycredit-components-module', 'https://ratenkauf.easycredit.de/api/resource/webcomponents/v3/easycredit-components/easycredit-components.esm.js', [], '1.0');
wp_enqueue_script('easycredit-components-module');
add_filter('script_loader_tag', [$this, 'add_module_nomodule_attribute'], 10, 3);
add_filter('script_loader_tag', [$this, 'add_module_module_attribute'], 10, 3);
}

public function enqueue_frontend_resources($hook)
Expand Down
2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/checkout/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '047e5523676c6adb3e80');
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '9257f97b799330b978c0');
2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/checkout/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const buildAdditionalParams = (detail) => {
};

const methods = getMethods();
const config = methods.easycredit_ratenkauf;
const [methodName, config] = Object.entries(methods)[0];

const ExpressButton = (props) => {
const ecCheckoutButton = useRef(null);
Expand Down
2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/frontend/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '706b8bf9e085474da379');
<?php return array('dependencies' => array(), 'version' => 'd2b78e60efe3a12c32a9');
2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/frontend/build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/frontend/build/styles.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '01cfee070c47109dc49b');
<?php return array('dependencies' => array(), 'version' => '61529801200e8ec59441');
2 changes: 1 addition & 1 deletion src/wc-easycredit/modules/frontend/build/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6bc9b62

Please sign in to comment.