-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aashish
committed
May 24, 2024
1 parent
6d76284
commit 6e3fac5
Showing
10 changed files
with
190 additions
and
11 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'ad14494b770706f08d98935ee6998d63'); |
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,98 @@ | ||
import {useEffect, useState, useRef} from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { registerPaymentMethod } from '@woocommerce/blocks-registry'; | ||
import { getSetting } from '@woocommerce/settings'; | ||
|
||
const settings = getSetting( 'omise_fpx_data', {} ) | ||
const label = decodeEntities( settings.title ) || 'No title set' | ||
const Label = ( props ) => { | ||
const { PaymentMethodLabel } = props.components | ||
return <PaymentMethodLabel text={ label } /> | ||
} | ||
|
||
const FpxPaymentMethod = (props) => { | ||
const {eventRegistration, emitResponse} = props; | ||
const {onPaymentSetup} = eventRegistration; | ||
const description = decodeEntities( settings.description || '' ) | ||
const { bank_list } = settings.data; | ||
const noPaymentMethods = __( 'FPX is currently not available.', 'omise' ); | ||
const bankRef = useRef(null); | ||
|
||
const onChange = (e) => { | ||
bankRef.current = e.target.value | ||
} | ||
|
||
useEffect(() => { | ||
const unsubscribe = onPaymentSetup(async () => { | ||
if (!bankRef.current) { | ||
return {type: emitResponse.responseTypes.ERROR, message: 'Select a bank'} | ||
} | ||
try { | ||
return { | ||
type: emitResponse.responseTypes.SUCCESS, | ||
meta: { | ||
paymentMethodData: { "bank": bankRef.current } | ||
} | ||
}; | ||
} catch (error) { | ||
return {type: emitResponse.responseTypes.ERROR, message: error.message} | ||
} | ||
}); | ||
return () => unsubscribe(); | ||
}, [ onPaymentSetup ]); | ||
|
||
return (<> | ||
{description && <p>{description}</p>} | ||
{ | ||
bank_list.length == 0 | ||
? <p>{noPaymentMethods}</p> | ||
: ( | ||
<fieldset id="omise-form-installment"> | ||
<div className="fpx-select-bank"> | ||
<label htmlFor="fpx-select-bank">Select Bank</label> | ||
<select | ||
className="fpx-bank-logo default" | ||
id="fpx-select-bank" | ||
name="source[bank]" | ||
defaultValue="" | ||
onChange={onChange} | ||
> | ||
<option value="" disabled={true}>-- Select your option --</option> | ||
{bank_list.map(bank => ( | ||
<option | ||
key={bank['code']} | ||
className={bank["code"]} | ||
value={bank["code"]} | ||
disabled={bank['active'] === "1" ? true : false} | ||
> | ||
{bank["name"]} | ||
{(!bank['active']) && " (offline)" } | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
<div className="fpx-terms-and-conditions-block"> | ||
<span>By clicking on the <b>"Place Order"</b> button, you agree to FPX's | ||
<a href="https://www.mepsfpx.com.my/FPXMain/termsAndConditions.jsp" target="_blank"> | ||
Terms and Conditions | ||
</a> | ||
</span> | ||
</div> | ||
</fieldset> | ||
) | ||
} | ||
</>) | ||
} | ||
|
||
registerPaymentMethod( { | ||
name: settings.name, | ||
label: <Label />, | ||
content: <FpxPaymentMethod />, | ||
edit: <FpxPaymentMethod />, | ||
canMakePayment: () => true, | ||
ariaLabel: label, | ||
supports: { | ||
features: settings.supports, | ||
} | ||
} ) |
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,10 +1,78 @@ | ||
<?php | ||
|
||
class Omise_Block_Fpx extends Omise_Block_Apm { | ||
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType; | ||
|
||
class Omise_Block_Fpx extends AbstractPaymentMethodType { | ||
/** | ||
* The gateway instance. | ||
*/ | ||
protected $gateway; | ||
|
||
/** | ||
* Payment method name/id/slug. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'omise_fpx'; | ||
|
||
/** | ||
* Initializes the payment method type. | ||
*/ | ||
public function initialize() { | ||
$this->settings = get_option("woocommerce_{$this->name}_settings", []); | ||
$gateways = WC()->payment_gateways->payment_gateways(); | ||
$this->gateway = $gateways[$this->name]; | ||
} | ||
|
||
/** | ||
* Returns if this payment method should be active. If false, the scripts will not be enqueued. | ||
* | ||
* @return boolean | ||
*/ | ||
public function is_active() { | ||
return $this->gateway->is_available(); | ||
} | ||
|
||
/** | ||
* Returns an array of scripts/handles to be registered for this payment method. | ||
* | ||
* @return array | ||
*/ | ||
public function get_payment_method_script_handles() { | ||
if (!wp_script_is("wc-{$this->name}-payments-blocks", 'enqueued')) { | ||
$script_asset = require __DIR__ . "/../assets/js/build/{$this->name}.asset.php"; | ||
wp_register_script( | ||
"wc-{$this->name}-payments-blocks", | ||
plugin_dir_url(__DIR__) . "assets/js/build/{$this->name}.js", | ||
$script_asset['dependencies'], | ||
$script_asset['version'], | ||
true | ||
); | ||
|
||
wp_enqueue_script("wc-{$this->name}-payments-blocks"); | ||
} | ||
|
||
return ["wc-{$this->name}-payments-blocks"]; | ||
} | ||
|
||
/** | ||
* Returns an array of key=>value pairs of data made available to the payment methods script. | ||
* | ||
* @return array | ||
*/ | ||
public function get_payment_method_data() { | ||
if (!is_checkout()) { | ||
return []; | ||
} | ||
|
||
return [ | ||
'name' => $this->name, | ||
'title' => $this->get_setting('title'), | ||
'description' => $this->get_setting('description'), | ||
'supports' => array_filter($this->gateway->supports, [$this->gateway, 'supports']), | ||
'data' => [ | ||
'bank_list' => $this->gateway->backend->get_available_banks() | ||
] | ||
]; | ||
} | ||
} |
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
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
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