-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Checkout Block * Implements @wordpress/scripts for block building * Use asset file
- Loading branch information
1 parent
0e067ab
commit c0bf7e1
Showing
9 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/node_modules/ | ||
/svn/ | ||
/vendor/ | ||
aplazame.latest.zip | ||
composer.lock | ||
docker-compose.override.yml | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"devDependencies": { | ||
"@wordpress/scripts": "^27.9.0" | ||
}, | ||
"scripts": { | ||
"build": "wp-scripts build --webpack-src-dir=resources --output-path=plugin/resources", | ||
"start": "wp-scripts start --webpack-src-dir=resources --output-path=plugin/resources" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; | ||
|
||
final class WC_Aplazame_Gateway_Blocks_Support extends AbstractPaymentMethodType { | ||
private $gateway; | ||
protected $name = WC_Aplazame::METHOD_ID; | ||
|
||
public function initialize() { | ||
$this->settings = get_option( "woocommerce_{$this->name}_settings", [] ); | ||
$gateways = WC()->payment_gateways->payment_gateways(); | ||
$this->gateway = $gateways[ $this->name ]; | ||
} | ||
|
||
public function is_active() { | ||
return $this->gateway->is_available(); | ||
} | ||
|
||
public function get_payment_method_script_handles() { | ||
$asset_path = plugin_dir_path( __FILE__ ) . '../resources/payment-block.asset.php'; | ||
$version = null; | ||
$dependencies = array(); | ||
if( file_exists( $asset_path ) ) { | ||
$asset = require $asset_path; | ||
$version = isset( $asset[ 'version' ] ) ? $asset[ 'version' ] : $version; | ||
$dependencies = isset( $asset[ 'dependencies' ] ) ? $asset[ 'dependencies' ] : $dependencies; | ||
} | ||
wp_register_script( | ||
'wc-aplazame-blocks-integration', | ||
plugin_dir_url( __FILE__ ) . '../resources/payment-block.js', | ||
$dependencies, | ||
$version, | ||
true | ||
); | ||
return [ 'wc-aplazame-blocks-integration' ]; | ||
} | ||
|
||
public function get_payment_method_data() { | ||
return [ | ||
'title' => $this->gateway->title, | ||
'description' => $this->gateway->settings['description'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "aplazame/payment-block", | ||
"version": "1.0.0", | ||
"title": "Aplazame Payment Block", | ||
"editorScript": "file:payment-block.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-element', 'wp-html-entities'), 'version' => 'cd602efc1a4a409b88bc'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"name": "aplazame/payment-block", | ||
"version": "1.0.0", | ||
"title": "Aplazame Payment Block", | ||
"editorScript": "file:payment-block.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { RawHTML } from '@wordpress/element'; | ||
|
||
const { registerPaymentMethod } = window.wc.wcBlocksRegistry | ||
const { getSetting } = window.wc.wcSettings | ||
const settings = getSetting( 'aplazame_data', {} ) | ||
const label = decodeEntities( settings.title ) | ||
|
||
const Content = () => { | ||
return <RawHTML>{ settings.description || '' }</RawHTML>; | ||
} | ||
|
||
const Label = ( props ) => { | ||
const { PaymentMethodLabel } = props.components | ||
return <PaymentMethodLabel text={ label } /> | ||
} | ||
|
||
registerPaymentMethod( | ||
{ | ||
name: "aplazame", | ||
label: <Label />, | ||
content: <Content />, | ||
edit: <Content />, | ||
canMakePayment: () => true, | ||
ariaLabel: label, | ||
supports: { | ||
features: settings.supports, | ||
} | ||
} | ||
) |