Skip to content

Commit

Permalink
refactor(Gateway): Refactored Payment Slip
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Sep 27, 2024
1 parent 6b02eda commit f6b5ee2
Show file tree
Hide file tree
Showing 23 changed files with 1,180 additions and 1,043 deletions.
2 changes: 2 additions & 0 deletions assets/scripts/admin/admin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { WpRouter } from '@wptoolset/router';
import { CompanySettingsController } from './controllers/company-settings.controller';
import { SlipSettingsController } from './controllers/slip-settings.controller';
import { OrderEditController } from './controllers/order-edit.controller';

document.addEventListener('DOMContentLoaded', () =>
new WpRouter({
wcsrbOrderEdit: () => new OrderEditController(),
wcsrbCompanySettings: () => new CompanySettingsController(),
wcsrbSlipSettings: () => new SlipSettingsController(),
}).loadEvents(),
Expand Down
16 changes: 16 additions & 0 deletions assets/scripts/admin/controllers/order-edit.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const $ = jQuery;

export class OrderEditController {
init(): void {}

finalize(): void {
$(document.body).on('click', 'button.wcsrb-copy-ips-qr', (e) => this.copyIpsQrCode(e));
}

private copyIpsQrCode(e: JQuery.ClickEvent): void {
e.preventDefault();
navigator.clipboard.writeText($(e.target).data('ips').s).then(() => {
$(e.target).parent().find('.ips-qr-copy-success').fadeIn('fast').delay(800).fadeOut('fast');
});
}
}
10 changes: 10 additions & 0 deletions assets/styles/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
user-select: none;
}
}

#wcsrb-ips-qr-code {
.ips-qr-copy-success {
display: inline-block;
line-height: 30px;
min-height: 30px;
margin-left: 10px;
color: rgb(134, 212, 76);
}
}
11 changes: 11 additions & 0 deletions assets/styles/email/template.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#outer_wrapper > tr:first-child > td:nth-child(2) {
width: 800px !important;
}

#template_body,
#template_container,
#template_footer,
#wrapper {
width: 100% !important;
max-width: 800px !important;
}
4 changes: 4 additions & 0 deletions assets/webpack/wpwp.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const config: Partial<WordPackConfig> = {
name: 'front',
files: ['./scripts/frontend/main.ts', './styles/main.scss'],
},
{
name: 'email',
files: ['./styles/email/template.scss'],
},
],
paths: {
scripts: { src: 'scripts', dist: 'js' },
Expand Down
45 changes: 23 additions & 22 deletions composer.lock

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

113 changes: 74 additions & 39 deletions config/pg-slip-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,75 @@
* @see Payment_Slip_Gateway
*/

use Automattic\WooCommerce\Utilities\LoggingUtil;

defined( 'ABSPATH' ) || exit;

$display_opts = static fn( $desc ) => array(
'title' => __( 'Visibility', 'serbian-addons-for-woocommerce' ),
'type' => 'multiselect',
'options' => array(
'order' => __( 'Store pages', 'serbian-addons-for-woocommerce' ),
'email' => __( 'Customer e-mails', 'serbian-addons-for-woocommerce' ),
),
'default' => array(),
'description' => $desc,
'desc_tip' => true,
'custom_attributes' => array(
'data-placeholder' => __( 'Select locations for display', 'serbian-addons-for-woocommerce' ),
'data-allow_clear' => 'true',
),
'class' => 'wc-enhanced-select',
);

$qr_img_desc = static function ( int $icon ) {
$desc = array();

$desc[] = sprintf(
// translators: %1$s customizer link html.
__( 'You can set the image via %1$s', 'serbian-addons-for-woocommerce' ),
sprintf(
'<a target="_blank" href="%1$s">%2$s</a> (%3$s)',
esc_url( admin_url( 'customize.php' ) ),
esc_html__( 'Customizer', 'default' ),
esc_html__( 'Site Identity', 'default' ),
),
);

if ( 0 < $icon ) {
$desc[] = sprintf(
// translators: %s current image HTML.
__( 'Current image: %s', 'serbian-addons-for-woocommerce' ),
wp_get_attachment_image(
get_option( 'site_icon' ),
array( 16, 16 ),
false,
),
);
}

return implode( '<br>', $desc );
};


return array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'serbian-addons-for-woocommerce' ),
'title' => __( 'Enabled', 'woocommerce' ),
'label' => __( 'Enable Payment Slip', 'serbian-addons-for-woocommerce' ),
'type' => 'checkbox',
'default' => 'no',
),
'title' => array(
'title' => __( 'Title', 'serbian-addons-for-woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the title which the user sees during checkout.', 'serbian-addons-for-woocommerce' ),
'default' => 'Payment Slip',
'title' => __( 'Title', 'woocommerce' ),
'type' => 'safe_text',
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
'default' => __( 'Payment Slip', 'serbian-addons-for-woocommerce' ),
'desc_tip' => true,
),
'description' => array(
'title' => __( 'Description', 'serbian-addons-for-woocommerce' ),
'title' => __( 'Description', 'woocommerce' ),
'type' => 'text',
'description' => __( 'This controls the description which the user sees during checkout.', 'serbian-addons-for-woocommerce' ),
'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ),
'default' => __( 'Pay by sending us money via wire transfer', 'serbian-addons-for-woocommerce' ),
'desc_tip' => true,
),
Expand All @@ -36,6 +85,8 @@
'type' => 'title',
'description' => '',
),
'display' => $display_opts( __( 'Where to display the QR Code', 'serbian-addons-for-woocommerce' ) ),

'style' => array(
'title' => __( 'Style', 'serbian-addons-for-woocommerce' ),
'type' => 'select',
Expand All @@ -58,6 +109,7 @@
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=wcsrb&section=company' ) . '">',
'</a>',
),
'default' => '',
),
'payment_code' => array(
'title' => __( 'Payment code', 'serbian-addons-for-woocommerce' ),
Expand Down Expand Up @@ -108,12 +160,7 @@
'description' => __( 'Settings for NBS IPS QR Code', 'serbian-addons-for-woocommerce' ),
),

'qrcode_shown' => array(
'title' => __( 'Show QR code', 'serbian-addons-for-woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Show QR code on the payment slip', 'serbian-addons-for-woocommerce' ),
'default' => 'yes',
),
'qrcode_shown' => $display_opts( __( 'Where to display the payment slip', 'serbian-addons-for-woocommerce' ) ),

'qrcode_color' => array(
'title' => __( 'Dot color', 'serbian-addons-for-woocommerce' ),
Expand All @@ -132,23 +179,15 @@
),

'qrcode_image' => array(
'title' => __( 'Show image', 'serbian-addons-for-woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Show image on QR code', 'serbian-addons-for-woocommerce' ),
'default' => 'yes',
'desc_tip' => __( 'Image that will be shown on the QR code. ', 'serbian-addons-for-woocommerce' ),
'description' => static fn() => sprintf(
// translators: %1$s opening link tag, %2$s Customizer title, %3$s closing link tag, %3$s current image HTML.
__( 'You can set it in %1$s%2$s%3$s. Current image is: %4$s', 'serbian-addons-for-woocommerce' ),
'<a target="_blank" href="' . admin_url( 'customize.php' ) . '">',
__( 'Customizer', 'default' ),
'</a>',
wp_get_attachment_image(
get_option( 'site_icon' ),
array( 16, 16 ),
false,
),
),
'title' => __( 'Show image', 'serbian-addons-for-woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Show image on QR code', 'serbian-addons-for-woocommerce' ),
'default' => 'yes',
'desc_tip' => __( 'Image that will be shown on the QR code. ', 'serbian-addons-for-woocommerce' ),
'description' => static fn() => $qr_img_desc( intval( get_option( 'site_icon', 0 ) ) ),
'custom_attributes' => static fn() => 0 === intval( get_option( 'site_icon', 0 ) )
? array( 'disabled' => 'disabled' )
: array(),
),

// Advanced Settings.
Expand All @@ -158,18 +197,14 @@
'description' => '',
),
'debug' => array(
'title' => __( 'Debug log', 'serbian-addons-for-woocommerce' ),
'title' => __( 'Debug log', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable logging', 'serbian-addons-for-woocommerce' ),
'label' => __( 'Enable logging', 'woocommerce' ),
'default' => 'no',
'description' => static fn() => sprintf(
// translators: %1$s log file path, %2$s line break.
__(
'Log Payment Slip events, inside %1$s %2$sNote: this may log personal information. We recommend using this for debugging purposes only and deleting the logs when finished.',
'serbian-addons-for-woocommerce',
),
'<code>' . WC_Log_Handler_File::get_log_file_path( 'payment-slip' ) . '</code>',
'<br>',
// translators: %s is a placeholder for a URL.
__( 'Log Payment Slip events and review them on the <a href="%s">Logs screen</a>.<br>Note: this may log personal information. We recommend using this for debugging purposes only and deleting the logs when finished.', 'serbian-addons-for-woocommerce' ),
esc_url( LoggingUtil::get_logs_tab_url() ),
),
),

Expand Down
17 changes: 17 additions & 0 deletions gen.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
POST https://www.nbs.rs/QRcode/api/qr/v1/generate?lang=en_US
Accept: application/json
Content-Type: text/plain
Host: www.nbs.rs
Origin: https://ips.nbs.rs

K:PR|V:01|C:1|R:160000000042863406|N:SGI
Pozeska
11000 Beograd, Srbija|I:RSD45,00|P:Miroslavski Astalovski Šćekić|SF:289|S:Plaćanje narudžbine|RO:97481472024

###

POST https://www.nbs.rs/QRcode/api/qr/v1/generate?lang=sr_RS_latn

K:PR|V:01|C:1|R:160000000042863406|N:SGI
Pozeska
11000 Beograd, Srbija|I:RSD45,01|P:Miroslavski Astalovski Šćekić|SF:289|S:Plaćanje narudžbine|RO:974814720241
Binary file modified languages/serbian-addons-for-woocommerce-sr_RS.mo
Binary file not shown.
Loading

0 comments on commit f6b5ee2

Please sign in to comment.