Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PWLocalUni Method #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* @author Paymentwall Inc. <[email protected]>
* @package Paymentwall\ThirdpartyIntegration\Magento
*
* Class Paymentwall_Paymentwall_Block_Checkout_Form_Method_Localuni
*/
class Paymentwall_Paymentwall_Block_Checkout_Form_Method_Pwlocaluni extends Paymentwall_Paymentwall_Block_Checkout_Form_Method_Abstract
{
/**
* Set template for block
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setPaymentModelName('pwlocaluni');
}

function getWidget()
{
$order = $this->getOrder();
$return = array(
'content' => '',
'status' => false
);

if ($order) {
try {
$model = $this->getPaymentModel();
$widget = $model->getPaymentWidget($order);

// Get widget iframe
$return['content'] = $widget->getHtmlCode(array(
'frameborder' => '0',
'width' => '100%',
'height' => '600'
));
$return['status'] = true;
} catch (Exception $e) {
Mage::logException($e);
$return['content'] = Mage::helper('paymentwall')->__('Errors, Please try again!');
}
} else {
$return['content'] = Mage::helper('paymentwall')->__('Order invalid'); //should redirect back to homepage
}

return $return;
}

/**
* Get last order
*/
protected function getOrder()
{
if (!$this->_order) {
$session = Mage::getSingleton('checkout/session');
$this->_order = $this->loadOrderById($session->getLastRealOrderId());
}
return $this->_order;
}

protected function loadOrderById($orderId)
{
return Mage::getModel('sales/order')->loadByIncrementId($orderId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* @author Paymentwall Inc. <[email protected]>
* @package Paymentwall\ThirdpartyIntegration\Magento
*
* Class Paymentwall_Paymentwall_Block_Checkout_Info_Method_Localuni
*/
class Paymentwall_Paymentwall_Block_Checkout_Info_Method_Pwlocaluni extends Mage_Payment_Block_Info
{
protected function _construct()
{
parent::_construct();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function __construct($code = '') {
* Init paymentwall configs
*/
public function initPaymentwallConfig($pingback = false) {
Paymentwall_Config::getInstance()->set(array(
'api_type' => Paymentwall_Config::API_GOODS,
'public_key' => $this->getConfigData('paymentwall_public_key'),
'private_key' => $this->getConfigData('paymentwall_private_key')
));
if ($pingback) {
$pwlocalModel = Mage::getModel('paymentwall/method_pwlocal');
Paymentwall_Config::getInstance()->setPrivateKey(
$pwlocalModel->getConfigData('paymentwall_private_key')
);
Paymentwall_Config::getInstance()->set(array(
'private_key' => $this->getConfigData('paymentwall_secret_key')
));
} else {
Paymentwall_Config::getInstance()->set(array(
'api_type' => Paymentwall_Config::API_GOODS,
'public_key' => $this->getConfigData('paymentwall_public_key'),
'private_key' => $this->getConfigData('paymentwall_private_key')
));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* @author Paymentwall Inc <[email protected]>
* @package Paymentwall\ThirdpartyIntegration\Magento\Model\Method
*/
class Paymentwall_Paymentwall_Model_Method_Pwlocaluni extends Paymentwall_Paymentwall_Model_Method_Abstract {

protected $_isInitializeNeeded = false;
protected $_canUseInternal = false;
protected $_canUseForMultishipping = false;
protected $_canCapture = true;
protected $_canAuthorize = true;
protected $_canVoid = false;
protected $_canReviewPayment = false;
protected $_canCreateBillingAgreement = false;

/**
* Constructor method.
* Set some internal properties
*/
public function __construct() {
parent::__construct('pwlocaluni');
}

public function getOrderPlaceRedirectUrl() {
return Mage::getUrl('paymentwall/payment/pwlocaluni', array('_secure' => true));
}

/**
* Generate Paymentwall Widget
* @param $order
* @return Paymentwall_Widget
*/
public function getPaymentWidget(Mage_Sales_Model_Order $order) {
$this->initPaymentwallConfig();

$customerId = $_SERVER['REMOTE_ADDR'];

if(Mage::getSingleton('customer/session')->isLoggedIn()){
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerId = $customer->getId();
}

$widget = new Paymentwall_Widget(
$customerId,
$this->getConfigData('paymentwall_widget_code'),
array(
new Paymentwall_Product(
$order->getIncrementId(),
$order->getGrandTotal(),
$order->getOrderCurrencyCode(),
'Order id #' . $order->getIncrementId(),
Paymentwall_Product::TYPE_FIXED
)
),
array_merge(
array(
'email' => $order->getCustomerEmail(),
'success_url' => $this->getConfigData('paymentwall_url'),
'test_mode' => (int)$this->getConfigData('paymentwall_istest'),
'integration_module' => 'magento',
'ps' => ('1' == $this->getConfigData('paymentwall_istest')) ? 'test' : 'cc'
),
$this->prepareUserProfile($order) // for User Profile API
)
);

return $widget;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Paymentwall_Paymentwall_Model_Pingback extends Mage_Core_Model_Abstract
{
const DEFAULT_PINGBACK_RESPONSE = 'OK';
const BRICK_METHOD = 'paymentwall_pwbrick';
const PWLOCAL_METHOD = 'paymentwall_pwlocal';

/**
* Handle pingback
Expand All @@ -25,11 +26,14 @@ public function handlePingback()
die("Order invalid");
}

$method = $order->getPayment()->getMethod();
// Load paymentwall configs
if ($order->getPayment()->getMethod() == self::BRICK_METHOD) {
if ($method == self::BRICK_METHOD) {
Mage::getModel('paymentwall/method_pwbrick')->initPaymentwallConfig(true);
} else {
} elseif ($method == self::PWLOCAL_METHOD) {
Mage::getModel('paymentwall/method_pwlocal')->initPaymentwallConfig();
} else {
Mage::getModel('paymentwall/method_pwlocaluni')->initPaymentwallConfig();
}

if ($pingback->validate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function pwlocalAction()
$this->renderLayout();
}

public function pwlocaluniAction()
{
$this->loadLayout();
$this->renderLayout();
}

/**
* 3Ds Processing
*/
Expand Down
13 changes: 12 additions & 1 deletion src/app/code/community/Paymentwall/Paymentwall/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<config>
<modules>
<Paymentwall_Paymentwall>
<version>1.2.6</version>
<version>1.2.7</version>
</Paymentwall_Paymentwall>
</modules>
<frontend>
Expand Down Expand Up @@ -62,6 +62,17 @@
<allowspecific>0</allowspecific>
<debug_mode>0</debug_mode>
</paymentwall_pwbrick>
<paymentwall_pwlocaluni>
<title>Paymentwall Uni</title>
<active>1</active>
<model>paymentwall/method_pwlocaluni</model>
<order_status>pending_payment</order_status>
<fee_payer>buyer</fee_payer>
<allowspecific>0</allowspecific>
<paymentwall_istest>0</paymentwall_istest>
<paymentwall_delivery>1</paymentwall_delivery>
<debug_mode>0</debug_mode>
</paymentwall_pwlocaluni>
</payment>
</default>
</config>
105 changes: 105 additions & 0 deletions src/app/code/community/Paymentwall/Paymentwall/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</order_status>
<paymentwall_project_key translate="label">
<label>Project Key</label>
<frontend_type>text</frontend_type>
<comment>Merchant Project API Key</comment>
<sort_order>25</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentwall_project_key>
<paymentwall_secret_key translate="label">
<label>Secret Key</label>
<frontend_type>text</frontend_type>
<comment>Merchant Secret API Key</comment>
<sort_order>28</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentwall_secret_key>
<paymentwall_public_key translate="label">
<label>Public Key</label>
<frontend_type>text</frontend_type>
Expand Down Expand Up @@ -161,6 +179,93 @@
</debug_mode>
</fields>
</paymentwall_pwbrick>
<paymentwall_pwlocaluni translate="label" module="paymentwall">
<label>Paymentwall Uni</label>
<frontend_type>text</frontend_type>
<sort_order>105</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</title>
<paymentwall_public_key translate="label">
<label>Project Key</label>
<frontend_type>text</frontend_type>
<sort_order>3</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentwall_public_key>
<paymentwall_private_key translate="label">
<label>Secret Key</label>
<frontend_type>text</frontend_type>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentwall_private_key>
<paymentwall_widget_code translate="label">
<label>Widget Code</label>
<frontend_type>text</frontend_type>
<sort_order>5</sort_order>
<comment>Only use for type Paymentwall Uni</comment>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paymentwall_widget_code>
<paymentwall_url translate="label">
<label>Success URL</label>
<frontend_type>text</frontend_type>
<sort_order>6</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</paymentwall_url>
<paymentwall_istest translate="label">
<label>Test Mode</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>7</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</paymentwall_istest>
<paymentwall_delivery translate="label">
<label>Enable Delivery Api</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>7</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</paymentwall_delivery>
<debug_mode translate="label">
<label>Debug Mode</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</debug_mode>
</fields>
</paymentwall_pwlocaluni>
</groups>
</payment>
</sections>
Expand Down
22 changes: 22 additions & 0 deletions src/app/design/frontend/base/default/layout/paymentwall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,26 @@
</block>
</reference>
</paymentwall_payment_pwlocal>
<paymentwall_payment_pwlocaluni>
<reference name="head">
<action method="setTitle">
<title>Paymentwall Uni Widget Checkout</title>
</action>
<action method="addItem">
<type>skin_js</type>
<name>js/paymentwall.js</name>
</action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-right.phtml</template>
</action>
</reference>
<reference name="content">
<block type="paymentwall/checkout_form_method_pwlocaluni" name="paymentwall_widget"
template="paymentwall/checkout/form/method/pwlocal.phtml">
<label>Paymentwall Uni Widget Checkout</label>
</block>
</reference>
</paymentwall_payment_pwlocaluni>
</layout>