Skip to content

Commit

Permalink
Moved charge() method to Omise_Payment_Offsite to avoid repeating sam…
Browse files Browse the repository at this point in the history
…e code. Payment method class can override the method if they have more request to pass to charge API.
  • Loading branch information
Aashish committed Oct 11, 2023
1 parent 01a0825 commit 0ed6a9c
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 90 deletions.
12 changes: 12 additions & 0 deletions includes/gateway/abstract-omise-payment-offsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,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);
}
}
11 changes: 0 additions & 11 deletions includes/gateway/class-omise-payment-alipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,4 @@ public function init_form_fields() {
),
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}
}
11 changes: 0 additions & 11 deletions includes/gateway/class-omise-payment-boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ public function init_form_fields() {
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

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

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

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

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

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

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . "_callback"
);
return OmiseCharge::create($requestData);
}

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

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . '_callback'
);
return OmiseCharge::create($requestData);
}

/**
* Get icons
*
Expand Down
11 changes: 0 additions & 11 deletions includes/gateway/class-omise-payment-shopeepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ public function init_form_fields() {
);
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . '_callback'
);
return OmiseCharge::create($requestData);
}

/**
* Return the right ShopeePay backend depending on the platform and availability of
* the backend in the capability
Expand Down
12 changes: 0 additions & 12 deletions includes/gateway/class-omise-payment-touch-n-go.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ public function GetMethodTitle() {
return $this->touch_and_go_wallet_title;
}

/**
* @inheritdoc
*/
public function charge($order_id, $order)
{
$requestData = $this->build_charge_request(
$order_id, $order, $this->source_type, $this->id . '_callback'
);
return OmiseCharge::create($requestData);
}

/**
* Get icons
*
Expand All @@ -95,5 +84,4 @@ public function get_icon() {
]);
return apply_filters( 'woocommerce_gateway_icon', $icon, $this->id );
}

}
2 changes: 1 addition & 1 deletion includes/gateway/traits/charge-request-builder-trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function build_charge_request(
]);
}

if (!$callback_endpoint) {
if ($callback_endpoint) {
$return_uri = $this->get_redirect_url($callback_endpoint, $order_id, $order);

return array_merge($request, [
Expand Down

0 comments on commit 0ed6a9c

Please sign in to comment.