Skip to content

Commit

Permalink
Pull request #79: RWC-79
Browse files Browse the repository at this point in the history
Merge in WWW/tornevall-networks-resurs-bank-payment-gateway-for-woocommerce from RWC-79 to master

* commit 'cb2f93326c27579e0f8110e69cefdd1180627689':
  Including RWC-236.
  RWC-79 Fix #38.
  • Loading branch information
Tornevall committed Nov 5, 2021
2 parents 508006d + cb2f933 commit 7562e50
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 5 deletions.
120 changes: 120 additions & 0 deletions css/costofpurchase.css
@@ -0,0 +1,120 @@
/*
Resurs Bank v2.2 Cost of Purchase Style.
- Thank you.
*/

body {
font-family: Arial, Helvetica, sans-serif !important;
font-size: 13px;
overflow-y: scroll;
}

.headText {
padding: 7px 0;
display: block;
}

.cost-of-purchase-box {
background-color: #fff;
border: 1px solid #ccc;
display: inline;
left: 0;
overflow: auto;
padding: 20px;
}

.cost-of-purchase-box p {
margin: 0 0 1em;
}

.cost-of-purchase-box h2 {
font-size: 1.5em;
line-height: 1.25;
margin-bottom: 0.45em;
}

.cost-of-purchase-box h3 {
font-size: 1.35em;
line-height: 1.25;
margin-bottom: 0.45em;
}

.cost-of-purchase-box .page {
text-align: left;
}

.cost-of-purchase-box table {
border: 0 none;
border-spacing: 0;
empty-cells: show;
font-size: 98%;
padding-bottom: 7px;
}

.cost-of-purchase-box table td {
border-bottom: 1px solid #bebcb7;
padding: 7px 14px;
text-align: center;
color: #006080;
font-weight: bold !important;
}

.cost-of-purchase-box .header:after, .readme-popup-box p:after {
clear: both;
content: ".";
display: block;
font-size: 0;
height: 0;
line-height: 0;
overflow: hidden;
}

.cost-of-purchase-box .header {
margin: 0 0 12px;
padding: 7px 0px;
position: relative;
text-align: left;
width: 100%;
z-index: 10;
color: #000;
}

.cost-of-purchase-box caption, th, td {
font-weight: normal;
text-align: left;
vertical-align: top;
}

.cost-of-purchase-box ul, ol {
list-style: none outside none;
}

.cost-of-purchase-box .main {
text-align: left;
}

.cost-of-purchase-box span.tailText {
font-size: 11.7px;
}

.priceinfoframe {
height: 800px !important;
}

.priceinfotablink {
}

.priceinfotab {
}

.resursAnnuityStyle {
font-size: 11px !important;
font-color: #990000 !important;
font-style: italic;
padding: 0px !important;
margin: 0px !important;
}

iframe {
height: 100% !important;
}
12 changes: 11 additions & 1 deletion css/resursbank.css
Expand Up @@ -8,4 +8,14 @@
padding: 5px;
margin: 5px;
font-size: 10px;
}
}

.resursReadMoreSpace {
padding-top: 5px !important;
margin-top: 5px !important;
font-size: 12px !important;
}

.resursReadMoreButton {
font-size: 12px !important;
}
18 changes: 18 additions & 0 deletions js/resursbank_global.js
Expand Up @@ -161,3 +161,21 @@ jQuery(document).ready(function () {
});
});
});


/**
* Render cost of purchase popup.
* @param method
* @param total
* @since 0.0.1.0
*/
function getRbReadMoreClicker(method, total) {
var costOfPurchaseUrl = getResursLocalization('ajaxify');
var costOfPurchaseVars = '?action=resursbank_get_cost_of_purchase&method=' + method + '&total=' + total;
//console.log(costOfPurchaseUrl+costOfPurchaseVars);
window.open(
costOfPurchaseUrl + costOfPurchaseVars,
'costOfPurchasePopup',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,width=650px,height=740px'
)
}
5 changes: 5 additions & 0 deletions src/Gateway/ResursDefault.php
Expand Up @@ -1308,6 +1308,11 @@ public function payment_fields()
]);
}

$fieldHtml .= $this->generic->getTemplate('checkout_paymentfield_after.phtml', [
'method' => $this->paymentMethodInformation,
'total' => isset($this->cart->total) ? $this->cart->total : 0
]);

echo $fieldHtml;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/WordPress.php
Expand Up @@ -64,6 +64,7 @@ private static function setupAjaxActions()
'get_internal_resynch',
'set_new_annuity',
'get_new_annuity_calculation',
'get_cost_of_purchase'
];

foreach ($actionList as $action) {
Expand Down
30 changes: 27 additions & 3 deletions src/Module/Data.php
Expand Up @@ -428,13 +428,15 @@ private static function getAnnuityHtml($wcDisplayPrice, $annuityMethod, $annuity
$monthlyPrice = Api::getResurs()->getAnnuityPriceByDuration($wcDisplayPrice, $annuityMethod, $annuityDuration);
if ($monthlyPrice >= $minimumPaymentLimit || self::getTestMode()) {
$annuityPaymentMethod = (array)Data::getPaymentMethodById($annuityMethod);

// Customized string.
$partPayString = self::getPartPayStringByTags(
WordPress::applyFilters(
'partPaymentString',
sprintf(
__('Part pay from %s per month.', 'trbwc'),
self::getWcPriceSpan($monthlyPrice)
__('Part pay from %s per month. | %s', 'trbwc'),
self::getWcPriceSpan($monthlyPrice),
self::getReadMoreString($annuityPaymentMethod, $monthlyPrice)
)
),
[
Expand All @@ -444,6 +446,7 @@ private static function getAnnuityHtml($wcDisplayPrice, $annuityMethod, $annuity
'paymentLimit' => $minimumPaymentLimit,
'paymentMethod' => $annuityPaymentMethod,
'isTest' => self::getTestMode(),
'readmore' => self::getReadMoreString($annuityPaymentMethod, $monthlyPrice),
]
);

Expand All @@ -457,6 +460,7 @@ private static function getAnnuityHtml($wcDisplayPrice, $annuityMethod, $annuity
'partPayString' => $partPayString,
'paymentMethod' => $annuityPaymentMethod,
'isTest' => self::getTestMode(),
'readmore' => self::getReadMoreString($annuityPaymentMethod, $monthlyPrice),
]
);

Expand Down Expand Up @@ -499,6 +503,22 @@ public static function getTestMode()
return in_array(self::getResursOption('environment'), ['test', 'staging']);
}

/**
* @param $annuityPaymentMethod
* @param $monthlyPrice
* @return string
* @since 0.0.1.0
*/
public static function getReadMoreString($annuityPaymentMethod, $monthlyPrice)
{
return sprintf(
'<span style="cursor:pointer !important; font-weight:bold;" onclick="getRbReadMoreClicker(\'%s\', %s)">%s</span>',
$annuityPaymentMethod['id'],
$monthlyPrice,
WordPress::applyFilters('partPaymentReadMoreString', __('Read more.', 'trbwc'))
);
}

/**
* @param $content
* @since 0.0.1.0
Expand All @@ -510,6 +530,7 @@ private static function getPartPayStringByTags($content, $data)
'currency' => get_woocommerce_currency_symbol(),
'monthlyPrice' => $data['monthlyPrice'],
'monthlyDuration' => $data['monthlyDuration'],
'readmore' => $data['readmore'],
],
$data
);
Expand All @@ -527,7 +548,10 @@ private static function getPartPayStringByTags($content, $data)
}

$methodTags = [
'id', 'description', 'type', 'specificType'
'id',
'description',
'type',
'specificType',
];

if (!empty($data['paymentMethod'])) {
Expand Down
29 changes: 29 additions & 0 deletions src/Module/PluginApi.php
Expand Up @@ -126,6 +126,35 @@ public static function importCredentials()
]);
}

/**
* @since 0.0.1.0
*/
public static function getCostOfPurchase()
{
$wooCommerceStyleSheet = get_stylesheet_directory_uri() . '/css/woocommerce.css';
$resursStyleSheet = Data::getGatewayUrl() . '/css/costofpurchase.css';

$method = WooCommerce::getRequest('method');
$total = WooCommerce::getRequest('total');
if (Data::getCustomerCountry() !== 'DK') {
$priceInfoHtml = Api::getResurs()->getCostOfPriceInformation($method, $total, true, true);
} else {
$priceInfoHtml = Api::getResurs()->getCostOfPriceInformation(Api::getPaymentMethods(), $total, false, true);
}

echo Data::getGenericClass()
->getTemplate(
'checkout_costofpurchase_default.phtml',
[
'wooCommerceStyleSheet' => $wooCommerceStyleSheet,
'resursStyleSheet' => $resursStyleSheet,
'priceInfoHtml' => $priceInfoHtml,
]
);

die;
}

/**
* @param null $expire
* @param null $noReply Boolean that returns the answer instead of replying live.
Expand Down
9 changes: 9 additions & 0 deletions templates/checkout_costofpurchase_default.phtml
@@ -0,0 +1,9 @@
<html>
<head>
<link rel="stylesheet" media="all" type="text/css" href="<?php echo $wooCommerceStyleSheet ?>">
<link rel="stylesheet" media="all" type="text/css" href="<?php echo $resursStyleSheet ?>">
</head>
<body>
<?php echo $priceInfoHtml ?>
</body>
</html>
2 changes: 1 addition & 1 deletion templates/checkout_paymentfield.phtml
Expand Up @@ -9,4 +9,4 @@
name="<?php echo $fieldName ?>"
onkeyup="setBillingInherit(this)"
value="<?php echo $fieldValue ?>">
</div>
</div>
9 changes: 9 additions & 0 deletions templates/checkout_paymentfield_after.phtml
@@ -0,0 +1,9 @@
<div class="resursReadMoreSpace">
<?php if ($method->specificType !== 'CARD' && $method->type !== 'PAYMENT_PROVIDER') { ?>
<button type="button" class="btn btn-info active resursReadMoreButton"
onclick="getRbReadMoreClicker('<?php echo $method->id ?>', <?php echo (float)$total ?>)"
>
<?php _e('Read more', 'trbwc') ?>
</button>
<?php } ?>
</div>

0 comments on commit 7562e50

Please sign in to comment.