-
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.
Integrate Internet banking with WC blocks
- Loading branch information
Aashish
committed
May 29, 2024
1 parent
f8dc006
commit c6216e3
Showing
12 changed files
with
122 additions
and
5 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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '5951a588e6a47ee3e88d47cac5cfe115'); | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '449ba1e9fbdfe36ffe11aee7d7ddd2b7'); |
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 |
---|---|---|
@@ -1 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '2abd4215eaac67e9b0541242851edae3'); | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '0870d052051799446a862b643aaa00a1'); |
1 change: 1 addition & 0 deletions
1
includes/blocks/assets/js/build/omise_internetbanking.asset.php
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' => '5a7c1ca9a881b022e773ff44a4c3f27c'); |
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
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,94 @@ | ||
import {useEffect, useState} 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_internetbanking_data', {} ) | ||
const label = decodeEntities( settings.title ) || 'No title set' | ||
const Label = ( props ) => { | ||
const { PaymentMethodLabel } = props.components | ||
return <PaymentMethodLabel text={ label } /> | ||
} | ||
|
||
const InternetBankingPaymentMethod = (props) => { | ||
const {eventRegistration, emitResponse} = props; | ||
const {onPaymentSetup} = eventRegistration; | ||
const description = decodeEntities( settings.description || '' ) | ||
const [selectedBank, setSelectedBank] = useState(null); | ||
|
||
const onBankSelected = (e) => { | ||
setSelectedBank(e.target.value) | ||
} | ||
|
||
useEffect(() => { | ||
const unsubscribe = onPaymentSetup(async () => { | ||
if (!selectedBank) { | ||
return {type: emitResponse.responseTypes.ERROR, message: 'Select a bank'} | ||
} | ||
|
||
try { | ||
return { | ||
type: emitResponse.responseTypes.SUCCESS, | ||
meta: { | ||
paymentMethodData: { | ||
"omise-offsite": selectedBank, | ||
} | ||
} | ||
}; | ||
} catch (error) { | ||
return {type: emitResponse.responseTypes.ERROR, message: error.message} | ||
} | ||
}); | ||
return () => unsubscribe(); | ||
}, [ | ||
emitResponse.responseTypes.ERROR, | ||
emitResponse.responseTypes.SUCCESS, | ||
onPaymentSetup, | ||
selectedBank | ||
]); | ||
|
||
return (<> | ||
{description && <p>{description}</p>} | ||
<fieldset id="omise-form-internetbanking"> | ||
<ul className="omise-banks-list"> | ||
{/* <!-- BAY --> */} | ||
<li className="item"> | ||
<input id="internet_banking_bay" type="radio" name="omise-offsite" value="internet_banking_bay" onChange={onBankSelected} /> | ||
<label htmlFor="internet_banking_bay"> | ||
<div className="bank-logo bay"></div> | ||
<div className="bank-label"> | ||
<span className="title">{ __( 'Krungsri Bank', 'omise' ) }</span><br/> | ||
<span className="omise-secondary-text">{ __( 'Fee: 15 THB (same zone), 15 THB (out zone)', 'omise' ) }</span> | ||
</div> | ||
</label> | ||
</li> | ||
|
||
{/* <!-- BBL --> */} | ||
<li className="item"> | ||
<input id="internet_banking_bbl" type="radio" name="omise-offsite" value="internet_banking_bbl" onChange={onBankSelected} /> | ||
<label htmlFor="internet_banking_bbl"> | ||
<div className="bank-logo bbl"></div> | ||
<div className="bank-label"> | ||
<span className="title">{ __( 'Bangkok Bank', 'omise' ) }</span><br/> | ||
<span className="omise-secondary-text">{ __( 'Fee: 10 THB (same zone), 20 THB (out zone)', 'omise' ) }</span> | ||
</div> | ||
</label> | ||
</li> | ||
</ul> | ||
</fieldset> | ||
|
||
</>) | ||
} | ||
|
||
registerPaymentMethod( { | ||
name: settings.name || "", | ||
label: <Label />, | ||
content: <InternetBankingPaymentMethod />, | ||
edit: <InternetBankingPaymentMethod />, | ||
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
class Omise_Block_InternetBanking extends Omise_Block_Payment { | ||
/** | ||
* Payment method name/id/slug. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'omise_internetbanking'; | ||
|
||
public function set_additional_data() { | ||
$this->additional_data = []; | ||
} | ||
} |
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