Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENGA3-1334]: Remove free products from the Atome bill #378

Merged
merged 3 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions includes/gateway/class-omise-payment-atome.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ private function register_omise_atome_scripts() {
public function payment_fields()
{
parent::payment_fields();
$viewData = $this->validateMinRequiredAmount();
$viewData = $this->validateAtomeRequest();

Omise_Util::render_view('templates/payment/form-atome.php', $viewData);
}

private function validateMinRequiredAmount()
private function validateAtomeRequest()
{
$limits = [
'thb' => [
Expand All @@ -103,7 +103,14 @@ private function validateMinRequiredAmount()
];

$currency = strtolower(get_woocommerce_currency());
$cartTotal = WC()->cart->total;
$cart = WC()->cart;

if ($cart->subtotal === 0) {
ajzkk marked this conversation as resolved.
Show resolved Hide resolved
return [
'status' => false,
'message' => 'Complimentary products cannot be billed.'
];
}

if (!isset($limits[$currency])) {
return [
Expand All @@ -114,7 +121,7 @@ private function validateMinRequiredAmount()

$limit = $limits[$currency];

if ($cartTotal < $limit['min']) {
if ($cart->total < $limit['min']) {
return [
'status' => false,
'message' => sprintf(
Expand All @@ -125,7 +132,7 @@ private function validateMinRequiredAmount()
];
}

if ($cartTotal > $limit['max']) {
if ($cart->total > $limit['max']) {
return [
'status' => false,
'message' => __(
Expand Down Expand Up @@ -191,14 +198,20 @@ private function getItems($order, $currency)

// Loop through ordered items
foreach ($items as $key => $item) {
// item don't have price. So we have to take subtotal and divide it by quantity to get the price
$pricePerItem = $item['subtotal'] / $item['qty'];

// Remove product from the list if the price is 0
if ((float)$item['subtotal'] === 0.00) {
ajzkk marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

// Check if product has variation.
$product = $item['variation_id'] ?
new WC_Product_Variation($item['variation_id'])
: new WC_Product($item['product_id']);

$sku = $product->get_sku();
// item don't have price. So we have to take subtotal and divide it by quantity to get the price
$pricePerItem = $item['subtotal'] / $item['qty'];

$products[$key] = [
'quantity' => $item['qty'],
Expand Down