Skip to content

Commit

Permalink
Merge branch 'dev-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mason authored and mason committed Apr 1, 2022
2 parents 88bd652 + 4a8fa5a commit c0c015b
Show file tree
Hide file tree
Showing 12 changed files with 697 additions and 443 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: payment, paymentgateway, woocommerce, ecommerce
Requires at least: 4.0 & WooCommerce 2.6+
Tested up to: Wordpress 5.7.2 & Woocommerce 5.3
PHP Version: 5.6 or higher
Stable tag: 1.7.3
Stable tag: 1.8.0
License: The MIT License (MIT)

Official Paymentwall module for WordPress WooCommerce.
Expand Down Expand Up @@ -37,6 +37,9 @@ View our full installation guide: <https://docs.paymentwall.com/modules/woocomme

== Changelog ==

= v1.8.0 [21/09/2021] =
* Upgrade brick version from 1.4 to 1.6

= v1.7.4 [10/11/2021]
* New option to open widget in Paymentwall hosted page

Expand Down
129 changes: 19 additions & 110 deletions src/assets/js/payment.js
Original file line number Diff line number Diff line change
@@ -1,113 +1,22 @@
function paymentListener(orderId, baseUrl) {
var pwInterval = setInterval(function () {
var r = new XMLHttpRequest();
r.open("POST", baseUrl + '/index.php?wc-api=paymentwall_gateway&action=ajax', true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
if (r.responseText) {
var data = JSON.parse(r.responseText);
if (data && data.status == '1') {
clearInterval(pwInterval);
location.href = data.url;
}
var Brick_Payment = (function () {
return {
createBrick(public_key, amount, currency, action, save_card) {
if (window.Brick !== undefined) {
return new Brick({
public_key: public_key,
amount: amount,
currency: currency,
container: 'brick-payments-container',
action: action,
form: {
show_zip: false, // show zip code
show_cardholder: true,
wcs_hide_email: false,
lang: 'en',
allow_storing_cards: save_card,
}
}, 'default')
}
};
var formData = new FormData();
formData.append('order_id', orderId);
r.send(formData);
}, 5000);
}

var Brick_Payment = {
brick: null,
form3Ds : '',
createBrick: function (public_key) {
this.brick = new Brick({
public_key: public_key,
form: {formatter: true}
}, 'custom');
},
brickTokenizeCard: function () {
this.brick.tokenizeCard({
card_number: jQuery('#card-number').val(),
card_expiration_month: jQuery('#card-expiration-month').val(),
card_expiration_year: jQuery('#card-expiration-year').val(),
card_cvv: jQuery('#card-cvv').val()
}, function (response) {
if (response.type == 'Error') {
var errors = "Brick error(s):<br/>" + " - " + (typeof response.error === 'string' ? response.error : response.error.join("<br/> - "));
Brick_Payment.showNotification(errors, 'error');
} else {
jQuery('#brick-token').val(response.token);
jQuery('#brick-fingerprint').val(Brick.getFingerprint());
jQuery('#brick-get-token-success').val(1);

Brick_Payment.sendPaymentRequest();
window.addEventListener("message", Brick_Payment.threeDSecureMessageHandle, false);
}
});
}, openConfirm3ds: function () {
var win = window.open("", "Brick: Verify 3D secure", "toolbar=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=1024, height=720");
win.document.body.innerHTML += Brick_Payment.form3Ds;
win.document.forms[0].submit();
return false;
}, threeDSecureMessageHandle: function (event) {
var origin = event.origin || event.originalEvent.origin;
if (origin !== "https://api.paymentwall.com") {
return;
}
Brick_Payment.showLoading();
var brickData = JSON.parse(event.data);
if (brickData && brickData.event == '3dSecureComplete') {
jQuery('#hidden-brick-secure-token').val(brickData.data.secure_token);
jQuery('#hidden-brick-charge-id').val(brickData.data.charge_id);
Brick_Payment.sendPaymentRequest();
}
},
sendPaymentRequest: function () {
jQuery.ajax({
type: 'POST',
url: '?wc-ajax=checkout',
data: jQuery('form.checkout').serialize(),
dataType: 'json',
encode: true,
beforeSend: function () {
Brick_Payment.showLoading();
},
success: function (response) {
if (response.result == 'success') {
Brick_Payment.showNotification(response.message);
window.location.href = response.redirect;
} else if (response.result == 'secure') {
Brick_Payment.form3Ds = response.secure;
var requireConfirm = "Please verify 3D-secure to continue checkout. <a href='javascript:void(0)' onclick='Brick_Payment.openConfirm3ds()'>Click here !</a>";
Brick_Payment.showNotification(requireConfirm);
} else if (response.result == 'failure') {
jQuery('#brick-loading').hide();
jQuery('#brick-errors').html(response.messages);
jQuery('#brick-errors').show();
} else {
Brick_Payment.showNotification(response.message, 'error');
}
}
});
}, showNotification: function (message, type) {
type = (type != undefined) ? type : 'message';
jQuery('#brick-loading').hide();
jQuery('#brick-errors').html('<ul class="woocommerce-' + type + '"><li> ' + message + ' </li></ul>');
jQuery('#brick-errors').show();
}, showLoading: function () {
jQuery('#brick-errors').hide();
jQuery('#brick-loading').show();
}
};

(function ($) {
$( document ).ready(function() {
$('.paymentwall-method .pw_payment_system').on('change', function () {
var paymentSystem = $(this).data('payment-system');
var inputPaymentSystem = $('#pw_gateway');
inputPaymentSystem.val(JSON.stringify(paymentSystem));
})
})
})(jQuery);
})()
26 changes: 8 additions & 18 deletions src/includes/admin/settings/brick.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@
'description' => __('Your Brick Private Key', PW_TEXT_DOMAIN),
'default' => ''
),
'test_mode' => array(
'title' => __('Test Mode', PW_TEXT_DOMAIN),
'type' => 'select',
'description' => __('Enable test mode', PW_TEXT_DOMAIN),
'options' => array(
'0' => 'No',
'1' => 'Yes'
),
'default' => '0'
),
'enable_delivery' => array(
'title' => __('Enable Delivery Confirmation API', PW_TEXT_DOMAIN),
'type' => 'select',
Expand All @@ -64,12 +54,12 @@
),
'default' => '1'
),
'saved_cards' => array(
'title' => __('Saved Cards', PW_TEXT_DOMAIN),
'lable' => __('Enable Payment via Saved Cards', PW_TEXT_DOMAIN),
'type' => 'checkbox',
'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Paymentwall servers, not on your store', PW_TEXT_DOMAIN),
'default' => 'no',
'desc_tip' => true,
)
// 'saved_cards' => array(
// 'title' => __('Saved Cards', PW_TEXT_DOMAIN),
// 'lable' => __('Enable Payment via Saved Cards', PW_TEXT_DOMAIN),
// 'type' => 'checkbox',
// 'description' => __('If enabled, users will be able to pay with a saved card during checkout. Card details are saved on Paymentwall servers, not on your store', PW_TEXT_DOMAIN),
// 'default' => 'no',
// 'desc_tip' => true,
// )
);
15 changes: 8 additions & 7 deletions src/includes/class-paymentwall-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,21 @@ function get_customer_orders($status, $billing_email) {
return $customer_orders;
}

function cumulative_payments_customer($status, $billing_email) {

function cumulative_payments_customer($status, $billing_email)
{

$customer_orders = $this->get_customer_orders($status, $billing_email);
$sum_total = 0;

if (!empty($customer_orders)) {
foreach ( $customer_orders as $customer_order ) {
foreach ($customer_orders as $customer_order) {
$order = new WC_Order($customer_order->ID);
$amount = $order->get_total();
$sum_total += $amount;
}

return $sum_total;
}

return $sum_total;
}

function s_datediff( $str_interval, $dt_menor, $dt_maior, $relative=false){
Expand Down Expand Up @@ -256,4 +257,4 @@ function get_subscription_data(WC_Subscription $subscription) {

return $subsData;
}
}
}
2 changes: 1 addition & 1 deletion src/includes/class-paymentwall-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ function prepare_delivery_confirmation_data($orderId, $deliveryStatus = '', $tra
}
return $data;
}
}
}
Loading

0 comments on commit c0c015b

Please sign in to comment.