Skip to content

Commit

Permalink
Merge pull request #14 from wirecard/TPWDCEE-505
Browse files Browse the repository at this point in the history
Tpwdcee 505
  • Loading branch information
jpy authored Nov 29, 2017
2 parents 62b2c9d + 208752a commit 1998e10
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 84 deletions.
15 changes: 15 additions & 0 deletions update/plg_vmpayment_wirecardceecheckout_update.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,19 @@
<maintainerurl>https://www.wirecard.at/</maintainerurl>
<targetplatform name="joomla" version="3.6"/>
</update>
<update>
<name>Wirecard Checkout Page</name>
<description>Wirecard - Your Full Service Payment Provider</description>
<type>plugin</type>
<folder>vmpayment</folder>
<element>wirecardceecheckout</element>
<version>1.7.4</version>
<client>site</client>
<downloads>
<downloadurl type="full" format="zip">https://github.com/wirecard/virtuemart3-wcp/archive/1.7.4.zip</downloadurl>
</downloads>
<maintainer>Wirecard</maintainer>
<maintainerurl>https://www.wirecard.at/</maintainerurl>
<targetplatform name="joomla" version="3.6"/>
</update>
</updates>
34 changes: 30 additions & 4 deletions wirecardceecheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class plgVmPaymentwirecardceecheckout extends vmPSPlugin

protected static $WINDOW_NAME = 'WirecardCEECheckoutFrame';
protected static $PLUGIN_NAME = 'VirtueMart2_CheckoutPage';
protected static $PLUGIN_VERSION = '1.7.3';
protected static $PLUGIN_VERSION = '1.7.4';

protected $_method;
protected $_order;
Expand Down Expand Up @@ -961,7 +961,11 @@ protected function _initiatePayment($cart)
}

if ( in_array($paymentType, array(WirecardCEE_QPay_PaymentType::IDL, WirecardCEE_QPay_PaymentType::EPS ) ) ) {
$client->setFinancialInstitution($_POST['financialInstitution']);
if (isset($_POST['financialInstitution'])) {
$client->setFinancialInstitution($_POST['financialInstitution']);
} else {
$client->setFinancialInstitution($sessionWirecard->additional["financialInstitution"]);
}
}
if (array_key_exists('ST', $order['details'])) {
$client->createConsumerMerchantCrmId($order['details']['ST']->email);
Expand Down Expand Up @@ -1040,7 +1044,7 @@ protected function _getEnabledPaymentTypes()
$paymentTypes[7]['image'] = strtolower(WirecardCEE_QPay_PaymentType::EPS);
$paymentTypes[7]['title'] = $this->_getPaymentTypeName(WirecardCEE_QPay_PaymentType::EPS);
$paymentTypes[7]['value'] = WirecardCEE_QPay_PaymentType::EPS;
$paymentTypes[9]['financial_inst'] = WirecardCEE_QPay_PaymentType::getFinancialInstitutions('EPS');
$paymentTypes[7]['financial_inst'] = WirecardCEE_QPay_PaymentType::getFinancialInstitutions('EPS');
}
if ((int)$this->_getMethod()->paymenttype_giropay == 1) {
$paymentTypes[8]['image'] = strtolower(WirecardCEE_QPay_PaymentType::GIROPAY);
Expand Down Expand Up @@ -1929,4 +1933,26 @@ function plgVmOnCheckAutomaticSelectedPayment(VirtueMartCart $cart, array $cart_
return $this->onCheckAutomaticSelected($cart, $cart_prices, $paymentCounter);
}

}
public function changePaymentTypeAjax($data)
{
$session = JFactory::getSession();
$sessionData = $session->get('WIRECARDCEECHECKOUT', 0, 'vm');
if (!empty($sessionData)) {
$sessionWirecard = unserialize($sessionData);
$sessionWirecard->paymenttype = $data["wirecard_paymenttype"];
$sessionWirecard->additional = $data["wcp_additional"];
}
$session->set('WIRECARDCEECHECKOUT', serialize($sessionWirecard), 'vm');
}

public function plgVmOnSelfCallFE()
{
$action = vRequest::getCmd('action');
$data = vRequest::getPost();
switch ($action) {
case "changePaymentTypeAjax":
$this->changePaymentTypeAjax($data);
break;
}
}
}
2 changes: 1 addition & 1 deletion wirecardceecheckout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<authorUrl>http://www.wirecard.at/</authorUrl>
<copyright>Copyright (C) 2013 Wirecard. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<version>1.7.3</version>
<version>1.7.4</version>
<description>VMPAYMENT_WIRECARDCEECHECKOUT_PAYMENT_DESCRIPTION</description>

<files>
Expand Down
194 changes: 115 additions & 79 deletions wirecardceecheckout/tmpl/displaypayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
$url = JURI::root() . 'images/stories/virtuemart/' . $this->_psType . '/';

foreach ( $viewData['paymenttypes'] as $pt ) {
?>
?>
<div class="vm-payment-plugin-single">
<input class="wirecard_paymenttype" id="wirecard_<?php echo strtolower( $pt['value'] ) ?>" type="radio"
name="wirecard_paymenttype"
value="<?php echo strtolower( $pt['value'] ) ?>" <?php if ( $viewData['paymenttype_selected'] == strtolower( $pt['value'] ) )
echo ' checked="checked"' ?> />
echo ' checked="checked"' ?> />

<label for="wirecard_<?php echo strtolower( $pt['value'] ) ?>">
<span class="vmpayment">
Expand All @@ -60,106 +60,122 @@
</span>
</label>
</div>
<?php if ( isset( $pt['birthday_header'] ) && $viewData['paymenttype_selected'] == strtolower( $pt['value'] ) ) { ?>
<div style="margin-left:23px;" class="additional-information">
<?php if ( isset( $pt['birthday_header'] ) ) { ?>
<div style="margin-left:23px; display: <?= ($viewData['paymenttype_selected'] !== strtolower( $pt['value'] )) ? 'none' : 'block';?>;" class="additional-information">
<b><?php echo $pt['birthday_header']; ?></b><br/>
<?php
$birthday = '<select name="wcp_day" id="wcp_day_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $day = 31; $day > 0; $day -- ) {
$selected = '';
if ($viewData['birth_day'] == $day){
$selected = 'selected';
}
$birthday .= '<option value="'.$day.'" '.$selected.'> '.$day.' </option>';
}
<?php
$birthday = '<select name="wcp_day" id="wcp_day_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $day = 31; $day > 0; $day -- ) {
$selected = '';
if ($viewData['birth_day'] == $day){
$selected = 'selected';
}
$birthday .= '<option value="'.$day.'" '.$selected.'> '.$day.' </option>';
}

$birthday .= '</select>';
$birthday .= '</select>';

$birthday .= '<select name="wcp_month" id="wcp_month_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $month = 12; $month > 0; $month -- ) {
$selected = '';
if ($viewData['birth_month'] == $month){
$selected = 'selected';
}
$birthday .= '<option value="'.$month.'" '.$selected.'> '.$month.' </option>';
}
$birthday .= '</select>';
$birthday .= '<select name="wcp_month" id="wcp_month_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $month = 12; $month > 0; $month -- ) {
$selected = '';
if ($viewData['birth_month'] == $month){
$selected = 'selected';
}
$birthday .= '<option value="'.$month.'" '.$selected.'> '.$month.' </option>';
}
$birthday .= '</select>';

$birthday .= '<select name="wcp_year" id="wcp_year_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $year = date( "Y" ); $year > 1900; $year -- ) {
$selected = '';
if ($viewData['birth_year'] == $year){
$selected = 'selected';
}
$birthday .= '<option value="'.$year.'" '.$selected.'> '.$year.' </option>';
}
$birthday .= '</select>';
echo $birthday;
?>
$birthday .= '<select name="wcp_year" id="wcp_year_'.strtolower($pt['value']).'" style="width:auto;">';
for ( $year = date( "Y" ); $year > 1900; $year -- ) {
$selected = '';
if ($viewData['birth_year'] == $year){
$selected = 'selected';
}
$birthday .= '<option value="'.$year.'" '.$selected.'> '.$year.' </option>';
}
$birthday .= '</select>';
echo $birthday;
?>
</div>
<?php } ?>
<?php } ?>

<?php if ( isset( $pt['additional_header'] ) && $viewData['paymenttype_selected'] == strtolower( $pt['value'] ) ) { ?>
<div style="margin-left:23px;" class="additional-information">
<?php if ( isset( $pt['additional_header'] ) ) { ?>
<div style="margin-left:23px; display: <?= ($viewData['paymenttype_selected'] !== strtolower( $pt['value'] )) ? 'none' : 'block';?>;" class="additional-information">
<b><?php echo $pt['additional_header']; ?></b><br/>
<label>
<input type="checkbox" id="consent_<?php echo strtolower( $pt['value'] ); ?>" class="required"
name="consent_<?php echo strtolower( $pt['value'] ); ?>"<?php echo $pt['consent_checked']; ?>>
<?php echo $pt['consent_text']; ?>
<?php echo $pt['consent_text']; ?>
</label>
</div>
<?php } ?>
<?php if ( isset( $pt['financial_inst'] ) && $viewData['paymenttype_selected'] == strtolower( $pt['value'] ) ) { ?>
<div style="margin-left:23px;" class="additional-information">
<?php } ?>
<?php if ( isset( $pt['financial_inst'] ) ) { ?>
<div style="margin-left:23px; display: <?= ($viewData['paymenttype_selected'] !== strtolower( $pt['value'] )) ? 'none' : 'block';?>;" class="additional-information">
<b><?php echo JText::_('VMPAYMENT_WIRECARDCEECHECKOUT_FINANCIAL_INST_HEADER'); ?></b><br/>
<select name="financialInstitution" id="financialInstitutions">
<?php foreach($pt['financial_inst'] as $key => $value) { ?>
<?php foreach($pt['financial_inst'] as $key => $value) { ?>
<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<div>
<script type="text/javascript">
jQuery('#checkoutForm').submit(function (event) {
jQuery('.wirecard_paymenttype').each(function () {
if (jQuery(this).prop('checked')) {
if (jQuery('#wcp_day_' + this.value).val()) {
var day = jQuery('#wcp_day_' + this.value).val();
var month = jQuery('#wcp_month_' + this.value).val();
var year = jQuery('#wcp_year_' + this.value).val();
var dateStr = year + '-' + month + '-' + day;
var minAge = 18;
function getData(selector) {
var data = {};
jQuery('input, select', selector).each(function(){
var input = jQuery(this);
data[input.attr('name')] = input.val()
});
return data;
}
function checkBirthday(selector, event) {
if (jQuery('#wcp_day_' + selector).val()) {
var day = jQuery('#wcp_day_' + selector).val();
var month = jQuery('#wcp_month_' + selector).val();
var year = jQuery('#wcp_year_' + selector).val();
var dateStr = year + '-' + month + '-' + day;
var minAge = 18;

var birthdate = new Date(dateStr);
var year = birthdate.getFullYear();
var today = new Date();
var limit = new Date((today.getFullYear() - minAge), today.getMonth(), today.getDate());
var birthdate = new Date(dateStr);
var year = birthdate.getFullYear();
var today = new Date();
var limit = new Date((today.getFullYear() - minAge), today.getMonth(), today.getDate());

if (birthdate > limit) {
jQuery('.vmLoadingDiv').remove();
jQuery('#checkoutFormSubmit').prop("disabled", false);
jQuery('#checkoutFormSubmit').addClass("vm-button-correct");
event.preventDefault();
alert("<?php echo JText::_( 'VMPAYMENT_WIRECARDCEECHECKOUT_BIRTHDAY_ERROR' ); ?>");
return;
}
}
var checkbox = null;
if (jQuery('#consent_' + this.value).length) {
checkbox = jQuery('#consent_' + this.value);
}
if (birthdate > limit) {
jQuery('.vmLoadingDiv').remove();
jQuery('#checkoutFormSubmit').prop("disabled", false);
jQuery('#checkoutFormSubmit').addClass("vm-button-correct");
alert("<?php echo JText::_( 'VMPAYMENT_WIRECARDCEECHECKOUT_BIRTHDAY_ERROR' ); ?>");
return false;
}
}
return true;
}
function checkPayolutionConsent(selector, event) {
var checkbox = null;
if (jQuery('#consent_' + selector).length) {
checkbox = jQuery('#consent_' + selector);
}

if (checkbox != null) {
if (!checkbox.prop('checked') ) {
jQuery('.vmLoadingDiv').remove();
jQuery('#checkoutFormSubmit').prop("disabled", false);
jQuery('#checkoutFormSubmit').addClass("vm-button-correct");
event.preventDefault();
alert("<?php echo JText::_( 'VMPAYMENT_WIRECARDCEECHECKOUT_PAYOLUTION_CONSENT_ACCEPT' ); ?>");
return;
}
if (checkbox != null) {
if (!checkbox.prop('checked') ) {
jQuery('.vmLoadingDiv').remove();
jQuery('#checkoutFormSubmit').prop("disabled", false);
jQuery('#checkoutFormSubmit').addClass("vm-button-correct");
event.preventDefault();
alert("<?php echo JText::_( 'VMPAYMENT_WIRECARDCEECHECKOUT_PAYOLUTION_CONSENT_ACCEPT' ); ?>");
return false;
}
}
return true;
}
jQuery("#checkoutForm").submit(function (event) {
jQuery('.wirecard_paymenttype').each(function () {
if (jQuery(this).prop('checked')) {
if (!checkBirthday(this.value, event) || !checkPayolutionConsent(this.value, event)) {
event.preventDefault();
}
}
});
Expand All @@ -168,11 +184,31 @@
jQuery('.wirecard_paymenttype').each(function () {
jQuery(this).change(function (evt) {
jQuery('#payment_id_<?php echo $viewData['paymentmethod_id'] ?>').prop('checked', true);
jQuery('.additional-information').hide();
jQuery(this).closest(".vm-payment-plugin-single").next(".additional-information").show();
});
});
jQuery('input[name=virtuemart_paymentmethod_id]').change(function (evt) {
jQuery('.additional-information').remove();
});
jQuery("button[name='updatecart']").click(function (event) {
event.preventDefault();
var val = jQuery('.wirecard_paymenttype:checked').val(),
data = getData(jQuery('.additional-information:visible'));
if (!checkBirthday(val, event) || !checkPayolutionConsent(this.value, event)) {
event.preventDefault();
} else {
jQuery.ajax({
type: "POST",
dataType: "json",
data: {"wcp_additional" : data, "wirecard_paymenttype": val},
url: "<?php echo JURI::root() ?>index.php?option=com_virtuemart&view=plugin&type=vmpayment&nosef=1&name=wirecardceecheckout&loadJS=1&action=changePaymentTypeAjax",
complete : function () {
jQuery('#paymentForm').submit();
}
});
}
});
</script>
</div>

0 comments on commit 1998e10

Please sign in to comment.