-
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 Konbini to WC blocks. (#464)
Co-authored-by: Aashish <aashish@omise.co>
- Loading branch information
1 parent
e98a3d2
commit 24dc83b
Showing
12 changed files
with
186 additions
and
8 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' => '85f6dde2a4f73007da7b68a01588b596'); | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '724dd47b1b5d55c38a76e60fc98ffc12'); |
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 @@ | ||
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '3ceaa9ba12ae6e7c920ff9466045ce83'); |
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,120 @@ | ||
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_konbini_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 [name, setName] = useState(null); | ||
const [email, setEmail] = useState(null); | ||
const [phone, setPhone] = useState(null); | ||
|
||
const onNameChange = (e) => { | ||
setName(e.target.value) | ||
} | ||
|
||
const onEmailChange = (e) => { | ||
setEmail(e.target.value) | ||
} | ||
|
||
const onPhoneChange = (e) => { | ||
setPhone(e.target.value) | ||
} | ||
|
||
useEffect(() => { | ||
const unsubscribe = onPaymentSetup(async () => { | ||
if (!name || !email || !phone) { | ||
return {type: emitResponse.responseTypes.ERROR, message: 'Name, email and phone fields are required'} | ||
} | ||
|
||
try { | ||
return { | ||
type: emitResponse.responseTypes.SUCCESS, | ||
meta: { | ||
paymentMethodData: { | ||
"omise_konbini_name": name, | ||
"omise_konbini_email": email, | ||
"omise_konbini_phone": phone, | ||
} | ||
} | ||
}; | ||
} catch (error) { | ||
return {type: emitResponse.responseTypes.ERROR, message: error.message} | ||
} | ||
}); | ||
return () => unsubscribe(); | ||
}, [ | ||
emitResponse.responseTypes.ERROR, | ||
emitResponse.responseTypes.SUCCESS, | ||
onPaymentSetup, | ||
name, | ||
email, | ||
phone | ||
]); | ||
|
||
return (<> | ||
{description && <p>{description}</p>} | ||
<fieldset id="omise-form-konbini"> | ||
<p className="form-row form-row-wide omise-required-field"> | ||
<label htmlFor="omise_konbini_name">{ __( 'Name', 'omise' ) }</label> | ||
<input | ||
id="omise_konbini_name" | ||
className="input-text" | ||
name="omise_konbini_name" | ||
type="text" | ||
maxLength="10" | ||
autoComplete="off" | ||
onChange={onNameChange} | ||
/> | ||
</p> | ||
|
||
<p className="form-row form-row-wide omise-required-field"> | ||
<label htmlFor="omise_konbini_email">{ __( 'Email', 'omise' ) }</label> | ||
<input | ||
id="omise_konbini_email" | ||
className="input-text" | ||
name="omise_konbini_email" | ||
type="text" | ||
maxLength="50" | ||
autoComplete="off" | ||
onChange={onEmailChange} | ||
/> | ||
</p> | ||
|
||
<p className="form-row form-row-wide omise-required-field"> | ||
<label htmlFor="omise_konbini_phone">{ __( 'Phone', 'omise' ) }</label> | ||
<input | ||
id="omise_konbini_phone" | ||
className="input-text" | ||
name="omise_konbini_phone" | ||
type="text" | ||
maxLength="11" | ||
autoComplete="off" | ||
onChange={onPhoneChange} | ||
/> | ||
</p> | ||
</fieldset> | ||
</>) | ||
} | ||
|
||
registerPaymentMethod( { | ||
name: settings.name || "", | ||
label: <Label />, | ||
content: <InternetBankingPaymentMethod />, | ||
edit: <InternetBankingPaymentMethod />, | ||
canMakePayment: () => settings.is_active, | ||
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_Konbini extends Omise_Block_Payment { | ||
/** | ||
* Payment method name/id/slug. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'omise_konbini'; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<fieldset id="omise-form-konbini"> | ||
<p class="form-row form-row-wide omise-required-field"> | ||
<label for="omise_konbini_name"><?php _e( 'Name', 'omise' ); ?></label> | ||
<input id="omise_konbini_name" class="input-text" name="omise_konbini_name" type="text" maxlength="10" autocomplete="off"> | ||
<label for="omise_konbini_name"><?php _e( 'Name', 'omise' ); ?></label> | ||
<input id="omise_konbini_name" class="input-text" name="omise_konbini_name" type="text" maxlength="10" autocomplete="off"> | ||
</p> | ||
|
||
<p class="form-row form-row-wide omise-required-field"> | ||
<label for="omise_konbini_email"><?php _e( 'Email', 'omise' ); ?></label> | ||
<input id="omise_konbini_email" class="input-text" name="omise_konbini_email" type="text" maxlength="50" autocomplete="off"> | ||
<label for="omise_konbini_email"><?php _e( 'Email', 'omise' ); ?></label> | ||
<input id="omise_konbini_email" class="input-text" name="omise_konbini_email" type="text" maxlength="50" autocomplete="off"> | ||
</p> | ||
|
||
<p class="form-row form-row-wide omise-required-field"> | ||
<label for="omise_konbini_phone"><?php _e( 'Phone', 'omise' ); ?></label> | ||
<input id="omise_konbini_phone" class="input-text" name="omise_konbini_phone" type="text" maxlength="11" autocomplete="off"> | ||
<label for="omise_konbini_phone"><?php _e( 'Phone', 'omise' ); ?></label> | ||
<input id="omise_konbini_phone" class="input-text" name="omise_konbini_phone" type="text" maxlength="11" autocomplete="off"> | ||
</p> | ||
</fieldset> |
38 changes: 38 additions & 0 deletions
38
tests/unit/includes/blocks/gateways/omise-block-konbini-test.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,38 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Brain\Monkey; | ||
|
||
class Omise_Block_Konbini_Test extends TestCase | ||
{ | ||
use MockPaymentGateways; | ||
|
||
public $obj; | ||
|
||
protected function setUp() : void | ||
{ | ||
parent::setUp(); | ||
$this->mockWcGateways(); | ||
require_once __DIR__ . '/../../../../../includes/blocks/gateways/abstract-omise-block-payment.php'; | ||
require_once __DIR__ . '/../../../../../includes/blocks/gateways/omise-block-konbini.php'; | ||
$this->obj = new Omise_Block_Konbini; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function set_additional_data() | ||
{ | ||
Monkey\Functions\expect('get_option')->andReturn(null); | ||
$this->obj->initialize(); | ||
$this->obj->set_additional_data(); | ||
|
||
$clazz = new \ReflectionClass($this->obj); | ||
$property = $clazz->getProperty('additional_data'); | ||
$property->setAccessible(true); | ||
$result = $property->getValue($this->obj); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertEmpty($result); | ||
} | ||
} |
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