Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:omise/omise-woocommerce into pro…
Browse files Browse the repository at this point in the history
…mptypay-qr-expires-in-count-down
  • Loading branch information
ajzkk committed Oct 16, 2023
2 parents 25f8c76 + 3cbd9d5 commit 81e0325
Show file tree
Hide file tree
Showing 52 changed files with 1,152 additions and 417 deletions.
2 changes: 1 addition & 1 deletion includes/admin/class-omise-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function render() {

$settings = $page->get_settings();

// This variable is used in the view.
// Although this variable looks like unsed, it will be available in the view.
$available_payment_methods = [];
$capabilities = Omise_Capabilities::retrieve();

Expand Down
46 changes: 34 additions & 12 deletions includes/admin/views/omise-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,47 @@

<table class="form-table">
<tbody>
<tr>
<th scope="row"><label><?php _e( 'Enable Dynamic Webhook', 'omise' ); ?></label></th>
<td>
<fieldset>
<select class="regular-text" name="dynamic_webhook" id="dynamic_webhook">
<option
value="0"
<?php echo $settings['dynamic_webhook'] ? 'selected' : '' ?>
>
No
</option>
<option
value="1"
<?php echo $settings['dynamic_webhook'] ? 'selected' : '' ?>
>
Yes
</option>
</select>
<p class="description">
<?php
echo __( 'If enabled, charge and refund events will be automatically set to be received at the URL below. This can be useful when you need multiple webhook endpoints on the same account. ' );
?>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Webhook endpoint', 'omise' ); ?></label></th>
<td>
<fieldset>
<code><?php echo get_rest_url( null, 'omise/webhooks' ); ?></code>
<p class="description">
<?php
echo sprintf(
wp_kses(
__( 'To enable <a href="%s">WebHooks</a> feature, you must setup an endpoint at <a href="%s"><strong>Opn Payments dashboard</strong></a> by using the above url <em>(HTTPS only)</em>.', 'omise' ),
array(
'a' => array( 'href' => array() ),
'em' => array(),
'strong' => array()
)
),
esc_url( 'https://www.omise.co/api-webhooks' ),
esc_url( 'https://dashboard.omise.co/v2/settings/webhooks' )
);
echo sprintf(
wp_kses(
__( 'Unless dynamic webhooks are enabled, you must add the URL below as a new endpoint on your <a href="%s">Opn Payments dashboard</a> (HTTPS only).', 'omise' ),
[
'a' => ['href' => []],
],
),
esc_url( 'https://dashboard.omise.co/v2/settings/webhooks' )
);
?>
</fieldset>
</td>
Expand Down
8 changes: 7 additions & 1 deletion includes/class-omise-setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function get_default_settings() {
'test_private_key' => '',
'live_public_key' => '',
'live_private_key' => '',
'dynamic_webhook' => 0,
'backends' => null,
);
}
Expand Down Expand Up @@ -138,7 +139,6 @@ public function update_settings( $data ) {
*/
public function is_test() {
$sandbox = $this->settings['sandbox'];

return isset( $sandbox ) && $sandbox == 'yes';
}

Expand Down Expand Up @@ -171,4 +171,10 @@ public function secret_key() {

return $this->settings['live_private_key'];
}

public function is_dynamic_webhook_enabled()
{
$dynamic_webhook = $this->settings['dynamic_webhook'];
return (bool)$dynamic_webhook;
}
}
23 changes: 14 additions & 9 deletions includes/gateway/abstract-omise-payment-base-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
abstract class Omise_Payment_Base_Card extends Omise_Payment
{
use Charge_Request_Builder;

const PAYMENT_ACTION_AUTHORIZE = 'manual_capture';
const PAYMENT_ACTION_AUTHORIZE_CAPTURE = 'auto_capture';

Expand Down Expand Up @@ -63,19 +65,22 @@ private function prepareChargeData($order_id, $order, $omise_customer_id, $card_
$data = [
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters(
'omise_charge_params_description',
'WooCommerce Order id ' . $order_id,
$order
),
'return_uri' => $this->getRedirectUrl('omise_callback', $order_id, $order),
'metadata' => $this->getMetadata(
'description' => 'WooCommerce Order id ' . $order_id,
'return_uri' => $this->get_redirect_url('omise_callback', $order_id, $order),
'metadata' => $this->get_metadata(
$order_id,
$order,
[ 'secure_form_enabled' => $this->getSecureFormState()]
)
),
];

$omise_settings = Omise_Setting::instance();

if ($omise_settings->is_dynamic_webhook_enabled()) {
$data = array_merge($data, [
'webhook_endpoints' => [ Omise_Util::get_webhook_url() ],
]);
}

if (!empty($omise_customer_id) && ! empty($card_id)) {
$data['customer'] = $omise_customer_id;
$data['card'] = $card_id;
Expand Down
22 changes: 8 additions & 14 deletions includes/gateway/abstract-omise-payment-offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@
/**
* @since 4.0
*/
abstract class Omise_Payment_Offline extends Omise_Payment {
abstract class Omise_Payment_Offline extends Omise_Payment
{
use Charge_Request_Builder;

protected $enabled_processing_notification = true;

/**
* @inheritdoc
*/
public function charge( $order_id, $order ) {
$total = $order->get_total();
$currency = $order->get_currency();
$metadata = array_merge(
apply_filters( 'omise_charge_params_metadata', array(), $order ),
array( 'order_id' => $order_id ) // override order_id as a reference for webhook handlers.
public function charge( $order_id, $order )
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type
);

return OmiseCharge::create( array(
'amount' => Omise_Money::to_subunit( $total, $currency ),
'currency' => $currency,
'description' => apply_filters( 'omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order ),
'source' => array( 'type' => $this->source_type ),
'metadata' => $metadata
) );
return OmiseCharge::create($requestData);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions includes/gateway/abstract-omise-payment-offsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
abstract class Omise_Payment_Offsite extends Omise_Payment
{
use Charge_Request_Builder;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -48,4 +50,16 @@ public function check_bank_selected($fields, $errors)
$errors->add('validation', __('Please select bank below', 'omise'));
}
}

/**
* Override charge() method in the child class if the payment method requires
* more data than received from build_charge_request()
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}
}
16 changes: 0 additions & 16 deletions includes/gateway/class-omise-payment-alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,4 @@ public function init_form_fields() {
),
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
'source' => ['type' => $this->source_type],
'return_uri' => $this->getRedirectUrl('omise_alipay_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
}
}
23 changes: 12 additions & 11 deletions includes/gateway/class-omise-payment-alipayplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ public function init_form_fields() {
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
'source' => [
'type' => $this->source_type,
'platform_type' => Omise_Util::get_platform_type(wc_get_user_agent())
],
'return_uri' => $this->getRedirectUrl('omise_' . $this->source_type . '_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
$requestData = $this->get_charge_request($order_id, $order);
return OmiseCharge::create($requestData);
}

public function get_charge_request($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
$requestData['source'] = array_merge($requestData['source'], [
'platform_type' => Omise_Util::get_platform_type(wc_get_user_agent())
]);
return $requestData;
}
}

Expand Down
37 changes: 19 additions & 18 deletions includes/gateway/class-omise-payment-atome.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,32 @@ private function validateAtomeRequest()
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
$requestData = $this->get_charge_request($order_id, $order);
return OmiseCharge::create($requestData);
}

public function get_charge_request($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);

$default_phone_selected = isset($_POST['omise_atome_phone_default']) ?
$_POST['omise_atome_phone_default']
: false;
$phone_number = (bool)$default_phone_selected ?
$order->get_billing_phone()
: sanitize_text_field($_POST['omise_atome_phone_number']);
$requestData['source'] = array_merge($requestData['source'], [
'phone_number' => $phone_number,
'shipping' => $this->getAddress($order),
'items' => $this->getItems($order, $order->get_currency())
]);

return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters(
'omise_charge_params_description',
'WooCommerce Order id ' . $order_id,
$order
),
'source' => [
'type' => $this->source_type,
'phone_number' => $phone_number,
'shipping' => $this->getAddress($order),
'items' => $this->getItems($order, $currency)
],
'return_uri' => $this->getRedirectUrl('omise_atome_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
return $requestData;
}

private function getAddress($order)
Expand Down
16 changes: 0 additions & 16 deletions includes/gateway/class-omise-payment-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ public function init_form_fields() {
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
'source' => ['type' => $this->source_type],
'return_uri' => $this->getRedirectUrl('omise_boost_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
}

/**
* Get icons
*
Expand Down
17 changes: 6 additions & 11 deletions includes/gateway/class-omise-payment-duitnow-obw.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,14 @@ public function payment_fields()
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
$source_bank = isset($_POST['source']['bank']) ? $_POST['source']['bank'] : '';
$currency = $order->get_currency();
return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
'source' => [
'type' => $this->source_type,
'bank' => sanitize_text_field($source_bank),
],
'return_uri' => $this->getRedirectUrl('omise_duitnow_obw_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
$requestData['source'] = array_merge($requestData['source'], [
'bank' => sanitize_text_field($source_bank),
]);
return OmiseCharge::create($requestData);
}

/**
Expand Down
16 changes: 0 additions & 16 deletions includes/gateway/class-omise-payment-duitnow-qr.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ public function init_form_fields() {
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
return OmiseCharge::create([
'amount' => Omise_Money::to_subunit($order->get_total(), $currency),
'currency' => $currency,
'description' => apply_filters('omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order),
'source' => ['type' => $this->source_type],
'return_uri' => $this->getRedirectUrl('omise_duitnow_qr_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
}

/**
* Get icons
*
Expand Down
Loading

0 comments on commit 81e0325

Please sign in to comment.