Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save speedupmate/8577843 to your computer and use it in GitHub Desktop.
Save speedupmate/8577843 to your computer and use it in GitHub Desktop.
Add Adyen payment method support to OneStepCheckout
<?xml version="1.0"?>
<!--
/**
* Madia Adyen Payment Module
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Madia
* @package Madia_Adyen
* @copyright Copyright (c) 2011 Madia (http://www.madia.nl)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* @category Payment Gateway
* @package Madia_Adyen
* @author Omar,Muhsin <info@madia.nl>
* @property Madia B.V
* @copyright Copyright (c) 2011 Madia BV (http://www.madia.nl)
*/
-->
<layout version="0.1.0">
<!-- references for OneStepCheckout -->
<onestepcheckout_index_index>
<reference name="head">
<action method="addJs"><script>madia/adyen/adyen.osc.js</script></action>
<action method="addJs"><script>madia/adyen/adyen.encrypt.js</script></action>
<action method="addJs"><script>madia/adyen/elv.js</script></action>
<action method="addCss"><stylesheet>css/adyenstyle.css</stylesheet></action>
</reference>
</onestepcheckout_index_index>
<!-- references for OneStepCheckout end -->
<checkout_onepage_index>
<reference name="head">
<action method="addJs"><script>madia/adyen/adyen.encrypt.js</script></action>
<action method="addJs"><script>madia/adyen/elv.js</script></action>
<action method="addCss"><stylesheet>css/adyenstyle.css</stylesheet></action>
</reference>
</checkout_onepage_index>
<checkout_multishipping_billing>
<reference name="head">
<action method="addJs"><script>madia/adyen/adyen.encrypt.js</script></action>
<action method="addJs"><script>madia/adyen/elv.js</script></action>
<action method="addCss"><stylesheet>css/adyenstyle.css</stylesheet></action>
</reference>
</checkout_multishipping_billing>
<checkout_onepage_success>
<reference name="content">
<block type="adyen/checkout_success" name="adyen.checkout.success" template="adyen/checkout/success.phtml"/>
</reference>
</checkout_onepage_success>
<checkout_multishipping_success translate="label">
<reference name="content">
<block type="adyen/checkout_success" name="adyen.checkout.success" template="adyen/checkout/success.phtml"/>
</reference>
</checkout_multishipping_success>
</layout>
<?php
/**
* Madia Adyen Payment Module
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* @category Madia
* @package Madia_Adyen
* @copyright Copyright (c) 2011 Madia (http://www.madia.nl)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* @category Payment Gateway
* @package Madia_Adyen
* @author Omar,Muhsin <info@madia.nl>
* @property Madia B.V
* @copyright Copyright (c) 2011 Madia BV (http://www.madia.nl)
*/
?>
<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
<li>
<label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
<div class="input-box">
<input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_owner]\"" : "data-encrypted-name=\"holderName\""); ?> value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
</div>
</li>
<li>
<label for="<?php echo $_code ?>_cc_type" class="required"><em>*</em><?php echo $this->__('Credit Card Type') ?></label>
<div class="input-box">
<select id="<?php echo $_code ?>_cc_type" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_type]\"" : ""); ?> title="<?php echo $this->__('Credit Card Type') ?>" class="required-entry">
<option value=""><?php echo $this->__('--Please Select--') ?></option>
<?php $_ccType = $this->getInfoData('cc_type') ?>
<?php foreach ($this->getCcAvailableTypes() as $_typeCode => $_typeName): ?>
<option value="<?php echo $_typeCode ?>"<?php if($_typeCode==$_ccType): ?> selected="selected"<?php endif ?>><?php echo $_typeName ?></option>
<?php endforeach ?>
</select>
</div>
</li>
<li>
<label for="<?php echo $_code ?>_cc_number" class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $_code ?>_cc_number" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_number]\"" : " data-encrypted-name=\"number\""); ?> title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type" value="" />
</div>
</li>
<li>
<label for="<?php echo $_code ?>_expiration" class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
<div class="input-box">
<div class="v-fix">
<select id="<?php echo $_code ?>_expiration" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_exp_month]\"" : "data-encrypted-name=\"expiryMonth\""); ?> class="month validate-cc-exp required-entry">
<?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
<?php foreach ($this->getCcMonths() as $k=>$v): ?>
<option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
<?php endforeach ?>
</select>
</div>
<div class="v-fix">
<?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
<select id="<?php echo $_code ?>_expiration_yr" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_exp_year]\"" : "data-encrypted-name=\"expiryYear\""); ?> class="year required-entry">
<?php foreach ($this->getCcYears() as $k=>$v): ?>
<option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
<?php endforeach ?>
</select>
</div>
</div>
</li>
<?php echo $this->getChildHtml() ?>
<?php if($this->hasVerification()): ?>
<li>
<label for="<?php echo $_code ?>_cc_cid" class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
<div class="input-box">
<div class="v-fix">
<input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry" id="<?php echo $_code ?>_cc_cid" <?php echo (!$this->isCseEnabled() ? "name=\"payment[cc_cid]\"" : "data-encrypted-name=\"cvc\""); ?> value="" />
</div>
<a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
</div>
</li>
<?php endif; ?>
<?php if($this->is3dSecureEnabled()): ?>
<?php endif; ?>
<?php if($this->hasInstallments()): ?>
<li>
<label for="<?php echo $_code ?>_installments" class="required"><em>*</em><?php echo $this->__('Installments') ?></label>
<div class="input-box">
<div class="v-fix">
<select id="<?php echo $_code ?>_installments" name="payment[additional_data]" class="number required-entry">
<?php foreach ($this->getPossibleInstallments() as $k=>$v): ?>
<option value="<?php echo $k?$k:'' ?>"><?php echo $v ?></option>
<?php endforeach ?>
</select>
</div>
</div>
</li>
<?php endif;?>
</ul>
<?php if ($this->isCseEnabled()): ?>
<input type="hidden" id="<?php echo $_code ?>_encrypted_form_expiry_generationtime" value="<?php echo date("c"); ?>" data-encrypted-name="generationtime" />
<script type="text/javascript">
//<![CDATA[
var cse_form = document.getElementById('onestepcheckout-form');
var cse_key = <?php echo json_encode($this->getCsePublicKey()); ?>;
var cse_options = {
name: 'payment[encrypted_data]',
force: true
};
// OneStepCheckout related edits and turned this prototype rewrite to proper wrap method
// also added encryptionFailed to adyen object scope
Event.observe(window, 'load', function() {
payment.save = payment.save.wrap(function(originalSaveMethod) {
if (payment.currentMethod && payment.currentMethod == '<?php echo $_code ?>') {
adyen.encrypt.encryptionFailed = false;
try {
adyen.encrypt.createEncryptedForm(cse_form, cse_key, cse_options);
} catch (e) {
adyen.encrypt.encryptionFailed = true;
}
var encryptedForm = document.getElementById(cse_options.name);
if (adyen.encrypt.encryptionFailed || !encryptedForm || encryptedForm.value.length == 0) {
alert("Warning: Adyen Client Side Encryption cannot succeed.");
}
}
originalSaveMethod();
});
});
//]]>
</script>
<?php endif;?>
//place this file to js/madia/adyen/ folder and you need to edit layout file to reference it to onestepcheckout_index_index
Event.observe(window, 'load', function () {
// check if we are dealing with OneStepCheckout
payment.isOneStepCheckout = $$('.onestepcheckout-place-order');
aydenencryptionenabled = $('adyen_cc_encrypted_form_expiry_generationtime');
payment.holdOneStepCheckout = true;
if (payment.isOneStepCheckout && aydenencryptionenabled) {
//bind event handlers to buttons
payment.isOneStepCheckout.each(function (elem) {
elem.observe('click', function (e) {
Event.stop(e);
if ('adyen_cc' == payment.currentMethod && payment.holdOneStepCheckout) {
window.already_placing_order = true;
//normally this is not called
payment.save();
} else {
window.already_placing_order = false;
}
});
});
//wrapp save before ayden
payment.save = payment.save.wrap(function (originalSaveMethod) {
if (adyen.encrypt.encryptionFailed && 'adyen_cc' == payment.currentMethod) {
return;
}
if (!adyen.encrypt.encryptionFailed && 'adyen_cc' == payment.currentMethod) {
window.already_placing_order = false;
$('onestepcheckout-place-order').click();
}
});
}
// check if we are dealing with OneStepCheckout end
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment