Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Google fonts other than Poppins #416

Merged
merged 20 commits into from Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions assets/javascripts/card-form-customization.js
Expand Up @@ -58,6 +58,28 @@ function getDesignFormValues() {
return formValues;
}

function handleFontChange() {
const fontName = document.getElementById('custom_sf_font_name');

if (fontName.value === OMISE_CUSTOM_FONT_OTHER) {
document.getElementById('custom_sf_custom_font_name').style.display = null
danfowler marked this conversation as resolved.
Show resolved Hide resolved
}

fontName.addEventListener('change', (event) => {
const customFontName = document.getElementById('custom_sf_custom_font_name');
const inputCustomFont = customFontName.querySelector('input')

if (event.target.value === OMISE_CUSTOM_FONT_OTHER) {
customFontName.style.display = null;
inputCustomFont.required = true;
} else {
customFontName.style.display = 'none';
inputCustomFont.value = '';
inputCustomFont.required = false;
}
});
}

function initOmiseCardForm() {
const customCardFormTheme = CARD_FORM_THEME ?? 'light';
document.querySelector('.omise-modal .content').style.background =
Expand Down Expand Up @@ -91,3 +113,4 @@ document.getElementById('omise-modal').addEventListener('click', (event) => {

setDesignFormValues();
handleColorInputChanges();
handleFontChange();
danfowler marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 9 additions & 1 deletion assets/javascripts/omise-embedded-card.js
Expand Up @@ -25,6 +25,14 @@ function showOmiseEmbeddedCardForm({
}
element.style.height = iframeElementHeight + 'px'

let fontName = font.name
const isCustomFontSet = font.name.toLowerCase().trim() === OMISE_CUSTOM_FONT_OTHER.toLowerCase()
const isCustomFontEmpty = font.custom_name.trim() === ''

if (isCustomFontSet && !isCustomFontEmpty) {
fontName = font.custom_name.trim()
}

OmiseCard.configure({
publicKey: publicKey,
element,
Expand All @@ -34,7 +42,7 @@ function showOmiseEmbeddedCardForm({
customCardFormHideRememberCard: hideRememberCard ?? false,
customCardFormBrandIcons: brandIcons ?? null,
style: {
fontFamily: font.name,
fontFamily: fontName,
fontSize: font.size,
input: {
height: input.height,
Expand Down
3 changes: 3 additions & 0 deletions includes/admin/class-omise-page-card-form-customization.php
Expand Up @@ -27,6 +27,7 @@ private function get_light_theme()
'font' => [
'name' => 'Poppins',
'size' => 16,
'custom_name' => ''
],
'input' => [
'height' => '44px',
Expand All @@ -51,6 +52,7 @@ private function get_dark_theme()
'font' => [
'name' => 'Poppins',
'size' => 16,
'custom_name' => ''
],
'input' => [
'height' => '44px',
Expand Down Expand Up @@ -110,6 +112,7 @@ protected function save($data)
$options[$componentKey][$key] = sanitize_text_field($data[$componentKey][$key]);
}
}

update_option(self::PAGE_NAME, $options);
$this->add_message('message', "Update has been saved!");
}
Expand Down
15 changes: 12 additions & 3 deletions includes/admin/views/omise-page-card-form-customization.php
Expand Up @@ -4,6 +4,7 @@
$cardFormTheme = $omiseCardGateway->get_option('card_form_theme');
$cardIcons = $omiseCardGateway->get_card_icons();
$publicKey = Omise()->settings()->public_key();
$customFontOther = 'Other';
?>

<link rel="stylesheet" href="<?php echo $assetUrl . '/css/card-form-customization.css'; ?>">
Expand All @@ -24,11 +25,18 @@
<tr>
<td class="text-bold" style="width: 250px;">Font Name</td>
<td>
<select class="select-input" name="font[name]">
<select id="custom_sf_font_name" class="select-input" name="font[name]">
<option value="Poppins">Poppins</option>
<option value="Circular" selected>Circular</option>
<option value="<?php echo $customFontOther ?>"><?php echo $customFontOther ?></option>
</select>
<div class="description">Match font used in form with your selected font</div>
</td>
</tr>

<tr id="custom_sf_custom_font_name" style="display: none;">
<td class="text-bold" style="width: 250px;"></td>
<td>
<input type="text" class="select-input" placeholder="Font Name" name="font[custom_name]" />
<div class="description">Specify other font name (note: only Google Fonts supported)</div>
</td>
</tr>

Expand Down Expand Up @@ -189,6 +197,7 @@
window.DEFAULT_FORM_DESIGN = JSON.parse(`<?php echo json_encode($formDesign) ?>`);
window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($cardIcons) ?>`);
window.LOCALE = `<?php echo get_locale(); ?>`;
window.OMISE_CUSTOM_FONT_OTHER = `<?php echo $customFontOther ?>`;
</script>
<script src="<?php echo $assetUrl . '/javascripts/omise-embedded-card.js'; ?>"></script>
<script src="<?php echo $assetUrl . '/javascripts/card-form-customization.js'; ?>"></script>
2 changes: 1 addition & 1 deletion includes/admin/views/omise-page-settings.php
Expand Up @@ -139,7 +139,7 @@
<?php
echo sprintf(
wp_kses(
__( 'Unless dynamic webhooks are enabled, you must add the URL below as a new endpoint on your <a href="%s">Opn Payments dashboard</a> (HTTPS only).', 'omise' ),
__( 'Unless dynamic webhooks are enabled, you must add the URL above as a new endpoint on your <a href="%s">Opn Payments dashboard</a> (HTTPS only).', 'omise' ),
[
'a' => ['href' => []],
],
Expand Down
2 changes: 1 addition & 1 deletion includes/gateway/class-omise-payment-creditcard.php
Expand Up @@ -148,7 +148,7 @@ function init_form_fields() {
'css' => Omise_Card_Image::get_css(),
'default' => Omise_Card_Image::get_amex_default_display(),
'description' => wp_kses(
__( 'This only controls the icons displayed on the checkout page.<br />It is not related to card processing on Omise payment gateway.', 'omise' ),
__( 'This only controls the icons displayed on the checkout page.<br />It is not related to card processing on OPN payment gateway.', 'omise' ),
danfowler marked this conversation as resolved.
Show resolved Hide resolved
array( 'br' => array() )
)
)
Expand Down
1 change: 1 addition & 0 deletions templates/myaccount/my-card.php
Expand Up @@ -56,5 +56,6 @@ class='button delete_card'
window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['formDesign']) ?>`);
window.CARD_BRAND_ICONS = JSON.parse(`<?php echo json_encode($viewData['cardIcons']) ?>`);
window.LOCALE = `<?php echo get_locale(); ?>`;
window.OMISE_CUSTOM_FONT_OTHER = 'Other';
</script>
<?php endif; ?>
1 change: 1 addition & 0 deletions templates/payment/form.php
Expand Up @@ -60,5 +60,6 @@
window.FORM_DESIGN = JSON.parse(`<?php echo json_encode($viewData['form_design']) ?>`);
window.LOCALE = `<?php echo get_locale(); ?>`;
window.HIDE_REMEMBER_CARD = `<?php echo $hideRememberCard ?>` == 'yes' ? true : false;
window.OMISE_CUSTOM_FONT_OTHER = 'Other';
</script>
<?php endif; ?>
@@ -0,0 +1,113 @@
<?php

use PHPUnit\Framework\TestCase;

/**
* @runTestsInSeparateProcesses
*/
class Omise_Page_Card_From_Customization_Test extends TestCase
{
public function setUp(): void
{
// mocking WP built-in functions
if (!function_exists('get_option')) {
function get_option() {}
}

Mockery::mock('alias:Omise_Admin_Page');
require_once __DIR__ . '/../../../../includes/admin/class-omise-page-card-form-customization.php';
}

public function tearDown(): void
{
Mockery::close();
}

/**
* @test
*/
public function testGetLightTheme()
{
$expected = [
'font' => [
'name' => 'Poppins',
'size' => 16,
'custom_name' => ''
],
'input' => [
'height' => '44px',
'border_radius' => '4px',
'border_color' => '#ced3de',
'active_border_color' => '#1451cc',
'background_color' => '#ffffff',
'label_color' => '#212121',
'text_color' => '#212121',
'placeholder_color' => '#98a1b2',
],
'checkbox' => [
'text_color' => '#1c2433',
'theme_color' => '#1451cc',
]
];

$obj = Omise_Page_Card_From_Customization::get_instance();

// calling private method
$themeValues = $this->invokeMethod($obj, 'get_light_theme', []);

$this->assertEqualsCanonicalizing($expected, $themeValues);
}

/**
* @test
*/
public function testGetDarkTheme()
{
$expected = [
'font' => [
'name' => 'Poppins',
'size' => 16,
'custom_name' => ''
],
'input' => [
'height' => '44px',
'border_radius' => '4px',
'border_color' => '#475266',
'active_border_color' => '#475266',
'background_color' => '#131926',
'label_color' => '#E6EAF2',
'text_color' => '#ffffff',
'placeholder_color' => '#DBDBDB',
],
'checkbox' => [
'text_color' => '#E6EAF2',
'theme_color' => '#1451CC',
]
];

$obj = Omise_Page_Card_From_Customization::get_instance();

// calling private method
$themeValues = $this->invokeMethod($obj, 'get_dark_theme', []);

$this->assertEqualsCanonicalizing($expected, $themeValues);
}

/**
* Call protected/private method of a class.
*
* @param object $object Instantiated object that we will run method on.
* @param string $methodName Method name to call
* @param array $parameters Array of parameters to pass into method.
*
* @return mixed Method return.
*/
public function invokeMethod($object, $methodName, array $parameters = [])
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);

return $method->invokeArgs($object, $parameters);
}
}
Expand Up @@ -42,6 +42,14 @@ public function returnThis()
};
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

public function getOrderMock($expectedAmount, $expectedCurrency)
{
// Create a mock of the $order object
Expand Down
Expand Up @@ -10,4 +10,12 @@ public function setUp(): void
Mockery::mock('alias:Omise_Payment')->makePartial();
require_once __DIR__ . '/../../../../includes/gateway/abstract-omise-payment-offline.php';
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}
}
16 changes: 8 additions & 8 deletions tests/unit/includes/gateway/bootstrap-test-setup.php
Expand Up @@ -18,6 +18,14 @@ function add_action() {}
}
}

/**
danfowler marked this conversation as resolved.
Show resolved Hide resolved
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

public function getOrderMock($expectedAmount, $expectedCurrency)
{
// Create a mock of the $order object
Expand Down Expand Up @@ -52,14 +60,6 @@ public function getOrderMock($expectedAmount, $expectedCurrency)
return $orderMock;
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

/**
* @runInSeparateProcess
*/
Expand Down
Expand Up @@ -24,6 +24,14 @@ function plugins_url() {}
}
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

public function testGetChargeRequest()
{
$expectedAmount = 999999;
Expand Down
Expand Up @@ -8,7 +8,6 @@ public function setUp(): void
{
$this->sourceType = 'fpx';
parent::setUp();
// require_once __DIR__ . '/../../../../includes/backends/class-omise-backend-fpx.php';
danfowler marked this conversation as resolved.
Show resolved Hide resolved
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-internetbanking.php';
}

Expand Down
Expand Up @@ -28,6 +28,14 @@ function sanitize_text_field() {
}
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

public function testGetChargeRequest()
{
$obj = new Omise_Payment_Konbini();
Expand Down
Expand Up @@ -29,6 +29,14 @@ function admin_url() {}
require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-promptpay.php';
}

/**
* close mockery after tests are done
*/
public function tearDown(): void
{
Mockery::close();
}

/**
* @test
*/
Expand Down