Skip to content

Commit

Permalink
Updated charge method to include webhook. Refactored some codes, adde…
Browse files Browse the repository at this point in the history
…d a test and updated other tests.
  • Loading branch information
Aashish committed Oct 10, 2023
1 parent a0475fd commit 053e976
Show file tree
Hide file tree
Showing 33 changed files with 339 additions and 251 deletions.
3 changes: 2 additions & 1 deletion includes/gateway/abstract-omise-payment-base-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ private function prepareChargeData($order_id, $order, $omise_customer_id, $card_
$order_id,
$order,
[ 'secure_form_enabled' => $this->getSecureFormState()]
)
),
'webhook_endpoints' => [ Omise_Util::getWebhookURL() ]
];

if (!empty($omise_customer_id) && ! empty($card_id)) {
Expand Down
3 changes: 2 additions & 1 deletion includes/gateway/abstract-omise-payment-offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function charge( $order_id, $order ) {
'currency' => $currency,
'description' => apply_filters( 'omise_charge_params_description', 'WooCommerce Order id ' . $order_id, $order ),
'source' => array( 'type' => $this->source_type ),
'metadata' => $metadata
'metadata' => $metadata,
'webhook_endpoints' => [ Omise_Util::getWebhookURL() ]
) );
}

Expand Down
2 changes: 2 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
16 changes: 7 additions & 9 deletions includes/gateway/class-omise-payment-alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ 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],
'return_uri' => $this->getRedirectUrl('omise_alipay_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}
}
20 changes: 9 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,16 @@ 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->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 OmiseCharge::create($requestData);
}
}

Expand Down
31 changes: 13 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,26 @@ private function validateAtomeRequest()
*/
public function charge($order_id, $order)
{
$currency = $order->get_currency();
$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 OmiseCharge::create($requestData);
}

private function getAddress($order)
Expand Down
16 changes: 7 additions & 9 deletions includes/gateway/class-omise-payment-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ 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],
'return_uri' => $this->getRedirectUrl('omise_boost_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

/**
Expand Down
20 changes: 9 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,17 @@ 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: 7 additions & 9 deletions includes/gateway/class-omise-payment-duitnow-qr.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ 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],
'return_uri' => $this->getRedirectUrl('omise_duitnow_qr_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

/**
Expand Down
21 changes: 9 additions & 12 deletions includes/gateway/class-omise-payment-fpx.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,17 @@ 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],
'source' => [
'type' => 'fpx',
'bank' => sanitize_text_field($source_bank),
],
'return_uri' => $this->getRedirectUrl('omise_fpx_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: 7 additions & 9 deletions includes/gateway/class-omise-payment-grabpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ 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],
'return_uri' => $this->getRedirectUrl('omise_grabpay_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

/**
Expand Down
32 changes: 16 additions & 16 deletions includes/gateway/class-omise-payment-installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,27 @@ public function getTotalAmount()
public function charge($order_id, $order)
{
$source_type = isset($_POST['source']['type']) ? $_POST['source']['type'] : '';
$installment_terms = isset($_POST[$source_type . '_installment_terms']) ? $_POST[$source_type . '_installment_terms'] : '';
$currency = $order->get_currency();
$provider = $this->backend->get_provider($source_type);

$payload = [
'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' => sanitize_text_field($source_type),
'installment_terms' => sanitize_text_field($installment_terms)
],
'return_uri' => $this->getRedirectUrl('omise_installment_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
];
$requestData = $this->build_charge_request(
$order_id,
$order,
$source_type,
$this->id . "_callback"
);

$installment_terms = $_POST[$source_type . '_installment_terms'];
$installment_terms = isset($installment_terms)
? sanitize_text_field($installment_terms)
: '';
$provider = $this->backend->get_provider($source_type);

if (isset($provider['zero_interest_installments'])) {
$payload['zero_interest_installments'] = $provider['zero_interest_installments'];
}
$requestData['source'] = array_merge($requestData['source'], [
'installment_terms' => $installment_terms
]);

return OmiseCharge::create($payload);
return OmiseCharge::create($requestData);
}

/**
Expand Down
17 changes: 8 additions & 9 deletions includes/gateway/class-omise-payment-internetbanking.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ public function payment_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' => sanitize_text_field($_POST['omise-offsite'])],
'return_uri' => $this->getRedirectUrl('omise_internetbanking_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$source_type = sanitize_text_field($_POST['omise-offsite']);
$requestData = $this->build_charge_request(
$order_id,
$order,
$source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

/**
Expand Down
22 changes: 17 additions & 5 deletions includes/gateway/class-omise-payment-konbini.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,34 @@ public function payment_fields() {
*/
public function charge($order_id, $order)
{
$konbini_name = isset( $_POST['omise_konbini_name'] ) ? sanitize_text_field( $_POST['omise_konbini_name'] ) : '';
$konbini_email = isset( $_POST['omise_konbini_email'] ) ? sanitize_text_field( $_POST['omise_konbini_email'] ) : '';
$konbini_phone = isset( $_POST['omise_konbini_phone'] ) ? sanitize_text_field( $_POST['omise_konbini_phone'] ) : '';
$konbini_name = isset( $_POST['omise_konbini_name'] ) ?
sanitize_text_field( $_POST['omise_konbini_name'] ) :
'';
$konbini_email = isset( $_POST['omise_konbini_email'] ) ?
sanitize_text_field( $_POST['omise_konbini_email'] ) :
'';
$konbini_phone = isset( $_POST['omise_konbini_phone'] ) ?
sanitize_text_field( $_POST['omise_konbini_phone'] ) :
'';

$currency = $order->get_order_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),
'description' => apply_filters(
'omise_charge_params_description',
'WooCommerce Order id ' . $order_id,
$order
),
'source' => [
'type' => $this->source_type,
'name' => $konbini_name,
'email' => $konbini_email,
'phone_number' => $konbini_phone
],
'metadata' => $this->getMetadata($order_id, $order)
'metadata' => $this->getMetadata($order_id, $order),
'webhook_endpoints' => [ Omise_Util::getWebhookURL() ],
]);
}

Expand Down
16 changes: 7 additions & 9 deletions includes/gateway/class-omise-payment-maybank-qr.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ 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],
'return_uri' => $this->getRedirectUrl('omise_maybank_qr_callback', $order_id, $order),
'metadata' => $this->getMetadata($order_id, $order)
]);
$requestData = $this->build_charge_request(
$order_id,
$order,
$this->source_type,
$this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

/**
Expand Down
Loading

0 comments on commit 053e976

Please sign in to comment.