Skip to content

Commit

Permalink
Merge pull request #375 from omise/release-v5.1.0
Browse files Browse the repository at this point in the history
Preparing release v5.1.0
  • Loading branch information
ajzkk committed May 15, 2023
2 parents 610528e + c62714c commit 791fb02
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 25 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

### [v5.1.0 _(May 15, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.1.0)
- Added Atome payment method. (PR [#364](https://github.com/omise/omise-woocommerce/pull/364))
- Installment minimum amount from capability API. (PR [#365](https://github.com/omise/omise-woocommerce/pull/365))
- Fixed Truemoney phone number input not displaying. (PR [#367](https://github.com/omise/omise-woocommerce/pull/367))
- Added Google pay icon. (PR [#368](https://github.com/omise/omise-woocommerce/pull/368))
- Fixed secure form not displaying on pay for order page. (PR [#371](https://github.com/omise/omise-woocommerce/pull/371))
- Added PayPay payment method. (PR [#372](https://github.com/omise/omise-woocommerce/pull/372))
- Fixed secured form database key mismatch. (PR [#373](https://github.com/omise/omise-woocommerce/pull/373))
- Fixed guest checkout with pay for order link. (PR [#374](https://github.com/omise/omise-woocommerce/pull/374))

### [v5.0.0 _(Apr 3, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.0.0)
- Replace credit card form with secure form with a feature flag options to switch between credit card forms. (PR [#354](https://github.com/omise/omise-woocommerce/pull/354))
Expand Down
11 changes: 11 additions & 0 deletions assets/images/googlepay.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/paypay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions assets/javascripts/omise-payment-atome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(function ($) {
const $form = $('form.checkout, form#order_review');

function hideError() {
$(".woocommerce-error").remove();
}

function showError(message) {
if (!message) {
return;
}

let $ulError = $("<ul>").addClass("woocommerce-error");
$ulError.html("<li>" + message + "</li>");
$form.prepend($ulError);
$("html, body").animate({ scrollTop:0 },"slow");
}

function omiseHandleError(message) {
$form.block({
message: null,
overlayCSS: {
background: '#fff url(' + wc_checkout_params.ajax_loader_url + ') no-repeat center',
backgroundSize: '16px 16px',
opacity: 0.6
}
});
showError(message);
$form.unblock();
return false;
}

function omiseFormHandler() {
hideError();
if ($('#payment_method_omise_atome').is(':checked')) {
if ($("#omise_atome_phone_default").is(":checked")) {
return true;
}

const phoneNumber = $('#omise_atome_phone_number').val();

if (!phoneNumber) {
return omiseHandleError('Phone number is required in Atome');
}

const phonePattern = /(\+)?([0-9]{10,13})/;

if (!phonePattern.test(phoneNumber)) {
return omiseHandleError('Phone number should be a number in Atome');
}

$form.unblock();
$form.submit();
}
}

$(function () {
$('form.checkout').on('checkout_place_order', function (e) {
return omiseFormHandler();
});
})
})(jQuery)
57 changes: 46 additions & 11 deletions assets/javascripts/omise-payment-form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,45 @@
opacity: 0.6
}
});
const billingAddress = {
country: document.getElementById('billing_country').value,
postal_code: document.getElementById('billing_postcode').value,
state: document.getElementById('billing_state').value,
city: document.getElementById('billing_city').value,
street1: document.getElementById('billing_address_1').value,
street2: document.getElementById('billing_address_2').value,

const billingAddress = getBillingAddress();
OmiseCard.requestCardToken(billingAddress);
}

/**
* @returns object | null
*/
function getBillingAddress() {
const billingAddress = {};
const billingAddressFields = {
'country': 'billing_country',
'postal_code': 'billing_postcode',
'state': 'billing_state',
'city': 'billing_city',
'street1': 'billing_address_1',
'street2': 'billing_address_2'
};

for (let key in billingAddressFields) {
const billingField = document.getElementById(billingAddressFields[key]);

// If the billing field is not present and the field
// is billing address 2, skip to the next field
if (!billingField && billingAddressFields[key] === 'billing_address_2') {
continue;
}

// If any other field is not present or the value is empty,
// return null to indicate billing address is not complete
if (!billingField || billingField.value.trim() === "") {
return null;
}

// construct address object required for token
billingAddress[key] = billingField.value.trim();
}
OmiseCard.requestCardToken(billingAddress)

return billingAddress;
}

function handleCreateOrder(payload) {
Expand All @@ -224,8 +254,8 @@
}
}

if(Boolean(omise_params.secure_form_enabled)) {
$(document).on('updated_checkout', function () {
function initializeSecureCardForm() {
if (Boolean(omise_params.secure_form_enabled)) {
showOmiseEmbeddedCardForm({
element: document.getElementById('omise-card'),
publicKey: omise_params.key,
Expand All @@ -240,7 +270,7 @@
$form.unblock()
}
})
});
}
}

$(function () {
Expand All @@ -263,6 +293,11 @@
$('.omise_token').remove();
});

$(document).on('updated_checkout', function () {
initializeSecureCardForm();
});

initializeSecureCardForm();
googlePay();
})
})(jQuery)
5 changes: 5 additions & 0 deletions includes/class-omise-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,9 @@ public function getShopeeBackend($sourceType)

return $this->getBackendByType($sourceType);
}

public function getInstallmentMinLimit()
{
return $this->capabilities['limits']['installment_amount']['min'];
}
}
4 changes: 3 additions & 1 deletion includes/class-omise-payment-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class Omise_Payment_Factory {
'Omise_Payment_ShopeePay',
'Omise_Payment_Maybank_QR',
'Omise_Payment_DuitNow_QR',
'Omise_Payment_DuitNow_OBW'
'Omise_Payment_DuitNow_OBW',
'Omise_Payment_Atome',
'Omise_Payment_PayPay'
);

/**
Expand Down
13 changes: 12 additions & 1 deletion includes/gateway/abstract-omise-payment-base-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function charge($order_id, $order)
}

$user = $order->get_user();
$omise_customer_id = $this->is_test() ? $user->test_omise_customer_id : $user->live_omise_customer_id;
$omise_customer_id = $this->getOmiseCustomerId($user);

// Saving card.
$saveCustomerCard = $_POST['omise_save_customer_card'];
Expand All @@ -38,6 +38,17 @@ public function charge($order_id, $order)
return OmiseCharge::create($data);
}

/**
* get omise customer id from user
* @param object|null $user
*/
private function getOmiseCustomerId($user) {
if(empty($user)) {
return null;
}
return $this->is_test() ? $user->test_omise_customer_id : $user->live_omise_customer_id;
}

/**
* Prepare request data to create a charge
* @param string $order_id
Expand Down
Loading

0 comments on commit 791fb02

Please sign in to comment.