Skip to content

Commit

Permalink
refactor/webhook api + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0zd0 committed Jun 20, 2024
1 parent 9fadd09 commit 56d02f6
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 171 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@ jobs:
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
path: node_modules
key: "${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}"
restore-keys: |
${{ runner.os }}-node-
- name: Cache vite dependencies
uses: actions/cache@v4
with:
path: |
~/.npm
vite/node_modules
path: vite/node_modules
key: "${{ runner.os }}-vite-${{ hashFiles('vite/bun.lockb') }}"
restore-keys: |
${{ runner.os }}-vite-
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?

.cache
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "reepay/checkout",
"description": "Get a plug-n-play payment solution for WooCommerce, that is easy to use, highly secure and is built to maximize the potential of your e-commerce.",
"version": "1.0.0",
"type": "wordpress-plugin",
"license": "GPL",
"autoload": {
Expand All @@ -25,6 +26,7 @@
"wp-coding-standards/wpcs": "^3.0"
},
"config": {
"cache-dir": ".cache/composer",
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
Expand Down
29 changes: 15 additions & 14 deletions composer.lock

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

142 changes: 80 additions & 62 deletions includes/Gateways/ReepayCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,25 +520,29 @@ public function generate_account_info_html( string $key, array $data ): string {
$account_info = null;
}

ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label><?php echo wp_kses_post( $data['title'] ); ?></label>
</th>
<td class="forminp">
<fieldset>
<?php if ( ! is_null( $account_info ) && ! is_null( $data['getter'] ) && ! empty( call_user_func( array( $account_info, $data['getter'] ) ) ) ) : ?>
<span>
<?php echo call_user_func( array( $account_info, $data['getter'] ) ); ?>
</span>
<?php endif; ?>
</fieldset>
</td>
</tr>
<?php

return ob_get_clean();
$html = <<<HTML
<tr valign="top">
<th scope="row" class="titledesc">
<label>%s</label>
</th>
<td class="forminp">
<fieldset>
%s
</fieldset>
</td>
</tr>
HTML;

$label = wp_kses_post( $data['title'] );
$span = <<<HTML
<span>%s</span>
HTML;

if ( ! is_null( $account_info ) && ! is_null( $data['getter'] ) && ! empty( call_user_func( array( $account_info, $data['getter'] ) ) ) ) {
$span = sprintf( $span, call_user_func( array( $account_info, $data['getter'] ) ) );
}

return sprintf( $html, $label, $span );
}

/**
Expand All @@ -564,20 +568,20 @@ public function generate_verify_key_html( string $key, array $data ): string {
return '';
}

ob_start();
?>
<tr valign="top">
<th></th>
<td class="forminp">
<fieldset>
<button name="save" class="button-primary woocommerce-save-button" type="submit" value="Save changes">
<?php _e( 'Save and verify', 'reepay-checkout-gateway' ); ?>
</button>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
$html = <<<HTML
<tr valign="top">
<th></th>
<td class="forminp">
<fieldset>
<button name="save" class="button-primary woocommerce-save-button" type="submit" value="Save changes">
%s
</button>
</fieldset>
</td>
</tr>
HTML;

return sprintf( $html, __( 'Save and verify', 'reepay-checkout-gateway' ) );
}

/**
Expand All @@ -587,6 +591,7 @@ public function generate_verify_key_html( string $key, array $data ): string {
* @param array $data Field data.
*
* @return string
* @throws Exception Exception.
* @see WC_Settings_API::generate_settings_html
*/
public function generate_webhook_status_html( string $key, array $data ): string {
Expand All @@ -609,35 +614,48 @@ public function generate_webhook_status_html( string $key, array $data ): string
$is_webhook_configured = $this->is_webhook_configured();
$this->test_mode = $default_test_mode;

ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label><?php _e( 'Webhook', 'reepay-checkout-gateway' ); ?></label>
</th>
<td class="forminp">
<fieldset>
<?php
if ( $is_webhook_configured ) :
?>
<span style="color: green;">
<?php esc_html_e( 'Active', 'reepay-checkout-gateway' ); ?>
</span>
<?php else : ?>
<span style="color: red;">
<?php esc_html_e( 'Configuration is required.', 'reepay-checkout-gateway' ); ?>
</span> <p>
<?php esc_html_e( 'Please check api credentials and save the settings. Webhook will be installed automatically.', 'reepay-checkout-gateway' ); ?>
</p>
<?php endif; ?>

<input type="hidden" name="<?php echo esc_attr( $this->get_field_key( $key ) ); ?>" value="<?php echo esc_attr( $is_webhook_configured ); ?>"/>
</fieldset>
</td>
</tr>
<?php

return ob_get_clean();
$html = <<<HTML
<tr valign="top">
<th scope="row" class="titledesc">
<label>%s</label>
</th>
<td class="forminp">
<fieldset>
%s
<input type="hidden" name="%s" value="%s"/>
</fieldset>
</td>
</tr>
HTML;

$label = __( 'Webhook', 'reepay-checkout-gateway' );
$input_name = esc_attr( $this->get_field_key( $key ) );
$input_value = esc_attr( $is_webhook_configured );

if ( $is_webhook_configured ) {
$span = <<<HTML
<span style="color: green;">
%s
</span>
HTML;
$span = sprintf( $span, esc_html__( 'Active', 'reepay-checkout-gateway' ) );
} else {
$span = <<<HTML
<span style="color: red;">
%s
</span>
<p>
%s
</p>
HTML;
$span = sprintf(
$span,
esc_html__( 'Configuration is required.', 'reepay-checkout-gateway' ),
esc_html__( 'Please check api credentials and save the settings. Webhook will be installed automatically.', 'reepay-checkout-gateway' )
);
}

return sprintf( $html, $label, $span, $input_name, $input_value );
}

/**
Expand Down
Loading

0 comments on commit 56d02f6

Please sign in to comment.